UNPKG

awv3

Version:
53 lines (45 loc) 2.12 kB
import * as THREE from 'three'; export default class Workplane extends THREE.Object3D { constructor() { super(); const geometry = new THREE.PlaneBufferGeometry(1, 1); const material = new THREE.MeshBasicMaterial({ color: 0x808080, side: THREE.DoubleSide, transparent: true, opacity: 0.1, }); const plane = new THREE.Mesh(geometry, material); plane.type = 'Workplane'; plane.userData.meta = {}; plane.renderOrder = 1000; const lineMaterial = new THREE.LineBasicMaterial({ color: 0x373737, transparent: true, opacity: 0.3 }); const lineGeometry = new THREE.Geometry(); lineGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, 0)); lineGeometry.vertices.push(new THREE.Vector3(0.5, -0.5, 0)); lineGeometry.vertices.push(new THREE.Vector3(0.5, 0.5, 0)); lineGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, 0)); lineGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, 0)); const outlines = new THREE.Line(lineGeometry, lineMaterial); outlines.renderOrder = 1000; this.add(plane); this.add(outlines); //this.measurable = true; } updateFromState(state) { this.children[0].userData.meta.id = state.id; this.quaternion.setFromUnitVectors( new THREE.Vector3(0, 0, 1), new THREE.Vector3().fromArray(state.members.Normal.value), ); this.position.fromArray(state.members.curPosition.value).applyQuaternion(this.quaternion); const bounds = state.members.Size.value; this.scale.setScalar(bounds); const csys = state.coordinateSystem.map(row => new THREE.Vector3().fromArray(row)); this.matrix.makeBasis(csys[1], csys[2], csys[3]).setPosition(csys[0]); this.matrix.multiply(new THREE.Matrix4().compose(this.position, this.quaternion, this.scale)); this.matrix.decompose(this.position, this.quaternion, this.scale); this.matrixWorldNeedsUpdate = true; this.updateMatrixWorld(); } }