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); }
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); } }
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); } }
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); } }
public int GetMaxTileNeighborCountEver(int tileID) { return(PackedListOfLists.GetListCount <Vector3>(this.tileIDToVerts_offsets, this.verts, tileID)); }
public int GetTileNeighborCount(int tileID) { return(PackedListOfLists.GetListCount <int>(this.tileIDToNeighbors_offsets, this.tileIDToNeighbors_values, tileID)); }
public void GetTileNeighbors(int tileID, List <int> outNeighbors) { PackedListOfLists.GetList <int>(this.tileIDToNeighbors_offsets, this.tileIDToNeighbors_values, tileID, outNeighbors); }
public void GetTileVerticesIndices(int tileID, List <int> outVertsIndices) { PackedListOfLists.GetListValuesIndices <Vector3>(this.tileIDToVerts_offsets, this.verts, tileID, outVertsIndices); }
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); }
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 int GetMaxTileNeighborCountEver(int tileID) { return(PackedListOfLists.GetListCount(tileIDToVerts_offsets, verts, tileID)); }
public void GetTileVertices(int tileID, List <Vector3> outVerts) { PackedListOfLists.GetList(tileIDToVerts_offsets, verts, tileID, outVerts); }