difficulty merging

master
howard 2021-04-13 00:02:01 -07:00
parent f46e0790f3
commit b7f71a8bef
1 changed files with 13 additions and 32 deletions

View File

@ -15,16 +15,18 @@ const pointMaterial = new THREE.PointsMaterial({
export async function drawDimension(cc) { export async function drawDimension(cc) {
let selection let selection
if (cc == 'd') {
if (cc == 'd') { ///////////////////////////
selection = await this.awaitSelection({ point: 2 }, { point: 1, line: 1 }) selection = await this.awaitSelection({ point: 2 }, { point: 1, line: 1 })
} else { } else {
selection = await this.awaitSelection({ line: 2 }) selection = await this.awaitSelection({ line: 2 })
} }///////////////////////////
if (selection == null) return; if (selection == null) return;
let line; let line;
if (cc == 'd') {
if (cc == 'd') { ///////////////////////////////
line = new THREE.LineSegments( line = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute('position', new THREE.BufferGeometry().setAttribute('position',
new THREE.Float32BufferAttribute(Array(3 * 8).fill(-0.001), 3) new THREE.Float32BufferAttribute(Array(3 * 8).fill(-0.001), 3)
@ -38,8 +40,7 @@ export async function drawDimension(cc) {
), ),
lineMaterial.clone() lineMaterial.clone()
); );
} }////////////////////////////////
const point = new THREE.Points( const point = new THREE.Points(
@ -48,17 +49,14 @@ export async function drawDimension(cc) {
), ),
pointMaterial.clone() pointMaterial.clone()
) )
line.userData.ids = selection.map(e => e.name) line.userData.ids = selection.map(e => e.name)
line.layers.enable(2) line.layers.enable(2)
point.layers.enable(2) point.layers.enable(2)
//////////////
let dimVal, ptLineOrder; let dimVal, ptLineOrder;
if (cc == 'd') { if (cc == 'd') { /////////////////////////////
if (selection.every(e => e.userData.type == 'point')) { if (selection.every(e => e.userData.type == 'point')) {
dimVal = 0; dimVal = 0;
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
@ -80,29 +78,24 @@ export async function drawDimension(cc) {
} }
} else { } else {
dimVal = getAngle(selection) dimVal = getAngle(selection)
} } ///////////////////////
////////////
this.obj3d.children[1].add(line).add(point) this.obj3d.children[1].add(line).add(point)
const onMove = this._onMoveDimension(point, line) const onMove = this._onMoveDimension(point, line)
point.label = document.createElement('div'); point.label = document.createElement('div');
console.log(dimVal, 'dim')
point.label.textContent = dimVal.toFixed(3); point.label.textContent = dimVal.toFixed(3);
point.label.contentEditable = true; point.label.contentEditable = true;
this.labelContainer.append(point.label) this.labelContainer.append(point.label)
let onEnd, onKey; let onEnd, onKey;
let add = await new Promise((res) => { let add = await new Promise((res) => {
onEnd = (e) => { onEnd = () => {
if (cc == 'd') { if (cc == 'd') { /////////////////////////
point.userData.offset = hyp2.toArray() // save offset vector from hyp2 point.userData.offset = hyp2.toArray() // save offset vector from hyp2
} else { } else {
point.userData.offset = vecArr[5].toArray() point.userData.offset = vecArr[5].toArray()
} } ///////////////////////////////////
res(true) res(true)
} }
onKey = (e) => e.key == 'Escape' && res(false) onKey = (e) => e.key == 'Escape' && res(false)
@ -119,7 +112,7 @@ export async function drawDimension(cc) {
line.geometry.computeBoundingSphere() line.geometry.computeBoundingSphere()
if (add) { if (add) {
if (cc == 'd') { if (cc == 'd') { ///////////////////////////
if (ptLineOrder) { if (ptLineOrder) {
this.constraints.set(++this.c_id, //??? this.constraints.set(++this.c_id, //???
[ [
@ -142,7 +135,7 @@ export async function drawDimension(cc) {
[-1, -1, selection[0].name, selection[1].name] [-1, -1, selection[0].name, selection[1].name]
] ]
) )
} } ////////////////////////////////////////
@ -150,16 +143,12 @@ export async function drawDimension(cc) {
selection[1].userData.constraints.push(this.c_id) selection[1].userData.constraints.push(this.c_id)
this.updateOtherBuffers() this.updateOtherBuffers()
line.name = this.c_id line.name = this.c_id
line.userData.type = 'dimension' line.userData.type = 'dimension'
point.name = this.c_id point.name = this.c_id
point.userData.type = 'dimension' point.userData.type = 'dimension'
point.label.addEventListener('focus', this.updateDim(this.c_id)) point.label.addEventListener('focus', this.updateDim(this.c_id))
} else { } else {
this.obj3d.children[1].children.splice(this.obj3d.children[1].length - 2, 2).forEach( this.obj3d.children[1].children.splice(this.obj3d.children[1].length - 2, 2).forEach(
@ -253,9 +242,6 @@ export function setDimLines() {
_p1 = this.obj3d.children[this.objIdx.get(ids[0])].geometry.attributes.position.array _p1 = this.obj3d.children[this.objIdx.get(ids[0])].geometry.attributes.position.array
_p2 = this.obj3d.children[this.objIdx.get(ids[1])].geometry.attributes.position.array _p2 = this.obj3d.children[this.objIdx.get(ids[1])].geometry.attributes.position.array
update( update(
dims[i].geometry.attributes.position, dims[i].geometry.attributes.position,
dims[i + 1].geometry.attributes.position, dims[i + 1].geometry.attributes.position,
@ -533,11 +519,6 @@ function unreflex(angle) {
} }
const getAngle = (Obj3dLines) => { const getAngle = (Obj3dLines) => {
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
const arr = Obj3dLines[i].geometry.attributes.position.array const arr = Obj3dLines[i].geometry.attributes.position.array