Пример #1
0
        private void Subdivide(Vector3 mins, Vector3 maxes)
        {
            float avgX = (mins.x + maxes.x) / 2;
            float avgY = (mins.y + maxes.y) / 2;
            float avgZ = (mins.z + maxes.z) / 2;

            var subnodes = new List<Triangle>[8];
            for (int i = 0; i < 8; i++)
            {
                subnodes[i] = new List<Triangle>();
            }
            _directTriangleChildren = new List<Triangle>();

            foreach (Triangle triangle in _triangles)
            {
                int subnodeIndex = AssignSubnode(triangle, avgX, avgY, avgZ);
                if (subnodeIndex == -1)
                {
                    _directTriangleChildren.Add(triangle);
                }
                else
                {
                    subnodes[subnodeIndex].Add(triangle);
                }
            }

            for (int i = 0; i < 8; i++)
            {
                if (subnodes[i].Count == 0) continue;
                _children[i] = new Octree(subnodes[i].ToArray(), _parentMesh);
            }
        }
Пример #2
0
 private void BuildOctree()
 {
     _octree = new Octree(_triangles, this);
 }