@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
57 lines (43 loc) • 969 B
JavaScript
import { Box3 } from "three";
/**
*
* @param {Object3D} object
* @param {AABB3} result
*/
export function three_computeObjectBoundingBox(object, result) {
const _sX = object.scale.x;
const _sY = object.scale.y;
const _sZ = object.scale.z;
object.scale.set(1, 1, 1);
const box3 = new Box3();
box3.expandByObject(object);
object.scale.set(_sX, _sY, _sZ);
const min = box3.min;
const max = box3.max;
let x0 = min.x;
let y0 = min.y;
let z0 = min.z;
let x1 = max.x;
let y1 = max.y;
let z1 = max.z;
// validate and fix missing bounds
if (x1 < x0) {
// no bounds
x0 = 0;
x1 = 0;
}
if (y1 < y0) {
// no bounds
y0 = 0;
y1 = 0;
}
if (z1 < z0) {
// no bounds
z0 = 0;
z1 = 0;
}
result.setBounds(
x0, y0, z0,
x1, y1, z1
);
}