build method

BVHNode build(
  1. double branchingFactor,
  2. double primitivesPerNode,
  3. double maxDepth,
  4. double currentDepth,
)

Builds this BVH node. That means the respective bounding volume is computed and the node's primitives are distributed under child nodes. This only happens if the maximum hierarchical depth is not yet reached and the node does contain enough primitives required for a split.

Implementation

/// is computed and the node's primitives are distributed under child nodes.
/// This only happens if the maximum hierarchical depth is not yet reached and
/// the node does contain enough primitives required for a split.
BVHNode build(double branchingFactor, double primitivesPerNode, double maxDepth, double currentDepth ) {
	computeBoundingVolume();

	// check depth and primitive count
	final primitiveCount = primitives.length / 9;
	final newPrimitiveCount = ( primitiveCount / branchingFactor ).floor();

	if ( ( currentDepth <= maxDepth ) && ( newPrimitiveCount >= primitivesPerNode ) ) {
		// split (distribute primitives on child BVH nodes)
		split( branchingFactor );

		// proceed with build on the next hierarchy level
		for ( int i = 0; i < branchingFactor; i ++ ) {
			children[ i ].build( branchingFactor, primitivesPerNode, maxDepth, currentDepth + 1 );
		}
	}

	return this;
}