Exemplo n.º 1
0
    public static void splitAt(B45LODNode root, IntVector3 atpos, int lod)
    {
        // calculate the index of the child in which the split will happen.
        int        ind           = 0;
        B45LODNode cur           = root;
        IntVector3 nodeCenterPos = IntVector3.Zero;

        int i = 0;

        for (; i < lod; i++)
        {
            nodeCenterPos.x = cur.pos.x + cur.logicalSize;
            nodeCenterPos.y = cur.pos.y + cur.logicalSize;
            nodeCenterPos.z = cur.pos.z + cur.logicalSize;

            ind = ((atpos.x > nodeCenterPos.x) ? 1 : 0) |
                  ((atpos.y > nodeCenterPos.y) ? 2 : 0) |
                  ((atpos.z > nodeCenterPos.z) ? 4 : 0);

            if (cur.isLeaf)
            {
                cur.split();
            }
            cur = cur.children[ind];
        }
    }
Exemplo n.º 2
0
    // obtain the level 0 node that associates with the given pos.
    public static B45LODNode readNode(IntVector3 atpos, B45LODNode root, int lod)
    {
        // calculate the index of the child in which the split will happen.
        int        ind           = 0;
        B45LODNode cur           = root;
        IntVector3 nodeCenterPos = IntVector3.Zero;

        while (true)
        {
            nodeCenterPos.x = cur.pos.x + cur.logicalSize / 2;
            nodeCenterPos.y = cur.pos.y + cur.logicalSize / 2;
            nodeCenterPos.z = cur.pos.z + cur.logicalSize / 2;

            ind = ((atpos.x >= nodeCenterPos.x) ? 1 : 0) |
                  ((atpos.y >= nodeCenterPos.y) ? 2 : 0) |
                  ((atpos.z >= nodeCenterPos.z) ? 4 : 0);

            if (cur.isLeaf)
            {
                cur.split();
            }
            cur = cur.children[ind];
            if (cur.pos.w == 0)
            {
                break;
            }
        }
        return(cur);
    }
Exemplo n.º 3
0
    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();
    }
Exemplo n.º 4
0
 public static void makeCubeRec(B45LODNode node)
 {
     node.makeCube();
     if (!node.isLeaf)
     {
         for (int i = 0; i < 8; i++)
         {
             makeCubeRec(node.children[i]);
         }
     }
 }
Exemplo n.º 5
0
 public static void merge(B45LODNode node)
 {
     if (!node.isLeaf)
     {
         for (int i = 0; i < 8; i++)
         {
             if (node.children[i] != null)
             {
                 merge(node.children[i]);
             }
             node.children[i] = null;
         }
     }
     node.children = null;
 }
Exemplo n.º 6
0
    public void split()
    {
        children = new B45LODNode[8];

        int lod = pos.w;
        int childLogicalSize = logicalSize >> 1;

        for (int i = 0; i < 8; i++)
        {
            IntVector4 apos = new IntVector4(pos);

            apos.w      = lod - 1;
            apos.x     += (i & 1) * childLogicalSize;
            apos.y     += ((i >> 1) & 1) * childLogicalSize;
            apos.z     += ((i >> 2) & 1) * childLogicalSize;
            children[i] = new B45LODNode(apos, this, i);
        }
    }
Exemplo n.º 7
0
 public B45LODNode(IntVector4 _pos, B45LODNode _parent, int _octant)
 {
     pos    = new IntVector4(_pos);
     parent = _parent;
     octant = _octant;
 }
Exemplo n.º 8
0
 void testLOD()
 {
     root = new B45LODNode(new IntVector4(0, 0, 0, 5), null, 0);
     B45LODNode.splitAt(root, new IntVector3(10, 20, 30), 3);
     B45LODNode.makeCubeRec(root);
 }
Exemplo n.º 9
0
 public BlockVectorNode(IntVector4 _pos, B45LODNode _parent, int _octant) : base(_pos, _parent, _octant)
 {
     isByteArrayMode = false;
 }
Exemplo n.º 10
0
 // clear
 public void Clear()
 {
     BlockVectorNode.Clear(bvtRoot);
     B45LODNode.merge((B45LODNode)bvtRoot);
     _chunks.Clear();
 }