diff --git a/dist/solver.wasm b/dist/solver.wasm index 04fd3bc..01d053c 100755 Binary files a/dist/solver.wasm and b/dist/solver.wasm differ diff --git a/src/extrude.js b/src/extrude.js index 24c84e9..6e6b734 100644 --- a/src/extrude.js +++ b/src/extrude.js @@ -13,6 +13,7 @@ export function extrude(sketch) { function findPair(node) { + if (node.userData.construction) return; visited.add(node) let linkedObj = linkedObjs.get(node.userData.l_id) let arr; @@ -25,8 +26,8 @@ export function extrude(sketch) { v2s.push(new THREE.Vector2(arr[i], arr[i + 1])) } - offSetPts.push(arr[0], arr[1]) - offSetPts.push(arr[arr.length - 3], arr[arr.length - 2]) + offSetPts.push(arr[0], arr[1]) //make work points for sketch creation + // offSetPts.push(arr[arr.length - 3], arr[arr.length - 2]) for (let i = 0; i < 2; i++) { let d = children[ @@ -46,7 +47,7 @@ export function extrude(sketch) { function findTouching(node) { for (let t of node.userData.constraints) { - if (constraints.get(t)[0] != 'coincident') continue + if (constraints.get(t)[0] != 'points_coincident') continue for (let c of constraints.get(t)[2]) { if (c == -1) continue; const d = children[objIdx.get(c)] diff --git a/src/sketcher/Sketch.js b/src/sketcher/Sketch.js index f0e2167..153d001 100644 --- a/src/sketcher/Sketch.js +++ b/src/sketcher/Sketch.js @@ -181,7 +181,6 @@ class Sketch { break; case 'd': this.drawDimensionPre() - this.mode = "arc" break; case 'x': this.deleteSelected() diff --git a/src/sketcher/drawDimension.js b/src/sketcher/drawDimension.js index 11a36aa..5aa0c73 100644 --- a/src/sketcher/drawDimension.js +++ b/src/sketcher/drawDimension.js @@ -1,6 +1,28 @@ import * as THREE from '../../node_modules/three/src/Three'; import { ptObj, lineObj, awaitPts } from '../utils/shared' +const color = { + hover: 0x00ff00, + lighting: 0xFFFFFF, + emissive: 0x072534, + d: 0xf5bc42, //datums: planes + p: 0x555555, //points + l: 0x555555, //lines + m: 0x156289, //mesh: extrude +} + +const lineMaterial = new THREE.LineBasicMaterial({ + linewidth: 2, + color: color.l, +}) + + +const pointMaterial = new THREE.PointsMaterial({ + color: color.p, + size: 4, +}) + + const DptObj = (n) => { const ret = new THREE.Points( new THREE.BufferGeometry().setAttribute('position', @@ -12,6 +34,7 @@ const DptObj = (n) => { ret.matrixAutoUpdate = false; ret.userData.constraints = [] + ret.userData.construction = true return ret } @@ -62,12 +85,15 @@ export async function drawDimensionPre() { p1.userData.constraints.push(this.c_id) p2.userData.constraints.push(this.c_id) + // this.updateOtherBuffers() + // console.log(points) - for (let i = 1; i++; i < points.length) { + const updatePoint = this.obj3d.children.length + for (let i = 1; i < points.length; i++) { if (i % 2) { this.constraints.set(++this.c_id, //??? increment investigation [ - 'coincident', -1, + 'points_coincident', -1, [points[i - 1].name, points[i].name, -1, -1] ] ) @@ -75,9 +101,10 @@ export async function drawDimensionPre() { points[i].userData.constraints.push(this.c_id) - } else { + } else { // even + + const toPush = [...points.slice(i - 1, i + 1), lines[i / 2 - 1]] - const toPush = [...points.slice(i - 2, i), lines[i / 2 - 1]] this.linkedObjs.set(this.l_id, ['line', toPush.map(e => e.name)]) for (let obj of toPush) { obj.userData.l_id = this.l_id @@ -95,11 +122,30 @@ export async function drawDimensionPre() { lines[i / 2 - 1].userData.constraints.push(this.c_id) } + this.obj3d.add(...toPush) // not to be confused with this.topush + } + if (i<=3) { // move pts to their respective spots to spread them + points[i].geometry.attributes.position.set(p1.geometry.attributes.position.array) + } else { + points[i].geometry.attributes.position.set(p2.geometry.attributes.position.array) + } } + lines[0].userData.construction = true + lines[2].userData.construction = true + + + + + + + + this.updatePointsBuffer(updatePoint) + this.updateOtherBuffers() + // line[1].geometry.attributes.position.set(p1.geometry.attributes.position.array) // line[1].geometry.attributes.position.set(p1.geometry.attributes.position.array, 3) @@ -117,7 +163,7 @@ export async function drawDimensionPre() { - return [p1, p2, line]; + return } export function drawLine(mouseLoc) { @@ -132,7 +178,7 @@ export function drawLine(mouseLoc) { this.constraints.set(++this.c_id, [ - 'coincident', -1, + 'points_coincident', -1, [this.obj3d.children[this.obj3d.children.length - 2].name, p1.name, -1, -1] ] ) diff --git a/src/utils/mouseEvents.js b/src/utils/mouseEvents.js index 67aeb85..2318a1e 100644 --- a/src/utils/mouseEvents.js +++ b/src/utils/mouseEvents.js @@ -13,7 +13,7 @@ export function onHover(e) { ); let hoverPts; - if (this.obj3d.name[0]=='s') { + if (this.obj3d.name[0] == 's') { hoverPts = raycaster.intersectObjects(this.obj3d.children) } else { hoverPts = raycaster.intersectObjects(this.obj3d.children, true) @@ -31,6 +31,7 @@ export function onHover(e) { idx.push(i) } } + // console.log(hoverPts, idx) if (!idx.length) idx.push(0) } @@ -92,13 +93,19 @@ export function onPick(e) { export function onDrag(e) { const mouseLoc = this.getLocation(e); - for (let x = 0; x < this.hovered.length; x++) { - const obj = this.hovered[x] - this.ptsBuf.set( - mouseLoc, - this.objIdx.get(obj.name) * 3 - ) - } + // for (let x = 0; x < this.hovered.length; x++) { + // const obj = this.hovered[x] + // this.ptsBuf.set( + // mouseLoc, + // this.objIdx.get(obj.name) * 3 + // ) + // } + + const obj = this.hovered[this.hovered.length-1] + this.ptsBuf.set( + mouseLoc, + this.objIdx.get(obj.name) * 3 + ) this.solve() this.obj3d.dispatchEvent({ type: 'change' }) diff --git a/wasm/solver.c b/wasm/solver.c index 4cffe5a..34881f3 100644 --- a/wasm/solver.c +++ b/wasm/solver.c @@ -77,6 +77,7 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float * { if (isnan((float)*p_ptr)) { + // printf("%i\n",i); p_ptr += 3; continue; } @@ -92,13 +93,14 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float * switch ((int)*l_ptr++) { case 0: - sys.entity[sys.entities++] = Slvs_MakeLineSegment(lh++, g, + // printf("matching %i\n",(int)*(l_ptr + 2)); + sys.entity[sys.entities++] = Slvs_MakeLineSegment((int)*(l_ptr + 2), g, 200, (int)*l_ptr, (int)*(l_ptr + 1)); break; case 1: /* And arc, centered at point 303, starting at point 304, ending at * point 305. */ - sys.entity[sys.entities++] = Slvs_MakeArcOfCircle(lh++, g, 200, 102, + sys.entity[sys.entities++] = Slvs_MakeArcOfCircle((int)*(l_ptr + 3), g, 200, 102, (int)*(l_ptr + 2), (int)*(l_ptr), (int)*(l_ptr + 1)); break; default: @@ -108,50 +110,15 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float * l_ptr += 4; } - for (int i = 0; i < nConst; i++) + for (int i = 0; i < nConst; i++, c_ptr += 6) { - - - - switch ((int)*c_ptr + 100000) - { - case SLVS_C_POINTS_COINCIDENT: - c_ptr += 2; - sys.constraint[sys.constraints++] = Slvs_MakeConstraint( - con_id++, g, - SLVS_C_POINTS_COINCIDENT, - 200, - 0.0, - (int)*c_ptr, (int)*(c_ptr + 1), 0, 0); - - c_ptr += 4; - break; - case 1: - - break; - default: - c_ptr += 6; - break; - } - - - - // if ((int)*c_ptr + 100000 == SLVS_C_POINTS_COINCIDENT) - // { - // c_ptr += 2; - // sys.constraint[sys.constraints++] = Slvs_MakeConstraint( - // con_id++, g, - // SLVS_C_POINTS_COINCIDENT, - // 200, - // 0.0, - // (int)*c_ptr, (int)*(c_ptr + 1), 0, 0); - - // c_ptr += 4; - // } - // else - // { - // c_ptr += 6; - // } + // printf("%i here %i\n",(int)*c_ptr, nConst); + sys.constraint[sys.constraints++] = Slvs_MakeConstraint( + con_id++, g, + (int)*c_ptr + 100000, + 200, + *(c_ptr + 1), + (int)*(c_ptr + 2), (int)*(c_ptr + 3), (int)*(c_ptr + 4), (int)*(c_ptr + 5)); } /* And solve. */