Esempio n. 1
0
        IEnumerator _GenerateShoreline()
        {
            var ts = System.TimeSpan.FromTicks(System.DateTime.Now.Ticks);

            //Load data
            heights         = ScmapEditor.Heights;
            heightmapWidth  = ScmapEditor.HeightmapWidth;
            heightmapHeight = ScmapEditor.HeightmapHeight;

            terrainSizeX    = ScmapEditor.Current.Teren.terrainData.size.x;
            terrainSizeY    = ScmapEditor.Current.Teren.terrainData.size.y;
            terrainSizeZ    = ScmapEditor.Current.Teren.terrainData.size.z;
            worldWaterLevel = ScmapEditor.GetWaterLevel();

            waterLevel = worldWaterLevel / terrainSizeY;

            //Clear
            ShoreLines.Clear();
            allEdges.Clear();

            thread              = new Thread(ThreadWork);
            thread.Priority     = System.Threading.ThreadPriority.AboveNormal;
            thread.IsBackground = false;
            thread.Start();

            while (thread.IsAlive)
            {
                yield return(null);
            }
            thread = null;

            //ThreadWork();
            //yield return null;

            //Clear
            heights = null;
            allEdges.Clear();
            ShoreLineTask        = null;
            IsShoreLineGenerated = true;

            GenericInfoPopup.ShowInfo("Shoreline generated in " + (System.TimeSpan.FromTicks(System.DateTime.Now.Ticks).TotalSeconds - ts.TotalSeconds).ToString("F4") + "s");
            //Debug.Log("Shoreline generated in time: " + (System.TimeSpan.FromTicks(System.DateTime.Now.Ticks).TotalSeconds - ts.TotalSeconds).ToString("F4"));
        }
    public Vector3 GetSnapPosition(Vector3 Pos)
    {
        if (UnitRenderer.BP.PhysicsLayerSub)
        {
            Vector3 PositionOnWater = ScmapEditor.SnapToTerrain(Pos, true);
            if (PositionOnWater.y > ScmapEditor.GetWaterLevel())
            {
                return(PositionOnWater);
            }

            Vector3 PositionUnderWater = ScmapEditor.SnapToTerrain(Pos, false);

            if (Mathf.Abs(PositionOnWater.y - PositionUnderWater.y) < UnitRenderer.BP.PhysicsElevation * 0.2f)
            {
                return(Vector3.Lerp(PositionOnWater, PositionUnderWater, 0.5f));
            }

            PositionOnWater.y += UnitRenderer.BP.PhysicsElevation * 0.1f;

            return(PositionOnWater);
        }
        return(ScmapEditor.SnapToTerrain(Pos, UnitRenderer.BP.PhysicsLayerWater));
    }
Esempio n. 3
0
 public bool IsOnWater()
 {
     return(ScmapEditor.Current.Teren.SampleHeight(MarkerObj.transform.position) < ScmapEditor.GetWaterLevel() && ScmapEditor.Current.map.Water.HasWater);
 }
Esempio n. 4
0
    public void OnRenderObject()
    {
        if (PreviewTex.IsPreview)
        {
            return;
        }

        if (Camera.current != RenderCamera || ScmapEditor.Current == null || ScmapEditor.Current.Teren == null)
        {
            return;
        }

        if (MapLuaParser.Current.SaveLuaFile.Data.areas.Length == 0)
        {
            return;
        }
        float Height = ScmapEditor.GetWaterLevel();

        GL.PushMatrix();
        // Set transformation matrix for drawing to
        // match our transform
        GL.MultMatrix(transform.localToWorldMatrix);

        Mat.SetPass(0);

        for (int a = 0; a < MapLuaParser.Current.SaveLuaFile.Data.areas.Length; a++)
        {
            if (MapLuaParser.Current.SaveLuaFile.Data.areas[a] == AreaInfo.SelectedArea)
            {
                continue;
            }

            GL.Begin(GL.LINES);

            Vector3 Pos0 = ScmapEditor.ScmapPosToWorld(new Vector3(MapLuaParser.Current.SaveLuaFile.Data.areas[a].rectangle.x, 0, MapLuaParser.Current.SaveLuaFile.Data.areas[a].rectangle.y));
            Pos0.y = ScmapEditor.Current.Teren.SampleHeight(Pos0);
            Vector3 Pos1 = ScmapEditor.ScmapPosToWorld(new Vector3(MapLuaParser.Current.SaveLuaFile.Data.areas[a].rectangle.width, 10, MapLuaParser.Current.SaveLuaFile.Data.areas[a].rectangle.height));
            Pos1.y = ScmapEditor.Current.Teren.SampleHeight(Pos1);

            Pos0.y = Mathf.Lerp(Pos0.y, Pos1.y, 0.5f);
            if (Pos0.y < Height)
            {
                Pos0.y = Height;
            }
            Pos1.y = Pos0.y;

            GL.Vertex(Pos0);
            GL.Vertex3(Pos0.x, Pos0.y, Pos1.z);

            GL.Vertex3(Pos0.x, Pos0.y, Pos1.z);
            GL.Vertex(Pos1);

            GL.Vertex(Pos1);
            GL.Vertex3(Pos1.x, Pos0.y, Pos0.z);

            GL.Vertex3(Pos1.x, Pos0.y, Pos0.z);
            GL.Vertex(Pos0);

            GL.End();
        }

        GL.PopMatrix();
    }
Esempio n. 5
0
        public static List <ShoreDepthPoint> GetShoreDepthPoints(float depth, Vector2 angleRange)
        {
            List <ShoreDepthPoint> points = new List <ShoreDepthPoint>(1024);

            heights         = ScmapEditor.Heights;
            heightmapWidth  = ScmapEditor.HeightmapWidth;
            heightmapHeight = ScmapEditor.HeightmapHeight;

            terrainSizeX = ScmapEditor.Current.Teren.terrainData.size.x;
            terrainSizeY = ScmapEditor.Current.Teren.terrainData.size.y;
            terrainSizeZ = ScmapEditor.Current.Teren.terrainData.size.z;

            worldWaterLevel = ScmapEditor.GetWaterLevel();

            waterLevel = worldWaterLevel / terrainSizeY;
            float shoreDepthLevel = (worldWaterLevel - depth) / terrainSizeY;


            for (int x = 1; x < heightmapWidth; x++)
            {
                for (int y = 1; y < heightmapHeight; y++)
                {
                    int x0 = x - 1;
                    int y0 = y - 1;

                    float h0 = heights[x0, y0];
                    float h1 = heights[x, y0];
                    float h2 = heights[x, y];
                    float h3 = heights[x0, y];

                    bool isOverWater0 = h0 > shoreDepthLevel;
                    bool isOverWater1 = h1 > shoreDepthLevel;
                    bool isOverWater2 = h2 > shoreDepthLevel;
                    bool isOverWater3 = h3 > shoreDepthLevel;

                    if (isOverWater0 != isOverWater1 || isOverWater1 != isOverWater2 || isOverWater2 != isOverWater3)
                    {
                        // Shore Detected!

                        float p0x = x0 / (heightmapWidth - 1f);
                        float p1x = x / (heightmapWidth - 1f);
                        float p0y = y0 / (heightmapHeight - 1f);
                        float p1y = y / (heightmapHeight - 1f);

                        Vector3 point0 = new Vector3(p0y * terrainSizeX, h0 * terrainSizeY, p0x * terrainSizeZ - terrainSizeZ);
                        Vector3 point1 = new Vector3(p0y * terrainSizeX, h1 * terrainSizeY, p1x * terrainSizeZ - terrainSizeZ);
                        Vector3 point2 = new Vector3(p1y * terrainSizeX, h2 * terrainSizeY, p1x * terrainSizeZ - terrainSizeZ);
                        Vector3 point3 = new Vector3(p1y * terrainSizeX, h3 * terrainSizeY, p0x * terrainSizeZ - terrainSizeZ);

                        Vector3 center = (point1 + point3) / 2f;
                        center.y = worldWaterLevel;

                        Vector3 normal0     = Vector3.Cross((point3 - point0).normalized, (point1 - point0).normalized).normalized;
                        Vector3 normal1     = Vector3.Cross((point1 - point2).normalized, (point3 - point2).normalized).normalized;
                        Vector3 finalNormal = (normal0 + normal1) / 2f;

                        float angle = Quaternion.LookRotation(finalNormal.normalized).eulerAngles.y;

                        while (angle < 0f)
                        {
                            angle += 360f;
                        }
                        while (angle > 360f)
                        {
                            angle -= 360f;
                        }



                        if (Mathf.Abs(Mathf.DeltaAngle(angle - 180f, angleRange.x)) <= angleRange.y)
                        {
                            points.Add(new ShoreDepthPoint(center, angle));
                        }
                    }
                }
            }

            return(points);
        }