private void UpdateNeighbour(Voxel v, Point3 worldCoord) { BlockInfo bi = SurfaceManager.GetSurface( SurfaceManager.GetID( GetNeighbours(worldCoord))); v.SetRotation(bi.rotation); int hash = ChunkManager.GetHash(worldCoord.ToChunkCoord()); Transform chunkContainer = null; foreach (Transform child in transform) { if (child.name == hash.ToString()) { chunkContainer = child; break; } } if (chunkContainer == null) { PlaceBlock(worldCoord, hash, bi); return; } Mesh mesh = Resources.Load("Meshes/Dev/" + bi.meshName) as Mesh; string name = Name(worldCoord); foreach (Transform block in chunkContainer) { if (block.name == name) { block.GetComponent <MeshFilter>().sharedMesh = mesh; block.transform.localRotation = bi.rotation; } } }
public void GetInfo(GameObject obj) { if (!CheckKey()) { return; } if (sb == null) { sb = new StringBuilder(); } sb.Remove(0, sb.Length); Point3 worldCoord = Point3.ToWorldBlockCoord(obj.transform.position); Voxel block = ChunkManager.GetBlock(worldCoord); if (block == null) { return; } Voxel[] neighbours = BlockManager.GetNeighbours(worldCoord); int blockID = SurfaceManager.GetID(neighbours); Point3 chunkCoord = worldCoord.ToChunkCoord(); int chunkID = ChunkManager.GetHash(chunkCoord); BlockInfo bi = SurfaceManager.GetSurface(blockID); sb.AppendLine("ID: " + blockID); sb.AppendLine("Type: " + block.GetBlockType()); sb.AppendLine("Chunk ID: " + chunkID); sb.AppendLine("Mesh: " + bi.meshName); sb.AppendLine("Rotation: " + bi.rotation.eulerAngles.y + "/" + obj.transform.rotation.eulerAngles.y + "/" + block.GetRotation().eulerAngles.y); sb.AppendLine("Local coord: " + worldCoord.ToLocalBlockCoord()); sb.AppendLine("World coord: " + worldCoord); sb.AppendLine("Chunk coord: " + chunkCoord); }
private void OnPlacedBlock(PlacedBlock msg) { Point3 worldCoord = msg.worldCoord; Voxel block = ChunkManager.GetBlock(worldCoord); if (block == null) { block = ChunkManager .AddChunk(worldCoord) .AddBlock(worldCoord.ToLocalBlockCoord()); } int hash = ChunkManager.GetHash(worldCoord.ToChunkCoord()); block.SetBlockType(msg.type); // Get neighbours, pass to surface manager Voxel[] neighbours = GetNeighbours(worldCoord); // Lookup mesh name and rotation based on neighbours BlockInfo bi = SurfaceManager.GetSurface( SurfaceManager.GetID(neighbours)); block.SetRotation(bi.rotation); for (int i = 0; i < neighbours.Length; i++) { if (neighbours[i] == null) { continue; } UpdateNeighbour(neighbours[i], worldCoord + checkSides[i]); } PlaceBlock(msg.worldCoord, hash, bi); }