not idea
parent
1d450bab1c
commit
9f19ed9fde
29
src/Scene.js
29
src/Scene.js
|
@ -13,7 +13,7 @@ import { extrude } from './extrude'
|
||||||
import { onHover, onPick } from './utils/mouseEvents';
|
import { onHover, onPick } from './utils/mouseEvents';
|
||||||
import { _vec2, _vec3, color, awaitPts } from './utils/shared'
|
import { _vec2, _vec3, color, awaitPts } from './utils/shared'
|
||||||
import { Vector3 } from 'three/src/Three';
|
import { Vector3 } from 'three/src/Three';
|
||||||
import {AxesHelper} from './utils/axes'
|
import { AxesHelper } from './utils/axes'
|
||||||
|
|
||||||
import CSG from "./utils/three-csg.js"
|
import CSG from "./utils/three-csg.js"
|
||||||
|
|
||||||
|
@ -190,32 +190,33 @@ function render() {
|
||||||
|
|
||||||
async function addSketch() {
|
async function addSketch() {
|
||||||
|
|
||||||
let references = await this.awaitPts(3)
|
let sketch;
|
||||||
|
|
||||||
const sketch = new Sketch(this.camera, this.canvas, this.store)
|
if (this.selected[0].name[0] == 'd') {
|
||||||
|
sketch = new Sketch(this.camera, this.canvas, this.store)
|
||||||
if (references.length == 1 && references[0].name[0] == 'd') {
|
sketch.obj3d.matrix = this.selected[0].matrix
|
||||||
this.obj3d.add(sketch.obj3d)
|
|
||||||
sketch.obj3d.matrix = references[0].matrix
|
|
||||||
sketch.plane.applyMatrix4(sketch.obj3d.matrix)
|
sketch.plane.applyMatrix4(sketch.obj3d.matrix)
|
||||||
sketch.obj3d.inverse = sketch.obj3d.matrix.clone().invert()
|
sketch.obj3d.inverse = sketch.obj3d.matrix.clone().invert()
|
||||||
|
} else {
|
||||||
} else if (references.length == 3) {
|
const references = await this.awaitPts(3);
|
||||||
this.obj3d.add(sketch.obj3d)
|
if (references.length != 3) return;
|
||||||
|
sketch = new Sketch(this.camera, this.canvas, this.store)
|
||||||
sketch.align(
|
sketch.align(
|
||||||
...references.map(
|
...references.map(
|
||||||
el => new Vector3(...el.geometry.attributes.position.array).applyMatrix4(el.matrixWorld)
|
el => new Vector3(...el.geometry.attributes.position.array).applyMatrix4(el.matrixWorld)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
} else {
|
|
||||||
console.log('cancelled')
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.obj3d.add(sketch.obj3d)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sketch.activate()
|
sketch.activate()
|
||||||
|
|
||||||
sketch.obj3d.addEventListener('change', this.render);
|
sketch.obj3d.addEventListener('change', this.render);
|
||||||
this.render()
|
this.render()
|
||||||
|
console.log('render')
|
||||||
this.store.dispatch({ type: 'rx-sketch', obj: sketch })
|
this.store.dispatch({ type: 'rx-sketch', obj: sketch })
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ export function extrude(sketch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
findPair(children[1])
|
findPair(children[3]) //??? need fixing
|
||||||
|
|
||||||
const shape = new THREE.Shape(v2s);
|
const shape = new THREE.Shape(v2s);
|
||||||
const extrudeSettings = { depth: 8, bevelEnabled: false };
|
const extrudeSettings = { depth: 8, bevelEnabled: false };
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { get3PtArc } from './drawArc'
|
||||||
import { _vec2, _vec3, raycaster, awaitPts } from '../utils/shared'
|
import { _vec2, _vec3, raycaster, awaitPts } from '../utils/shared'
|
||||||
import { replacer, reviver } from '../utils/mapJSONReplacer'
|
import { replacer, reviver } from '../utils/mapJSONReplacer'
|
||||||
import { AxesHelper } from '../utils/axes'
|
import { AxesHelper } from '../utils/axes'
|
||||||
import { drawDimension } from './drawDimension';
|
import { drawDimension, _onMoveDimension } from './drawDimension';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,11 +45,9 @@ class Sketch {
|
||||||
this.constraints = new Map()
|
this.constraints = new Map()
|
||||||
this.c_id = 0;
|
this.c_id = 0;
|
||||||
|
|
||||||
this.sub = new THREE.Group();
|
this.obj3d.add(new THREE.Group().add(new AxesHelper(2)));
|
||||||
this.obj3d.add(this.sub);
|
this.obj3d.add(new THREE.Group());
|
||||||
const axesHelper = new AxesHelper(2);
|
this.obj3d.add(new THREE.Group());
|
||||||
this.sub.add(axesHelper);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,6 +106,7 @@ class Sketch {
|
||||||
this.drawPreClick2 = drawPreClick2.bind(this);
|
this.drawPreClick2 = drawPreClick2.bind(this);
|
||||||
this.drawOnClick2 = drawOnClick2.bind(this);
|
this.drawOnClick2 = drawOnClick2.bind(this);
|
||||||
this.drawDimension = drawDimension.bind(this)
|
this.drawDimension = drawDimension.bind(this)
|
||||||
|
this._onMoveDimension = _onMoveDimension.bind(this)
|
||||||
|
|
||||||
this.awaitPts = awaitPts.bind(this);
|
this.awaitPts = awaitPts.bind(this);
|
||||||
|
|
||||||
|
@ -117,6 +116,7 @@ class Sketch {
|
||||||
this.onRelease = onRelease.bind(this);
|
this.onRelease = onRelease.bind(this);
|
||||||
this.onKeyPress = this.onKeyPress.bind(this);
|
this.onKeyPress = this.onKeyPress.bind(this);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -335,11 +335,11 @@ class Sketch {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
- loop to update all the children that are points
|
- loop to update all the children that are points
|
||||||
- we skip first triplet because it refers to a non-geometry child
|
- why +6? we skip first two triplets because it refers to a non-geometry children
|
||||||
- we also sneak in updating lines children as well, by checking when ptsBuf[ptr] is NaN
|
- we also sneak in updating lines children as well, by checking when ptsBuf[ptr] is NaN
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (let i = 1, ptr = (pts_buffer >> 2) + 3; i < this.obj3d.children.length; i += 1, ptr += 3) {
|
for (let i = 3, ptr = (pts_buffer >> 2) + 9; i < this.obj3d.children.length; i += 1, ptr += 3) {
|
||||||
// for (let i = 0, ptr = (pts_buffer >> 2) + 3; i < this.obj3d.children.length; i += 1, ptr += 3) {
|
// for (let i = 0, ptr = (pts_buffer >> 2) + 3; i < this.obj3d.children.length; i += 1, ptr += 3) {
|
||||||
|
|
||||||
const pos = this.obj3d.children[i].geometry.attributes.position;
|
const pos = this.obj3d.children[i].geometry.attributes.position;
|
||||||
|
|
|
@ -17,9 +17,6 @@ export async function drawDimension() {
|
||||||
|
|
||||||
if (pts.length != 2) return;
|
if (pts.length != 2) return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const line = new THREE.LineSegments(
|
const line = new THREE.LineSegments(
|
||||||
new THREE.BufferGeometry().setAttribute('position',
|
new THREE.BufferGeometry().setAttribute('position',
|
||||||
new THREE.Float32BufferAttribute(3 * 8, 3)
|
new THREE.Float32BufferAttribute(3 * 8, 3)
|
||||||
|
@ -34,21 +31,72 @@ export async function drawDimension() {
|
||||||
pointMaterial.clone()
|
pointMaterial.clone()
|
||||||
)
|
)
|
||||||
|
|
||||||
const group = this.obj3d.children[0]
|
line.userData.construction = true
|
||||||
group.add(line)
|
point.userData.construction = true
|
||||||
group.add(point)
|
|
||||||
|
const groupLines = this.obj3d.children[1]
|
||||||
|
const groupPts = this.obj3d.children[2]
|
||||||
|
groupLines.add(line)
|
||||||
|
groupPts.add(point)
|
||||||
|
|
||||||
|
const onMove = this._onMoveDimension(...pts, point, line)
|
||||||
|
|
||||||
|
let onEnd, onKey;
|
||||||
|
|
||||||
|
let add = await new Promise((res) => {
|
||||||
|
onEnd = (e) => res(true)
|
||||||
|
onKey = (e) => e.key == 'Escape' && res(false)
|
||||||
|
|
||||||
|
this.canvas.addEventListener('pointermove', onMove)
|
||||||
|
this.canvas.addEventListener('pointerdown', onEnd)
|
||||||
|
window.addEventListener('keydown', onKey)
|
||||||
|
})
|
||||||
|
|
||||||
|
this.canvas.removeEventListener('pointermove', onMove)
|
||||||
|
this.canvas.removeEventListener('pointerdown', onEnd)
|
||||||
|
window.removeEventListener('keydown', onKey)
|
||||||
|
|
||||||
|
if (add) {
|
||||||
|
this.constraints.set(++this.c_id, //???
|
||||||
|
[
|
||||||
|
'pt_pt_distance', 10,
|
||||||
|
[pts[0].name, pts[1].name, -1, -1]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
pts[0].userData.constraints.push(this.c_id)
|
||||||
|
pts[1].userData.constraints.push(this.c_id)
|
||||||
|
|
||||||
|
this.updateOtherBuffers()
|
||||||
|
|
||||||
|
line.name = this.c_id
|
||||||
|
point.name = this.c_id
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
[groupLines.splice(groupLines.length - 1),
|
||||||
|
groupPts.splice(groupLines.length - 1)].forEach(
|
||||||
|
e => {
|
||||||
|
e.geometry.dispose()
|
||||||
|
e.material.dispose()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
sc.render()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function _onMoveDimension(_p1, _p2, point, line) {
|
||||||
|
|
||||||
|
const p1 = new THREE.Vector2(..._p1.geometry.attributes.position.array.slice(0, 2))
|
||||||
|
const p2 = new THREE.Vector2(..._p2.geometry.attributes.position.array.slice(0, 2))
|
||||||
|
const p3 = new THREE.Vector2()
|
||||||
let dir, hyp, proj, perp, p1e, p2e, loc;
|
let dir, hyp, proj, perp, p1e, p2e, loc;
|
||||||
|
|
||||||
const p1 = new THREE.Vector2(...pts[0].geometry.attributes.position.array.slice(0, 2))
|
return (e) => {
|
||||||
const p2 = new THREE.Vector2(...pts[1].geometry.attributes.position.array.slice(0, 2))
|
|
||||||
const p3 = new THREE.Vector2()
|
|
||||||
|
|
||||||
const onMove = (e) => {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
loc = this.getLocation(e)
|
loc = this.getLocation(e)
|
||||||
p3.set(loc.x, loc.y)
|
p3.set(loc.x, loc.y)
|
||||||
|
|
||||||
|
@ -79,54 +127,4 @@ export async function drawDimension() {
|
||||||
point.geometry.attributes.position.needsUpdate = true;
|
point.geometry.attributes.position.needsUpdate = true;
|
||||||
sc.render()
|
sc.render()
|
||||||
}
|
}
|
||||||
|
|
||||||
let onEnd, onKey;
|
|
||||||
|
|
||||||
let add = await new Promise((res) => {
|
|
||||||
onEnd = (e) => {
|
|
||||||
res(true)
|
|
||||||
this.updateOtherBuffers()
|
|
||||||
}
|
|
||||||
onKey = (e) => {
|
|
||||||
if (e.key == 'Escape') res(false)
|
|
||||||
}
|
|
||||||
this.canvas.addEventListener('pointermove', onMove)
|
|
||||||
this.canvas.addEventListener('pointerdown', onEnd)
|
|
||||||
window.addEventListener('keydown', onKey)
|
|
||||||
})
|
|
||||||
|
|
||||||
this.canvas.removeEventListener('pointermove', onMove)
|
|
||||||
this.canvas.removeEventListener('pointerdown', onEnd)
|
|
||||||
this.canvas.removeEventListener('keydown', onKey)
|
|
||||||
|
|
||||||
if (add) {
|
|
||||||
this.constraints.set(++this.c_id, //???
|
|
||||||
[
|
|
||||||
'pt_pt_distance', 10,
|
|
||||||
[pts[0].name, pts[1].name, -1, -1]
|
|
||||||
]
|
|
||||||
)
|
|
||||||
pts[0].userData.constraints.push(this.c_id)
|
|
||||||
pts[1].userData.constraints.push(this.c_id)
|
|
||||||
|
|
||||||
this.updateOtherBuffers()
|
|
||||||
|
|
||||||
line.name = this.c_id
|
|
||||||
point.name = this.c_id
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
group.children.splice(group.children.length - 2).forEach(
|
|
||||||
e => {
|
|
||||||
e.geometry.dispose()
|
|
||||||
e.material.dispose()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
sc.render()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,6 @@ const lineObj = (n = 1) => {
|
||||||
|
|
||||||
async function awaitPts(n) {
|
async function awaitPts(n) {
|
||||||
let references = this.selected.slice()
|
let references = this.selected.slice()
|
||||||
|
|
||||||
let end = false;
|
let end = false;
|
||||||
while (references.length < n && !end) {
|
while (references.length < n && !end) {
|
||||||
let pt;
|
let pt;
|
||||||
|
@ -68,15 +67,12 @@ async function awaitPts(n) {
|
||||||
onKey = (e) => e.key == 'Escape' && rej()
|
onKey = (e) => e.key == 'Escape' && rej()
|
||||||
onEnd = (e) => res(this.hovered[0])
|
onEnd = (e) => res(this.hovered[0])
|
||||||
|
|
||||||
this.canvas.addEventListener('pointerdown', onEnd)
|
this.canvas.addEventListener('pointerdown', onEnd,{ once: true })
|
||||||
window.addEventListener('keydown', onKey)
|
window.addEventListener('keydown', onKey,{ once: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
if (pt.name[0] == 'p') {
|
if (pt.name[0] == 'p') {
|
||||||
references.push(pt)
|
references.push(pt)
|
||||||
} else if (pt.name[0] == 'd') {
|
|
||||||
references = [pt]
|
|
||||||
end = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue