From 8ec7c9161393b3807e4241d5c3f7b1898819a008 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 14 Jan 2021 18:38:53 -0500 Subject: [PATCH] fix mirror normals bug --- notes.md | 1 - src/kiri/widget.js | 15 ++++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/notes.md b/notes.md index 804e7576..d668158e 100644 --- a/notes.md +++ b/notes.md @@ -3,7 +3,6 @@ ## `C` cosmetic, `F` functional, `P` performance, `B` bug fix * `B` normals possibly inverted on faces in 2D to 3D conversion -* `B` some normals inverted on mirrored parts * `B` normalize left, bottom, right pop menu time/click and value persistence * `B` origin bug (Onshape?) when switching modes in 2.5 and 2.6 diff --git a/src/kiri/widget.js b/src/kiri/widget.js index 15ff2b00..ace821a8 100644 --- a/src/kiri/widget.js +++ b/src/kiri/widget.js @@ -273,7 +273,6 @@ // fix invalid normals geometry.computeFaceNormals(); geometry.computeVertexNormals(); - // to fix mirroring of normals not working as expected mesh.material.side = THREE.DoubleSide; mesh.castShadow = true; mesh.receiveShadow = true; @@ -512,18 +511,12 @@ PRO._mirror = function() { this.setWireframe(false); this.clearSlices(); - let i, - o = this.track, - geo = this.mesh.geometry, - at = geo.attributes, - pa = at.position.array, - nm = at.normal.array; - for (i = 0 ; i < pa.length; i += 3) { - pa[i] = -pa[i]; - nm[i] = -nm[i]; - } + this.mesh.applyMatrix4(new THREE.Matrix4().makeScale(-1, 1, 1)); + let geo = this.mesh.geometry, + o = this.track; geo.computeFaceNormals(); geo.computeVertexNormals(); + this.mesh.position.x = -this.mesh.position.x; o.mirror = !o.mirror; this.modified = true; };