@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
42 lines (32 loc) • 1.02 kB
JavaScript
import { ShadedGeometry } from "../../graphics/ecs/mesh-v2/ShadedGeometry.js";
import { AABB3 } from "../../../core/geom/3d/aabb/AABB3.js";
const scratch_aabb3 = new AABB3();
/**
*
* @param {AABB3} out
* @param {EntityNode} root
*/
export function entity_node_expand_bounding_box_to_fit(out, root) {
const sg = root.entity.getComponent(ShadedGeometry);
if (sg !== null) {
sg.getBoundingBox(scratch_aabb3);
out.expandToFit(scratch_aabb3);
}
const children = root.children;
const child_count = children.length;
for (let i = 0; i < child_count; i++) {
const child = children[i];
entity_node_expand_bounding_box_to_fit(out, child);
}
}
/**
*
* @param {AABB3} out
* @param {EntityNode} root
*/
export function entity_node_compute_bounding_box(out, root) {
// init bounds
out.setNegativelyInfiniteBounds();
// expand bounds to fit the tree
entity_node_expand_bounding_box_to_fit(out, root);
}