Пример #1
0
        public void GeneratingPoints_Line(int number, EPMPoint.PointType type, Vector2d lineStart, Vector2d lineEnd, double maxDistance, bool uniformly = true)
        {
            Vector2d dir        = lineEnd - lineStart;
            double   lineLength = dir.Length();
            double   uniLength  = lineLength / number;

            dir.Normalize();
            Vector2d normal = new Vector2d(-dir.y, dir.x);

            for (int i = 0; i < number; i++)
            {
                Vector2d v2 = new Vector2d();
                if (uniformly)
                {
                    v2.x = RandomDouble(i * uniLength, (i + 1) * uniLength);
                }
                else
                {
                    v2.x = RandomDouble(0, lineLength);
                }

                v2.y = RandomDouble(-maxDistance, maxDistance);


                v2 = lineStart + v2.x * dir + v2.y * normal;
                if (IsPointInValidRange(v2))
                {
                    EPMPoint p = new EPMPoint(type, new Vector3d(v2.x, 0, v2.y));
                    m_vertexList.Add(p);
                }
            }
        }
Пример #2
0
 public Color GetColorByType(EPMPoint.PointType type)
 {
     if (m_materialAgent == null)
     {
         return(Color.white);
     }
     return(g_typeColorDic[type]);
 }
Пример #3
0
 public void SetColorByType(EPMPoint.PointType type, Color newColor)
 {
     if (m_materialAgent == null)
     {
         return;
     }
     g_typeColorDic[type] = newColor;
     m_materialAgent.SetColor(type, newColor);
 }
Пример #4
0
 public void GeneratingPoints_Square(int number, EPMPoint.PointType type, Vector2d startPos, Vector2d endPos)
 {
     for (int i = 0; i < number; i++)
     {
         Vector2d v2 = new Vector2d(RandomDouble(startPos.x, endPos.x), RandomDouble(startPos.y, endPos.y));
         if (IsPointInValidRange(v2))
         {
             EPMPoint p = new EPMPoint(type, new Vector3d(v2.x, 0, v2.y));
             m_vertexList.Add(p);
         }
     }
 }
        public Vector2 getUV(EPMPoint.PointType type)
        {
            int t      = Mathf.RoundToInt(Mathf.Log((int)type, 2f));
            int row    = t / 8;
            int column = t % 8;

            Vector2 ret = new Vector2();

            ret.x = column / 8f + 1 / 16f;
            ret.y = row / 8f + 1 / 16f;
            return(ret);
        }
        private void DrawSingleTypeColor(EPMPoint.PointType type)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(type.ToString(), GUILayout.Width(150));
            Color c        = m_creator.GetColorByType(type);
            Color newColor = EditorGUILayout.ColorField(c, GUILayout.Width(50));

            if (c.r != newColor.r || c.g != newColor.g || c.b != newColor.b)
            {
                m_creator.SetColorByType(type, newColor);
            }
            EditorGUILayout.EndHorizontal();
        }
Пример #7
0
        //public static bool operator == (EPMShape shape1,EPMShape shape2)
        //      {
        //          return shape1.Equals(shape2);
        //      }

        //      public static bool operator !=(EPMShape shape1, EPMShape shape2)
        //      {
        //          return !shape1.Equals(shape2);
        //      }

        public virtual bool HasPointType(EPMPoint.PointType type, int LeastNumber = 1)
        {
            for (int i = 0; i < g_pointList.Count; i++)
            {
                if (g_pointList[i].HasType(type))
                {
                    LeastNumber--;
                    if (LeastNumber <= 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #8
0
        public void GeneratingPoints_Ring(int number, EPMPoint.PointType type, Vector2d center, double minRadius, double maxRadius, bool uniformly = true)
        {
            double uniDegree = System.Math.PI * 2 / number;
            double c1        = (maxRadius - minRadius) / 3 + minRadius;
            double c2        = maxRadius - (maxRadius - minRadius) / 3;

            for (int i = 0; i < number;)
            {
                Vector2d v2 = new Vector2d();
                if (uniformly)
                {
                    double radius = RandomDouble(minRadius, c1);
                    v2.x = System.Math.Cos(uniDegree * i) * radius + center.x;
                    v2.y = System.Math.Sin(uniDegree * i) * radius + center.y;

                    if (IsPointInValidRange(v2))
                    {
                        EPMPoint p = new EPMPoint(type, new Vector3d(v2.x, 0, v2.y));
                        m_vertexList.Add(p);
                    }

                    radius = RandomDouble(c2, maxRadius);
                    v2.x   = System.Math.Cos(uniDegree * (i + 1)) * radius + center.x;
                    v2.y   = System.Math.Sin(uniDegree * (i + 1)) * radius + center.y;

                    if (IsPointInValidRange(v2))
                    {
                        EPMPoint p = new EPMPoint(type, new Vector3d(v2.x, 0, v2.y));
                        m_vertexList.Add(p);
                    }
                    i += 2;
                }
                else
                {
                    double radius = RandomDouble(minRadius, maxRadius);
                    double degree = (double)RandomDouble(0, 2 * System.Math.PI);
                    v2.x = System.Math.Cos(degree) * radius + center.x;
                    v2.y = System.Math.Sin(degree) * radius + center.y;

                    if (IsPointInValidRange(v2))
                    {
                        EPMPoint p = new EPMPoint(type, new Vector3d(v2.x, 0, v2.y));
                        m_vertexList.Add(p);
                    }
                    i++;
                }
            }
        }
        public void SetColor(EPMPoint.PointType type, Color color)
        {
            int t       = Mathf.RoundToInt(Mathf.Log((int)type, 2f));
            int row     = t / 8;
            int column  = t % 8;
            int start_x = column * 8;
            int start_y = row * 8;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    texture.SetPixel(start_x + i, start_y + j, color);
                }
            }
            texture.Apply();
        }
        public static Color GetDefaultColor(EPMPoint.PointType type)
        {
            switch (type)
            {
            case EPMPoint.PointType.Ground:
                return(new Color(75 / 255f, 161 / 255f, 75 / 255f));

            case EPMPoint.PointType.Mountain:
                return(new Color(0.3f, 0.1f, 0.1f));

            case EPMPoint.PointType.MountainSummit:
                return(new Color(1f, 1f, 1f));

            case EPMPoint.PointType.Hill:
                return(new Color(178 / 255f, 126 / 255f, 126 / 255f));

            case EPMPoint.PointType.Road:
                return(new Color(200 / 255f, 200 / 255f, 200 / 255f));

            case EPMPoint.PointType.RoadSide:
                return(new Color(143 / 255f, 122 / 255f, 85 / 255f));

            case EPMPoint.PointType.River:
                return(new Color(7 / 255f, 152 / 255f, 253 / 255f));

            case EPMPoint.PointType.RiverSide:
                return(new Color(75 / 255f, 63 / 255f, 23 / 255f));

            case EPMPoint.PointType.Sand:
                return(new Color(165 / 255f, 165 / 255f, 33 / 255f));

            case EPMPoint.PointType.Soil:
                return(new Color(73 / 255f, 53 / 255f, 49 / 255f));

            case EPMPoint.PointType.Ocean:
                return(new Color(0, 100 / 255f, 200 / 255f));

            case EPMPoint.PointType.OceanSide:
                return(new Color(139 / 255f, 125 / 255f, 78 / 255f));

            default:
                return(new Color(1, 0, 0));
            }
        }
Пример #11
0
        public void GeneratingBase(int number, EPMPoint.PointType type)
        {
            m_vertexList.Add(new EPMPoint(type, g_startPoint));
            m_vertexList.Add(new EPMPoint(type, new Vector2d(g_endPoint.x, g_startPoint.y)));
            m_vertexList.Add(new EPMPoint(type, g_endPoint));
            m_vertexList.Add(new EPMPoint(type, new Vector2d(g_startPoint.x, g_endPoint.y)));

            for (int i = 0; i < number; i++)
            {
                Vector2d v2 = new Vector2d(RandomDouble(g_startPoint.x, g_endPoint.x), RandomDouble(g_startPoint.y, g_endPoint.y));
                EPMPoint p  = new EPMPoint(type, new Vector3d(v2.x, 0, v2.y));
                m_vertexList.Add(p);
            }

            GeneratingPoints_Line((int)(getXLength() / 5), type, g_startPoint, new Vector2d(g_endPoint.x, g_startPoint.y), 0, true);
            GeneratingPoints_Line((int)(getZlength() / 5), type, new Vector2d(g_endPoint.x, g_startPoint.y), g_endPoint, 0, true);
            GeneratingPoints_Line((int)(getXLength() / 5), type, g_endPoint, new Vector2d(g_startPoint.x, g_endPoint.y), 0, true);
            GeneratingPoints_Line((int)(getZlength() / 5), type, new Vector2d(g_startPoint.x, g_endPoint.y), g_startPoint, 0, true);
        }
Пример #12
0
        public void GenerateRiverSegment(Vector2d start, Vector2d end, float halfWidth)
        {
            Vector2d dir    = end - start;
            double   length = dir.Length() / 4f;

            dir.Normalize();
            Vector2d normal     = new Vector2d(-dir.y, dir.x);
            double   sideLength = halfWidth * 0.05;

            m_terrain.DeletePoints_Line(start, end, halfWidth * 2.5);
            EPMPoint.PointType type = EPMPoint.PointType.RiverSide;
            m_terrain.GeneratingPoints_Line((int)length, type, start + normal * (halfWidth * 1.8f), end + normal * (halfWidth * 1.8f), sideLength, true);
            m_terrain.GeneratingPoints_Line((int)length, type, start + normal * (halfWidth * 1.1f), end + normal * (halfWidth * 1.1f), sideLength, true);
            m_terrain.GeneratingPoints_Line((int)length, type, start + normal * (halfWidth * 0.9f), end + normal * (halfWidth * 0.9f), sideLength, true);
            m_terrain.GeneratingPoints_Line((int)length, type, start + normal * (halfWidth * 0.7f), end + normal * (halfWidth * 0.7f), 0, true);
            m_terrain.GeneratingPoints_Line((int)length, type, start - normal * (halfWidth * 0.7f), end - normal * (halfWidth * 0.7f), 0, true);
            m_terrain.GeneratingPoints_Line((int)length, type, start - normal * (halfWidth * 0.9f), end - normal * (halfWidth * 0.9f), sideLength, true);
            m_terrain.GeneratingPoints_Line((int)length, type, start - normal * (halfWidth * 1.1f), end - normal * (halfWidth * 1.1f), sideLength, true);
            m_terrain.GeneratingPoints_Line((int)length, type, start - normal * (halfWidth * 1.8f), end - normal * (halfWidth * 1.8f), sideLength, true);
        }
Пример #13
0
        public void GeneratingPoints_Circle(int number, EPMPoint.PointType type, Vector2d center, double radius)
        {
            double SquaredRadius = radius * radius;

            for (int i = 0; i < number; i++)
            {
                Vector2d v2 = new Vector2d(center.x + RandomDouble(-radius, radius), center.y + RandomDouble(-radius, radius));
                if (v2.SquaredDistance(center) > SquaredRadius)
                {
                    i--;
                }
                else
                {
                    if (IsPointInValidRange(v2))
                    {
                        EPMPoint p = new EPMPoint(type, new Vector3d(v2.x, 0, v2.y));
                        m_vertexList.Add(p);
                    }
                }
            }
        }
Пример #14
0
        public void RenderSingleGround(List <Vector2d> ground, EPMPoint.PointType type)
        {
            int             groundEnums = EPMPoint.GetGroundEnums();
            List <EPMPoint> plist       = m_terrain.ExtractPoints_ByRegion(ground, null, groundEnums);

            for (int i = 0; i < plist.Count; i++)
            {
                plist[i].SetType(type);
            }

            List <EPMTriangle> triangleList = m_terrain.ExtractTriangles_ByVertex(plist);

            for (int i = 0; i < triangleList.Count; i++)
            {
                if (!triangleList[i].HasShapeType(groundEnums))
                {
                    continue;
                }
                triangleList[i].TryDetermineType();
            }
            EPMPreDefinedTools.CheckAndSetTileTypeByNeighbor(m_terrain, EPMPoint.GetGroundEnums(), EPMPoint.GenerateTypesInt(false, type), type);
        }
Пример #15
0
 public void SetType(EPMPoint.PointType type)
 {
     g_shapeType        = type;
     g_isTypeDetermined = true;
 }
Пример #16
0
 public bool HasShapeType(EPMPoint.PointType type)
 {
     return(HasShapeType(EPMPoint.GenerateTypesInt(false, type)));
 }
Пример #17
0
        public static void ExtractSide(EPMDelaunayTerrain terrain, EPMPoint.PointType oldType, EPMPoint.PointType sideType, double inLength = 2f)
        {
            List <EPMTriangle> list      = terrain.ExtractTriangles_ByTypes(null, EPMPoint.GenerateTypesInt(false, oldType));
            List <EPMPoint>    allPoints = terrain.ExtractPoints_All();
            List <EPMTriangle> sideList  = new List <EPMTriangle>();
            int groundEnum = EPMPoint.GetGroundEnums();

            for (int i = 0; i < list.Count; i++)
            {
                EPMTriangle t = (EPMTriangle)list[i];
                int         count = 0;
                int         ep1, ep2;
                ep1 = ep2 = 0;
                for (int j = 0; j < t.g_shareEdgeNeighbors.Count; j++)
                {
                    //The edge has an ground tile neighbor.
                    if (t.g_shareEdgeNeighbors[j].HasShapeType(groundEnum))
                    {
                        count++;
                        t.GetShareEdge((EPMTriangle)t.g_shareEdgeNeighbors[j], out ep1, out ep2);
                    }
                }

                if (count == 1)
                {
                    if (!t.g_visited)
                    {
                        sideList.Add(t);
                        t.g_visited = true;
                    }

                    int ep3 = t.g_sortedIndexList[0];
                    if (ep3 == ep1 || ep3 == ep2)
                    {
                        ep3 = t.g_sortedIndexList[1];
                    }
                    if (ep3 == ep1 || ep3 == ep2)
                    {
                        ep3 = t.g_sortedIndexList[2];
                    }

                    Vector2d p1, p2, p3;
                    p1 = allPoints[ep1].pos2d;
                    p2 = allPoints[ep2].pos2d;
                    p3 = allPoints[ep3].pos2d;

                    Vector2d dir    = p2 - p1;
                    Vector2d normal = new Vector2d(-dir.y, dir.x);
                    normal.Normalize();
                    if ((p3 - p1) * normal < 0)
                    {
                        normal = -normal;
                    }

                    for (int k = 0; k < t.g_shareEdgeNeighbors.Count; k++)
                    {
                        if (t.g_shareEdgeNeighbors[k].HasShapeType(oldType))
                        {
                            EPMTriangle nei = (EPMTriangle)t.g_shareEdgeNeighbors[k];
                            if (nei.g_visited == false)
                            {
                                nei.g_visited = true;
                                sideList.Add(nei);
                            }
                            for (int j = 0; j < nei.g_sharePointNeighbors.Count; j++)
                            {
                                EPMTriangle t2 = (EPMTriangle)nei.g_sharePointNeighbors[j];
                                if (t2.HasShapeType(oldType) && t2.g_visited == false)
                                {
                                    Vector2d v2  = t2.g_pointList[0].pos2d;
                                    double   dot = (v2 - p1) * normal;
                                    if (dot >= inLength)
                                    {
                                        continue;
                                    }

                                    v2  = t2.g_pointList[1].pos2d;
                                    dot = (v2 - p1) * normal;
                                    if (dot >= inLength)
                                    {
                                        continue;
                                    }

                                    v2  = t2.g_pointList[2].pos2d;
                                    dot = (v2 - p1) * normal;
                                    if (dot >= inLength)
                                    {
                                        continue;
                                    }

                                    t2.g_visited = true;
                                    sideList.Add((EPMTriangle)nei.g_sharePointNeighbors[j]);
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < sideList.Count; i++)
            {
                sideList[i].SetType(sideType);
            }

            for (int i = 0; i < list.Count; i++)
            {
                EPMTriangle t = (EPMTriangle)list[i];
                if (t.HasShapeType(sideType))
                {
                    continue;
                }
                bool finded = true;
                for (int j = 0; j < t.g_shareEdgeNeighbors.Count; j++)
                {
                    if (t.g_shareEdgeNeighbors[j].HasShapeType(oldType))
                    {
                        finded = false;
                        break;
                    }
                }
                if (finded)
                {
                    t.SetType(sideType);
                }
            }

            for (int i = 0; i < list.Count; i++)
            {
                list[i].g_visited = false;
            }
        }
Пример #18
0
        public static void ExtractCenter(EPMDelaunayTerrain terrain, List <List <Vector2d> > pointList, EPMPoint.PointType oldType, EPMPoint.PointType newType, double halfWidth)
        {
            List <EPMTriangle> intersectList = new List <EPMTriangle>();
            List <EPMTriangle> oldTypeList   = terrain.ExtractTriangles_ByTypes(null, EPMPoint.GenerateTypesInt(false, oldType));

            for (int i = 0; i < pointList.Count; i++)
            {
                List <Vector2d> lineSet = pointList[i];
                for (int j = 0; j < lineSet.Count; j++)
                {
                    intersectList.AddRange(terrain.ExtractTriangles_PointsInCircle(lineSet[j], halfWidth, 1, oldTypeList));
                    if (j >= 1)
                    {
                        Vector2d dir = lineSet[j] - lineSet[j - 1];
                        dir.Normalize();
                        Vector2d normal = new Vector2d(-dir.y, dir.x);
                        intersectList.AddRange(terrain.ExtractTriangles_PointsInLineWithDistance(lineSet[j - 1] - dir * halfWidth, lineSet[j] + dir * halfWidth, halfWidth, 1, oldTypeList));
                        intersectList.AddRange(terrain.ExtractTriangles_IntersectLine(lineSet[j - 1] + normal * halfWidth - dir * halfWidth, lineSet[j] + normal * halfWidth + dir * halfWidth, oldTypeList));
                        intersectList.AddRange(terrain.ExtractTriangles_IntersectLine(lineSet[j - 1] - normal * halfWidth - dir * halfWidth, lineSet[j] - normal * halfWidth + dir * halfWidth, oldTypeList));
                    }
                }
            }

            for (int i = 0; i < intersectList.Count; i++)
            {
                EPMTriangle t = (EPMTriangle)intersectList[i];
                t.g_pointList[0].g_type = newType;
                t.g_pointList[1].g_type = newType;
                t.g_pointList[2].g_type = newType;
                t.SetType(newType);
            }
            intersectList.Clear();
            CheckAndSetTileTypeByNeighbor(terrain, oldType, newType, newType);
        }
Пример #19
0
 public static void CheckAndSetTileTypeByNeighbor(EPMDelaunayTerrain terrain, EPMPoint.PointType checkType, EPMPoint.PointType neighborType, EPMPoint.PointType newTypeForPassCheck, EPMPoint.PointType newTypeForNotPassCheck, int minNeighborCount = 2, bool shareEdge = true, bool alsoSetPointsType = false)
 {
     CheckAndSetTileTypeByNeighbor(terrain, EPMPoint.GenerateTypesInt(false, checkType), EPMPoint.GenerateTypesInt(false, neighborType), newTypeForPassCheck, newTypeForNotPassCheck, true, minNeighborCount, shareEdge, alsoSetPointsType);
 }
Пример #20
0
 public static void CheckAndSetTileTypeByNeighbor(EPMDelaunayTerrain terrain, int checkTypeEnum, int neighborTypeEnum, EPMPoint.PointType newTypeForPassCheck, int minNeighborCount = 2, bool shareEdge = true, bool alsoSetPointsType = false)
 {
     CheckAndSetTileTypeByNeighbor(terrain, checkTypeEnum, neighborTypeEnum, newTypeForPassCheck, EPMPoint.PointType.Ground, false, minNeighborCount, shareEdge, alsoSetPointsType);
 }
Пример #21
0
        public static void CheckAndSetTileTypeByNeighbor(EPMDelaunayTerrain terrain, int checkTypeEnum, int neighborTypeEnum, EPMPoint.PointType newTypeForPassCheck, EPMPoint.PointType newTypeForNotPassCheck, bool processNotPassChcek = true, int minNeighborCount = 2, bool shareEdge = true, bool alsoSetPointsType = false)
        {
            List <EPMTriangle> triangleList = terrain.ExtractTriangles_ByTypes(null, checkTypeEnum);

            if (shareEdge)
            {
                for (int i = 0; i < triangleList.Count; i++)
                {
                    EPMTriangle t     = (EPMTriangle)triangleList[i];
                    int         count = 0;
                    for (int j = 0; j < t.g_shareEdgeNeighbors.Count; j++)
                    {
                        if (t.g_shareEdgeNeighbors[j].HasShapeType(neighborTypeEnum))
                        {
                            count++;
                        }
                        if (count >= minNeighborCount)
                        {
                            t.g_visited = true;
                            break;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < triangleList.Count; i++)
                {
                    EPMTriangle t     = (EPMTriangle)triangleList[i];
                    int         count = 0;
                    for (int j = 0; j < t.g_sharePointNeighbors.Count; j++)
                    {
                        if (t.g_sharePointNeighbors[j].HasShapeType(neighborTypeEnum))
                        {
                            count++;
                        }
                        if (count >= minNeighborCount)
                        {
                            t.g_visited = true;
                            break;
                        }
                    }
                }
            }

            for (int i = 0; i < triangleList.Count; i++)
            {
                EPMTriangle t = triangleList[i];
                if (t.g_visited)
                {
                    t.g_visited = false;
                    t.SetType(newTypeForPassCheck);
                    if (alsoSetPointsType)
                    {
                        t.g_pointList[0].g_type = newTypeForPassCheck;
                        t.g_pointList[1].g_type = newTypeForPassCheck;
                        t.g_pointList[2].g_type = newTypeForPassCheck;
                    }
                }
                else if (processNotPassChcek)
                {
                    t.SetType(newTypeForNotPassCheck);
                    if (alsoSetPointsType)
                    {
                        t.g_pointList[0].g_type = newTypeForNotPassCheck;
                        t.g_pointList[1].g_type = newTypeForNotPassCheck;
                        t.g_pointList[2].g_type = newTypeForNotPassCheck;
                    }
                }
            }
        }