UNPKG

awv3

Version:
30 lines (27 loc) 1.21 kB
import * as THREE from 'three' import BaseGraphics from './base' export default class Linear extends BaseGraphics { constructor(...args) { super(...args, 4, 0, 2) } updateFromState(info, ...args) { const [start, end, dim] = ['startPt', 'endPt', 'dimPt'].map(x => new THREE.Vector3().fromArray(info.dimension.members[x].value), ) var dir = new THREE.Vector3( Math.cos(info.dimension.members.angle.value), Math.sin(info.dimension.members.angle.value), 0, ) const [startFoot, endFoot] = [start, end].map(x => x.clone().sub(dim).projectOnVector(dir).add(dim)) if (endFoot.clone().sub(startFoot).dot(dir) < 0) dir.negate() const outside = dim.clone().sub(startFoot).dot(dim.clone().sub(endFoot)) > 0 this.updateLine(0, start, startFoot) this.updateLine(1, startFoot, dim) this.updateLine(2, dim, endFoot) this.updateLine(3, endFoot, end) this.updateArrow(0, startFoot, dir.clone().multiplyScalar(outside ? 1 : -1)) this.updateArrow(1, endFoot, dir.clone().multiplyScalar(outside ? -1 : 1)) super.updateFromState(info, ...args) } }