ugly but works

This commit is contained in:
howard 2021-04-17 02:09:35 -07:00
parent ebc0088305
commit abb7891a7e
7 changed files with 43 additions and 43 deletions

View File

@ -315,6 +315,7 @@ export class Scene {
const { byId, tree } = this.store.getState().treeEntries const { byId, tree } = this.store.getState().treeEntries
while (idx < que.length) { while (idx < que.length) {
curId = que[idx++] curId = que[idx++]
console.log(curId,byId,'cc')
const info = byId[curId].userData.featureInfo const info = byId[curId].userData.featureInfo
let newNode let newNode

View File

@ -153,10 +153,12 @@ class Sketch {
activate() { activate() {
console.log('activatee') console.log('activate sketch')
window.addEventListener('keydown', this.onKeyPress) window.addEventListener('keydown', this.onKeyPress)
this.canvas.addEventListener('pointerdown', this.onPick) this.canvas.addEventListener('pointerdown', this.onPick)
this.canvas.addEventListener('pointermove', this.onHover) this.canvas.addEventListener('pointermove', this.onHover)
this.store.dispatch({ type: 'set-active-sketch', activeSketchId: this.obj3d.name }) this.store.dispatch({ type: 'set-active-sketch', activeSketchId: this.obj3d.name })
this.setDimLines() this.setDimLines()
@ -168,6 +170,17 @@ class Sketch {
this.scene.activeSketch = this this.scene.activeSketch = this
window.sketcher = this window.sketcher = this
// overkill but good solution if this check was more costly
this.hasChanged = false
this.idOnActivate = id
const changeDetector = (e) => {
if (this.selected.length && e.buttons) {
this.canvas.removeEventListener('pointermove', changeDetector)
this.hasChanged = true
}
}
this.canvas.addEventListener('pointermove', changeDetector)
} }
deactivate() { deactivate() {
@ -335,9 +348,9 @@ class Sketch {
} }
for (let i = 0; i < arr.length - 1; i++) { for (let i = 0; i < arr.length - 1; i++) {
setCoincident.call(this,[ setCoincident.call(this, [
this.obj3d.children[this.objIdx.get(arr[i])], this.obj3d.children[this.objIdx.get(arr[i])],
this.obj3d.children[this.objIdx.get(arr[i+1])] this.obj3d.children[this.objIdx.get(arr[i + 1])]
]) ])
} }

View File

@ -190,9 +190,7 @@ export function onPick(e) {
case 'point': case 'point':
this.canvas.addEventListener('pointermove', this.onDrag); this.canvas.addEventListener('pointermove', this.onDrag);
this.canvas.addEventListener('pointerup', () => { this.canvas.addEventListener('pointerup', this.onRelease)
this.onRelease()
})
break; break;
default: default:
@ -244,7 +242,7 @@ export function onDrag(e) {
export function onRelease() { export function onRelease(e) {
this.canvas.removeEventListener('pointermove', this.onDrag) this.canvas.removeEventListener('pointermove', this.onDrag)
this.canvas.removeEventListener('pointermove', this.onDragDim) this.canvas.removeEventListener('pointermove', this.onDragDim)
this.canvas.removeEventListener('pointerup', this.onRelease) this.canvas.removeEventListener('pointerup', this.onRelease)

View File

@ -1,6 +1,6 @@
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import React, { useState } from 'react' import React, { } from 'react'
import { createStore, applyMiddleware } from 'redux' import { createStore, applyMiddleware } from 'redux'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
@ -32,16 +32,13 @@ const store = createStore(reducer, {}, applyMiddleware(logger))
// const store = createStore(reducer, sc.loadState(), applyMiddleware(logger)) // const store = createStore(reducer, sc.loadState(), applyMiddleware(logger))
const App = ({ store }) => { const App = ({ store }) => (
<Provider store={store}>
return <Provider store={store}>
<NavBar /> <NavBar />
<Tree /> <Tree />
<ToolTip /> <ToolTip />
</Provider> </Provider>
}; )
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
ReactDOM.render(<App store={store} />, document.getElementById('react')); ReactDOM.render(<App store={store} />, document.getElementById('react'));

View File

@ -49,18 +49,30 @@ export const Dialog = () => {
case 'sketch': case 'sketch':
return <> return <>
<MdDone <MdDone
// className="btn w-auto h-full p-3.5 mr-6"
className="btn w-auto h-full p-3.5" className="btn w-auto h-full p-3.5"
onClick={() => { onClick={() => {
// dispatch({ type: 'update-descendents', sketch}) if (sc.activeSketch.hasChanged || sc.activeSketch.idOnActivate != id) {
sc.activeSketch.deactivate() console.log(sc.activeSketch)
for (let k in sc.store.getState().treeEntries.tree[sc.activeSketch.obj3d.name]) {
console.log('circlllles',k)
sc.refreshNode(k)
}
sc.render() sc.render()
}
// dispatch({ type: 'update-descendents', sketch})
sc.activeSketch.deactivate()
dispatch({ type: "clear-dialog" }) dispatch({ type: "clear-dialog" })
}} }}
/> />
<MdClose className="btn w-auto h-full p-3.5 mr-6" <MdClose className="btn w-auto h-full p-3.5 mr-6"
onClick={() => { onClick={() => {
if (sc.activeSketch.hasChanged || sc.activeSketch.idOnActivate != id) {
console.log('has changed')
dispatch({ type: "cancel-sketch" }) dispatch({ type: "cancel-sketch" })
sc.render()
}
sc.activeSketch.deactivate() sc.activeSketch.deactivate()
dispatch({ type: "clear-dialog" }) dispatch({ type: "clear-dialog" })
} }

View File

@ -31,30 +31,9 @@ export const NavBar = () => {
forceUpdate() forceUpdate()
} }
useEffect(() => {
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])
// useEffect(() => {
// console.log(treeEntriesById)
// }, [treeEntriesById])
const sketchModeButtons = [ const sketchModeButtons = [
// [MdDone, () => {
// // dispatch({ type: 'update-descendents', sketch})
// sc.activeSketch.deactivate()
// sc.render()
// forceUpdate()
// }, 'Finish'],
[Icon.Extrude, () => { [Icon.Extrude, () => {
sc.activeSketch.deactivate() sc.activeSketch.deactivate()
dispatch({ type: 'set-dialog', action: 'extrude', target: sc.activeSketch }) dispatch({ type: 'set-dialog', action: 'extrude', target: sc.activeSketch })

View File

@ -13,6 +13,7 @@ const defaultState = {
activeSketchId: "" activeSketchId: ""
} }
let cache
export function treeEntries(state = defaultState, action) { export function treeEntries(state = defaultState, action) {
switch (action.type) { switch (action.type) {
@ -32,7 +33,7 @@ export function treeEntries(state = defaultState, action) {
} }
case 'set-active-sketch': case 'set-active-sketch':
window.cache = JSON.stringify(state.byId[action.activeSketchId]) cache = JSON.stringify(state.byId[action.activeSketchId])
return update(state, { return update(state, {
visible: { [action.activeSketchId]: { $set: true } }, visible: { [action.activeSketchId]: { $set: true } },
activeSketchId: { $set: action.activeSketchId }, activeSketchId: { $set: action.activeSketchId },
@ -45,7 +46,6 @@ export function treeEntries(state = defaultState, action) {
case 'cancel-sketch': case 'cancel-sketch':
const sketch = sc.loadSketch(cache) const sketch = sc.loadSketch(cache)
console.log(cache, sketch)
const deletedObj = sc.obj3d.children.splice(state.order[state.activeSketchId] + 1, 1, const deletedObj = sc.obj3d.children.splice(state.order[state.activeSketchId] + 1, 1,
sketch.obj3d sketch.obj3d