partial implementation of regrouping
This commit is contained in:
parent
fb41d6be3e
commit
646441e5e5
4 changed files with 45 additions and 17 deletions
|
|
@ -102,8 +102,13 @@ function restore_space() {
|
|||
.map(id => { return { id, md: cached[id] } })
|
||||
.filter(r => r.md) // filter cache misses
|
||||
.map(r => new mesh.model(r.md, r.id).applyMatrix(mcache[r.id]));
|
||||
mesh.api.log.emit(`restored ${models.length} model(s)`);
|
||||
mesh.api.group.new(models, id).applyMatrix(mcache[id]);
|
||||
if (models.length) {
|
||||
mesh.api.log.emit(`restored ${models.length} model(s)`);
|
||||
mesh.api.group.new(models, id).applyMatrix(mcache[id]);
|
||||
} else {
|
||||
mesh.api.log.emit(`removed empty group ${id}`);
|
||||
mesh.db.space.remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
// restore global cache only after objects are restored
|
||||
|
|
@ -292,6 +297,7 @@ function space_init(data) {
|
|||
case 'KeyW':
|
||||
return api.wireframe();
|
||||
case 'KeyG':
|
||||
if (shiftKey) return api.tool.regroup();
|
||||
return api.grid();
|
||||
case 'KeyL':
|
||||
return api.log.toggle();
|
||||
|
|
|
|||
|
|
@ -355,6 +355,23 @@ let tool = {
|
|||
tempedit.focus();
|
||||
},
|
||||
|
||||
regroup(models) {
|
||||
models = fallback(models, true);
|
||||
if (models.length === 0) {
|
||||
return;
|
||||
}
|
||||
api.log.emit(`regrouping ${models.length} model(s)`);
|
||||
let bounds = util.bounds(models);
|
||||
let { mid} = bounds;
|
||||
for (let m of models) {
|
||||
m.ungroup();
|
||||
}
|
||||
mesh.api.group.new(models)
|
||||
.centerModels()
|
||||
.position(mid.x, mid.y, mid.z)
|
||||
.select();
|
||||
},
|
||||
|
||||
analyze(models, opt = { compound: true }) {
|
||||
models = fallback(models);
|
||||
api.log.emit('analyzing mesh(es)...').pin();
|
||||
|
|
|
|||
|
|
@ -59,7 +59,8 @@ mesh.group = class MeshGroup extends mesh.object {
|
|||
}
|
||||
|
||||
// @param model {MeshModel}
|
||||
remove(model) {
|
||||
// @param free {boolean} prevent cleanup of model so it can be re-used
|
||||
remove(model, opt = { free: true }) {
|
||||
// console.log('group',this,'remove',model);
|
||||
// remove all models and group
|
||||
if (arguments.length === 0) {
|
||||
|
|
@ -75,7 +76,7 @@ mesh.group = class MeshGroup extends mesh.object {
|
|||
// trigger sync with worker
|
||||
worker.group_remove({id: this.id, model: model.id});
|
||||
// ensure worker cleanup of model
|
||||
model.remove(true);
|
||||
if (opt.free) model.remove(true);
|
||||
// auto-remove group when empty
|
||||
if (this.group3.children.length === 0) {
|
||||
mesh.api.group.remove(this);
|
||||
|
|
|
|||
|
|
@ -224,19 +224,6 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
return this.vertices / 3;
|
||||
}
|
||||
|
||||
// todo -- put model into its own group
|
||||
ungroup() {
|
||||
// get current world coordinates
|
||||
let { mid } = meh.getBoundingBox();
|
||||
// transform mesh into world coordinates
|
||||
// move mesh to origin
|
||||
// create and add to group
|
||||
// move group center back to original center
|
||||
geo.moveMesh(-mid.x, -mid.y, -mid.z);
|
||||
geo.computeBoundingBox();
|
||||
this.move(mid.x, mid.y, mid.z);
|
||||
}
|
||||
|
||||
// get, set, or toggle visibility of model and wireframe
|
||||
visible(bool) {
|
||||
if (bool === undefined) {
|
||||
|
|
@ -417,6 +404,23 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
});
|
||||
}
|
||||
|
||||
// release from a group but remain in memory and storage
|
||||
// so it can be re-assigned to another group
|
||||
ungroup() {
|
||||
this.group.remove(this, { free: false });
|
||||
this.group = undefined;
|
||||
|
||||
// get current world coordinates
|
||||
// let { mid } = this.mesh.getBoundingBox();
|
||||
// let { geometry } = this.mesh;
|
||||
// move group center back to original center
|
||||
// geometry.moveMesh(-mid.x, -mid.y, -mid.z);
|
||||
// geometry.computeBoundingBox();
|
||||
// this.move(mid.x, mid.y, mid.z);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// remove model from group and space
|
||||
remove() {
|
||||
if (arguments.length === 0) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue