UNPKG

awv3

Version:
25 lines (22 loc) 1.15 kB
import * as THREE from 'three'; import BaseGraphics from './base'; export default class Linear extends BaseGraphics { constructor(...args) { super(...args, 4, 0, 2); } updateFromState(state, ...args) { const [start, end, dim] = ['startPt', 'endPt', 'dimPt'].map(x => new THREE.Vector3().fromArray(state.members[x].value)); var dir = new THREE.Vector3(Math.cos(state.members.angle.value), Math.sin(state.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(state, ...args); } }