Class: OctreeNode

PD. OctreeNode

Implements a simple spatial subdivision method to make the ray tracing of model triangles more efficient.

An octree manages its structure to optimize for spatial searches. Unlike linear data structures such as arrays or dictionaries, an octree will iteratively subdivide itself into eight smaller octants when it contains more than eight triangles, thereby adding an additional level to the spatial tree.

Octrees can be used to very quickly find all the elements/triangles that occupy a specific position or volume of space.

This class is derived and adapted from the THREE.Octree addon.


new OctreeNode( [box])

Create a new Octree node.

Parameters:
Name Type Argument Description
box THREE.Box3 <optional>

An optional bounding box for this octree, defaults to undefined.

Author:
  • drajmarsh

Members


:THREE.Box|null

box

The bounding extents of this spatial node.

Type
  • THREE.Box | null

:Array

subTrees

Stores any subtrees within this spatial node.

Type
  • Array

:Array

triangles

Stores the triangles at this spatial node.

Type
  • Array

Methods


getCapsuleTriangles(capsule, triangles)

Collects all the triangles from the subtrees intersected by the given capsule.

The aim of this method is to reduce the number of triangle intersection tests to only those that the capsule has any possibility of intersecting. Thus, you only need to test those that are added to the triangles array.

Parameters:
Name Type Description
capsule PD.Capsule

The capsule to intersect the octree with.

triangles Array

The array to add test triangles to.

Returns:

Returns the triangles array.

Type
Array

getIntersectedNodes(ray, nodes)

Collects all nodes from the subtrees intersected by the given ray.

The aim of this method is to reduce the number of node/triangle intersection tests to only those that the ray has any possibility of intersecting. Thus, you only need to test the triangles within the nodes added to the array.

Parameters:
Name Type Description
ray THREE.Ray

The ray to intersect the octree with.

nodes Array

An array to add intersected tree nodes to.

Returns:

Returns the triangles array.

Type
Array

getRayTriangles(ray, triangles)

Collects all the triangles from the subtrees intersected by the given ray.

The aim of this method is to reduce the number of triangle intersection tests to only those that the ray has any possibility of intersecting. Thus, you only need to test those that are added to the triangles array.

Parameters:
Name Type Description
ray THREE.Ray

The ray to intersect the octree with.

triangles Array

An array to add test triangles to.

Returns:

Returns the triangles array.

Type
Array

getSphereTriangles(sphere, triangles)

Collects all the triangles from the subtrees intersected by the given sphere.

The aim of this method is to reduce the number of triangle intersection tests to only those that the sphere has any possibility of intersecting. Thus, you only need to test those that are added to the triangles array.

Parameters:
Name Type Description
sphere THREE.Sphere

The sphere to intersect the octree with.

triangles Array

The array to add test triangles to.

Returns:

Returns the triangles array.

Type
Array