From 7a93b3e5c832b81e39ebac29015ff01d7ae71c92 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Sun, 19 Nov 2017 13:04:14 +0100 Subject: [PATCH] update 3d cut --- src/d3/ShapeMesh.js | 54 ++++++++++++++++++++++++------------- src/shape/shapeDataUtils.js | 12 ++++++++- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/d3/ShapeMesh.js b/src/d3/ShapeMesh.js index cd1e5cd..f098606 100644 --- a/src/d3/ShapeMesh.js +++ b/src/d3/ShapeMesh.js @@ -62,18 +62,30 @@ class ShapeMesh extends THREE.Object3D { this._color = color; this._fill = fill; - this.visible = shapeData.solid; - this.updatePoints(shapeData); this._checkHoles(holes, active); } + add(object) { + if (!this.children.includes(object)) super.add(object); + } + remove(object) { + if (this.children.includes(object)) super.remove(object); + } + _checkHoles(holes, active) { + let changed = false; + + const visible = this._shapeData.solid || active; + if (visible !== this.visible) { + this.visible = visible; + changed = true; + } + if (active) { - this._holeMesh.visible = false; - this._mesh.visible = true; - return false; + this.remove(this._holeMesh); + this.add(this._mesh); } holes = holes.map(hole => hole.mesh._mesh); @@ -84,23 +96,26 @@ class ShapeMesh extends THREE.Object3D { }); if (holes.length === 0) { - this._holeMesh.visible = false; - this._mesh.visible = true; - return false; + this.remove(this._holeMesh); + this.add(this._mesh); + return changed; } // is coliding with holes const objectGeometry = new THREE.Geometry().fromBufferGeometry(this._mesh.geometry); let objectBSP = new THREE_BSP(objectGeometry); + objectGeometry.dispose(); for (const hole of holes) { const holeGeometry = new THREE.Geometry().fromBufferGeometry(hole.geometry); - const holeBSP = new THREE_BSP(holeGeometry) + const holeBSP = new THREE_BSP(holeGeometry); + holeGeometry.dispose(); objectBSP = objectBSP.subtract(holeBSP) } + this._holeMesh.geometry.dispose(); this._holeMesh.geometry = objectBSP.toMesh().geometry; - this._holeMesh.visible = true; - this._mesh.visible = false; + this.add(this._holeMesh); + this.remove(this._mesh); return true; } @@ -137,12 +152,6 @@ class ShapeMesh extends THREE.Object3D { changed = true; } - if (!shapeData.solid) { - this.visible = shapeData.solid || active; - this.setOpaque(true); - changed = true; - } - if (this._checkHoles(holes, active)) { changed = true; } @@ -152,12 +161,19 @@ class ShapeMesh extends THREE.Object3D { } setOpaque(opaque) { - this._mesh.material.opacity = opaque ? 1.0 : 1.0 - DESELECT_TRANSPARENCY; - this._mesh.material.transparent = !opaque; + let opacity; + if (this._shapeData.solid) { + opacity = opaque ? 1.0 : DESELECT_TRANSPARENCY; + } else { + opacity = 0.0; + } + this._mesh.material.opacity = opacity; + this._mesh.material.transparent = opacity !== 1; } dispose() { this._mesh.geometry.dispose(); + this._meshHole.geometry.dispose(); } updatePoints(shapeData) { diff --git a/src/shape/shapeDataUtils.js b/src/shape/shapeDataUtils.js index fc5d4ce..eb113af 100644 --- a/src/shape/shapeDataUtils.js +++ b/src/shape/shapeDataUtils.js @@ -72,6 +72,12 @@ function shapeDataToShapeRaw(shapeData) { // TODO can maybe be memoized export const determineActiveShape = (state) => { + const activeTransformer = state.d2.eraser.active || + state.d2.transform.active || + state.d3.height.active || + state.d3.sculpt.activeHandle !== null || + state.d3.twist.active; + const selectedObjects = state.selection.objects.map(({ id }) => id); const activeShapes = {}; for (const id in state.objectsById) { @@ -79,7 +85,11 @@ export const determineActiveShape = (state) => { activeShapes[id] = true; continue; } - activeShapes[id] = state.d2.transform.active && selectedObjects.includes(id); + if (activeTransformer && !state.objectsById[id].solid) { + activeShapes[id] = true; + continue; + } + activeShapes[id] = selectedObjects.includes(id) && activeTransformer; } return activeShapes; };