/// <summary> /// Translate an octree node. /// </summary> /// <param name="root"></param> /// <param name="octree"></param> public void TranslateTree(VoxelLocation root, IOctreeVoxelMesh octree) { VoxelLocation nextRoot = new VoxelLocation(); for (int x = 0; x < 2; ++x) { for (int y = 0; y < 2; ++y) { for (int z = 0; z < 2; ++z) { IVoxelMesh child = octree.GetChild(x, y, z); if (child != null) { nextRoot.Set(root).Add( x * octree.Width / 2, y * octree.Height / 2, z * octree.Depth / 2 ); if (child is IOctreeVoxelMesh) { this.TranslateTree(nextRoot, (IOctreeVoxelMesh)child); } else { this.TranslateLeaf(nextRoot, child); } } } } } }
public void TranslateMap(VoxelLocation start, IMapVoxelMesh map) { VoxelLocation chunckStart = new VoxelLocation(); foreach (VoxelLocation chunckLocation in map.Keys()) { IVoxelMesh chunck = map.GetChild(chunckLocation); chunckStart.Set(chunckLocation).Mul(map.ChildWidth, map.ChildHeight, map.ChildDepth); if (chunck is IOctreeVoxelMesh) { this.TranslateTree(chunckStart, (IOctreeVoxelMesh)chunck); } else { this.TranslateLeaf(chunckStart, chunck); } } }
public void DebugMap(VoxelLocation start, IMapVoxelMesh map, int startDeep, int endDeep) { this.DebugLeaf(start, map, startDeep, endDeep); VoxelLocation chunckStart = new VoxelLocation(); foreach (VoxelLocation chunckLocation in map.Keys()) { IVoxelMesh chunck = map.GetChild(chunckLocation); chunckStart.Set(chunckLocation).Mul(map.ChildWidth, map.ChildHeight, map.ChildDepth); if (chunck is IOctreeVoxelMesh) { this.DebugTree(chunckStart, (IOctreeVoxelMesh)chunck, startDeep - 1, endDeep - 1); } else { this.DebugLeaf(chunckStart, chunck, startDeep - 1, endDeep - 1); } } }
/// <summary> /// Translate an octree leaf. /// </summary> /// <param name="root"></param> /// <param name="mesh"></param> public void TranslateLeaf(VoxelLocation root, IVoxelMesh mesh) { VoxelLocation start = mesh.Start; VoxelLocation end = mesh.End; VoxelLocation finalLocation = new VoxelLocation(); for (int x = start.X; x < end.X; ++x) { for (int y = start.Y; y < end.Y; ++y) { for (int z = start.Z; z < end.Z; ++z) { finalLocation.Set(root).Add(x,y,z); this.Translate(finalLocation, this.VoxelMesh.Mesh, finalLocation); } } } }