working snap mvp
parent
cfb80a46ba
commit
7727e1516f
File diff suppressed because one or more lines are too long
|
@ -58,6 +58,7 @@ export function drawPreClick2(e) {
|
||||||
const mouseLoc = this.getLocation(e).toArray();
|
const mouseLoc = this.getLocation(e).toArray();
|
||||||
|
|
||||||
if (this.mode == "line") {
|
if (this.mode == "line") {
|
||||||
|
this.snap = true
|
||||||
drawLine2(mouseLoc, this.toPush)
|
drawLine2(mouseLoc, this.toPush)
|
||||||
} else if (this.mode == 'arc') {
|
} else if (this.mode == 'arc') {
|
||||||
drawArc2(mouseLoc, this.toPush)
|
drawArc2(mouseLoc, this.toPush)
|
||||||
|
@ -76,6 +77,26 @@ export function drawOnClick2(e) {
|
||||||
|
|
||||||
// a this.mode == "" will prevent event chain from persisisting
|
// a this.mode == "" will prevent event chain from persisisting
|
||||||
if (this.mode == "line") {
|
if (this.mode == "line") {
|
||||||
|
console.log(this.hovered)
|
||||||
|
|
||||||
|
|
||||||
|
if (this.hovered.length >= 2) {
|
||||||
|
this.constraints.set(++this.c_id, //??? why incremennt before not after
|
||||||
|
[
|
||||||
|
'points_coincident', -1,
|
||||||
|
[this.hovered[this.hovered.length - 2].name, this.hovered[this.hovered.length - 1].name, -1, -1]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
this.updateOtherBuffers()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
this.snap = false
|
||||||
this.subsequent = true
|
this.subsequent = true
|
||||||
this.drawOnClick1(e)
|
this.drawOnClick1(e)
|
||||||
|
|
||||||
|
@ -139,6 +160,7 @@ export function drawClear() {
|
||||||
this.scene.render()
|
this.scene.render()
|
||||||
this.subsequent = false
|
this.subsequent = false
|
||||||
this.toPush = []
|
this.toPush = []
|
||||||
|
this.snap = false
|
||||||
|
|
||||||
this.mode = ""
|
this.mode = ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,4 +33,5 @@ export function drawLine2(mouseLoc, toPush) {
|
||||||
|
|
||||||
line.geometry.attributes.position.set(mouseLoc, 3)
|
line.geometry.attributes.position.set(mouseLoc, 3)
|
||||||
line.geometry.attributes.position.needsUpdate = true;
|
line.geometry.attributes.position.needsUpdate = true;
|
||||||
|
line.geometry.computeBoundingSphere();
|
||||||
}
|
}
|
|
@ -10,7 +10,6 @@ export function extrude(sketch, depth) {
|
||||||
let v2s = []
|
let v2s = []
|
||||||
|
|
||||||
function findPair(node) {
|
function findPair(node) {
|
||||||
// console.log(node.name, 'xx')
|
|
||||||
if (node.userData.construction) return;
|
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)
|
||||||
|
|
|
@ -5,7 +5,9 @@ import { onDimMoveEnd } from './drawDimension'
|
||||||
let ptLoc
|
let ptLoc
|
||||||
|
|
||||||
export function onHover(e) {
|
export function onHover(e) {
|
||||||
if (( this.mode && this.mode!='dimension') || e.buttons) return
|
if ((this.mode && this.mode != 'dimension' && !this.snap) || e.buttons) return
|
||||||
|
// if (( this.mode && this.mode!='dimension') || e.buttons) return
|
||||||
|
// console.log('here')
|
||||||
|
|
||||||
raycaster.setFromCamera(
|
raycaster.setFromCamera(
|
||||||
new THREE.Vector2(
|
new THREE.Vector2(
|
||||||
|
@ -17,30 +19,30 @@ export function onHover(e) {
|
||||||
|
|
||||||
let hoverPts;
|
let hoverPts;
|
||||||
|
|
||||||
|
|
||||||
if (this.obj3d.userData.type != 'sketch') {
|
if (this.obj3d.userData.type != 'sketch') {
|
||||||
this.selpoints[0].visible = false // hide selpoint[0] before each redraw
|
this.selpoints[0].visible = false // hide selpoint[0] before each redraw
|
||||||
raycaster.layers.set(1)
|
raycaster.layers.set(1)
|
||||||
hoverPts = raycaster.intersectObjects(this.obj3d.children, true)
|
hoverPts = raycaster.intersectObjects(this.obj3d.children, true) // has side effect of updating bounding spheres
|
||||||
} else {
|
} else {
|
||||||
// raycaster.layers.set(0)
|
|
||||||
raycaster.layers.set(2)
|
raycaster.layers.set(2)
|
||||||
|
// if (this.snap) return
|
||||||
hoverPts = raycaster.intersectObjects([...this.dimGroup.children, ...this.obj3d.children])
|
hoverPts = raycaster.intersectObjects([...this.dimGroup.children, ...this.obj3d.children])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let idx = []
|
let idx = []
|
||||||
if (hoverPts.length) {
|
|
||||||
|
|
||||||
|
const thresh = this.snap ? 1 : 0.0001
|
||||||
|
if (hoverPts.length) {
|
||||||
let minDist = Infinity;
|
let minDist = Infinity;
|
||||||
for (let i = 0; i < hoverPts.length; i++) {
|
for (let i = 0; i < hoverPts.length; i++) {
|
||||||
if (!hoverPts[i].distanceToRay) continue;
|
if (!hoverPts[i].distanceToRay) continue;
|
||||||
if (hoverPts[i].distanceToRay < minDist - 0.0001) {
|
if (hoverPts[i].distanceToRay < minDist - thresh) {
|
||||||
idx = [i]
|
idx = [i]
|
||||||
|
|
||||||
if (this.obj3d.userData.type != 'sketch') break
|
if (this.obj3d.userData.type != 'sketch') break
|
||||||
|
|
||||||
minDist = hoverPts[i].distanceToRay
|
minDist = hoverPts[i].distanceToRay
|
||||||
} else if (Math.abs(hoverPts[i].distanceToRay - minDist) < 0.0001) {
|
} else if (hoverPts[i].distanceToRay < minDist + thresh) {
|
||||||
idx.push(i)
|
idx.push(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,8 +116,7 @@ export function onHover(e) {
|
||||||
|
|
||||||
let draggedLabel;
|
let draggedLabel;
|
||||||
export function onPick(e) {
|
export function onPick(e) {
|
||||||
if (( this.mode && this.mode!='dimension') || e.buttons != 1) return
|
if ((this.mode && this.mode != 'dimension') || e.buttons != 1) return
|
||||||
// if (this.mode || e.buttons != 1 || e.ctrlKey || e.metaKey) return
|
|
||||||
|
|
||||||
if (this.hovered.length) {
|
if (this.hovered.length) {
|
||||||
let obj = this.hovered[this.hovered.length - 1]
|
let obj = this.hovered[this.hovered.length - 1]
|
||||||
|
|
|
@ -47,34 +47,6 @@ export const NavBar = () => {
|
||||||
forceUpdate()
|
forceUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
// const mirror = (plane) => {
|
|
||||||
// if (sc.selected.length != 2 || ) {
|
|
||||||
// alert('please first select two bodies for boolean operation')
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// const [m1, m2] = sc.selected
|
|
||||||
|
|
||||||
// const mesh = sc.boolOp(m1, m2, code)
|
|
||||||
|
|
||||||
// sc.obj3d.add(mesh)
|
|
||||||
|
|
||||||
// dispatch({
|
|
||||||
// type: 'set-entry-visibility', obj: {
|
|
||||||
// [m1.name]: false,
|
|
||||||
// [m2.name]: false,
|
|
||||||
// [mesh.name]: true,
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// dispatch({
|
|
||||||
// type: 'rx-boolean', mesh, deps: [m1.name, m2.name]
|
|
||||||
// })
|
|
||||||
|
|
||||||
|
|
||||||
// sc.render()
|
|
||||||
// forceUpdate()
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
const addSketch = () => {
|
const addSketch = () => {
|
||||||
const sketch = sc.addSketch()
|
const sketch = sc.addSketch()
|
||||||
|
@ -150,7 +122,7 @@ export const NavBar = () => {
|
||||||
sc.render()
|
sc.render()
|
||||||
sc.activeSketch.setClean()
|
sc.activeSketch.setClean()
|
||||||
}
|
}
|
||||||
, 'Save']
|
, 'Save'],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,17 +181,13 @@ export const NavBar = () => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='w-auto h-full flex'>
|
<div className='w-auto h-full flex'>
|
||||||
{sketchActive ?
|
{(sketchActive ? sketchModeButtons : partModeButtons).map(
|
||||||
sketchModeButtons.map(([Icon, fcn, txt], idx) => (
|
([Icon, fcn, txt], idx) => (
|
||||||
|
Icon !== undefined ?
|
||||||
<Icon className="btn text-gray-200 w-auto h-full p-3.5" tooltip={txt}
|
<Icon className="btn text-gray-200 w-auto h-full p-3.5" tooltip={txt}
|
||||||
onClick={fcn} key={idx}
|
onClick={fcn} key={idx}
|
||||||
/>
|
/> :
|
||||||
))
|
<div className="w-12 h-full"></div>
|
||||||
:
|
|
||||||
partModeButtons.map(([Icon, fcn, txt], idx) => (
|
|
||||||
<Icon className="btn text-gray-200 w-auto h-full p-3.5" tooltip={txt}
|
|
||||||
onClick={fcn} key={idx}
|
|
||||||
/>
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue