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)`); api.log.emit(`regrouping ${models.length} model(s)`);
let bounds = util.bounds(models); let bounds = util.bounds(models);
let { mid} = bounds; let { mid } = bounds;
for (let m of models) { Promise.all(models.map(m => m.ungroup())).then(() => {
m.ungroup(); mesh.api.group.new(models)
} .centerModels()
mesh.api.group.new(models) .position(mid.x, mid.y, mid.z)
.centerModels() .select();
.position(mid.x, mid.y, mid.z) });
.select();
}, },
analyze(models, opt = { compound: true }) { analyze(models, opt = { compound: true }) {

View file

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

View file

@ -185,6 +185,8 @@ mesh.model = class MeshModel extends mesh.object {
geo._model_invalid = true; geo._model_invalid = true;
if (indices) geo.setIndex(new BufferAttribute(indices, 1)); if (indices) geo.setIndex(new BufferAttribute(indices, 1));
if (!normals) geo.computeVertexNormals(); if (!normals) geo.computeVertexNormals();
// allows raycasting to work
geo.computeBoundingSphere();
// persist in db so it can be restored on page load // persist in db so it can be restored on page load
mapp.db.space.put(this.id, { file: this.file, mesh: vertices }); mapp.db.space.put(this.id, { file: this.file, mesh: vertices });
// sync data to worker // sync data to worker
@ -410,15 +412,13 @@ mesh.model = class MeshModel extends mesh.object {
this.group.remove(this, { free: false }); this.group.remove(this, { free: false });
this.group = undefined; this.group = undefined;
// get current world coordinates return worker.model_duplicate({
// let { mid } = this.mesh.getBoundingBox(); matrix: this.matrix,
// let { geometry } = this.mesh; id: this.id,
// move group center back to original center opt: {}
// geometry.moveMesh(-mid.x, -mid.y, -mid.z); }).then(data => {
// geometry.computeBoundingBox(); this.reload(data);
// this.move(mid.x, mid.y, mid.z); });
return this;
} }
// remove model from group and space // remove model from group and space