extrude is wierd
parent
1e9067f482
commit
bf2aaf1b94
|
@ -33,6 +33,9 @@ class Sketcher extends THREE.Group {
|
||||||
this.orientSketcher(plane)
|
this.orientSketcher(plane)
|
||||||
this.add(new THREE.PlaneHelper(this.plane, 1, 0xffff00));
|
this.add(new THREE.PlaneHelper(this.plane, 1, 0xffff00));
|
||||||
|
|
||||||
|
this.sketch = new THREE.Group();
|
||||||
|
this.add(this.sketch);
|
||||||
|
|
||||||
this.raycaster = new THREE.Raycaster();
|
this.raycaster = new THREE.Raycaster();
|
||||||
this.raycaster.params.Line.threshold = 0.4;
|
this.raycaster.params.Line.threshold = 0.4;
|
||||||
this.raycaster.params.Points.threshold = 2;
|
this.raycaster.params.Points.threshold = 2;
|
||||||
|
@ -141,7 +144,7 @@ class Sketcher extends THREE.Group {
|
||||||
|
|
||||||
|
|
||||||
deleteSelected() {
|
deleteSelected() {
|
||||||
let minI = this.children.length;
|
let minI = this.sketch.children.length;
|
||||||
|
|
||||||
for (let obj of this.selected) {
|
for (let obj of this.selected) {
|
||||||
minI = Math.min(minI, this.delete(obj))
|
minI = Math.min(minI, this.delete(obj))
|
||||||
|
@ -195,10 +198,10 @@ class Sketcher extends THREE.Group {
|
||||||
if (!link) return Infinity;
|
if (!link) return Infinity;
|
||||||
link = link[1]
|
link = link[1]
|
||||||
|
|
||||||
let i = this.children.indexOf(link[0])
|
let i = this.sketch.children.indexOf(link[0])
|
||||||
|
|
||||||
for (let j = 0; j < link.length; j++) {
|
for (let j = 0; j < link.length; j++) {
|
||||||
const obj = this.children[i + j]
|
const obj = this.sketch.children[i + j]
|
||||||
obj.geometry.dispose()
|
obj.geometry.dispose()
|
||||||
obj.material.dispose()
|
obj.material.dispose()
|
||||||
|
|
||||||
|
@ -207,7 +210,7 @@ class Sketcher extends THREE.Group {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.children.splice(i, link.length)
|
this.sketch.children.splice(i, link.length)
|
||||||
|
|
||||||
this.linkedObjs.delete(obj.l_id)
|
this.linkedObjs.delete(obj.l_id)
|
||||||
|
|
||||||
|
@ -215,8 +218,8 @@ class Sketcher extends THREE.Group {
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePointsBuffer(startingIdx = 0) {
|
updatePointsBuffer(startingIdx = 0) {
|
||||||
for (let i = startingIdx; i < this.children.length; i++) {
|
for (let i = startingIdx; i < this.sketch.children.length; i++) {
|
||||||
const obj = this.children[i]
|
const obj = this.sketch.children[i]
|
||||||
this.objIdx.set(obj.id, i)
|
this.objIdx.set(obj.id, i)
|
||||||
if (obj.type == "Points") {
|
if (obj.type == "Points") {
|
||||||
this.ptsBuf.set(obj.geometry.attributes.position.array, 3 * i)
|
this.ptsBuf.set(obj.geometry.attributes.position.array, 3 * i)
|
||||||
|
@ -256,16 +259,16 @@ class Sketcher extends THREE.Group {
|
||||||
Module.HEAPF32.set(this.linksBuf, links_buffer >> 2)
|
Module.HEAPF32.set(this.linksBuf, links_buffer >> 2)
|
||||||
|
|
||||||
Module["_solver"](
|
Module["_solver"](
|
||||||
this.children.length, pts_buffer,
|
this.sketch.children.length, pts_buffer,
|
||||||
this.constraints.size, constraints_buffer,
|
this.constraints.size, constraints_buffer,
|
||||||
this.linkedObjs.size, links_buffer)
|
this.linkedObjs.size, links_buffer)
|
||||||
|
|
||||||
let ptr = pts_buffer >> 2;
|
let ptr = pts_buffer >> 2;
|
||||||
|
|
||||||
|
|
||||||
for (let i = 0; i < this.children.length; i += 1) {
|
for (let i = 0; i < this.sketch.children.length; i += 1) {
|
||||||
|
|
||||||
const pos = this.children[i].geometry.attributes.position;
|
const pos = this.sketch.children[i].geometry.attributes.position;
|
||||||
if (isNaN(Module.HEAPF32[ptr])) {
|
if (isNaN(Module.HEAPF32[ptr])) {
|
||||||
|
|
||||||
pos.array[0] = Module.HEAPF32[ptr - 6]
|
pos.array[0] = Module.HEAPF32[ptr - 6]
|
||||||
|
|
|
@ -13,8 +13,8 @@ export function drawOnClick1(e) {
|
||||||
this.toPush = sketchArc(mouseLoc)
|
this.toPush = sketchArc(mouseLoc)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updatePoint = this.children.length
|
this.updatePoint = this.sketch.children.length
|
||||||
this.add(...this.toPush)
|
this.sketch.add(...this.toPush)
|
||||||
|
|
||||||
this.linkedObjs.set(this.l_id, [this.mode, this.toPush])
|
this.linkedObjs.set(this.l_id, [this.mode, this.toPush])
|
||||||
for (let obj of this.toPush) {
|
for (let obj of this.toPush) {
|
||||||
|
@ -65,7 +65,7 @@ export function drawClear() {
|
||||||
this.domElement.removeEventListener('pointermove', this.drawPreClick2);
|
this.domElement.removeEventListener('pointermove', this.drawPreClick2);
|
||||||
this.domElement.removeEventListener('pointerdown', this.drawOnClick2);
|
this.domElement.removeEventListener('pointerdown', this.drawOnClick2);
|
||||||
|
|
||||||
this.delete(this.children[this.children.length - 1])
|
this.delete(this.sketch.children[this.sketch.children.length - 1])
|
||||||
|
|
||||||
this.dispatchEvent({ type: 'change' })
|
this.dispatchEvent({ type: 'change' })
|
||||||
this.subsequent = false
|
this.subsequent = false
|
||||||
|
|
|
@ -7,14 +7,13 @@ export function extrude() {
|
||||||
|
|
||||||
let constraints = this.constraints;
|
let constraints = this.constraints;
|
||||||
let linkedObjs = this.linkedObjs;
|
let linkedObjs = this.linkedObjs;
|
||||||
let children = this.children;
|
let children = this.sketch.children;
|
||||||
let visited = new Set()
|
let visited = new Set()
|
||||||
let v2s = []
|
let v2s = []
|
||||||
|
|
||||||
function findPair(node) {
|
function findPair(node) {
|
||||||
visited.add(node)
|
visited.add(node)
|
||||||
let linkedObj = linkedObjs.get(node.l_id)
|
let linkedObj = linkedObjs.get(node.l_id)
|
||||||
console.log(linkedObj)
|
|
||||||
let arr;
|
let arr;
|
||||||
if (linkedObj[0] == 'line') {
|
if (linkedObj[0] == 'line') {
|
||||||
arr = linkedObj[1][2].geometry.attributes.position.array
|
arr = linkedObj[1][2].geometry.attributes.position.array
|
||||||
|
@ -43,7 +42,7 @@ export function extrude() {
|
||||||
for (let d of constraints.get(t)[2]) {
|
for (let d of constraints.get(t)[2]) {
|
||||||
if (d == -1 || d == node) continue;
|
if (d == -1 || d == node) continue;
|
||||||
if (d == children[1]) {
|
if (d == children[1]) {
|
||||||
console.log('touching found')
|
console.log('loop found')
|
||||||
} else {
|
} else {
|
||||||
if (!visited.has(d)) {
|
if (!visited.has(d)) {
|
||||||
findPair(d)
|
findPair(d)
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -1,101 +0,0 @@
|
||||||
import * as THREE from 'three/src/Three'
|
|
||||||
|
|
||||||
export function onHover(e) {
|
|
||||||
if (this.mode || e.buttons) return
|
|
||||||
|
|
||||||
if (this.hovered.length) {
|
|
||||||
for (let ob of this.hovered) {
|
|
||||||
if (ob && !this.selected.has(ob)) {
|
|
||||||
ob.material.color.set(0x555555)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.hovered = []
|
|
||||||
// this.dispatchEvent({ type: 'change' })
|
|
||||||
}
|
|
||||||
|
|
||||||
this.raycaster.setFromCamera(
|
|
||||||
new THREE.Vector2(
|
|
||||||
(e.clientX / window.innerWidth) * 2 - 1,
|
|
||||||
- (e.clientY / window.innerHeight) * 2 + 1
|
|
||||||
),
|
|
||||||
this.camera
|
|
||||||
);
|
|
||||||
|
|
||||||
const hoverPts = this.raycaster.intersectObjects(this.children)
|
|
||||||
|
|
||||||
// console.log(hoverPts)
|
|
||||||
if (hoverPts.length) {
|
|
||||||
let minDist = Infinity;
|
|
||||||
let idx = []
|
|
||||||
for (let i = 0; i < hoverPts.length; i++) {
|
|
||||||
if (!hoverPts[i].distanceToRay) continue;
|
|
||||||
if (hoverPts[i].distanceToRay < minDist) {
|
|
||||||
minDist = hoverPts[i].distanceToRay
|
|
||||||
idx = [i]
|
|
||||||
} else if (hoverPts[i].distanceToRay == minDist) {
|
|
||||||
idx.push(i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// if (!idx.length) idx.push(0)
|
|
||||||
|
|
||||||
for (let i of idx) {
|
|
||||||
hoverPts[i].object.material.color.set(0x00ff00)
|
|
||||||
// hoverPts[i].object.material.color.set(0xff0000)
|
|
||||||
this.hovered.push(hoverPts[i].object)
|
|
||||||
}
|
|
||||||
this.dispatchEvent({ type: 'change' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function onPick(e) {
|
|
||||||
if (this.mode || e.buttons != 1) return
|
|
||||||
|
|
||||||
if (this.hovered.length) {
|
|
||||||
|
|
||||||
for (let h of this.hovered) {
|
|
||||||
this.selected.add(h)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.hovered[0].type == "Points") {
|
|
||||||
this.domElement.addEventListener('pointermove', this.onDrag);
|
|
||||||
this.domElement.addEventListener('pointerup', this.onRelease)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let obj of this.selected) {
|
|
||||||
obj.material.color.set(0x555555)
|
|
||||||
}
|
|
||||||
this.dispatchEvent({ type: 'change' })
|
|
||||||
this.selected.clear()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onDrag(e) {
|
|
||||||
const mouseLoc = this.getLocation(e);
|
|
||||||
|
|
||||||
for (let h of this.hovered) {
|
|
||||||
this.ptsBuf.set(
|
|
||||||
mouseLoc,
|
|
||||||
this.objIdx.get(h.id) * 3
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.solve()
|
|
||||||
this.dispatchEvent({ type: 'change' })
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function onRelease() {
|
|
||||||
this.domElement.removeEventListener('pointermove', this.onDrag)
|
|
||||||
this.domElement.removeEventListener('pointerup', this.onRelease)
|
|
||||||
|
|
||||||
for (let ii of this.hovered) {
|
|
||||||
ii.geometry.computeBoundingSphere()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ export function onHover(e) {
|
||||||
this.camera
|
this.camera
|
||||||
);
|
);
|
||||||
|
|
||||||
const hoverPts = this.raycaster.intersectObjects(this.children)
|
const hoverPts = this.raycaster.intersectObjects(this.sketch.children)
|
||||||
|
|
||||||
// console.log(hoverPts)
|
// console.log(hoverPts)
|
||||||
if (hoverPts.length) {
|
if (hoverPts.length) {
|
||||||
|
|
|
@ -42,12 +42,12 @@ export function sketchLine(mouseLoc) {
|
||||||
this.constraints.set(++this.c_id,
|
this.constraints.set(++this.c_id,
|
||||||
[
|
[
|
||||||
'coincident', -1,
|
'coincident', -1,
|
||||||
[this.children[this.children.length - 2], p1, -1, -1]
|
[this.sketch.children[this.sketch.children.length - 2], p1, -1, -1]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
p1.constraints.add(this.c_id)
|
p1.constraints.add(this.c_id)
|
||||||
this.children[this.children.length - 2].constraints.add(this.c_id)
|
this.sketch.children[this.sketch.children.length - 2].constraints.add(this.c_id)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue