void writeToBlockVectors(IntVector3 index, IntVector3 localIndex, byte b0, byte b1) { IntVector3 shiftVec = IntVector3.Zero; shiftVec.x = index.x << Block45Constants._shift; shiftVec.y = index.y << Block45Constants._shift; shiftVec.z = index.z << Block45Constants._shift; try{ // Add try for StackOverflowException BlockVectorNode newRootNode = bvtRoot.reroot(shiftVec); bvtRoot = newRootNode; } catch (Exception e) { Debug.LogWarning("Unexpected exception while writing block to" + index + e); return; } BlockVectorNode bvNode = BlockVectorNode.readNode(shiftVec, bvtRoot); bvNode.write(localIndex.x + Block45Constants._numVoxelsPrefix, localIndex.y + Block45Constants._numVoxelsPrefix, localIndex.z + Block45Constants._numVoxelsPrefix, b0, b1); }
// this function should only be used by the root node. public BlockVectorNode reroot(IntVector3 atpos) { if (covers(atpos) == false) { // make a new node that can cover atpos IntVector4 newRootPos = new IntVector4(pos.XYZ, pos.w + 1); int maskX = 0; int maskY = 0; int maskZ = 0; if (atpos.x < pos.x) { maskX = 1; } if (atpos.y < pos.y) { maskY = 1; } if (atpos.z < pos.z) { maskZ = 1; } newRootPos.x -= maskX * logicalSize; newRootPos.y -= maskY * logicalSize; newRootPos.z -= maskZ * logicalSize; BlockVectorNode newRoot = new BlockVectorNode(newRootPos, null, 0); this.parent = newRoot; newRoot.Split(); int thisOctant = maskX + (maskY << 1) + (maskZ << 2); newRoot.children[thisOctant] = null; newRoot.children[thisOctant] = this; this.octant = thisOctant; return(newRoot.reroot(atpos)); } return(this); }