BVH
Classes
Bounding Volume Hierarchy. 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 is inlined for speed. 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. 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 is inlined for speed. 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 - .data_float32 ⇒
Float32Array - .root ⇒
number - .root
- .size ⇒
number - .node_capacity ⇒
number - .node_capacity
- .isBVH :
boolean - .trim()
- .allocate_node() ⇒
number - .release_node(id)
- .node_is_leaf(id) ⇒
boolean - .node_get_user_data(id) ⇒
number - .node_set_user_data(id, value)
- .node_get_child1(id) ⇒
number - .node_set_child1(node, child1)
- .node_get_child2(id) ⇒
number - .node_set_child2(node, child2)
- .node_get_parent(id) ⇒
number - .node_set_parent(node, parent)
- .node_get_height(id) ⇒
number - .node_set_height(id, height)
- .node_get_aabb(id, result)
- .node_set_aabb(id, aabb)
- .node_move_aabb(id, aabb)
- .node_set_aabb_primitive(id, x0, y0, z0, x1, y1, z1)
- .node_get_surface_area(id) ⇒
number - .node_get_combined_surface_area(index_a, index_b) ⇒
number - .node_set_combined_aabb(destination, index_a, index_b)
- .insert_leaf(leaf) ⇒
void - .remove_leaf(leaf) ⇒
void - .node_assign_children(parent, child_1, child_2)
- .node_assign_children_only(parent, child_1, child_2)
- .release_all()
- .traverse(callback, [ctx])
- .collect_nodes_all(destination, destination_offset) ⇒
number - .swap_nodes(a, b) ⇒
boolean
- .data_buffer ⇒
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
| Param | Type |
|---|---|
| v | number |
bvH.size ⇒ number
Number of used nodes. Note that this is not the same as number of live nodes Is the same as number of live nodes if compaction was performed recently
Kind: instance property of BVH
bvH.node_capacity ⇒ number
Kind: instance property of BVH
bvH.node_capacity
Kind: instance property of BVH
| Param | Type |
|---|---|
| v | number |
bvH.isBVH : boolean
Used for type checking
Kind: instance property of BVH
Read only: true
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
| Param | Type |
|---|---|
| id | number |
bvH.node_is_leaf(id) ⇒ boolean
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
bvH.node_get_user_data(id) ⇒ number
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
bvH.node_set_user_data(id, value)
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
| value | number |
bvH.node_get_child1(id) ⇒ number
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
bvH.node_set_child1(node, child1)
Kind: instance method of BVH
| Param | Type |
|---|---|
| node | number |
| child1 | number |
bvH.node_get_child2(id) ⇒ number
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
bvH.node_set_child2(node, child2)
Kind: instance method of BVH
| Param | Type |
|---|---|
| node | number |
| child2 | number |
bvH.node_get_parent(id) ⇒ number
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
bvH.node_set_parent(node, parent)
Kind: instance method of BVH
| Param | Type |
|---|---|
| node | number |
| parent | number |
bvH.node_get_height(id) ⇒ number
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
bvH.node_set_height(id, height)
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
| height | number |
bvH.node_get_aabb(id, result)
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
| result | Array.<number> | Float32Array |
bvH.node_set_aabb(id, aabb)
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
| aabb | Array.<number> | ArrayLike.<number> | AABB3 |
bvH.node_move_aabb(id, aabb)
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
| aabb | Array.<number> |
bvH.node_set_aabb_primitive(id, x0, y0, z0, x1, y1, z1)
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
| x0 | number |
| y0 | number |
| z0 | number |
| x1 | number |
| y1 | number |
| z1 | number |
bvH.node_get_surface_area(id) ⇒ number
Kind: instance method of BVH
| Param | Type |
|---|---|
| id | number |
bvH.node_get_combined_surface_area(index_a, index_b) ⇒ number
Kind: instance method of BVH
| Param | Type |
|---|---|
| index_a | number |
| index_b | number |
bvH.node_set_combined_aabb(destination, index_a, index_b)
Kind: instance method of BVH
| Param | Type |
|---|---|
| destination | number |
| index_a | number |
| index_b | number |
bvH.insert_leaf(leaf) ⇒ void
Kind: instance method of BVH
| Param | Type |
|---|---|
| leaf | number |
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
| Param | Type |
|---|---|
| leaf | number |
bvH.node_assign_children(parent, child_1, child_2)
Utility method for assigning both children at once Children must be valid nodes (non-null)
Kind: instance method of BVH
| Param | Type |
|---|---|
| parent | number |
| child_1 | number |
| child_2 | number |
bvH.node_assign_children_only(parent, child_1, child_2)
Utility method for assigning both children at once Children must be valid nodes (non-null) Does not update bounds.
Kind: instance method of BVH
| Param | Type |
|---|---|
| parent | number |
| child_1 | number |
| child_2 | number |
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
| Param | Type |
|---|---|
| callback | function |
| [ctx] | * |
bvH.collect_nodes_all(destination, destination_offset) ⇒ number
Kind: instance method of BVH
| Param | Type |
|---|---|
| destination | Array.<number> |
| destination_offset | number |
bvH.swap_nodes(a, b) ⇒ boolean
Swap two nodes in memory
Kind: instance method of BVH
| Param | Type |
|---|---|
| a | number |
| b | number |
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