fix model center on regroup, duplicate relative to group dimensions
This commit is contained in:
parent
d413861451
commit
0da9019acb
3 changed files with 9 additions and 5 deletions
|
|
@ -1154,7 +1154,11 @@ const tool = {
|
|||
models = fallback(models, true);
|
||||
if (models.length) {
|
||||
log(`regrouping ${models.length} model(s)`);
|
||||
return mesh.api.group.new(models.map(m => m.ungroup()));
|
||||
let group = mesh.api.group.new(models.map(m => m.ungroup()));
|
||||
let bounds = group.bounds;
|
||||
models.forEach(m => m.centerTo(bounds.mid));
|
||||
console.log({ bounds, group, models });
|
||||
return group;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -925,7 +925,7 @@ function ui_build() {
|
|||
let g_pos = util.average(s_grp.map(g => g.object.position));
|
||||
let g_rot = util.average(s_grp.map(g => g.object.rotation));
|
||||
let g_id = s_grp.map(g => g.id).join(' ');
|
||||
let h_grp = sblock('orient', g_id, grid3(
|
||||
let h_grp = sblock('move', g_id, grid3(
|
||||
util.extract(g_pos, map),
|
||||
util.extract(g_rot).map(r => (r * rad).round(2).toFixed(map.fixed)),
|
||||
und, und, 'group'
|
||||
|
|
|
|||
|
|
@ -245,7 +245,6 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
// moves mesh object center to target
|
||||
centerTo(to) {
|
||||
this.log('model-centerto', to);
|
||||
let pos = this.position();
|
||||
let { mid } = this.bounds;
|
||||
let abs = this.world_bounds.mid;
|
||||
this.translate(
|
||||
|
|
@ -291,6 +290,7 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
if (opt.x) return this.reload(data);
|
||||
let model = new mesh.model({ file: `${this.file}`, mesh: data });
|
||||
let group = opt.group || mesh.api.group.new();
|
||||
let bounds = this.group.bounds;
|
||||
group.add(model);
|
||||
model.position(pos.x, pos.y, pos.z);
|
||||
model.wireframe(this.wireframe());
|
||||
|
|
@ -298,9 +298,9 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
api.selection.add(model);
|
||||
}
|
||||
if (opt.mirror) {
|
||||
group.move(0, 0, group.bounds.dim.z);
|
||||
group.move(0, 0, bounds.dim.z);
|
||||
} else if (opt.shift) {
|
||||
group.move(group.bounds.dim.x, 0, 0);
|
||||
group.move(bounds.dim.x, 0, 0);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue