Click or drag to resize
Ab4d.SharpEngine logo

MeshOctree Class

MeshOctree class organizes the triangles in 3D space into multiple levels of MeshOctreeNode objects so that the search of a triangle or check for triangle ray intersection is very efficient. Each MeshOctreeNode divide its space into 8 child MeshOctreeNode.
Inheritance Hierarchy
SystemObject
  Ab4d.SharpEngine.UtilitiesMeshOctree

Namespace: Ab4d.SharpEngine.Utilities
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 3.2.9386+3a404a3e1ebfa4efd231da7fe6f10dfb23b95dc4
Syntax
C#
public class MeshOctree

The MeshOctree type exposes the following members.

Constructors
 NameDescription
Public methodMeshOctree(PositionNormalTextureVertex, Int32, Int32, Single) Creates a new instance of MeshOctree. The instance is created with a standard vertex buffer format (an array of PositionNormalTextureVertex). If you need to create an MeshOctree with an array of positions instead, then use the other constructor.
Public methodMeshOctree(Vector3, Int32, Int32, Single) Creates a new instance of MeshOctree. The instance is created with an array of positions (array of Vector3 values). If you need to create an MeshOctree with a standard vertex buffer format (an array of PositionNormalTexture) instead, then use the other constructor.
Public methodMeshOctree(PositionNormalTextureVertex, Int32, BoundingBox, Int32, Single) Creates a new instance of MeshOctree. The instance is created with a standard vertex buffer format (an array of PositionNormalTexture). If you need to create an MeshOctree with an array of positions instead, then use the other constructor.
Public methodMeshOctree(Vector3, Int32, BoundingBox, Int32, Single) Creates a new instance of MeshOctree. The instance is created with an array of positions (array of Vector3 values). If you need to create an MeshOctree with a standard vertex buffer format (an array of PositionNormalTexture) instead, then use the other constructor.
Top
Methods
 NameDescription
Public methodCollectBoundingBoxesInLevel CollectBoundingBoxesInLevel is a diagnostics method and returns a list of bounding boxes from child nodes.
Public methodDumpNodeStatistics Writes string that describes the details about this MeshOctree to the console (when the application is debugged in Visual Studio the result is written to Output window or Immediate Window if started from there; in Rider the result is written to Debug Output window).
Public methodGetAllHitResults HitTest method executes a ray hit test on this octree and returns a list of RayHitTestResult with all the hit results sorted from the closest to the farthest. If no triangle is hit, an empty list is returned. To get only the closest hit results call method.
Public methodGetNodesCountInLevel GetNodesCountInLevel is a diagnostics method and returns the number of nodes (MeshOctreeNode objects) in the specified node level.
Public methodGetNodeStatistics GetNodeStatistics is a diagnostics method and returns a string that describes the details about this MeshOctree.
Public methodGetTrianglesCountInLevel GetTrianglesCountInLevel is a diagnostics method and returns the number of triangles in the specified node level.
Public methodHitTest HitTest method executes a ray hit test on this octree and returns a RayHitTestResult with the closest triangle in this octree that is hit by the specified ray. If not triangle is hit, null is returned. To get all hit results call method.
Top
Fields
 NameDescription
Public fieldExpandChildBoundingBoxes ExpandChildBoundingBoxes is a float that defined how much the bounding boxes of node overlap. By default, the value is set to 0.2 - so each bounding box is extended for 20% (but it does not go out of the parent's bounding box). This way the triangles that lay on node borders will be put into the child nodes instead of having them in the parent node (there we need to do a hit test every time).
Public fieldMaxNodeLevel Number of levels used for MeshOctree - bigger number reduces the number of triangles in each node but increased the MeshOctree initialization time and used memory. Default value is 4.
Public fieldRootNode Root MeshOctreeNode
Top
Remarks

MeshOctree class organizes the triangles in 3D space into multiple levels of MeshOctreeNode objects so that the search of a triangle or check for triangle ray intersection is very efficient. Each MeshOctreeNode divide its space into 8 child MeshOctreeNode.

The number of levels (depth) is defined by the MaxNodeLevel that can be specified with the constructor. Bigger number reduces the number of triangles in each node but increased the MeshOctree initialization time and used memory.

MeshOctree objects are usually used for very efficient hit testing of meshes with many triangles. For example, when a standard hit testing is used on a 3D mesh, then the ray needs to be tested for intersection with each triangle in the mesh. Because meshes can have many triangles this can take a lot of time. When MeshOctree are used, then first the MeshOctree nodes that intersect the ray are found and then only the triangles in those nodes are checked for intersection with the ray. This massively decreases the number of required intersection tests.

See Also