UNPKG

awv3

Version:
94 lines (74 loc) 3.08 kB
import _regeneratorRuntime from "@babel/runtime/regenerator"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import * as THREE from 'three'; import Ccref from '../ccref'; import BaseGraphics from './base'; import { setMaterialMeta } from './index'; var 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 var box = new THREE.Box3(new THREE.Vector3(1e9, 1e9, 1e9), new THREE.Vector3(1e9, 1e9, 1e9)); //note: this material applies only to transparent quad (icon's background) var backMaterial = new THREE.MeshBasicMaterial({ color: 0xdddddd, side: THREE.DoubleSide, polygonOffset: true, polygonOffsetFactor: -5.0, polygonOffsetUnits: -25.0 }); var Constraint = /*#__PURE__*/ function (_BaseGraphics) { _inheritsLoose(Constraint, _BaseGraphics); function Constraint(texture) { var _this; _this = _BaseGraphics.call(this) || this; //flat-colored, highlightable quad _this.localMesh = new THREE.Mesh(geometry, backMaterial.clone()); _this.localMesh.type = 'SketcherMesh'; _this.localMesh.material.meta = {}; _this.localMesh.material.meta.box = box; _this.localMesh.material.meta.material = setMaterialMeta(backMaterial); //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); return _this; } var _proto = Constraint.prototype; _proto.updateFromGeomParams = function updateFromGeomParams(geomParams) { var _this2 = this; _BaseGraphics.prototype.updateFromGeomParams.call(this, geomParams); if (this.iconMesh.material.map === null) _asyncToGenerator( /*#__PURE__*/ _regeneratorRuntime.mark(function _callee() { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return geomParams.texture; case 2: _this2.iconMesh.material.map = _context.sent; _this2.iconMesh.material.needsUpdate = true; case 4: case "end": return _context.stop(); } } }, _callee, this); }))(); }; _proto.updateFromSketcherAndId = function updateFromSketcherAndId(sketcher, id) { _BaseGraphics.prototype.updateFromSketcherAndId.call(this, sketcher, id); sketcher.constraintVisualizer.updateConstraint(new Ccref(sketcher, id)); }; return Constraint; }(BaseGraphics); export { Constraint as default };