Beispiel #1
0
        public override BaseBVHController <Value> Build(IList <Bounds> Bous, IList <Value> Vals)
        {
            Clear();

            var galaxy  = Bous.Select(b => b.center).Encapsulate();
            var min     = galaxy.min;
            var size    = galaxy.size;
            var sizeInv = new Vector3(1f / size.x, 1f / size.y, 1f / size.z);

            for (var i = 0; i < Bous.Count; i++)
            {
                var bb = Bous [i];
                var p  = Vector3.Scale(bb.center - min, sizeInv);
                var id = MortonCodeInt.Encode(p.x, p.y, p.z);
                _indices.Add(i);
                _ids.Add(id);
            }

            _root = Sort(_indices, _ids, 0, _indices.Count, _pool, MortonCodeInt.STRIDE_BITS);
            if (_root != null)
            {
                _root.Build(new IndexedList <Bounds> (_indices, Bous), new IndexedList <Value> (_indices, Vals));
            }

            return(this);
        }
Beispiel #2
0
        public void EditorTest()
        {
            Assert.AreEqual(0, MortonCodeInt.Encode(0, 0, 0));

            Assert.AreEqual(1, MortonCodeInt.Encode(1, 0, 0));
            Assert.AreEqual(8, MortonCodeInt.Encode(2, 0, 0));

            Assert.AreEqual(2, MortonCodeInt.Encode(0, 1, 0));
            Assert.AreEqual(16, MortonCodeInt.Encode(0, 2, 0));

            Assert.AreEqual(4, MortonCodeInt.Encode(0, 0, 1));
            Assert.AreEqual(32, MortonCodeInt.Encode(0, 0, 2));

            Assert.AreEqual(7, MortonCodeInt.Encode(1, 1, 1));
            Assert.AreEqual((1 << 24), MortonCodeInt.Encode(256, 0, 0));
        }