point not working

master
howard 2021-04-21 21:39:23 -07:00
parent 25791f40b9
commit f7cc65dda2
5 changed files with 28 additions and 25 deletions

View File

@ -56,6 +56,8 @@ export class Scene {
cameraDist * Math.cos(xzAngle)
);
this.camera.layers.enable(3)
const controls = new TrackballControls(this.camera, this.canvas);
controls.target.set(0, 0, 0);
controls.update();

View File

@ -257,6 +257,7 @@ class Sketch {
break;
case 'p':
this.mode = "point"
this.snap = true
this.canvas.addEventListener('pointerdown', this.drawOnClick1, { once: true })
break;
case 'd':

View File

@ -71,13 +71,13 @@ export function drawOnClick1(e) {
} else if (this.mode == 'point') {
} else if (this.mode == "point") {
this.toPush = drawPoint(mouseLoc)
}
this.toPush.forEach(element => {
element.layers.enable(2)
});
// this.toPush.forEach(element => {
// element.layers.enable(2)
// });
this.updatePoint = this.obj3d.children.length
this.obj3d.add(...this.toPush)
@ -94,10 +94,8 @@ 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') {
this.snap = true
drawArc2(mouseLoc, this.toPush)
}
@ -112,14 +110,18 @@ export function drawOnClick2(e) {
this.updatePointsBuffer(this.updatePoint)
this.updateOtherBuffers()
// a this.mode == "" will prevent event chain from persisisting
if (this.mode == "line") {
// a this.mode == "" here will prevent event chain from persisisting
if (this.hovered.length>=2) {
this.toPush.forEach(element => {
element.layers.enable(2)
});
if (this.mode == "line") {
if (this.hovered.length) {
this.constraints.set(++this.c_id, //??? why incremennt before not after
[
'points_coincident', -1,
[this.hovered[this.hovered.length - 2].name, this.toPush[1].name, -1, -1]
[this.hovered[this.hovered.length - 1].name, this.toPush[1].name, -1, -1]
]
)
this.updateOtherBuffers()
@ -133,11 +135,11 @@ export function drawOnClick2(e) {
this.drawOnClick1(e)
} else if (this.mode == "arc") {
if (this.hovered.length>=2) {
if (this.hovered.length) {
this.constraints.set(++this.c_id, //??? why incremennt before not after
[
'points_coincident', -1,
[this.hovered[this.hovered.length - 2].name, this.toPush[1].name, -1, -1]
[this.hovered[this.hovered.length - 1].name, this.toPush[1].name, -1, -1]
]
)
this.updateOtherBuffers()
@ -207,9 +209,10 @@ export function drawClear() {
export function drawPoint(mouseLoc) {
console.log('heeeeeeeeer')
const p1 = ptObj()
p1.matrixAutoUpdate = false;
p1.userData.constraints = []
p1.geometry.attributes.position.set(mouseLoc)
p1.geometry.attributes.position.set(mouseLoc.slice())
return [p1]
}

View File

@ -17,6 +17,7 @@ export function drawLine(mouseLoc) {
line.userData.constraints = []
line.geometry.attributes.position.set(mouseLoc)
p1.geometry.attributes.position.set(mouseLoc)
@ -34,4 +35,5 @@ export function drawLine2(mouseLoc, toPush) {
line.geometry.attributes.position.set(mouseLoc, 3)
line.geometry.attributes.position.needsUpdate = true;
line.geometry.computeBoundingSphere();
}

View File

@ -1,13 +1,12 @@
import * as THREE from '../node_modules/three/src/Three';
import { raycaster, setHover } from './shared';
import { onDimMoveEnd } from './drawDimension'
import { connectAdvanced } from 'react-redux';
let ptLoc
export function onHover(e) {
if ((this.mode && this.mode != 'dimension' && !this.snap) || e.buttons) return
// if (( this.mode && this.mode!='dimension') || e.buttons) return
// if ((this.mode && this.mode != 'dimension' && !this.snap) || e.buttons) return
if (e.buttons) return
raycaster.setFromCamera(
new THREE.Vector2(
@ -23,10 +22,11 @@ export function onHover(e) {
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) // has side effect of updating bounding spheres
hoverPts = raycaster.intersectObjects(this.obj3d.children, true)
} else {
raycaster.layers.set(2)
// if (this.snap) return
// intersectObjects has side effect of updating bounding spheres
// which may lead to unexpected results if you leave boundspheres un-updated
hoverPts = raycaster.intersectObjects([...this.dimGroup.children, ...this.obj3d.children])
}
@ -56,6 +56,7 @@ export function onHover(e) {
if (idx.length) { // after filtering, if hovered objs still exists
// console.log(idx)
if (hoverPts[idx[0]].object != this.hovered[0]) { // if the previous hovered obj is not the same as current
@ -71,13 +72,7 @@ export function onHover(e) {
for (let x = 0; x < idx.length; x++) {
let obj = hoverPts[idx[x]].object
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') {