refactored polyline working

master
howard 2021-03-24 13:47:12 -07:00
parent 0d67c75d64
commit 031f438333
6 changed files with 90412 additions and 392 deletions

90741
dist/bundle.js vendored

File diff suppressed because one or more lines are too long

1
dist/bundle.js.map vendored Normal file

File diff suppressed because one or more lines are too long

BIN
dist/solver.wasm vendored

Binary file not shown.

View File

@ -157,6 +157,9 @@ export class Sketcher extends THREE.Group {
this.mode = "" this.mode = ""
break; break;
case 'l': case 'l':
if (this.mode == 'line') {
this.clear()
}
this.domElement.addEventListener('pointerdown', this.onClick_1) this.domElement.addEventListener('pointerdown', this.onClick_1)
this.mode = "line" this.mode = "line"
break; break;
@ -248,7 +251,10 @@ export class Sketcher extends THREE.Group {
onDrag(e) { onDrag(e) {
const mouseLoc = this.getLocation(e); const mouseLoc = this.getLocation(e);
this.geomGroup.children[this.grabPtIdx].geometry.attributes.position.set(mouseLoc); this.geomGroup.children[this.grabPtIdx].geometry.attributes.position.set(mouseLoc);
this.updatePointsBuffer()
this.solve() this.solve()
// console.log(this.geomGroup.children[this.grabPtIdx].geometry.attributes.position.array)
// this.geomGroup.children[this.grabPtIdx].geometry.attributes.position.needsUpdate = true;
this.dispatchEvent({ type: 'change' }) this.dispatchEvent({ type: 'change' })
} }
@ -300,7 +306,6 @@ export class Sketcher extends THREE.Group {
i = 0; i = 0;
for (let [key, obj] of this.linkedObjs) { for (let [key, obj] of this.linkedObjs) {
console.log(obj[0])
this.linksBuf.set( this.linksBuf.set(
[ [
this.linkNum[obj[1]], this.linkNum[obj[1]],
@ -308,7 +313,6 @@ export class Sketcher extends THREE.Group {
], ],
(i) * 5 (i) * 5
) )
console.log(this.linksBuf)
i++ i++
} }
@ -526,11 +530,12 @@ export class Sketcher extends THREE.Group {
solve() { solve() {
// for (let i = 0, p = 0; i < this.geomGroup.children.length; i++) { for (let i = 0, p = 0; i < this.geomGroup.children.length; i++) {
// this.ptsBuf[p++] = this.geomGroup.children[i].geometry.attributes.position.array[0] if (this.geomGroup.children[i].type == "Points") {
// this.ptsBuf[p++] = this.geomGroup.children[i].geometry.attributes.position.array[1] this.ptsBuf[2 * i] = this.geomGroup.children[i].geometry.attributes.position.array[0]
// } this.ptsBuf[2 * i + 1] = this.geomGroup.children[i].geometry.attributes.position.array[1]
this.updatePointsBuffer() }
}
const pts_buffer = Module._malloc(this.ptsBuf.length * this.ptsBuf.BYTES_PER_ELEMENT) const pts_buffer = Module._malloc(this.ptsBuf.length * this.ptsBuf.BYTES_PER_ELEMENT)
Module.HEAPF32.set(this.ptsBuf, pts_buffer >> 2) Module.HEAPF32.set(this.ptsBuf, pts_buffer >> 2)
@ -549,15 +554,17 @@ export class Sketcher extends THREE.Group {
for (let i = 0; i < this.geomGroup.children.length; i += 1) { for (let i = 0; i < this.geomGroup.children.length; i += 1) {
const pos = this.geomGroup.children[i].geometry.attributes.position; const pos = this.geomGroup.children[i].geometry.attributes.position;
// console.log(pos.array)
if (isNaN(Module.HEAPF32[ptr])) { if (isNaN(Module.HEAPF32[ptr])) {
pos.array[0] = Module.HEAPF32[ptr - 4] pos.array[0] = Module.HEAPF32[ptr - 4]
pos.array[1] = Module.HEAPF32[ptr - 3] pos.array[1] = Module.HEAPF32[ptr - 3]
pos.array[3] = Module.HEAPF32[ptr - 2] pos.array[3] = Module.HEAPF32[ptr - 2]
pos.array[4] = Module.HEAPF32[ptr - 1] pos.array[4] = Module.HEAPF32[ptr - 1]
} else { } else {
pos.array[0] = Module.HEAPF32[ptr++] pos.array[0] = Module.HEAPF32[ptr]
pos.array[1] = Module.HEAPF32[ptr++] pos.array[1] = Module.HEAPF32[ptr + 1]
} }
ptr += 2;
pos.needsUpdate = true; pos.needsUpdate = true;
} }

View File

@ -75,7 +75,6 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
int p_start = sys.params; int p_start = sys.params;
for (int i = 0; i < nPts; i++) for (int i = 0; i < nPts; i++)
{ {
printf("i: %i %f %f \n", i,(float)*p_ptr,(float)*(p_ptr+1));
if (isnan((float)*p_ptr)) if (isnan((float)*p_ptr))
{ {
p_ptr+=2; p_ptr+=2;
@ -91,28 +90,26 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
if (*l_ptr++ == 0) if (*l_ptr++ == 0)
{ {
sys.entity[sys.entities++] = Slvs_MakeLineSegment(lh++, g, sys.entity[sys.entities++] = Slvs_MakeLineSegment(lh++, g,
200, (int)*l_ptr++, (int)*l_ptr++); 200, (int)*l_ptr, (int)*(l_ptr+1));
l_ptr += 2; l_ptr += 4;
} else { } else {
l_ptr += 4; l_ptr += 4;
} }
} }
printf("nconst: %i \n", nConst);
for (int i = 0; i < nConst; i++) for (int i = 0; i < nConst; i++)
{ {
if ((int)*c_ptr == 0) if ((int)*c_ptr == 0)
{ {
c_ptr+=2; c_ptr+=2;
printf("const: %i %i \n", (int)*c_ptr, (int)*(c_ptr+1));
sys.constraint[sys.constraints++] = Slvs_MakeConstraint( sys.constraint[sys.constraints++] = Slvs_MakeConstraint(
con_id++, g, con_id++, g,
SLVS_C_POINTS_COINCIDENT, SLVS_C_POINTS_COINCIDENT,
200, 200,
0.0, 0.0,
(int)*c_ptr++, (int)*c_ptr++, 0, 0); (int)*c_ptr, (int)*(c_ptr+1), 0, 0);
c_ptr += 2; c_ptr += 4;
} else { } else {
c_ptr += 6; c_ptr += 6;
@ -122,7 +119,6 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
/* And solve. */ /* And solve. */
Slvs_Solve(&sys, g); Slvs_Solve(&sys, g);
printf("npts: %i \n", nPts);
if (sys.result == SLVS_RESULT_OKAY) if (sys.result == SLVS_RESULT_OKAY)
{ {
// printf("solved okay\n"); // printf("solved okay\n");
@ -134,7 +130,6 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
buf_pt_start+=2; buf_pt_start+=2;
continue; continue;
} }
printf("res: %i %f %f \n",i, (float)sys.param[p_start].val, (float)sys.param[p_start+1].val);
*buf_pt_start++ = (float)sys.param[p_start++].val; *buf_pt_start++ = (float)sys.param[p_start++].val;
*buf_pt_start++ = (float)sys.param[p_start++].val; *buf_pt_start++ = (float)sys.param[p_start++].val;
} }
@ -163,12 +158,12 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
sys.param = CheckMalloc(50 * sizeof(sys.param[0])); sys.param = CheckMalloc(500 * sizeof(sys.param[0]));
sys.entity = CheckMalloc(50 * sizeof(sys.entity[0])); sys.entity = CheckMalloc(500 * sizeof(sys.entity[0]));
sys.constraint = CheckMalloc(50 * sizeof(sys.constraint[0])); sys.constraint = CheckMalloc(500 * sizeof(sys.constraint[0]));
sys.failed = CheckMalloc(50 * sizeof(sys.failed[0])); sys.failed = CheckMalloc(500 * sizeof(sys.failed[0]));
sys.faileds = 50; sys.faileds = 500;
// Example2d(150.0); // Example2d(150.0);

View File

@ -7,6 +7,6 @@ module.exports = merge(common, {
mode: 'development', mode: 'development',
// devtool: 'inline-source-map', devtool: 'inline-source-map',
}); });