//Rotates a given IUV coordinate counterclockwise n amount around the face. private IUV RotateUV(IUV coord, int width, int amount) { IUV temp; for (int i = 0; i < amount; i++) { temp = new IUV(coord.i, (width - 1 - coord.v), coord.u); coord = temp; } return(coord); }
public Chunk(Planet planet, Face face, int u, int v) { this.planet = planet; this.face = face; this.faceCoord = new IUV(face.index, u, v); this.planetGenerator = planet.PlanetGenerator; CalculateCentre(planet.faceResolution, planet.radius); //Add lod levels based on planet presets lodMeshes = new LodData[planet.detailLevels.Length]; for (int i = 0; i < planet.detailLevels.Length; i++) { lodMeshes[i] = new LodData(planet.detailLevels[i].lod, UpdateChunk, planetGenerator); } //Debug.Log("Chunk [" + iuv.x + "," + iuv.y + "," + iuv.z + "] has been constructed"); }
public void FindConnected() { int edgeLimit = planet.faceResolution; int chunkIndex = 0; //Debug.Log("---------" + chunkID + "---------"); for (int u = faceCoord.u - 1; u <= faceCoord.u + 1; u++) { for (int v = faceCoord.v - 1; v <= faceCoord.v + 1; v++) { int edgeCount = 0; int rotation = 0; IUV newFaceCoord = new IUV(0, 0, 0); if (u >= edgeLimit) { edgeCount++; //Find North edge newFaceCoord = new IUV(face.north, 0, v); rotation = face.correctionNorth; } if (u < 0) { edgeCount++; //Find South edge newFaceCoord = new IUV(face.south, edgeLimit - 1, v); rotation = face.correctionSouth; } if (v >= edgeLimit) { edgeCount++; //Find East edge newFaceCoord = new IUV(face.east, u, 0); rotation = face.correctionEast; } if (v < 0) { edgeCount++; //Find West edge newFaceCoord = new IUV(face.west, u, edgeLimit - 1); rotation = face.correctionWest; } //If we have more than 2 edges, this is a virtual space and can be ignored if (edgeCount < 2) { if (edgeCount == 1) { //One edge found- this chunk is on a different side of the cube! if (rotation != 0) { //Rotate the face to get the correct lineup newFaceCoord = RotateUV(newFaceCoord, edgeLimit, rotation); } } else { //No edges found so its on this side of the cube newFaceCoord = new IUV(faceCoord.i, u, v); } //Add this chunk! if (planet.ChunkDictionary.ContainsKey(newFaceCoord)) { Chunk selectedChunk = planet.ChunkDictionary[newFaceCoord]; if (selectedChunk != this) { connectedChunks[chunkIndex] = selectedChunk; //Debug.Log(chunkIndex + ": " + connectedChunks[chunkIndex].chunkID + " (edge count " + edgeCount + ")"); chunkIndex++; } } } } } //Clean up the array Chunk[] tempArray = new Chunk[chunkIndex]; for (int i = 0; i < chunkIndex; i++) { tempArray[i] = connectedChunks[i]; } connectedChunks = tempArray; }