fix/simplify matrix updates

This commit is contained in:
Stewart Allen 2022-01-09 23:58:59 -05:00
commit c487faacf6
3 changed files with 14 additions and 49 deletions

View file

@ -227,7 +227,6 @@ mesh.model = class MeshModel extends mesh.object {
} }
updateBoundsBox() { updateBoundsBox() {
this.updateMatrix();
mesh.util.defer(this.group.deferUBB); mesh.util.defer(this.group.deferUBB);
} }

View file

@ -54,10 +54,6 @@ mesh.object = class MeshObject {
publish.destroy(this.id); publish.destroy(this.id);
} }
updateMatrix() {
publish.matrix({ id: this.id, matrix: this.object.matrix });
}
applyMatrix(elements) { applyMatrix(elements) {
if (elements) { if (elements) {
this.object.applyMatrix4(new THREE.Matrix4().fromArray(elements)); this.object.applyMatrix4(new THREE.Matrix4().fromArray(elements));
@ -90,11 +86,7 @@ mesh.object = class MeshObject {
move(x = 0, y = 0, z = 0) { move(x = 0, y = 0, z = 0) {
let pos = this.position(); let pos = this.position();
pos.set(pos.x + x, pos.y + y, pos.z + z); return this.position(pos.x + x, pos.y + y, pos.z + z);
this.updateBoundsBox();
space.update();
moto.client.fn.object_move({id: this.id, x, y, z});
return this;
} }
scale() { scale() {
@ -103,19 +95,16 @@ mesh.object = class MeshObject {
return scale; return scale;
} }
scale.set(...arguments); scale.set(...arguments);
this.updateBoundsBox(); this.matrixChanged();
let [ x, y, z ] = arguments; let [ x, y, z ] = arguments;
moto.client.fn.object_scale({id: this.id, x, y, z}); moto.client.fn.object_scale({id: this.id, x, y, z});
space.update();
} }
rotate(x = 0, y = 0, z = 0) { rotate(x = 0, y = 0, z = 0) {
if (x) this.object.rotateOnWorldAxis(new THREE.Vector3(1,0,0), x); 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 (y) this.object.rotateOnWorldAxis(new THREE.Vector3(0,1,0), y);
if (z) this.object.rotateOnWorldAxis(new THREE.Vector3(0,0,1), z); if (z) this.object.rotateOnWorldAxis(new THREE.Vector3(0,0,1), z);
this.updateBoundsBox(); this.matrixChanged();
worker.object_rotate({id: this.id, x, y, z});
space.update();
return this; return this;
} }
@ -124,20 +113,12 @@ mesh.object = class MeshObject {
if (arguments.length === 0) { if (arguments.length === 0) {
return rotation; return rotation;
} }
rotation.set(...arguments); return this.qrotation(new THREE.Quaternion().setFromEuler(new THREE.Euler(...arguments)));
this.updateBoundsBox();
let { x, y, z } = rotation;
worker.object_rotation({id: this.id, x, y, z});
space.update();
return this;
} }
qrotation(quaternion) { qrotation(quaternion) {
this.object.setRotationFromQuaternion(quaternion); this.object.setRotationFromQuaternion(quaternion);
this.updateBoundsBox(); this.matrixChanged();
let { w, x, y, z } = quaternion;
worker.object_qrotation({id: this.id, w, x, y, z});
space.update();
return this; return this;
} }
@ -147,9 +128,8 @@ mesh.object = class MeshObject {
return pos; return pos;
} }
pos.set(...arguments); pos.set(...arguments);
let [ x, y, z ] = arguments; this.matrixChanged();
worker.object_position({id: this.id, x, y, z}); return this;
space.update();
} }
showBounds(bool) { showBounds(bool) {
@ -161,7 +141,6 @@ mesh.object = class MeshObject {
} }
updateBoundsBox() { updateBoundsBox() {
this.updateMatrix();
let helper = this._boundsBox; let helper = this._boundsBox;
let world = space.world; let world = space.world;
if (helper) { if (helper) {
@ -177,6 +156,13 @@ mesh.object = class MeshObject {
world.add(helper); world.add(helper);
} }
} }
matrixChanged() {
this.object.updateMatrix();
this.updateBoundsBox();
space.update();
publish.matrix({ id: this.id, matrix: this.object.matrix });
}
}; };
})(); })();

View file

@ -94,26 +94,6 @@ let object = {
destroy(data) { destroy(data) {
delete cache[data.id]; delete cache[data.id];
},
move(data) {
let { id, x, y, z } = data;
},
position(data) {
let { id, x, y, z } = data;
},
rotate(data) {
let { id, x, y, z } = data;
},
rotation(data) {
let { id, x, y, z } = data;
},
qrotation(data) {
let { id, w, x, y, z } = data;
} }
}; };