コード例 #1
0
    private void CreateTree(ulong[] data, uint boundExtent, string objectName)
    {
        //Init buffers
        _Buffers = new List <Node> [_MaxDepth];
        for (int i = 0; i < _MaxDepth; ++i)
        {
            _Buffers[i] = new List <Node>();
        }

        //_Writer = new StreamWriter(File.Open("Assets/Data/TreeNoNewlines.txt", FileMode.OpenOrCreate, FileAccess.Write));
        _BWriter = new BinaryWriter(File.Open($"Assets/Data/{objectName}_Svo.bin", FileMode.OpenOrCreate, FileAccess.Write));

        //build tree, ignore certain morton (see VoxelDataCreator::WriteVoxelData())
        ulong ignoreMorton = Morton.morton3DEncode(boundExtent, boundExtent, boundExtent);

        for (int i = 0; i < data.Length; ++i)
        {
            //ignore empty morton
            if (data[i] == ignoreMorton || data[i] == 0)
            {
                continue;
            }

            //only get the 63-bits
            data[i] &= 0x7FFFFFFFFFFFFFFF;

            if (_CurrentMorton != data[i])
            {
                AddEmptyVoxels(data[i] - _CurrentMorton);
            }

            Node node = new Node(); //leaf node
            node._morton = data[i];
            _Buffers[_MaxDepth - 1].Add(node);

            RefineBuffers(_MaxDepth - 1);

            _CurrentMorton++;
        }

        //Finalize tree
        FinalizeTree();

        //write header
        WriteHeader(objectName);

        //_Writer.Dispose();
        _BWriter.Dispose();
    }
コード例 #2
0
    private void EncodeVoxels(VoxelSystem.Voxel_t[] voxels, int boundExtent, out List <ulong> mortons)
    {
        //write mortons to temp array
        ulong m = 0;

        mortons = new List <ulong>();
        foreach (VoxelSystem.Voxel_t v in voxels)
        {
            //can only send 21 bits to the encryptor, so make sure the positions aren't exeeding limit
            if (((uint)v.position.x > 0x1FFFFF) ||
                ((uint)v.position.y > 0x1FFFFF) ||
                ((uint)v.position.z > 0x1FFFFF))
            {
                Debug.LogAssertion("one of the positions is larger than 2097152, try reducing the resolution");
            }

            //ignore defaults
            if (v.position == new Vector3(boundExtent, boundExtent, boundExtent))
            {
                continue;
            }

            //Encode the position
            m = Morton.morton3DEncode((uint)v.position.x, (uint)v.position.y, (uint)v.position.z);

            //only use the 63 first bits, the rest is signs and fill indicator
            m &= 0x7FFFFFFFFFFFFFFF;

            //ulong idx = m;

            //set last bit to indicate fill
            m |= (ulong)1 << 63;

            //write 64-bits
            //mortons[idx] = m;
            mortons.Add(m);
        }

        //sort array
        mortons.Sort();
    }