semi working dimension line

master
howard 2021-04-02 21:05:28 -07:00
parent 3dd7d47071
commit fdf5dc628b
6 changed files with 83 additions and 63 deletions

BIN
dist/solver.wasm vendored

Binary file not shown.

View File

@ -13,6 +13,7 @@ export function extrude(sketch) {
function findPair(node) { function findPair(node) {
if (node.userData.construction) return;
visited.add(node) visited.add(node)
let linkedObj = linkedObjs.get(node.userData.l_id) let linkedObj = linkedObjs.get(node.userData.l_id)
let arr; let arr;
@ -25,8 +26,8 @@ export function extrude(sketch) {
v2s.push(new THREE.Vector2(arr[i], arr[i + 1])) v2s.push(new THREE.Vector2(arr[i], arr[i + 1]))
} }
offSetPts.push(arr[0], arr[1]) offSetPts.push(arr[0], arr[1]) //make work points for sketch creation
offSetPts.push(arr[arr.length - 3], arr[arr.length - 2]) // offSetPts.push(arr[arr.length - 3], arr[arr.length - 2])
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
let d = children[ let d = children[
@ -46,7 +47,7 @@ export function extrude(sketch) {
function findTouching(node) { function findTouching(node) {
for (let t of node.userData.constraints) { 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]) { for (let c of constraints.get(t)[2]) {
if (c == -1) continue; if (c == -1) continue;
const d = children[objIdx.get(c)] const d = children[objIdx.get(c)]

View File

@ -181,7 +181,6 @@ class Sketch {
break; break;
case 'd': case 'd':
this.drawDimensionPre() this.drawDimensionPre()
this.mode = "arc"
break; break;
case 'x': case 'x':
this.deleteSelected() this.deleteSelected()

View File

@ -1,6 +1,28 @@
import * as THREE from '../../node_modules/three/src/Three'; import * as THREE from '../../node_modules/three/src/Three';
import { ptObj, lineObj, awaitPts } from '../utils/shared' 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 DptObj = (n) => {
const ret = new THREE.Points( const ret = new THREE.Points(
new THREE.BufferGeometry().setAttribute('position', new THREE.BufferGeometry().setAttribute('position',
@ -12,6 +34,7 @@ const DptObj = (n) => {
ret.matrixAutoUpdate = false; ret.matrixAutoUpdate = false;
ret.userData.constraints = [] ret.userData.constraints = []
ret.userData.construction = true
return ret return ret
} }
@ -62,12 +85,15 @@ export async function drawDimensionPre() {
p1.userData.constraints.push(this.c_id) p1.userData.constraints.push(this.c_id)
p2.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) { if (i % 2) {
this.constraints.set(++this.c_id, //??? increment investigation this.constraints.set(++this.c_id, //??? increment investigation
[ [
'coincident', -1, 'points_coincident', -1,
[points[i - 1].name, points[i].name, -1, -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) 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)]) this.linkedObjs.set(this.l_id, ['line', toPush.map(e => e.name)])
for (let obj of toPush) { for (let obj of toPush) {
obj.userData.l_id = this.l_id 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) 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)
// line[1].geometry.attributes.position.set(p1.geometry.attributes.position.array, 3) // 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) { export function drawLine(mouseLoc) {
@ -132,7 +178,7 @@ export function drawLine(mouseLoc) {
this.constraints.set(++this.c_id, this.constraints.set(++this.c_id,
[ [
'coincident', -1, 'points_coincident', -1,
[this.obj3d.children[this.obj3d.children.length - 2].name, p1.name, -1, -1] [this.obj3d.children[this.obj3d.children.length - 2].name, p1.name, -1, -1]
] ]
) )

View File

@ -13,7 +13,7 @@ export function onHover(e) {
); );
let hoverPts; let hoverPts;
if (this.obj3d.name[0]=='s') { if (this.obj3d.name[0] == 's') {
hoverPts = raycaster.intersectObjects(this.obj3d.children) hoverPts = raycaster.intersectObjects(this.obj3d.children)
} else { } else {
hoverPts = raycaster.intersectObjects(this.obj3d.children, true) hoverPts = raycaster.intersectObjects(this.obj3d.children, true)
@ -31,6 +31,7 @@ export function onHover(e) {
idx.push(i) idx.push(i)
} }
} }
// console.log(hoverPts, idx)
if (!idx.length) idx.push(0) if (!idx.length) idx.push(0)
} }
@ -92,13 +93,19 @@ export function onPick(e) {
export function onDrag(e) { export function onDrag(e) {
const mouseLoc = this.getLocation(e); const mouseLoc = this.getLocation(e);
for (let x = 0; x < this.hovered.length; x++) { // for (let x = 0; x < this.hovered.length; x++) {
const obj = this.hovered[x] // const obj = this.hovered[x]
this.ptsBuf.set( // this.ptsBuf.set(
mouseLoc, // mouseLoc,
this.objIdx.get(obj.name) * 3 // 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.solve()
this.obj3d.dispatchEvent({ type: 'change' }) this.obj3d.dispatchEvent({ type: 'change' })

View File

@ -77,6 +77,7 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
{ {
if (isnan((float)*p_ptr)) if (isnan((float)*p_ptr))
{ {
// printf("%i\n",i);
p_ptr += 3; p_ptr += 3;
continue; continue;
} }
@ -92,13 +93,14 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
switch ((int)*l_ptr++) switch ((int)*l_ptr++)
{ {
case 0: 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)); 200, (int)*l_ptr, (int)*(l_ptr + 1));
break; break;
case 1: case 1:
/* And arc, centered at point 303, starting at point 304, ending at /* And arc, centered at point 303, starting at point 304, ending at
* point 305. */ * 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)); (int)*(l_ptr + 2), (int)*(l_ptr), (int)*(l_ptr + 1));
break; break;
default: default:
@ -108,50 +110,15 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
l_ptr += 4; l_ptr += 4;
} }
for (int i = 0; i < nConst; i++) for (int i = 0; i < nConst; i++, c_ptr += 6)
{ {
// printf("%i here %i\n",(int)*c_ptr, nConst);
sys.constraint[sys.constraints++] = Slvs_MakeConstraint(
con_id++, g,
switch ((int)*c_ptr + 100000) (int)*c_ptr + 100000,
{ 200,
case SLVS_C_POINTS_COINCIDENT: *(c_ptr + 1),
c_ptr += 2; (int)*(c_ptr + 2), (int)*(c_ptr + 3), (int)*(c_ptr + 4), (int)*(c_ptr + 5));
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;
// }
} }
/* And solve. */ /* And solve. */