improve belt rotation (still buggy)

This commit is contained in:
Stewart Allen 2020-12-07 21:38:39 -05:00
commit 43acc4e652
3 changed files with 20 additions and 8 deletions

View file

@ -18,6 +18,7 @@
## `C` cosmetic, `F` functional, `P` performance, `B` bug fix ## `C` cosmetic, `F` functional, `P` performance, `B` bug fix
* `B` normals possibly inverted on faces in 2D to 3D conversion
* `F` right click / context menu (object deletion, etc) * `F` right click / context menu (object deletion, etc)
* `F` detect and report slow framerates * `F` detect and report slow framerates
* `P` duplicate objects should share same slice data unless rotated or scaled * `P` duplicate objects should share same slice data unless rotated or scaled

View file

@ -27,8 +27,8 @@
rotate(set) { rotate(set) {
this.view.rotation.x = -set.angle * (Math.PI/180); this.view.rotation.x = -set.angle * (Math.PI/180);
this.view.position.y = -set.centerz + set.movez; this.view.position.y += -set.dy;
this.view.position.z = -set.movez/2; this.view.position.z += -set.dz;
} }
destroy() { destroy() {

View file

@ -75,14 +75,25 @@ KIRI.worker = {
widget.mesh = null; widget.mesh = null;
widget.points = null; widget.points = null;
widget.loadVertices(widget.vertices); widget.loadVertices(widget.vertices);
let bbox1 = widget.getBoundingBox(true); let bb1 = widget.getBoundingBox(true);
let zd = bb1.max.z - bb1.min.z; // z dim
// let cy1 = (bb1.max.y + bb1.min.y) / 2;
// let cz1 = (bb1.max.z + bb1.min.z) / 2;
widget.setPoints(null);
widget._rotate(rotation,0,0,true); widget._rotate(rotation,0,0,true);
widget.center(); widget.center(false, true);
let bb2 = widget.getBoundingBox(true);
// let cy2 = (bb2.max.y + bb2.min.y) / 2;
// let cz2 = (bb2.max.z + bb2.min.z) / 2;
// let angle = Math.atan2(cy1-cy2, cz1-cz2) * (180 / Math.PI);
widget.rotated = true; widget.rotated = true;
let bbox2 = widget.getBoundingBox(true); let rc = Math.sin(Math.PI/4);
let centerz = (bbox2.max.z - bbox2.min.z) / 2; let cz = (bb2.max.z - bb2.min.z) / 2; // center z post rotate
let movez = centerz - (bbox1.max.z - bbox1.min.z) / 2; let dy = cz * rc; // dy = cz rotated 45
widget.rotinfo = { centerz, movez, angle: 45 }; let dz = dy - zd / 2;
// console.log({cy1,cz1,cy2,cz2,angle,cy});
widget.rotinfo = { angle: 45, dy, dz };
widget.getBoundingBox(true);
} }
widget.slice(settings, function(error) { widget.slice(settings, function(error) {