persist object scale / rotation / position

This commit is contained in:
Stewart Allen 2022-01-09 21:05:14 -05:00
commit 55b59d9cb1
7 changed files with 81 additions and 22 deletions

View file

@ -7,6 +7,7 @@
gapp.register("mesh.object", [
"add.three", // dep: add.three
"moto.license", // dep: moto.license
"moto.broker", // dep: moto.broker
"mesh.api", // dep: mesh.api
]);
@ -16,6 +17,12 @@ if (mesh.object) return;
let space = moto.Space;
let worker = moto.client.fn;
// broker updates generated by objects
let publish = {
matrix: gapp.broker.bind("object_matrix"),
destroy: gapp.broker.bind("object_destroy"),
};
mesh.object = class MeshObject {
constructor(id) {
@ -37,8 +44,30 @@ mesh.object = class MeshObject {
return mesh.util.bounds(this.object);
}
// manage lifecycle with worker, mesh app caches, etc
destroy() {
// update worker state
worker.object_destroy({id: this.id});
// update object store
mesh.db.space.remove(this.id);
// main app cache workspace updates
publish.destroy(this.id);
}
updateMatrix() {
publish.matrix({ id: this.id, matrix: this.object.matrix });
}
applyMatrix(elements) {
if (elements) {
this.object.applyMatrix4(new THREE.Matrix4().fromArray(elements));
}
return this;
}
focus() {
mesh.api.focus(this.object);
return this;
}
floor() {
@ -132,6 +161,7 @@ mesh.object = class MeshObject {
}
updateBoundsBox() {
this.updateMatrix();
let helper = this._boundsBox;
let world = space.world;
if (helper) {