From 4076c90e58f740c8569d2229783cdc63ef7e0138 Mon Sep 17 00:00:00 2001 From: howard Date: Sat, 17 Apr 2021 03:25:43 -0700 Subject: [PATCH] ugly but works 2 --- src/Scene.js | 4 ++++ src/Sketch.js | 8 ++++++-- src/react/dialog.jsx | 7 +++++-- src/react/navBar.jsx | 11 ++++++++++- src/react/reducer.js | 3 +++ 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Scene.js b/src/Scene.js index 2a6d126..2fbbbf7 100644 --- a/src/Scene.js +++ b/src/Scene.js @@ -412,10 +412,14 @@ async function addSketch() { sketch.activate() this.render() + + } window.sc = new Scene(store) sc.loadState() + + // sc.camera.layers.enable(1) // rc.layers.set(1) \ No newline at end of file diff --git a/src/Sketch.js b/src/Sketch.js index 7742148..bac77aa 100644 --- a/src/Sketch.js +++ b/src/Sketch.js @@ -5,7 +5,7 @@ import * as THREE from '../node_modules/three/src/Three'; import { _vec2, _vec3, raycaster, awaitSelection, ptObj, setHover } from './shared' import { drawOnClick1, drawOnClick2, drawPreClick2, drawOnClick3, drawPreClick3, drawClear, drawPoint } from './drawEvents' -import { onHover, onDrag, onPick, onRelease } from './mouseEvents' +import { onHover, onDrag, onPick, onRelease, clearSelection} from './mouseEvents' import { setCoincident, setOrdinate, setTangent } from './constraintEvents' import { get3PtArc } from './drawArc' import { replacer, reviver } from './utils' @@ -148,6 +148,7 @@ class Sketch { this.onKeyPress = this.onKeyPress.bind(this); this.setHover = setHover.bind(this); + this.clearSelection = clearSelection.bind(this) } @@ -186,6 +187,7 @@ class Sketch { } deactivate() { + console.log('deactivateeeeeeee') window.removeEventListener('keydown', this.onKeyPress) this.canvas.removeEventListener('pointerdown', this.onPick) this.canvas.removeEventListener('pointermove', this.onHover) @@ -195,7 +197,9 @@ class Sketch { this.obj3d.traverse(e => e.layers.disable(2)) this.scene.axes.visible = false this.scene.activeSketch = null - this.selected = [] + + this.clearSelection() + } diff --git a/src/react/dialog.jsx b/src/react/dialog.jsx index 3020160..13a98f5 100644 --- a/src/react/dialog.jsx +++ b/src/react/dialog.jsx @@ -72,11 +72,14 @@ export const Dialog = () => { if (sc.activeSketch.hasChanged || sc.activeSketch.idOnActivate != id) { console.log('has changed') dispatch({ type: "cancel-sketch" }) + sc.store.getState().treeEntries.byId[sc.activeSketch.obj3d.name].deactivate() + } else { + + sc.activeSketch.deactivate() } - sc.activeSketch.deactivate() - sc.render() + sc.render() dispatch({ type: "clear-dialog" }) } diff --git a/src/react/navBar.jsx b/src/react/navBar.jsx index d811a56..bdfeb71 100644 --- a/src/react/navBar.jsx +++ b/src/react/navBar.jsx @@ -31,7 +31,16 @@ export const NavBar = () => { forceUpdate() } - + useEffect(() => { // hacky way to handle mounting and unmounting mouse listeners for feature mode + if (!activeSketchId) { + sc.canvas.addEventListener('pointermove', sc.onHover) + sc.canvas.addEventListener('pointerdown', sc.onPick) + return () => { + sc.canvas.removeEventListener('pointermove', sc.onHover) + sc.canvas.removeEventListener('pointerdown', sc.onPick) + } + } + }, [activeSketchId]) const sketchModeButtons = [ [Icon.Extrude, () => { diff --git a/src/react/reducer.js b/src/react/reducer.js index 36afd91..8c833f6 100644 --- a/src/react/reducer.js +++ b/src/react/reducer.js @@ -50,12 +50,15 @@ export function treeEntries(state = defaultState, action) { const deletedObj = sc.obj3d.children.splice(state.order[state.activeSketchId] + 1, 1, sketch.obj3d )[0] + console.log('spliced and starting to delete') deletedObj.traverse((obj) => { if (obj.geometry) obj.geometry.dispose() if (obj.material) obj.material.dispose() }) + // sketch.deactivate() + return update(state, { activeSketchId: { $set: "" }, byId: { [state.activeSketchId]: { $set: sketch } },