diff --git a/dist/solver.wasm b/dist/solver.wasm index 01d053c..a4a67f0 100755 Binary files a/dist/solver.wasm and b/dist/solver.wasm differ diff --git a/src/Scene.js b/src/Scene.js index 95ff9d1..e21d596 100644 --- a/src/Scene.js +++ b/src/Scene.js @@ -300,7 +300,7 @@ async function addSketch() { } window.sc = new Scene(store) -sc.loadState() +// sc.loadState() diff --git a/src/Sketch.js b/src/Sketch.js index bc5e70a..d019f06 100644 --- a/src/Sketch.js +++ b/src/Sketch.js @@ -2,11 +2,11 @@ import * as THREE from '../node_modules/three/src/Three'; -import { _vec2, _vec3, raycaster, awaitPts } from './shared' +import { _vec2, _vec3, raycaster, awaitPts, ptObj } from './shared' -import { drawOnClick1, drawOnClick2, drawPreClick2, drawClear } from './drawEvents' +import { drawOnClick1, drawOnClick2, drawPreClick2, drawClear, drawPoint } from './drawEvents' import { onHover, onDrag, onPick, onRelease } from './mouseEvents' -import { setCoincident } from './constraintEvents' +import { setCoincident, setOrdinate } from './constraintEvents' import { get3PtArc } from './drawArc' import { replacer, reviver } from './utils' import { AxesHelper } from './sketchAxes' @@ -47,13 +47,25 @@ class Sketch { this.l_id = 0; this.constraints = new Map() - this.c_id = 0; + this.c_id = 1; this.obj3d.add(new THREE.Group().add(new AxesHelper(0.5))); this.obj3d.add(new THREE.Group()); this.obj3d.add(new THREE.Group()); this.labels = [] + + + const p1 = ptObj() + p1.matrixAutoUpdate = false; + p1.userData.constraints = [] + this.obj3d.add(p1) + this.updatePointsBuffer() + + + + + } else { @@ -138,7 +150,7 @@ class Sketch { this.canvas.addEventListener('pointermove', this.onHover) this.store.dispatch({ type: 'set-active-sketch', sketch: this.obj3d.name }) - + this.setDimLines() window.sketcher = this @@ -199,6 +211,14 @@ class Sketch { case 'd': this.drawDimension() this.mode = "" + break; + case 'p': + this.canvas.addEventListener('pointerdown', + (e) => { + drawPoint.call(this, e) + } + ) + break; case 'x': this.deleteSelected() @@ -207,6 +227,18 @@ class Sketch { setCoincident.call(this) + this.mode = "" + break; + case 'v': + + setOrdinate.call(this, 0) + + this.mode = "" + break; + case 'h': + + setOrdinate.call(this, 1) + this.mode = "" break; @@ -340,12 +372,12 @@ class Sketch { updateBoundingSpheres() { - for (let x = 3; x < this.obj3d.children.length; x++) { + for (let x = 3; x < this.obj3d.children.length; x++) { // geometry boundign spheres const obj = this.obj3d.children[x] obj.geometry.computeBoundingSphere() } - - for (let x = 0; x < this.obj3d.children[1].children.length; x++) { + + for (let x = 0; x < this.obj3d.children[1].children.length; x++) { // dimension bounding sphere const obj = this.obj3d.children[1].children[x] obj.geometry.computeBoundingSphere() } @@ -354,8 +386,8 @@ class Sketch { raycaster.setFromCamera( _vec2.set( - (e.clientX - this.rect.left)/ this.rect.width * 2 - 1, - - (e.clientY - this.rect.top)/ this.rect.height * 2 + 1 + (e.clientX - this.rect.left) / this.rect.width * 2 - 1, + - (e.clientY - this.rect.top) / this.rect.height * 2 + 1 ), this.camera ); diff --git a/src/constraintEvents.js b/src/constraintEvents.js index 521334f..bf0c5fc 100644 --- a/src/constraintEvents.js +++ b/src/constraintEvents.js @@ -1,22 +1,5 @@ -export function addDimension(ent1, ent2, distance) { - - - // if (ent1.type ==) - - this.constraints.set(++this.c_id, - [ - 'distance', distance, - [p1, p2, -1, -1] - ] - ) - - ent1.userData.constraints.push(this.c_id) - ent2.userData.constraints.push(this.c_id) -} - - export function setCoincident() { const s = new Set() const toComb = [] @@ -41,12 +24,37 @@ export function setCoincident() { this.updateOtherBuffers() this.solve() - + this.updateBoundingSpheres() + // update state of points - for (let obj of this.selected) { - obj.geometry.computeBoundingSphere() - obj.material.color.set(0x555555) - } + // for (let obj of this.selected) { + // obj.geometry.computeBoundingSphere() + // obj.material.color.set(0x555555) + // } this.selected = [] this.obj3d.dispatchEvent({ type: 'change' }) } + + +export function setOrdinate(dir = 0) { + + + const line = this.selected[0] + this.constraints.set(++this.c_id, + [ + dir ? 'vertical' : 'horizontal', -1, + [-1, -1, line.name, -1] /////// + ] + ) + line.userData.constraints.push(this.c_id) + + + this.updateOtherBuffers() + this.solve() + this.updateBoundingSpheres() + + this.selected = [] + this.obj3d.dispatchEvent({ type: 'change' }) +} + + diff --git a/src/drawEvents.js b/src/drawEvents.js index 3d78ca8..765a701 100644 --- a/src/drawEvents.js +++ b/src/drawEvents.js @@ -2,6 +2,7 @@ import { drawArc, drawArc2 } from './drawArc' import { drawLine, drawLine2 } from './drawLine' // import { drawDimension } from "./drawDimension"; +import { ptObj } from './shared' export function drawOnClick1(e) { if (e.buttons !== 1) return @@ -95,3 +96,16 @@ export function drawClear() { this.toPush = [] } } + + +export function drawPoint(e) { + + const mouseLoc = this.getLocation(e).toArray(); + const p1 = ptObj() + p1.matrixAutoUpdate = false; + p1.userData.constraints = [] + p1.geometry.attributes.position.set(mouseLoc) + this.obj3d.add(p1) + this.updatePointsBuffer() + this.obj3d.dispatchEvent({ type: 'change' }) +} \ No newline at end of file diff --git a/src/drawLine.js b/src/drawLine.js index e1f8831..4f1f16d 100644 --- a/src/drawLine.js +++ b/src/drawLine.js @@ -33,6 +33,8 @@ export function drawLine(mouseLoc) { p1.userData.constraints.push(this.c_id) this.obj3d.children[this.obj3d.children.length - 2].userData.constraints.push(this.c_id) + + } diff --git a/src/extrude.js b/src/extrude.js index 3c47dc3..cdcadb7 100644 --- a/src/extrude.js +++ b/src/extrude.js @@ -64,7 +64,7 @@ export function extrude(sketch) { } - findPair(children[3]) //??? need fixing + findPair(children[4]) //??? need fixing const shape = new THREE.Shape(v2s); const extrudeSettings = { depth: 8, bevelEnabled: false }; diff --git a/src/patch.js b/src/patch.js index b8ee71f..75e9d99 100644 --- a/src/patch.js +++ b/src/patch.js @@ -5,7 +5,10 @@ import { LineSegments, MeshBasicMaterial, Float32BufferAttribute, BufferGeometry, Mesh, DoubleSide } from '../node_modules/three/src/Three' -class Patch extends Mesh { + +import * as THREE from '../node_modules/three/src/Three'; + +class Patch extends THREE.Mesh { constructor(s = 1) { diff --git a/src/react/toolTip.jsx b/src/react/toolTip.jsx index e3ae4f5..5620d8f 100644 --- a/src/react/toolTip.jsx +++ b/src/react/toolTip.jsx @@ -12,7 +12,7 @@ export const ToolTip = () => { * child mouseover is novel. If it's not, we ignore the event */ - const [state, setState] = useState(null) + const [text, setText] = useState(null) const ref = useRef() @@ -38,14 +38,11 @@ export const ToolTip = () => { prevTooltip.current = tooltip // svg workaround clearTimeout(timeout.current) - if (tooltip) { let { left, top, width, height } = node.getBoundingClientRect() left = left + width / 2 - getTextWidth(tooltip) / 2 - 4 // 4 is padding top = top + height + 6 // 6 is arrow height/width - - setState(tooltip) - + setText(tooltip) if (activated.current) { ref.current.setAttribute('style', `left:${left}px; top:${top}px; visibility:visible`) } else { @@ -54,22 +51,16 @@ export const ToolTip = () => { activated.current = true }, 1000); } - } else { - ref.current.setAttribute('style', `visibility:hidden`) activated.current = false - } - }) - - }, []) return