Пример #1
0
        /////////////////////////////////////////

        public MeshRayTestOptimized(Vector3F[] vertices, int[] indices)
        {
            this.vertices = vertices;
            this.indices  = indices;

            if (vertices.Length != 0 && indices.Length != 0)
            {
                var bounds = Bounds.Cleared;
                foreach (var vertex in vertices)
                {
                    bounds.Add(vertex);
                }

                var initSettings = new OctreeContainer.InitSettings();
                initSettings.InitialOctreeBounds       = bounds;
                initSettings.OctreeBoundsRebuildExpand = Vector3.Zero;
                initSettings.MinNodeSize = bounds.GetSize() / 50;
                octreeContainer          = new OctreeContainer(initSettings);

                for (int nTriangle = 0; nTriangle < indices.Length / 3; nTriangle++)
                {
                    var vertex0 = vertices[indices[nTriangle * 3 + 0]];
                    var vertex1 = vertices[indices[nTriangle * 3 + 1]];
                    var vertex2 = vertices[indices[nTriangle * 3 + 2]];

                    var triangleBounds = new Bounds(vertex0);
                    triangleBounds.Add(vertex1);
                    triangleBounds.Add(vertex2);

                    octreeContainer.AddObject(triangleBounds, 1);
                }
            }
        }
        void ObjectsInSpace_DestroyOctree()
        {
            if (octree != null)
            {
                for (int n = 0; n < octreeObjects.Count; n++)
                {
                    var obj = octreeObjects[n];
                    if (obj != null)
                    {
                        obj.sceneOctreeIndex = -1;
                    }
                }
                octreeObjects.Clear();

                octree.Dispose();
                octree = null;
            }
        }
        void ObjectsInSpace_CreateOctree()
        {
            if (octree != null)
            {
                Log.Fatal("Component_Scene: ObjectsInSpace_CreateOctree: sceneOctree != null.");
            }

            //create octree
            var settings = new OctreeContainer.InitSettings();

            settings.InitialOctreeBounds = CalculateTotalBoundsOfObjectsInSpace(true);
            settings.AmountOfObjectsOutsideOctreeBoundsToRebuld = OctreeObjectCountOutsideOctreeToRebuld;
            settings.OctreeBoundsRebuildExpand = OctreeBoundsRebuildExpand;
            settings.MinNodeSize = OctreeMinNodeSize;
            settings.ObjectCountThresholdToCreateChildNodes = OctreeObjectCountToCreateChildNodes;
            settings.MaxNodeCount = OctreeMaxNodeCount;
            octree = new OctreeContainer(settings);

            //update objects
            foreach (var obj in GetComponents <Component_ObjectInSpace>(false, true, true))
            {
                ObjectsInSpace_ObjectUpdate(obj);
            }
        }
Пример #4
0
 public void Dispose()
 {
     octreeContainer?.Dispose();
     octreeContainer = null;
 }