working snap mvp

master
howard 2021-04-21 13:21:26 -07:00
parent cfb80a46ba
commit 7727e1516f
6 changed files with 44 additions and 53 deletions

File diff suppressed because one or more lines are too long

View File

@ -58,6 +58,7 @@ export function drawPreClick2(e) {
const mouseLoc = this.getLocation(e).toArray();
if (this.mode == "line") {
this.snap = true
drawLine2(mouseLoc, this.toPush)
} else if (this.mode == 'arc') {
drawArc2(mouseLoc, this.toPush)
@ -76,6 +77,26 @@ export function drawOnClick2(e) {
// a this.mode == "" will prevent event chain from persisisting
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.drawOnClick1(e)
@ -139,6 +160,7 @@ export function drawClear() {
this.scene.render()
this.subsequent = false
this.toPush = []
this.snap = false
this.mode = ""
}

View File

@ -33,4 +33,5 @@ export function drawLine2(mouseLoc, toPush) {
line.geometry.attributes.position.set(mouseLoc, 3)
line.geometry.attributes.position.needsUpdate = true;
line.geometry.computeBoundingSphere();
}

View File

@ -10,7 +10,6 @@ export function extrude(sketch, depth) {
let v2s = []
function findPair(node) {
// console.log(node.name, 'xx')
if (node.userData.construction) return;
visited.add(node)
let linkedObj = linkedObjs.get(node.userData.l_id)

View File

@ -5,7 +5,9 @@ import { onDimMoveEnd } from './drawDimension'
let ptLoc
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(
new THREE.Vector2(
@ -17,30 +19,30 @@ export function onHover(e) {
let hoverPts;
if (this.obj3d.userData.type != 'sketch') {
this.selpoints[0].visible = false // hide selpoint[0] before each redraw
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 {
// raycaster.layers.set(0)
raycaster.layers.set(2)
// if (this.snap) return
hoverPts = raycaster.intersectObjects([...this.dimGroup.children, ...this.obj3d.children])
}
let idx = []
if (hoverPts.length) {
const thresh = this.snap ? 1 : 0.0001
if (hoverPts.length) {
let minDist = Infinity;
for (let i = 0; i < hoverPts.length; i++) {
if (!hoverPts[i].distanceToRay) continue;
if (hoverPts[i].distanceToRay < minDist - 0.0001) {
if (hoverPts[i].distanceToRay < minDist - thresh) {
idx = [i]
if (this.obj3d.userData.type != 'sketch') break
minDist = hoverPts[i].distanceToRay
} else if (Math.abs(hoverPts[i].distanceToRay - minDist) < 0.0001) {
} else if (hoverPts[i].distanceToRay < minDist + thresh) {
idx.push(i)
}
}
@ -114,8 +116,7 @@ export function onHover(e) {
let draggedLabel;
export function onPick(e) {
if (( this.mode && this.mode!='dimension') || e.buttons != 1) return
// if (this.mode || e.buttons != 1 || e.ctrlKey || e.metaKey) return
if ((this.mode && this.mode != 'dimension') || e.buttons != 1) return
if (this.hovered.length) {
let obj = this.hovered[this.hovered.length - 1]
@ -154,7 +155,7 @@ export function onPick(e) {
this.setHover(obj, 1)
} else {
this.setHover(this.selected[idx], 0)
this.selected.splice(idx, 1)

View File

@ -47,34 +47,6 @@ export const NavBar = () => {
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 sketch = sc.addSketch()
@ -150,7 +122,7 @@ export const NavBar = () => {
sc.render()
sc.activeSketch.setClean()
}
, 'Save']
, 'Save'],
]
@ -209,17 +181,13 @@ export const NavBar = () => {
</div>
</div>
<div className='w-auto h-full flex'>
{sketchActive ?
sketchModeButtons.map(([Icon, fcn, txt], idx) => (
<Icon className="btn text-gray-200 w-auto h-full p-3.5" tooltip={txt}
onClick={fcn} key={idx}
/>
))
:
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}
/>
{(sketchActive ? sketchModeButtons : partModeButtons).map(
([Icon, fcn, txt], idx) => (
Icon !== undefined ?
<Icon className="btn text-gray-200 w-auto h-full p-3.5" tooltip={txt}
onClick={fcn} key={idx}
/> :
<div className="w-12 h-full"></div>
))
}
</div>