Beispiel #1
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);
        }
 public void GetTileNeighbors(int tileID, List <int> outNeighbors)
 {
     PackedListOfLists.GetList(tileIDToNeighbors_offsets, tileIDToNeighbors_values, tileID, outNeighbors);
 }
        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);
        }
 public void GetTileVertices(int tileID, List <Vector3> outVerts)
 {
     PackedListOfLists.GetList(tileIDToVerts_offsets, verts, tileID, outVerts);
 }