From 51f53bf7528dba4420ece3af287fda2521ad6632 Mon Sep 17 00:00:00 2001 From: howard Date: Sat, 10 Apr 2021 03:53:44 -0700 Subject: [PATCH] fix basic extrude --- src/Scene.js | 15 +++++---- src/mouseEvents.js | 77 +++++++++++++++++++++---------------------- src/react/depTree.mjs | 17 ++++++++-- src/react/toolTip.jsx | 1 - src/react/tree.jsx | 15 +++++++-- todo.txt | 48 +++++++++++++-------------- 6 files changed, 94 insertions(+), 79 deletions(-) diff --git a/src/Scene.js b/src/Scene.js index 5668dec..743f36e 100644 --- a/src/Scene.js +++ b/src/Scene.js @@ -72,6 +72,8 @@ export class Scene { freePt.material.size=8 freePt.visible = false freePt.depthTest = false + freePt.userData.type = 'point' + helpersGroup.add(freePt); } @@ -211,14 +213,16 @@ export class Scene { for (let x = 0; x < this.selected.length; x++) { const obj = this.selected[x] obj.material.color.set(color[obj.userData.type]) + if (obj.userData.type == 'point') obj.visible = false } + this.selected = [] + for (let x = 0; x < this.hovered.length; x++) { const obj = this.selected[x] obj.material.color.set(color[obj.userData.type]) } + this.obj3d.dispatchEvent({ type: 'change' }) - this.selected = [] - console.log('fireed') } @@ -226,10 +230,8 @@ export class Scene { subtract (m1, m2) { let bspA = CSG.fromMesh(m1) let bspB = CSG.fromMesh(m2) - m1.traverse(e=>e.layers.disable(0)) - m2.traverse(e=>e.layers.disable(0)) - // m1.visible = false - // m2.visible = false + m1.traverse(e=>e.layers.disableAll()) + m2.traverse(e=>e.layers.disableAll()) // // Subtract one bsp from the other via .subtract... other supported modes are .union and .intersect @@ -240,6 +242,7 @@ export class Scene { let mesh = CSG.toMesh(bspResult, m1.matrix, m1.material) mesh.userData.type = 'mesh' mesh.name = `${m1.name}-${m2.name}` + mesh.layers.enable(1) const edges = new THREE.EdgesGeometry( mesh.geometry, 15 ); edges.type = 'BufferGeometry' diff --git a/src/mouseEvents.js b/src/mouseEvents.js index 12e94b9..cf62349 100644 --- a/src/mouseEvents.js +++ b/src/mouseEvents.js @@ -18,6 +18,7 @@ export function onHover(e) { let hoverPts; if (this.obj3d.userData.type != 'sketch') { + this.obj3d.children[0].children[0].visible = false raycaster.layers.set(1) hoverPts = raycaster.intersectObjects(this.obj3d.children, true) } else { @@ -49,8 +50,10 @@ export function onHover(e) { } + if (idx.length) { // after filtering, if hovered objs still exists + console.log(hoverPts) if (hoverPts[idx[0]].object != this.hovered[0]) { // if the previous hovered obj is not the same as current for (let x = 0; x < this.hovered.length; x++) { // first clear old hovers that are not selected @@ -58,16 +61,11 @@ export function onHover(e) { if (!this.selected.includes(obj)) { if (typeof obj == 'object') { obj.material.color.set(color[obj.userData.type]) - if (this.obj3d.userData.type != 'sketch') { if (obj.userData.type == 'mesh') { obj.children[0].material.color.set(color['line']) } } - - } else { - // this.obj3d.children[0].children[this.fptObj[obj]].visible = false - this.obj3d.children[0].children[0].visible = false } } } @@ -127,9 +125,6 @@ export function onHover(e) { obj.children[0].material.color.set(color['line']) } } - } else { - // this.obj3d.children[0].children[this.fptObj[obj]].visible = false - this.obj3d.children[0].children[0].visible = false } } } @@ -148,11 +143,12 @@ export function onPick(e) { if (this.mode || e.buttons != 1) return if (this.hovered.length) { - const obj = this.hovered[this.hovered.length - 1] + let obj = this.hovered[this.hovered.length - 1] - this.selected.push(this.hovered[this.hovered.length - 1]) - if (this.obj3d.userData.type != 'sketch') { + if (this.obj3d.userData.type == 'sketch') { + this.selected.push(obj) + } else { if (typeof obj == 'object') { if (obj.userData.type == "mesh") { obj.material.color.set(hoverColor[obj.userData.type]) @@ -166,52 +162,53 @@ export function onPick(e) { pp.geometry.attributes.position.needsUpdate = true pp.visible = true + obj = pp this.fptObj[obj] = this.fptIdx this.fptIdx++ } + this.obj3d.dispatchEvent({ type: 'change' }) + this.selected.push(obj) + return; } - if (typeof this.hovered[0] == 'object') { - switch (this.hovered[0].userData.type) { - case 'dimension': - const idx = this.obj3d.children[1].children.indexOf(this.hovered[0]) - if (idx % 2) { + switch (obj.userData.type) { + case 'dimension': + const idx = this.obj3d.children[1].children.indexOf(this.hovered[0]) + if (idx % 2) { - this.onDragDim = this._onMoveDimension( - this.obj3d.children[1].children[idx], - this.obj3d.children[1].children[idx - 1], - ) - this.canvas.addEventListener('pointermove', this.onDragDim); - this.canvas.addEventListener('pointerup', this.onRelease) - } - - draggedLabel = this.obj3d.children[1].children[idx].label - draggedLabel.style.zIndex = -1; - break; - case 'point': - - this.canvas.addEventListener('pointermove', this.onDrag); + this.onDragDim = this._onMoveDimension( + this.obj3d.children[1].children[idx], + this.obj3d.children[1].children[idx - 1], + ) + this.canvas.addEventListener('pointermove', this.onDragDim); this.canvas.addEventListener('pointerup', this.onRelease) - break; + } - default: - break; - } + draggedLabel = this.obj3d.children[1].children[idx].label + draggedLabel.style.zIndex = -1; + break; + case 'point': + + this.canvas.addEventListener('pointermove', this.onDrag); + this.canvas.addEventListener('pointerup', this.onRelease) + break; + + default: + break; } } else { for (let x = 0; x < this.selected.length; x++) { const obj = this.selected[x] - if (typeof obj == 'object') { - obj.material.color.set(color[obj.userData.type]) - if (this.obj3d.userData.type != 'sketch' && obj.userData.type == 'mesh') { + obj.material.color.set(color[obj.userData.type]) + if (this.obj3d.userData.type != 'sketch') { + if (obj.userData.type == 'mesh') { obj.children[0].material.color.set(color['line']) + } else if (obj.userData.type == 'point') { + obj.visible = false } - } else { - this.obj3d.children[0].children[this.fptObj[obj] + 1].visible = false } } - this.obj3d.children[0].children[0].visible = false this.obj3d.dispatchEvent({ type: 'change' }) this.selected = [] } diff --git a/src/react/depTree.mjs b/src/react/depTree.mjs index 93cb31a..f41c114 100644 --- a/src/react/depTree.mjs +++ b/src/react/depTree.mjs @@ -33,10 +33,11 @@ export class DepTree { } - deleteNode(id) { + + getDescendents(id) { const dfs = (id) => { visited.add(id) - nodesToDel.push(id) + desc.push(id) for (let k in this.tree[id]) { if (!visited.has(k)) { dfs(k) @@ -45,10 +46,20 @@ export class DepTree { } const visited = new Set() + const desc = [] - const nodesToDel = [] dfs(id) + return desc + } + + + + deleteNode(id) { + + + const nodesToDel = this.getDescendents(id) + nodesToDel.sort((a, b) => this.order[b] - this.order[a]) diff --git a/src/react/toolTip.jsx b/src/react/toolTip.jsx index 96324d8..5620d8f 100644 --- a/src/react/toolTip.jsx +++ b/src/react/toolTip.jsx @@ -68,7 +68,6 @@ export const ToolTip = () => { function getTextWidth(text, font = "16px sans-serif") { - console.log(text) // https://stackoverflow.com/a/21015393 // re-use canvas object for better performance let canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas")); diff --git a/src/react/tree.jsx b/src/react/tree.jsx index 2b83318..0fa8639 100644 --- a/src/react/tree.jsx +++ b/src/react/tree.jsx @@ -46,12 +46,13 @@ const TreeEntry = ({ entId }) => { const [_, forceUpdate] = useReducer(x => x + 1, 0); // const vis = obj3d.visible - const vis = obj3d.layers.mask&1 + const vis = obj3d.layers.mask & 1 return
{ activeSketchId && treeEntries[activeSketchId].deactivate() + console.log(entry) entry.activate() sc.clearSelection() sc.activeSketch = entry; @@ -95,7 +96,7 @@ const TreeEntry = ({ entId }) => { vis ? { - obj3d.traverse((e)=>e.layers.disable(0)) + obj3d.traverse((e) => e.layers.disableAll()) sc.render() forceUpdate() }} @@ -103,7 +104,15 @@ const TreeEntry = ({ entId }) => { : { - obj3d.traverse((e)=>e.layers.enable(0)) + if (obj3d.userData.type == 'sketch') { + obj3d.traverse((e) => e.layers.enable(0)) + } else { + obj3d.traverse((e) => { + e.layers.enable(0) + e.layers.enable(1) + }) + + } sc.render() forceUpdate() }} diff --git a/todo.txt b/todo.txt index cd18839..81aba93 100644 --- a/todo.txt +++ b/todo.txt @@ -1,42 +1,38 @@ -fix css on design tree (a lot of work) \ +fix css on design tree (a lot of work) \\ done clear dim on exit exit sketch / rehydrate when back or after loading \\\ done - dimension to origin // done - -- select sketch for extrusion -reattaching sketch -- need to auto hide ( consume) when new boolean created \\ +- need to auto hide ( consume) when new boolean created \\ done - sensible default names, like extrude 1, sketch 1, leverage react for this -boolean flesh out refresh / replace mesh / delete mesh +boolean flesh out refresh / replace mesh + - / delete mesh \\ done - create derived part using relationship as name \\ done - hidden bodies messes up hover highlight \\ fixed - add for union and intersect - - auto update + - consume skeches after extrude // done - - consume skeches after extrude -extrude edit dialog. directio and magnitude - -fix extrusion loop find - -file save -stl export - -angle -other constraints / sprite +vertical // done +horizontal // done -tangent -vertical -horizontal -angle +- select sketch for extrusion +- boolean unable to select click + +auto update extrude +extrude dialogue + +loopfind +button panel cleanup +file save, stl export + +constriant buttons ,tangent, angle - - - -finish mode messed up after restore \ No newline at end of file +constraint labels +reattach sketch +auto snap +tree ent renaming and better default names \ No newline at end of file