public void Import(byte[] buffer) { // vector octree root BlockVectorNode root = ((B45OctreeDataSource)_blockDS).bvtRoot; ((B45OctreeDataSource)_blockDS).Clear(); MemoryStream ms = new MemoryStream(buffer); BinaryReader _in = new BinaryReader(ms); int readVersion = _in.ReadInt32(); switch (readVersion) { case 2: int Size = _in.ReadInt32(); for (int i = 0; i < Size; i++) { int x = _in.ReadInt32(); int y = _in.ReadInt32(); int z = _in.ReadInt32(); IntVector3 index = new IntVector3(x, y, z); try{ root = ((B45OctreeDataSource)_blockDS).bvtRoot.reroot(index); } catch (Exception e) { Debug.LogWarning("Unexpected exception while importing" + index + e); break; } ((B45OctreeDataSource)_blockDS).bvtRoot = root; BlockVectorNode bvnode = BlockVectorNode.readNode(new IntVector3(x, y, z), root); //BlockVectorNode bvnode = node; if (bvnode.blockVectors == null) { bvnode.blockVectors = new List <BlockVector>() as List <BlockVector>; } // calculate the position relative to the block chunk's position. x = x & Block45Constants._mask; y = y & Block45Constants._mask; z = z & Block45Constants._mask; bvnode.blockVectors.Add(new BlockVector( x + Block45Constants._numVoxelsPrefix, y + Block45Constants._numVoxelsPrefix, z + Block45Constants._numVoxelsPrefix, _in.ReadByte(), _in.ReadByte())); } break; } _in.Close(); ms.Close(); }
B45ChunkData CreateChunk(IntVector4 index) { B45ChunkData chunk = new B45ChunkData(colliderMan); chunk.BuildList = _chunkRebuildList; writeChunk(index.x, index.y, index.z, chunk); chunk.ChunkPosLod_w = new IntVector4( (index.x), (index.y), (index.z), 0); chunk.bp(); chunk.AddToBuildList(); // make the bv node. if (true) { 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 creating chunk to" + index + e); return(chunk); } BlockVectorNode bvNode = BlockVectorNode.readNode(shiftVec, bvtRoot); if (bvNode.chunk != null) { // already a chunk has been assigned to this node. something is wrong here. return(chunk); } bvNode.chunk = chunk; chunk._bvNode = bvNode; bvNode.isByteArrayMode = true; } return(chunk); }
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); }