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 = ""
break;
case 'l':
if (this.mode == 'line') {
this.clear()
}
this.domElement.addEventListener('pointerdown', this.onClick_1)
this.mode = "line"
break;
@ -248,7 +251,10 @@ export class Sketcher extends THREE.Group {
onDrag(e) {
const mouseLoc = this.getLocation(e);
this.geomGroup.children[this.grabPtIdx].geometry.attributes.position.set(mouseLoc);
this.updatePointsBuffer()
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' })
}
@ -300,7 +306,6 @@ export class Sketcher extends THREE.Group {
i = 0;
for (let [key, obj] of this.linkedObjs) {
console.log(obj[0])
this.linksBuf.set(
[
this.linkNum[obj[1]],
@ -308,7 +313,6 @@ export class Sketcher extends THREE.Group {
],
(i) * 5
)
console.log(this.linksBuf)
i++
}
@ -338,7 +342,7 @@ export class Sketcher extends THREE.Group {
return i
}
updatePointsBuffer(startingIdx=0) {
updatePointsBuffer(startingIdx = 0) {
for (let i = startingIdx; i < this.geomGroup.children.length; i++) {
const obj = this.geomGroup.children[i]
this.objIdx.set(obj.id, i)
@ -526,11 +530,12 @@ export class Sketcher extends THREE.Group {
solve() {
// for (let i = 0, p = 0; i < this.geomGroup.children.length; i++) {
// this.ptsBuf[p++] = this.geomGroup.children[i].geometry.attributes.position.array[0]
// this.ptsBuf[p++] = this.geomGroup.children[i].geometry.attributes.position.array[1]
// }
this.updatePointsBuffer()
for (let i = 0, p = 0; i < this.geomGroup.children.length; i++) {
if (this.geomGroup.children[i].type == "Points") {
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]
}
}
const pts_buffer = Module._malloc(this.ptsBuf.length * this.ptsBuf.BYTES_PER_ELEMENT)
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) {
const pos = this.geomGroup.children[i].geometry.attributes.position;
// console.log(pos.array)
if (isNaN(Module.HEAPF32[ptr])) {
pos.array[0] = Module.HEAPF32[ptr-4]
pos.array[1] = Module.HEAPF32[ptr-3]
pos.array[3] = Module.HEAPF32[ptr-2]
pos.array[4] = Module.HEAPF32[ptr-1]
pos.array[0] = Module.HEAPF32[ptr - 4]
pos.array[1] = Module.HEAPF32[ptr - 3]
pos.array[3] = Module.HEAPF32[ptr - 2]
pos.array[4] = Module.HEAPF32[ptr - 1]
} else {
pos.array[0] = Module.HEAPF32[ptr++]
pos.array[1] = Module.HEAPF32[ptr++]
pos.array[0] = Module.HEAPF32[ptr]
pos.array[1] = Module.HEAPF32[ptr + 1]
}
ptr += 2;
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;
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))
{
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)
{
sys.entity[sys.entities++] = Slvs_MakeLineSegment(lh++, g,
200, (int)*l_ptr++, (int)*l_ptr++);
l_ptr += 2;
200, (int)*l_ptr, (int)*(l_ptr+1));
l_ptr += 4;
} else {
l_ptr += 4;
}
}
printf("nconst: %i \n", nConst);
for (int i = 0; i < nConst; i++)
{
if ((int)*c_ptr == 0)
{
c_ptr+=2;
printf("const: %i %i \n", (int)*c_ptr, (int)*(c_ptr+1));
sys.constraint[sys.constraints++] = Slvs_MakeConstraint(
con_id++, g,
SLVS_C_POINTS_COINCIDENT,
200,
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 {
c_ptr += 6;
@ -122,7 +119,6 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
/* And solve. */
Slvs_Solve(&sys, g);
printf("npts: %i \n", nPts);
if (sys.result == SLVS_RESULT_OKAY)
{
// 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;
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;
}
@ -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[])
{
sys.param = CheckMalloc(50 * sizeof(sys.param[0]));
sys.entity = CheckMalloc(50 * sizeof(sys.entity[0]));
sys.constraint = CheckMalloc(50 * sizeof(sys.constraint[0]));
sys.param = CheckMalloc(500 * sizeof(sys.param[0]));
sys.entity = CheckMalloc(500 * sizeof(sys.entity[0]));
sys.constraint = CheckMalloc(500 * sizeof(sys.constraint[0]));
sys.failed = CheckMalloc(50 * sizeof(sys.failed[0]));
sys.faileds = 50;
sys.failed = CheckMalloc(500 * sizeof(sys.failed[0]));
sys.faileds = 500;
// Example2d(150.0);

View File

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