UNPKG

awv3

Version:
33 lines (28 loc) 1.12 kB
import * as THREE from 'three'; import BaseGraphics from './base'; const geometry = new THREE.BoxBufferGeometry(1, 1, 0); const material = new THREE.MeshBasicMaterial({ color: 0x3378a2, side: THREE.DoubleSide, polygonOffset: true, polygonOffsetFactor: -1, polygonOffsetUnits: -5, }); export default class Line extends BaseGraphics { constructor() { super(); this.localMesh = new THREE.Mesh(geometry, material.clone()); this.localMesh.type = 'SketcherMesh'; this.localMesh.material.meta = {}; this.add(this.localMesh); } updateFromGeomParams(geomParams) { super.updateFromGeomParams(geomParams); const dir = geomParams.end.clone().sub(geomParams.start).normalize(); const length = geomParams.start.distanceTo(geomParams.end); this.localMesh.position.lerpVectors(geomParams.start, geomParams.end, 0.5); this.localMesh.quaternion.setFromUnitVectors(new THREE.Vector3(1, 0, 0), dir); this.localMesh.scale.set(Math.max(length, 1e-3), geomParams.scale, 1e-3); this.updateMetaBox(); } }