Skip to main content

BVH

Classes

BVH

Bounding Volume Hierarchy implementation. Stores unsigned integer values at leaves, these are typically IDs or Index values. Highly optimized both in terms of memory usage and CPU. Most of the code inlined. No allocation are performed during usage (except for growing the tree capacity). RAM usage: 40 bytes per node. Compared with V8s per-object allocation size of 80 bytes

Constants

COLUMN_USER_DATA : number

A non-leaf node have both CHILD_1 and CHILD_2 set, when CHILD_1 is not set - it's a leaf node So we can utilize space of CHILD_2 to store USER_DATA, hence there is overlap in schema

NULL_NODE : number
CAPACITY_GROW_MULTIPLIER : number
CAPACITY_GROW_MIN_STEP : number
ELEMENT_WORD_COUNT : number

How many words are used for a single NODE in the tree One "word" is 4 bytes for the sake of alignment

INITIAL_CAPACITY : number

How many nodes can be stored in the newly constructed tree before allocation needs to take place

NODE_CAPACITY_LIMIT : number

Tree can not contain more than this number of nodes

BVH

Bounding Volume Hierarchy implementation. Stores unsigned integer values at leaves, these are typically IDs or Index values. Highly optimized both in terms of memory usage and CPU. Most of the code inlined. No allocation are performed during usage (except for growing the tree capacity). RAM usage: 40 bytes per node. Compared with V8s per-object allocation size of 80 bytes

Kind: global class
See: https://blog.dashlane.com/how-is-data-stored-in-v8-js-engine-memory

bvH.data_buffer ⇒ ArrayBuffer

Access raw data Useful for serialization If you intend to modify the data directly - make sure you fully understand the implications of doing so

Kind: instance property of BVH

bvH.data_float32 ⇒ Float32Array

Kind: instance property of BVH

bvH.root ⇒ number

Kind: instance property of BVH

bvH.root

Make sure you understand what you're doing before using this

Kind: instance property of BVH

ParamType
vnumber

bvH.node_capacity ⇒ number

Kind: instance property of BVH

bvH.node_capacity

Kind: instance property of BVH

ParamType
vnumber

bvH.trim()

Trim allocated memory region to only contain allocated nodes

Kind: instance method of BVH

bvH.allocate_node() ⇒ number

Kind: instance method of BVH

bvH.release_node(id)

Release memory used by the node back into the pool NOTE: Make sure that the node is not "live" (not attached to the hierarchy), otherwise this operation may corrupt the tree

Kind: instance method of BVH

ParamType
idnumber

bvH.node_is_leaf(id) ⇒ boolean

Kind: instance method of BVH

ParamType
idnumber

bvH.node_get_user_data(id) ⇒ number

Kind: instance method of BVH

ParamType
idnumber

bvH.node_set_user_data(id, value)

Kind: instance method of BVH

ParamType
idnumber
valuenumber

bvH.node_get_child1(id) ⇒ number

Kind: instance method of BVH

ParamType
idnumber

bvH.node_set_child1(node, child1)

Kind: instance method of BVH

ParamType
nodenumber
child1number

bvH.node_get_child2(id) ⇒ number

Kind: instance method of BVH

ParamType
idnumber

bvH.node_set_child2(node, child2)

Kind: instance method of BVH

ParamType
nodenumber
child2number

bvH.node_get_parent(id) ⇒ number

Kind: instance method of BVH

ParamType
idnumber

bvH.node_set_parent(node, parent)

Kind: instance method of BVH

ParamType
nodenumber
parentnumber

bvH.node_get_height(id) ⇒ number

Kind: instance method of BVH

ParamType
idnumber

bvH.node_set_height(id, height)

Kind: instance method of BVH

ParamType
idnumber
heightnumber

bvH.node_get_aabb(id, result)

Kind: instance method of BVH

ParamType
idnumber
resultArray.<number> | Float32Array

bvH.node_set_aabb(id, aabb)

Kind: instance method of BVH

ParamType
idnumber
aabbArray.<number> | ArrayLike.<number> | AABB3

bvH.node_move_aabb(id, aabb)

Kind: instance method of BVH

ParamType
idnumber
aabbArray.<number>

bvH.node_set_aabb_primitive(id, x0, y0, z0, x1, y1, z1)

Kind: instance method of BVH

ParamType
idnumber
x0number
y0number
z0number
x1number
y1number
z1number

bvH.node_get_surface_area(id) ⇒ number

Kind: instance method of BVH

ParamType
idnumber

bvH.node_get_combined_surface_area(index_a, index_b) ⇒ number

Kind: instance method of BVH

ParamType
index_anumber
index_bnumber

bvH.node_set_combined_aabb(destination, index_a, index_b)

Kind: instance method of BVH

ParamType
destinationnumber
index_anumber
index_bnumber

bvH.insert_leaf(leaf) ⇒ void

Kind: instance method of BVH

ParamType
leafnumber

bvH.remove_leaf(leaf) ⇒ void

NOTE: Leaf node is not released, make sure to call #release_node separately when you no longer need the leaf node

Kind: instance method of BVH

ParamType
leafnumber

bvH.release_all()

Release all nodes, this essentially resets the tree to empty state NOTE: For performance reasons, released memory is not reset, this means that attempting to access cleared nodes' memory will yield garbage data

Kind: instance method of BVH

bvH.traverse(callback, [ctx])

Kind: instance method of BVH

ParamType
callbackfunction
[ctx]*

bvH.collect_nodes_all(destination, destination_offset) ⇒ number

Kind: instance method of BVH

ParamType
destinationArray.<number>
destination_offsetnumber

bvH.swap_nodes(a, b) ⇒ boolean

Swap two nodes in memory

Kind: instance method of BVH

ParamType
anumber
bnumber

COLUMN_USER_DATA : number

A non-leaf node have both CHILD_1 and CHILD_2 set, when CHILD_1 is not set - it's a leaf node So we can utilize space of CHILD_2 to store USER_DATA, hence there is overlap in schema

Kind: global constant
Read only: true

NULL_NODE : number

Kind: global constant

CAPACITY_GROW_MULTIPLIER : number

Kind: global constant
Read only: true

CAPACITY_GROW_MIN_STEP : number

Kind: global constant
Read only: true

ELEMENT_WORD_COUNT : number

How many words are used for a single NODE in the tree One "word" is 4 bytes for the sake of alignment

Kind: global constant
Read only: true

INITIAL_CAPACITY : number

How many nodes can be stored in the newly constructed tree before allocation needs to take place

Kind: global constant
Read only: true

NODE_CAPACITY_LIMIT : number

Tree can not contain more than this number of nodes

Kind: global constant