improve indexdb promised. fix multiple spaces access. add workspace persist + restore for mesh
This commit is contained in:
parent
a5cf4a7a87
commit
96145b370b
9 changed files with 192 additions and 64 deletions
|
|
@ -26,8 +26,8 @@ let worker = moto.client.fn;
|
|||
mesh.group = class MeshGroup extends mesh.object {
|
||||
|
||||
// @param group {MeshModel[]}
|
||||
constructor(models = []) {
|
||||
super();
|
||||
constructor(models = [], id) {
|
||||
super(id);
|
||||
this.group = new THREE.Group();
|
||||
this.models = [];
|
||||
for (let model of models) {
|
||||
|
|
@ -51,11 +51,14 @@ mesh.group = class MeshGroup extends mesh.object {
|
|||
space.update();
|
||||
call.model_add({model, group:this});
|
||||
worker.group_add({id: this.id, model:model.id});
|
||||
// update data store
|
||||
mesh.db.space.put(this.id, this.models.map(m => m.id));
|
||||
return this;
|
||||
}
|
||||
|
||||
// @param model {MeshModel}
|
||||
remove(model) {
|
||||
// console.log('group',this,'remove',model);
|
||||
// remove all models and group
|
||||
if (arguments.length === 0) {
|
||||
for (let m of this.models.slice()) {
|
||||
|
|
@ -63,18 +66,24 @@ mesh.group = class MeshGroup extends mesh.object {
|
|||
}
|
||||
return;
|
||||
}
|
||||
model.group = undefined;
|
||||
this.models.remove(model);
|
||||
this.group.remove(model.mesh);
|
||||
// create message for listeners
|
||||
call.model_remove({model, group:this});
|
||||
// trigger sync with worker
|
||||
worker.group_remove({id: this.id, model:model.id});
|
||||
worker.group_remove({id: this.id, model: model.id});
|
||||
// ensure worker cleanup of model
|
||||
model.remove(true);
|
||||
// auto-remove group when empty
|
||||
if (this.group.children.length === 0) {
|
||||
mesh.api.group.remove(this);
|
||||
// update worker state
|
||||
worker.object_destroy({id: this.id});
|
||||
// update object store
|
||||
mesh.db.space.remove(this.id);
|
||||
} else {
|
||||
// update data store
|
||||
mesh.db.space.put(this.id, this.models.map(m => m.id));
|
||||
}
|
||||
space.update();
|
||||
return this;
|
||||
|
|
|
|||
Loading…
Reference in a new issue