fixing delete, still one thing
parent
87c7c3e55c
commit
b3162d97f7
|
@ -39,7 +39,6 @@
|
|||
<div id="react"></div>
|
||||
<canvas id="c"></canvas>
|
||||
<div id="stats"></div>
|
||||
<!-- <script src="redux.bundle.js"></script> -->
|
||||
<script src="index.bundle.js"></script>
|
||||
<script src="renderer.bundle.js"></script>
|
||||
<script src="solver.js"></script>
|
||||
|
|
|
@ -151,25 +151,58 @@ class Sketcher extends THREE.Group {
|
|||
}
|
||||
|
||||
deleteSelected() {
|
||||
let minI = this.children.length;
|
||||
|
||||
for (let obj of this.selected) {
|
||||
minI = Math.min(minI, this.delete(obj))
|
||||
}
|
||||
const toDelete = [...this.selected]
|
||||
.filter(e => e.type == 'Line')
|
||||
.sort((a, b) => b.id - a.id)
|
||||
.map(e => {
|
||||
const i = this.objIdx.get(e.id)
|
||||
this.delete(i)
|
||||
return i
|
||||
})
|
||||
|
||||
// this.updatePointsBuffer(minI)
|
||||
this.updatePointsBuffer()
|
||||
|
||||
this.updatePointsBuffer(toDelete[0])
|
||||
// this.updatePointsBuffer()
|
||||
this.updateOtherBuffers()
|
||||
|
||||
this.selected.clear()
|
||||
this.dispatchEvent({ type: 'change' })
|
||||
}
|
||||
|
||||
delete(i) {
|
||||
const obj = this.children[i]
|
||||
let link = this.linkedObjs.get(obj.l_id)
|
||||
if (!link) return;
|
||||
link = link[1]
|
||||
|
||||
console.log('delete',link.length)
|
||||
for (let j = 0; j < link.length; j++) {
|
||||
const obj = this.children[i + j]
|
||||
obj.geometry.dispose()
|
||||
obj.material.dispose()
|
||||
|
||||
for (let c_id of obj.constraints) {
|
||||
console.log(j,c_id)
|
||||
this.deleteConstraints(c_id)
|
||||
}
|
||||
}
|
||||
|
||||
this.children.splice(i, link.length)
|
||||
|
||||
this.linkedObjs.delete(obj.l_id)
|
||||
|
||||
}
|
||||
|
||||
|
||||
deleteConstraints(c_id) {
|
||||
for (let ob of this.constraints.get(c_id)[2]) {
|
||||
if (ob == -1) continue
|
||||
for (let idx of this.constraints.get(c_id)[2]) { //////////
|
||||
if (idx == -1) continue
|
||||
const ob = this.children[this.objIdx.get(idx)]
|
||||
if (ob) {
|
||||
ob.constraints.delete(c_id)
|
||||
}
|
||||
}
|
||||
this.constraints.delete(c_id)
|
||||
}
|
||||
|
||||
|
@ -179,7 +212,7 @@ class Sketcher extends THREE.Group {
|
|||
this.constraintsBuf.set(
|
||||
[
|
||||
this.constraintNum[obj[0]], obj[1],
|
||||
...obj[2].map(ele => this.objIdx.get(ele.id) ?? -1),
|
||||
...obj[2].map(ele => this.objIdx.get(ele) ?? -1),
|
||||
],
|
||||
(i) * 6
|
||||
)
|
||||
|
@ -191,7 +224,7 @@ class Sketcher extends THREE.Group {
|
|||
this.linksBuf.set(
|
||||
[
|
||||
this.linkNum[obj[0]],
|
||||
...obj[1].map(ele => this.objIdx.get(ele.id) ?? -1),
|
||||
...obj[1].map(ele => this.objIdx.get(ele) ?? -1),
|
||||
],
|
||||
(i) * 5
|
||||
)
|
||||
|
@ -200,29 +233,7 @@ class Sketcher extends THREE.Group {
|
|||
|
||||
}
|
||||
|
||||
delete(obj) {
|
||||
let link = this.linkedObjs.get(obj.l_id)
|
||||
if (!link) return Infinity;
|
||||
link = link[1]
|
||||
|
||||
let i = this.children.indexOf(link[0])
|
||||
|
||||
for (let j = 0; j < link.length; j++) {
|
||||
const obj = this.children[i + j]
|
||||
obj.geometry.dispose()
|
||||
obj.material.dispose()
|
||||
|
||||
for (let c_id of obj.constraints) {
|
||||
this.deleteConstraints(c_id)
|
||||
}
|
||||
}
|
||||
|
||||
this.children.splice(i, link.length)
|
||||
|
||||
this.linkedObjs.delete(obj.l_id)
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
updatePointsBuffer(startingIdx = 0) {
|
||||
for (let i = startingIdx; i < this.children.length; i++) {
|
||||
|
@ -299,7 +310,7 @@ class Sketcher extends THREE.Group {
|
|||
*/
|
||||
for (let [k, obj] of this.linkedObjs) {
|
||||
if (obj[0] != 'arc') continue;
|
||||
const [p1, p2, c, arc] = obj[1]
|
||||
const [p1, p2, c, arc] = obj[1].map(e => this.children[this.objIdx.get(e)])
|
||||
|
||||
const points = get3PtArc(
|
||||
p1.geometry.attributes.position.array,
|
||||
|
|
|
@ -68,7 +68,7 @@ export function setCoincident() {
|
|||
this.constraints.set(++this.c_id,
|
||||
[
|
||||
'coincident', -1,
|
||||
[toComb[i - 1], toComb[i], -1, -1]
|
||||
[toComb[i - 1].id, toComb[i].id, -1, -1] ///////
|
||||
]
|
||||
)
|
||||
toComb[i].constraints.add(this.c_id)
|
||||
|
|
|
@ -16,7 +16,7 @@ export function drawOnClick1(e) {
|
|||
this.updatePoint = this.children.length
|
||||
this.add(...this.toPush)
|
||||
|
||||
this.linkedObjs.set(this.l_id, [this.mode, this.toPush])
|
||||
this.linkedObjs.set(this.l_id, [this.mode, this.toPush.map(e=>e.id)])
|
||||
for (let obj of this.toPush) {
|
||||
obj.l_id = this.l_id
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ export function drawClear() {
|
|||
this.domElement.removeEventListener('pointermove', this.drawPreClick2);
|
||||
this.domElement.removeEventListener('pointerdown', this.drawOnClick2);
|
||||
|
||||
this.delete(this.children[this.children.length - 1])
|
||||
this.delete(this.updatePoint)
|
||||
|
||||
this.dispatchEvent({ type: 'change' })
|
||||
this.subsequent = false
|
||||
|
|
|
@ -5,6 +5,7 @@ export function extrude(sketch) {
|
|||
let constraints = sketch.constraints;
|
||||
let linkedObjs = sketch.linkedObjs;
|
||||
let children = sketch.children;
|
||||
let objIdx = sketch.objIdx;
|
||||
let visited = new Set()
|
||||
let v2s = []
|
||||
|
||||
|
@ -13,16 +14,18 @@ export function extrude(sketch) {
|
|||
let linkedObj = linkedObjs.get(node.l_id)
|
||||
let arr;
|
||||
if (linkedObj[0] == 'line') {
|
||||
arr = linkedObj[1][2].geometry.attributes.position.array
|
||||
// console.log(children, objIdx, linkedObj)
|
||||
arr = children[objIdx.get(linkedObj[1][2])].geometry.attributes.position.array
|
||||
} else if (linkedObj[0] == 'arc') {
|
||||
arr = linkedObj[1][3].geometry.attributes.position.array
|
||||
arr = children[objIdx.get(linkedObj[1][3])].geometry.attributes.position.array
|
||||
}
|
||||
for (let i = 0; i < arr.length; i += 3) {
|
||||
v2s.push(new THREE.Vector2(arr[i], arr[i + 1]))
|
||||
}
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
let d = linkedObj[1][i]
|
||||
// let d = linkedObj[1][i]
|
||||
let d = children[objIdx.get(linkedObj[1][i])]
|
||||
if (d == -1 || d == node) continue;
|
||||
if (d == children[1]) {
|
||||
console.log('pair found')
|
||||
|
@ -36,8 +39,10 @@ export function extrude(sketch) {
|
|||
function findTouching(node) {
|
||||
for (let t of node.constraints) {
|
||||
if (constraints.get(t)[0] != 'coincident') continue
|
||||
for (let d of constraints.get(t)[2]) {
|
||||
if (d == -1 || d == node) continue;
|
||||
for (let c of constraints.get(t)[2]) {
|
||||
if (c == -1) continue;
|
||||
const d = children[objIdx.get(c)]
|
||||
if (d == node) continue;
|
||||
if (d == children[1]) {
|
||||
console.log('loop found')
|
||||
} else {
|
||||
|
|
|
@ -41,7 +41,7 @@ export function sketchLine(mouseLoc) {
|
|||
this.constraints.set(++this.c_id,
|
||||
[
|
||||
'coincident', -1,
|
||||
[this.children[this.children.length - 2], p1, -1, -1]
|
||||
[this.children[this.children.length - 2].id, p1.id, -1, -1]
|
||||
]
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue