proper fix for regrouping

This commit is contained in:
Stewart Allen 2022-01-20 21:53:06 -05:00
commit 37f23fc153
3 changed files with 17 additions and 17 deletions

View file

@ -362,14 +362,13 @@ let tool = {
}
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();
let { mid } = bounds;
Promise.all(models.map(m => m.ungroup())).then(() => {
mesh.api.group.new(models)
.centerModels()
.position(mid.x, mid.y, mid.z)
.select();
});
},
analyze(models, opt = { compound: true }) {

View file

@ -277,6 +277,7 @@ function ui_build() {
h.div({ _: "edit", class: "head" }),
// h.div({ class: "vsep" }),
h.button({ _: 'duplicate', onclick: tool.duplicate }),
h.button({ _: '(re)group', onclick: tool.regroup }),
h.button({ _: 'merge', onclick: tool.merge }),
h.button({ _: 'mirror', onclick: tool.mirror }),
h.button({ _: 'split', onclick: call.edit_split }),

View file

@ -185,6 +185,8 @@ mesh.model = class MeshModel extends mesh.object {
geo._model_invalid = true;
if (indices) geo.setIndex(new BufferAttribute(indices, 1));
if (!normals) geo.computeVertexNormals();
// allows raycasting to work
geo.computeBoundingSphere();
// persist in db so it can be restored on page load
mapp.db.space.put(this.id, { file: this.file, mesh: vertices });
// sync data to worker
@ -410,15 +412,13 @@ mesh.model = class MeshModel extends mesh.object {
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;
return worker.model_duplicate({
matrix: this.matrix,
id: this.id,
opt: {}
}).then(data => {
this.reload(data);
});
}
// remove model from group and space