fix split/merge. avoid mirroring cached array

This commit is contained in:
Stewart Allen 2022-01-20 00:33:42 -05:00
commit f28cd07ba1
4 changed files with 8 additions and 3 deletions

View file

@ -295,6 +295,7 @@ function space_init(data) {
case 'KeyL':
return api.log.toggle();
case 'KeyS':
if (shiftKey) return call.edit_split();
return selection.visible({toggle:true});
case 'KeyB':
return selection.boundsBox({toggle:true});

View file

@ -152,6 +152,7 @@ mesh.group = class MeshGroup extends mesh.object {
// ok, this is confusing, but necessary for now :/
setSelected() {
super.select();
return this;
}
};

View file

@ -143,10 +143,13 @@ mesh.model = class MeshModel extends mesh.object {
id: this.id,
opt
}).then(data => {
mesh.api.group.new([new mesh.model({
let group = mesh.api.group.new([new mesh.model({
file: `${this.file}`,
mesh: data
})]).setSelected();
if (opt.mirror) {
group.move(0, 0, group.bounds.dim.z);
}
});
}

View file

@ -75,13 +75,13 @@ let model = {
let { id, matrix, opt } = data;
let array = translate_encode(id, matrix);
if (opt.mirror) {
array = array.slice();
// find max z and invert z
let maxz = -Infinity;
for (let i=2, l=array.length; i<l; i += 3) {
maxz = Math.max(maxz, array[i]);
array[i] = -array[i];
}
maxz *= 2;
for (let i=0, l=array.length; i<l; i += 9) {
// swap first two vertices in face to invert normals
let v1 = array.slice(i, i+3);
@ -89,7 +89,7 @@ let model = {
array[i+j] = array[i+j+3];
array[i+j+3] = v1[j];
}
// move part up in Z
// move part up by maxz to compensate for z inversion
array[i+2] += maxz;
array[i+5] += maxz;
array[i+8] += maxz;