compact THREE references

This commit is contained in:
Stewart Allen 2022-01-12 11:46:10 -05:00
commit e258e3d916
6 changed files with 52 additions and 41 deletions

View file

@ -18,6 +18,8 @@ if (mesh.object) return;
let space = moto.Space;
let worker = moto.client.fn;
let { Matrix4, Vector3, Box3, Box3Helper, Quaternion, Euler } = THREE;
// broker updates generated by objects
let publish = {
matrix: gapp.broker.bind("object_matrix"),
@ -57,7 +59,7 @@ mesh.object = class MeshObject {
applyMatrix(elements) {
if (elements) {
this.object.applyMatrix4(new THREE.Matrix4().fromArray(elements));
this.object.applyMatrix4(new Matrix4().fromArray(elements));
}
return this;
}
@ -122,9 +124,9 @@ mesh.object = class MeshObject {
}
rotate(x = 0, y = 0, z = 0) {
if (x) this.object.rotateOnWorldAxis(new THREE.Vector3(1,0,0), x);
if (y) this.object.rotateOnWorldAxis(new THREE.Vector3(0,1,0), y);
if (z) this.object.rotateOnWorldAxis(new THREE.Vector3(0,0,1), z);
if (x) this.object.rotateOnWorldAxis(new Vector3(1,0,0), x);
if (y) this.object.rotateOnWorldAxis(new Vector3(0,1,0), y);
if (z) this.object.rotateOnWorldAxis(new Vector3(0,0,1), z);
this.matrixChanged();
return this;
}
@ -134,7 +136,7 @@ mesh.object = class MeshObject {
if (arguments.length === 0) {
return rotation;
}
return this.qrotation(new THREE.Quaternion().setFromEuler(new THREE.Euler(...arguments)));
return this.qrotation(new Quaternion().setFromEuler(new Euler(...arguments)));
}
qrotation(quaternion) {
@ -173,11 +175,11 @@ mesh.object = class MeshObject {
}
if (this._showBounds) {
let { mid, dim } = this.bounds;
let b3 = new THREE.Box3().setFromCenterAndSize(
new THREE.Vector3(mid.x, mid.y, mid.z),
new THREE.Vector3(dim.x, dim.y, dim.z)
let b3 = new Box3().setFromCenterAndSize(
new Vector3(mid.x, mid.y, mid.z),
new Vector3(dim.x, dim.y, dim.z)
);
let helper = this._boundsBox = new THREE.Box3Helper(b3, 0x555555);
let helper = this._boundsBox = new Box3Helper(b3, 0x555555);
world.add(helper);
return true;
}