normalize util.bound to Box3 extensions

This commit is contained in:
Stewart Allen 2022-01-10 20:08:49 -05:00
commit b8877f1225
4 changed files with 7 additions and 8 deletions

View file

@ -75,9 +75,7 @@
this.boundingBox = null;
this.computeBoundingBox();
}
let bbox = this.boundingBox;
// bbox.dim = bbox.max.clone().sub(bbox.min);
return bbox;
return this.boundingBox;
};
BP.moveMesh = function(x = 0, y = 0, z = 0) {

View file

@ -396,12 +396,12 @@ let util = mesh.util = {
z: box.max.y
}
};
bnd.size = {
bnd.size = bnd.dim = {
x: bnd.max.x - bnd.min.x,
y: bnd.max.y - bnd.min.y,
z: bnd.max.z - bnd.min.z
};
bnd.center = {
bnd.center = bnd.mid = {
x: (bnd.max.x + bnd.min.x) / 2,
y: -(bnd.max.y + bnd.min.y) / 2,
z: (bnd.max.z + bnd.min.z) / 2

View file

@ -103,6 +103,7 @@ mesh.model = class MeshModel extends mesh.object {
meh.castShadow = true;
meh.renderOrder = 1;
// center vertices then restore mesh object position
// still this doesn't work. scale broken for bounding boxes
// let mid = meh.getBoundingBox().mid;
// geo.moveMesh(-mid.x, -mid.y, -mid.x);
// this.move(mid.x, mid.y, mid.x);

View file

@ -145,10 +145,10 @@ mesh.object = class MeshObject {
world.remove(helper);
}
if (this._showBounds) {
let { center, size } = this.bounds;
let { mid, dim } = this.bounds;
let b3 = new THREE.Box3().setFromCenterAndSize(
new THREE.Vector3(center.x, center.y, center.z),
new THREE.Vector3(size.x, size.y, size.z)
new THREE.Vector3(mid.x, mid.y, mid.z),
new THREE.Vector3(dim.x, dim.y, dim.z)
);
let helper = this._boundsBox = new THREE.Box3Helper(b3, 0x555555);
world.add(helper);