public static int rec_count_dbg(BlockVectorNode node) { int count = 0; if (node.chunk != null) { count = node.chunk.getFillRate(); } if (node.isLeaf == false) { for (int i = 0; i < 8; i++) { count += BlockVectorNode.rec_count_dbg(node.children[i] as BlockVectorNode); } } return(count); }
public void OctreeUpdate(IntVector3 cursorPos) { List <BlockVectorNode> blkNodeToConv = new List <BlockVectorNode>(); // check if there are block vector nodes that should be converted into lod chunks. // BlockVectorNode.rec_findLod(cursorPos, bvtRoot, blkNodeToConv); // for(int i = 0; i < blkNodeToConv.Count; i++){ // BlockVectorNode bvNode = blkNodeToConv[i]; // // // shift xyz // IntVector4 shiftXYZ = IntVector4.Zero; // shiftXYZ.x = bvNode.Pos.x >> Block45Constants._shift; // shiftXYZ.y = bvNode.Pos.y >> Block45Constants._shift; // shiftXYZ.z = bvNode.Pos.z >> Block45Constants._shift; // shiftXYZ.w = bvNode.Pos.w; // // // if(!_chunks.ContainsKey(shiftXYZ) ) // { // // B45ChunkData newChunk = CreateChunk(shiftXYZ); // // bvNode.chunk = newChunk; // newChunk._bvNode = bvNode; // // _chunks[shiftXYZ] = newChunk; // newChunk.bp(); // } // if(bvNode.blockVectors != null && bvNode.chunk != null){ // bvNode.chunk.bp(); // try // { // BlockVectorNode.BlockVectors2ChunkData(bvNode.blockVectors, bvNode.chunk.DataVT); // } // catch(Exception ex){ // int sdkf = 0; // } // bvNode.blockVectors.Clear(); // bvNode.blockVectors = null; // } // } // check if there are block vector nodes that should be converted into real chunks(byte array mode). BlockVectorNode.rec_find(cursorPos, bvtRoot, blkNodeToConv); // for(int i = 0; i < blkNodeToConv.Count; i++){ //// blkNodeToConv[i].makeCube(); // } //// B45LODNode.makeCubeRec(bvtRoot as B45LODNode); int elementCount1 = 0; int fills1 = 0; int fillsIn_Chunks1 = 0; if (b45Building.DebugMode) { elementCount1 = BlockVectorNode.rec_count(bvtRoot); fills1 = BlockVectorNode.rec_count_dbg(bvtRoot); fillsIn_Chunks1 = countpoints(); } for (int i = 0; i < blkNodeToConv.Count; i++) { BlockVectorNode bvNode = blkNodeToConv[i]; // shift xyz IntVector4 shiftXYZ = IntVector4.Zero; shiftXYZ.x = bvNode.Pos.x >> Block45Constants._shift; shiftXYZ.y = bvNode.Pos.y >> Block45Constants._shift; shiftXYZ.z = bvNode.Pos.z >> Block45Constants._shift; if (!_chunks.ContainsKey(shiftXYZ)) { B45ChunkData newChunk = CreateChunk(shiftXYZ); bvNode.chunk = newChunk; newChunk._bvNode = bvNode; _chunks[shiftXYZ] = newChunk; newChunk.bp(); } if (bvNode.blockVectors != null && bvNode.chunk != null) { bvNode.chunk.bp(); try { BlockVectorNode.BlockVectors2ChunkData(bvNode.blockVectors, bvNode.chunk.DataVT); } catch { //int sdkf = 0; } bvNode.blockVectors.Clear(); bvNode.blockVectors = null; } } if (b45Building.DebugMode) { int elementCount2 = BlockVectorNode.rec_count(bvtRoot); int fills2 = BlockVectorNode.rec_count_dbg(bvtRoot); int fillsIn_Chunks2 = countpoints(); Debug.LogError("B45 Octree State: " + elementCount1 + " / " + fills1 + " / " + fillsIn_Chunks1 + " ------------- " + elementCount2 + " / " + fills2 + " / " + fillsIn_Chunks2); // check for chunks that are out of view } //List<BlockVectorNode> bvToDispose = new List<BlockVectorNode>(); List <B45ChunkData> cdToDispose = new List <B45ChunkData>(); foreach (KeyValuePair <IntVector4, B45ChunkData> kvp in _chunks) { BlockVectorNode bvNode = kvp.Value._bvNode; B45ChunkData cd = kvp.Value; if (bvNode == null) { Debug.LogError("node null!"); } if (!bvNode.isCloseTo(cursorPos) && cd != null ) { // this node is too far from the camera, put it in the dispose list cd.bp(); cdToDispose.Add(cd); // _chunks.Remove(kvp.Key); } } for (int i = 0; i < cdToDispose.Count; i++) { B45ChunkData cd = cdToDispose[i]; // convert the chunk data from byte array mode to block vector mode if (cd != null && cd.isBeingDestroyed == false) { cd.setBeingDestroyed(); cd.bp(); cd._bvNode.blockVectors = BlockVectorNode.ChunkData2BlockVectors(cd.DataVT); cd._bvNode.isByteArrayMode = false; cd._bvNode.removeCube(); // remove this chunk from memory cd._bvNode.chunk = null; deferredRemoveList.Add(cd); } else { //int sdgf = 0; } } deferredRemoval(); }