UNPKG

awv3

Version:
45 lines (40 loc) 1.91 kB
import * as THREE from 'three'; import Ccref from '../ccref'; import BaseGraphics from './base'; const geometry = new THREE.PlaneBufferGeometry(1, 1); // rubber-band selection doesn't support empty (min=inf max=-inf) bounding boxes, put the box in the unlikely place const box = new THREE.Box3(new THREE.Vector3(1e9, 1e9, 1e9), new THREE.Vector3(1e9, 1e9, 1e9)); export default class Constraint extends BaseGraphics { constructor(texture) { super(); //flat-colored, highlightable quad this.localMesh = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({ color: 0xdddddd, side: THREE.DoubleSide, polygonOffset: true, polygonOffsetFactor: -5.0, polygonOffsetUnits: -25.0, })); this.localMesh.type = 'SketcherMesh'; this.localMesh.material.meta = {}; this.localMesh.material.meta.box = box; //textured semi-transparent icon this.iconMesh = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({ color: 0xffffff, side: THREE.DoubleSide, transparent: true, depthWrite: false, opacity: 1.0, //note: this huge offset is very hacky: it is here to prevent selected localMesh being on top polygonOffset: true, polygonOffsetFactor: -15.0, polygonOffsetUnits: -75.0, })); this.add(this.localMesh); this.localMesh.add(this.iconMesh); } updateFromGeomParams(geomParams) { super.updateFromGeomParams(geomParams); if (this.iconMesh.material.map === null) (async () => { this.iconMesh.material.map = await geomParams.texture; this.iconMesh.material.needsUpdate = true; })(); } updateFromSketcherAndId(sketcher, id) { super.updateFromSketcherAndId(sketcher, id); sketcher.constraintVisualizer.updateConstraint(new Ccref(sketcher, id)); } }