add simple mesh/group list

This commit is contained in:
Stewart Allen 2022-01-02 16:30:05 -05:00
commit 930e591c44
7 changed files with 149 additions and 29 deletions

View file

@ -50,6 +50,10 @@ let selection = {
return mdl;
},
contains(object) {
return selected.contains(object);
},
// @param group {MeshObject[]}
set(objects) {
selected = objects;
@ -82,6 +86,9 @@ let selection = {
for (let group of groups) {
group.material(mesh.material.unselected);
}
// prevent selection of model and its group
let mgsel = selected.filter(s => s instanceof mesh.model).map(m => m.group);
selected = selected.filter(sel => !mgsel.contains(sel));
for (let object of selected) {
object.material(mesh.material.selected);
}

View file

@ -8,6 +8,7 @@ gapp.register("mesh.group", [
"add.array", // dep: add.array
"add.three", // dep: add.three
"moto.license", // dep: moto.license
"moto.broker", // dep: moto.broker
"mesh.object", // dep: mesh.object
"mesh.model", // dep: mesh.model
"mesh.api", // dep: mesh.api
@ -16,12 +17,15 @@ gapp.register("mesh.group", [
let mesh = self.mesh = self.mesh || {};
if (mesh.group) return;
let broker = gapp.broker;
let call = broker.send;
let space = moto.Space;
let worker = moto.client.fn;
mesh.group = class MeshGroup extends mesh.object {
// @param group {mesh.model[]}
// @param group {MeshModel[]}
constructor(models = []) {
super();
this.group = new THREE.Group();
@ -45,6 +49,7 @@ mesh.group = class MeshGroup extends mesh.object {
this.models.addOnce(model);
this.group.add(model.mesh);
space.update();
call.model_add({model, group:this});
worker.group_add({id: this.id, model:model.id});
return this;
}
@ -61,6 +66,8 @@ mesh.group = class MeshGroup extends mesh.object {
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});
model.remove(true);

View file

@ -18,7 +18,7 @@ gapp.finalize("mesh.work", [
]);
// compensation for space/world/platform rotation
let space_rotation = new THREE.Matrix4().makeRotationX(Math.PI / 2);
let core_matrix = new THREE.Matrix4().makeRotationX(Math.PI / 2);
let { client, worker } = moto;
let cache = {};
@ -38,14 +38,14 @@ let model = {
let geo = new THREE.BufferGeometry();
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
geo.computeVertexNormals();
cacheUpdate(id, { name, geo });
cacheUpdate(id, { name, geo, matrix: core_matrix.clone() });
},
debug(data) {
let { matrix, id } = data;
let rec = cache[id];
let geo = rec.geo.clone();
let m4 = space_rotation.clone().multiply( new THREE.Matrix4().fromArray(matrix) );
let m4 = core_matrix.clone().multiply( new THREE.Matrix4().fromArray(matrix) );
geo.applyMatrix4(m4);
// for debugging state / matrix ops
return geo.attributes.position.array;
@ -59,11 +59,6 @@ let group = {
remove(data) {
let { id, model } = data;
},
create(data) {
let { id, type } = data;
cache[id] = { id, type };
}
};
@ -78,23 +73,23 @@ let object = {
},
move(data) {
let { id, type, x, y, z } = data;
let { id, x, y, z } = data;
},
position(data) {
let { id, type, x, y, z } = data;
let { id, x, y, z } = data;
},
rotate(data) {
let { id, type, x, y, z } = data;
let { id, x, y, z } = data;
},
rotation(data) {
let { id, type, x, y, z } = data;
let { id, x, y, z } = data;
},
qrotation(data) {
let { id, type, w, x, y, z } = data;
let { id, w, x, y, z } = data;
}
};