BVH2D
Classes
2D Bounding Volume Hierarchy implementation. Based on BVH (3D) implementation
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
BVH2D
2D Bounding Volume Hierarchy implementation. Based on BVH (3D) implementation
Kind: global class
- BVH2D
- .root ⇒
number - .node_capacity ⇒
number - .node_capacity
- .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 - .release_all()
- .traverse(callback, [ctx])
- .collect_nodes_all(destination, destination_offset) ⇒
number - .swap_nodes(a, b) ⇒
boolean
- .root ⇒
bvH2D.root ⇒ number
Kind: instance property of BVH2D
bvH2D.node_capacity ⇒ number
Kind: instance property of BVH2D
bvH2D.node_capacity
Kind: instance property of BVH2D
| Param | Type |
|---|---|
| v | number |
bvH2D.trim()
Trim allocated memory region to only contain allocated nodes
Kind: instance method of BVH2D
bvH2D.allocate_node() ⇒ number
Kind: instance method of BVH2D
bvH2D.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 BVH2D
| Param | Type |
|---|---|
| id | number |
bvH2D.node_is_leaf(id) ⇒ boolean
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
bvH2D.node_get_user_data(id) ⇒ number
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
bvH2D.node_set_user_data(id, value)
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
| value | number |
bvH2D.node_get_child1(id) ⇒ number
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
bvH2D.node_set_child1(node, child1)
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| node | number |
| child1 | number |
bvH2D.node_get_child2(id) ⇒ number
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
bvH2D.node_set_child2(node, child2)
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| node | number |
| child2 | number |
bvH2D.node_get_parent(id) ⇒ number
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
bvH2D.node_set_parent(node, parent)
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| node | number |
| parent | number |
bvH2D.node_get_height(id) ⇒ number
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
bvH2D.node_set_height(id, height)
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
| height | number |
bvH2D.node_get_aabb(id, result)
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
| result | Array.<number> | Float32Array |
bvH2D.node_set_aabb(id, aabb)
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
| aabb | Array.<number> | ArrayLike.<number> |
bvH2D.node_move_aabb(id, aabb)
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
| aabb | Array.<number> |
bvH2D.node_set_aabb_primitive(id, x0, y0, z0, x1, y1, z1)
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
| x0 | number |
| y0 | number |
| z0 | number |
| x1 | number |
| y1 | number |
| z1 | number |
bvH2D.node_get_surface_area(id) ⇒ number
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| id | number |
bvH2D.node_get_combined_surface_area(index_a, index_b) ⇒ number
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| index_a | number |
| index_b | number |
bvH2D.node_set_combined_aabb(destination, index_a, index_b)
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| destination | number |
| index_a | number |
| index_b | number |
bvH2D.insert_leaf(leaf) ⇒ void
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| leaf | number |
bvH2D.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 BVH2D
| Param | Type |
|---|---|
| leaf | number |
bvH2D.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 BVH2D
bvH2D.traverse(callback, [ctx])
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| callback | function |
| [ctx] | * |
bvH2D.collect_nodes_all(destination, destination_offset) ⇒ number
Kind: instance method of BVH2D
| Param | Type |
|---|---|
| destination | Array.<number> |
| destination_offset | number |
bvH2D.swap_nodes(a, b) ⇒ boolean
Swap two nodes in memory
Kind: instance method of BVH2D
| 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