add model groups, async font load, array addOnce

This commit is contained in:
Stewart Allen 2021-12-29 23:52:48 -05:00
commit 5506567ecf
8 changed files with 54 additions and 28 deletions

View file

@ -25,17 +25,33 @@ let api = mesh.api = {
models: {
all: models,
add: model => {
if (!models.contains(model)) {
space.model.add(model.mesh);
models.push(model);
add: (list, group = new THREE.Group()) => {
if (!Array.isArray(list)) {
list = [ list ];
}
for (let model of list) {
models.addOnce(model);
model.group = group;
group.add(model.mesh);
}
space.world.add(group);
space.refresh();
},
remove: Array.handle(model => {
space.model.remove(model.mesh);
models.remove(model);
})
remove: list => {
if (!Array.isArray(list)) {
list = [ list ];
}
for (let model of list) {
if (models.remove(model)) {
model.group.remove(model.mesh);
if (model.group.children.length === 0) {
space.world.remove(model.group);
}
space.refresh();
}
}
}
}
};

View file

@ -51,6 +51,17 @@ mesh.model = class MeshModel {
meh.renderOrder = 1;
return meh;
}
get group() {
return this._group;
}
set group(gv) {
if (this._group && this._group !== gv) {
throw "model cannot change groups";
}
this._group = gv;
}
};
})();