示例#1
0
        private static void FinalizeGeneratedTile(List <int> generatedTileVerts)
        {
            if ((generatedTileVerts.Count != 5 && generatedTileVerts.Count != 6) || generatedTileVerts.Count > 6)
            {
                Log.Error("Planet shape generation internal error: generated a tile with " + generatedTileVerts.Count + " vertices. Only 5 and 6 are allowed.");
                return;
            }
            if (PlanetShapeGenerator.ShouldDiscardGeneratedTile(generatedTileVerts))
            {
                return;
            }
            int count = PlanetShapeGenerator.tileIDToFinalVerts_offsets.Count;

            PlanetShapeGenerator.tileIDToFinalVerts_offsets.Add(PlanetShapeGenerator.finalVerts.Count);
            int i      = 0;
            int count2 = generatedTileVerts.Count;

            while (i < count2)
            {
                int index = generatedTileVerts[i];
                PlanetShapeGenerator.finalVerts.Add(PlanetShapeGenerator.verts[index]);
                PlanetShapeGenerator.vertToTileIDs_values[PlanetShapeGenerator.vertToTileIDs_values.IndexOf(-1, PlanetShapeGenerator.vertToTileIDs_offsets[index])] = count;
                i++;
            }
            PackedListOfLists.AddList <int>(PlanetShapeGenerator.tileIDToVerts_offsets, PlanetShapeGenerator.tileIDToVerts_values, generatedTileVerts);
        }
示例#2
0
        private static void CalculateTileNeighbors()
        {
            List <int> list = new List <int>();
            int        i    = 0;

            for (int count = tileIDToVerts_offsets.Count; i < count; i++)
            {
                tmpNeighborsToAdd.Clear();
                PackedListOfLists.GetList(tileIDToVerts_offsets, tileIDToVerts_values, i, tmpVerts);
                int j = 0;
                for (int count2 = tmpVerts.Count; j < count2; j++)
                {
                    PackedListOfLists.GetList(vertToTileIDs_offsets, vertToTileIDs_values, tmpVerts[j], tmpTileIDs);
                    PackedListOfLists.GetList(vertToTileIDs_offsets, vertToTileIDs_values, tmpVerts[(j + 1) % tmpVerts.Count], list);
                    int k = 0;
                    for (int count3 = tmpTileIDs.Count; k < count3; k++)
                    {
                        int num = tmpTileIDs[k];
                        if (num != i && num != -1 && list.Contains(num))
                        {
                            tmpNeighborsToAdd.Add(num);
                        }
                    }
                }
                PackedListOfLists.AddList(tileIDToNeighbors_offsets, tileIDToNeighbors_values, tmpNeighborsToAdd);
            }
        }
示例#3
0
        private static void CalculateTileNeighbors()
        {
            List <int> list  = new List <int>();
            int        i     = 0;
            int        count = PlanetShapeGenerator.tileIDToVerts_offsets.Count;

            for (; i < count; i++)
            {
                PlanetShapeGenerator.tmpNeighborsToAdd.Clear();
                PackedListOfLists.GetList(PlanetShapeGenerator.tileIDToVerts_offsets, PlanetShapeGenerator.tileIDToVerts_values, i, PlanetShapeGenerator.tmpVerts);
                int j      = 0;
                int count2 = PlanetShapeGenerator.tmpVerts.Count;
                for (; j < count2; j++)
                {
                    PackedListOfLists.GetList(PlanetShapeGenerator.vertToTileIDs_offsets, PlanetShapeGenerator.vertToTileIDs_values, PlanetShapeGenerator.tmpVerts[j], PlanetShapeGenerator.tmpTileIDs);
                    PackedListOfLists.GetList(PlanetShapeGenerator.vertToTileIDs_offsets, PlanetShapeGenerator.vertToTileIDs_values, PlanetShapeGenerator.tmpVerts[(j + 1) % PlanetShapeGenerator.tmpVerts.Count], list);
                    int k      = 0;
                    int count3 = PlanetShapeGenerator.tmpTileIDs.Count;
                    for (; k < count3; k++)
                    {
                        int num = PlanetShapeGenerator.tmpTileIDs[k];
                        if (num != i && num != -1 && list.Contains(num))
                        {
                            PlanetShapeGenerator.tmpNeighborsToAdd.Add(num);
                        }
                    }
                }
                PackedListOfLists.AddList(PlanetShapeGenerator.tileIDToNeighbors_offsets, PlanetShapeGenerator.tileIDToNeighbors_values, PlanetShapeGenerator.tmpNeighborsToAdd);
            }
        }
示例#4
0
 private static void FinalizeGeneratedTile(List <int> generatedTileVerts)
 {
     if ((generatedTileVerts.Count != 5 && generatedTileVerts.Count != 6) || generatedTileVerts.Count > 6)
     {
         Log.Error("Planet shape generation internal error: generated a tile with " + generatedTileVerts.Count + " vertices. Only 5 and 6 are allowed.");
     }
     else if (!ShouldDiscardGeneratedTile(generatedTileVerts))
     {
         int count = tileIDToFinalVerts_offsets.Count;
         tileIDToFinalVerts_offsets.Add(finalVerts.Count);
         int i = 0;
         for (int count2 = generatedTileVerts.Count; i < count2; i++)
         {
             int index = generatedTileVerts[i];
             finalVerts.Add(verts[index]);
             vertToTileIDs_values[vertToTileIDs_values.IndexOf(-1, vertToTileIDs_offsets[index])] = count;
         }
         PackedListOfLists.AddList(tileIDToVerts_offsets, tileIDToVerts_values, generatedTileVerts);
     }
 }
示例#5
0
 public int GetMaxTileNeighborCountEver(int tileID)
 {
     return(PackedListOfLists.GetListCount <Vector3>(this.tileIDToVerts_offsets, this.verts, tileID));
 }
示例#6
0
 public int GetTileNeighborCount(int tileID)
 {
     return(PackedListOfLists.GetListCount <int>(this.tileIDToNeighbors_offsets, this.tileIDToNeighbors_values, tileID));
 }
示例#7
0
 public void GetTileNeighbors(int tileID, List <int> outNeighbors)
 {
     PackedListOfLists.GetList <int>(this.tileIDToNeighbors_offsets, this.tileIDToNeighbors_values, tileID, outNeighbors);
 }
示例#8
0
 public void GetTileVerticesIndices(int tileID, List <int> outVertsIndices)
 {
     PackedListOfLists.GetListValuesIndices <Vector3>(this.tileIDToVerts_offsets, this.verts, tileID, outVertsIndices);
 }
示例#9
0
        private static void Subdivide(bool lastPass)
        {
            PackedListOfLists.GenerateVertToTrisPackedList(PlanetShapeGenerator.verts, PlanetShapeGenerator.tris, PlanetShapeGenerator.vertToTris_offsets, PlanetShapeGenerator.vertToTris_values);
            int count  = PlanetShapeGenerator.verts.Count;
            int i      = 0;
            int count2 = PlanetShapeGenerator.tris.Count;

            while (i < count2)
            {
                TriangleIndices triangleIndices = PlanetShapeGenerator.tris[i];
                Vector3         vector          = (PlanetShapeGenerator.verts[triangleIndices.v1] + PlanetShapeGenerator.verts[triangleIndices.v2] + PlanetShapeGenerator.verts[triangleIndices.v3]) / 3f;
                PlanetShapeGenerator.verts.Add(vector.normalized * PlanetShapeGenerator.radius);
                i++;
            }
            PlanetShapeGenerator.newTris.Clear();
            if (lastPass)
            {
                PlanetShapeGenerator.vertToTileIDs_offsets.Clear();
                PlanetShapeGenerator.vertToTileIDs_values.Clear();
                PlanetShapeGenerator.tileIDToVerts_offsets.Clear();
                PlanetShapeGenerator.tileIDToVerts_values.Clear();
                int j      = 0;
                int count3 = PlanetShapeGenerator.verts.Count;
                while (j < count3)
                {
                    PlanetShapeGenerator.vertToTileIDs_offsets.Add(PlanetShapeGenerator.vertToTileIDs_values.Count);
                    if (j >= count)
                    {
                        for (int k = 0; k < 6; k++)
                        {
                            PlanetShapeGenerator.vertToTileIDs_values.Add(-1);
                        }
                    }
                    j++;
                }
            }
            for (int l = 0; l < count; l++)
            {
                PackedListOfLists.GetList <int>(PlanetShapeGenerator.vertToTris_offsets, PlanetShapeGenerator.vertToTris_values, l, PlanetShapeGenerator.adjacentTris);
                int count4 = PlanetShapeGenerator.adjacentTris.Count;
                if (!lastPass)
                {
                    for (int m = 0; m < count4; m++)
                    {
                        int num = PlanetShapeGenerator.adjacentTris[m];
                        int v   = count + num;
                        int nextOrderedVertex = PlanetShapeGenerator.tris[num].GetNextOrderedVertex(l);
                        int num2 = -1;
                        for (int n = 0; n < count4; n++)
                        {
                            if (m != n)
                            {
                                TriangleIndices triangleIndices2 = PlanetShapeGenerator.tris[PlanetShapeGenerator.adjacentTris[n]];
                                if (triangleIndices2.v1 == nextOrderedVertex || triangleIndices2.v2 == nextOrderedVertex || triangleIndices2.v3 == nextOrderedVertex)
                                {
                                    num2 = PlanetShapeGenerator.adjacentTris[n];
                                    break;
                                }
                            }
                        }
                        if (num2 >= 0)
                        {
                            int v2 = count + num2;
                            PlanetShapeGenerator.newTris.Add(new TriangleIndices(l, v2, v));
                        }
                    }
                }
                else if (count4 == 5 || count4 == 6)
                {
                    int num3 = 0;
                    int nextOrderedVertex2 = PlanetShapeGenerator.tris[PlanetShapeGenerator.adjacentTris[num3]].GetNextOrderedVertex(l);
                    int num4 = num3;
                    int currentTriangleVertex = nextOrderedVertex2;
                    PlanetShapeGenerator.generatedTileVerts.Clear();
                    for (int num5 = 0; num5 < count4; num5++)
                    {
                        int item = count + PlanetShapeGenerator.adjacentTris[num4];
                        PlanetShapeGenerator.generatedTileVerts.Add(item);
                        int nextAdjacentTriangle = PlanetShapeGenerator.GetNextAdjacentTriangle(num4, currentTriangleVertex, PlanetShapeGenerator.adjacentTris);
                        int nextOrderedVertex3   = PlanetShapeGenerator.tris[PlanetShapeGenerator.adjacentTris[nextAdjacentTriangle]].GetNextOrderedVertex(l);
                        num4 = nextAdjacentTriangle;
                        currentTriangleVertex = nextOrderedVertex3;
                    }
                    PlanetShapeGenerator.FinalizeGeneratedTile(PlanetShapeGenerator.generatedTileVerts);
                }
            }
            PlanetShapeGenerator.tris.Clear();
            PlanetShapeGenerator.tris.AddRange(PlanetShapeGenerator.newTris);
        }
示例#10
0
        private static void Subdivide(bool lastPass)
        {
            PackedListOfLists.GenerateVertToTrisPackedList(verts, tris, vertToTris_offsets, vertToTris_values);
            int count = verts.Count;
            int i     = 0;

            for (int count2 = tris.Count; i < count2; i++)
            {
                TriangleIndices triangleIndices = tris[i];
                Vector3         vector          = (verts[triangleIndices.v1] + verts[triangleIndices.v2] + verts[triangleIndices.v3]) / 3f;
                verts.Add(vector.normalized * radius);
            }
            newTris.Clear();
            if (lastPass)
            {
                vertToTileIDs_offsets.Clear();
                vertToTileIDs_values.Clear();
                tileIDToVerts_offsets.Clear();
                tileIDToVerts_values.Clear();
                int j = 0;
                for (int count3 = verts.Count; j < count3; j++)
                {
                    vertToTileIDs_offsets.Add(vertToTileIDs_values.Count);
                    if (j >= count)
                    {
                        for (int k = 0; k < 6; k++)
                        {
                            vertToTileIDs_values.Add(-1);
                        }
                    }
                }
            }
            for (int l = 0; l < count; l++)
            {
                PackedListOfLists.GetList(vertToTris_offsets, vertToTris_values, l, adjacentTris);
                int count4 = adjacentTris.Count;
                if (!lastPass)
                {
                    for (int m = 0; m < count4; m++)
                    {
                        int num = adjacentTris[m];
                        int v   = count + num;
                        int nextOrderedVertex = tris[num].GetNextOrderedVertex(l);
                        int num2 = -1;
                        for (int n = 0; n < count4; n++)
                        {
                            if (m != n)
                            {
                                TriangleIndices triangleIndices2 = tris[adjacentTris[n]];
                                if (triangleIndices2.v1 == nextOrderedVertex || triangleIndices2.v2 == nextOrderedVertex || triangleIndices2.v3 == nextOrderedVertex)
                                {
                                    num2 = adjacentTris[n];
                                    break;
                                }
                            }
                        }
                        if (num2 >= 0)
                        {
                            int v2 = count + num2;
                            newTris.Add(new TriangleIndices(l, v2, v));
                        }
                    }
                }
                else if (count4 == 5 || count4 == 6)
                {
                    int num3 = 0;
                    int nextOrderedVertex2 = tris[adjacentTris[num3]].GetNextOrderedVertex(l);
                    int num4 = num3;
                    int currentTriangleVertex = nextOrderedVertex2;
                    generatedTileVerts.Clear();
                    for (int num5 = 0; num5 < count4; num5++)
                    {
                        int item = count + adjacentTris[num4];
                        generatedTileVerts.Add(item);
                        int nextAdjacentTriangle = GetNextAdjacentTriangle(num4, currentTriangleVertex, adjacentTris);
                        int nextOrderedVertex3   = tris[adjacentTris[nextAdjacentTriangle]].GetNextOrderedVertex(l);
                        num4 = nextAdjacentTriangle;
                        currentTriangleVertex = nextOrderedVertex3;
                    }
                    FinalizeGeneratedTile(generatedTileVerts);
                }
            }
            tris.Clear();
            tris.AddRange(newTris);
        }
示例#11
0
 public int GetMaxTileNeighborCountEver(int tileID)
 {
     return(PackedListOfLists.GetListCount(tileIDToVerts_offsets, verts, tileID));
 }
示例#12
0
 public void GetTileVertices(int tileID, List <Vector3> outVerts)
 {
     PackedListOfLists.GetList(tileIDToVerts_offsets, verts, tileID, outVerts);
 }