snap improvements

master
howard 2021-04-21 15:32:34 -07:00
parent 33f572e3c2
commit 25791f40b9
3 changed files with 20 additions and 9 deletions

View File

@ -122,6 +122,7 @@ export function drawArc4(mouseLoc, toPush) {
points points
); );
arc.geometry.attributes.position.needsUpdate = true; arc.geometry.attributes.position.needsUpdate = true;
arc.geometry.computeBoundingSphere()
arc.userData.ccw = ccw; arc.userData.ccw = ccw;
return ccw return ccw

View File

@ -33,6 +33,7 @@ export function drawOnClick1(e) {
} else { } else {
console.log(this.hovered)
if (this.hovered.length) { if (this.hovered.length) {
this.constraints.set(++this.c_id, //??? why incremennt before not after this.constraints.set(++this.c_id, //??? why incremennt before not after
@ -41,6 +42,8 @@ export function drawOnClick1(e) {
[this.hovered[this.hovered.length - 1].name, this.toPush[0].name, -1, -1] [this.hovered[this.hovered.length - 1].name, this.toPush[0].name, -1, -1]
] ]
) )
this.hovered[this.hovered.length - 1].userData.constraints.push(this.c_id)
this.toPush[0].userData.constraints.push(this.c_id)
this.updateOtherBuffers() this.updateOtherBuffers()
} }
@ -59,6 +62,8 @@ export function drawOnClick1(e) {
[this.hovered[this.hovered.length - 1].name, this.toPush[0].name, -1, -1] [this.hovered[this.hovered.length - 1].name, this.toPush[0].name, -1, -1]
] ]
) )
this.hovered[this.hovered.length - 1].userData.constraints.push(this.c_id)
this.toPush[0].userData.constraints.push(this.c_id)
this.updateOtherBuffers() this.updateOtherBuffers()
} }
@ -110,11 +115,11 @@ 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") {
if (this.hovered.length >= 2) { if (this.hovered.length>=2) {
this.constraints.set(++this.c_id, //??? why incremennt before not after this.constraints.set(++this.c_id, //??? why incremennt before not after
[ [
'points_coincident', -1, 'points_coincident', -1,
[this.hovered[this.hovered.length - 2].name, this.hovered[this.hovered.length - 1].name, -1, -1] [this.hovered[this.hovered.length - 2].name, this.toPush[1].name, -1, -1]
] ]
) )
this.updateOtherBuffers() this.updateOtherBuffers()
@ -127,13 +132,12 @@ export function drawOnClick2(e) {
} else if (this.mode == "point") { } else if (this.mode == "point") {
this.drawOnClick1(e) this.drawOnClick1(e)
} else if (this.mode == "arc") { } else if (this.mode == "arc") {
this.snap = false
if (this.hovered.length >= 2) { if (this.hovered.length>=2) {
this.constraints.set(++this.c_id, //??? why incremennt before not after this.constraints.set(++this.c_id, //??? why incremennt before not after
[ [
'points_coincident', -1, 'points_coincident', -1,
[this.hovered[this.hovered.length - 2].name, this.hovered[this.hovered.length - 1].name, -1, -1] [this.hovered[this.hovered.length - 2].name, this.toPush[1].name, -1, -1]
] ]
) )
this.updateOtherBuffers() this.updateOtherBuffers()

View File

@ -1,6 +1,7 @@
import * as THREE from '../node_modules/three/src/Three'; import * as THREE from '../node_modules/three/src/Three';
import { raycaster, setHover } from './shared'; import { raycaster, setHover } from './shared';
import { onDimMoveEnd } from './drawDimension' import { onDimMoveEnd } from './drawDimension'
import { connectAdvanced } from 'react-redux';
let ptLoc let ptLoc
@ -18,7 +19,7 @@ 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)
@ -34,7 +35,7 @@ export function onHover(e) {
const thresh = this.snap ? 1 : 0.0001 const thresh = this.snap ? 1 : 0.0001
if (hoverPts.length) { if (hoverPts.length) {
console.log('here', hoverPts) // console.log('here', hoverPts)
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;
@ -70,9 +71,14 @@ export function onHover(e) {
for (let x = 0; x < idx.length; x++) { for (let x = 0; x < idx.length; x++) {
let obj = hoverPts[idx[x]].object let obj = hoverPts[idx[x]].object
// if (!this.snap || (this.snap && x < idx.length-1) ) { if (this.snap) {
if (idx.length==1 || x != idx.length - 1) {
setHover(obj, 1, false)
}
} else {
setHover(obj, 1, false) setHover(obj, 1, false)
// } }
if (this.obj3d.userData.type != 'sketch' && obj.userData.type == 'point') { if (this.obj3d.userData.type != 'sketch' && obj.userData.type == 'point') {
ptLoc = obj.geometry.attributes.position.array ptLoc = obj.geometry.attributes.position.array