UNPKG

awv3

Version:
119 lines (91 loc) 3.09 kB
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import * as THREE from 'three'; import Object3 from '../../three/object3'; import { createCaption } from '../../three/helpers'; var sphereRadius = 3; var sphereSegments = 32; var sphereColor = 0x000000; var defaultOpacity = 0.7; var selectedScale = 1.2; //TODO: copypaste from csys/graphics.js var InteractiveMesh = /*#__PURE__*/ function (_THREE$Mesh) { _inheritsLoose(InteractiveMesh, _THREE$Mesh); function InteractiveMesh(geometry, material) { var _this; _this = _THREE$Mesh.call(this, geometry, material) || this; _this.createInteraction({ priority: 1000, types: ['Workpoint'] }); var _arr = Object.values(Object3.Events); for (var _i = 0; _i < _arr.length; _i++) { var category = _arr[_i]; var _arr2 = Object.values(category); for (var _i2 = 0; _i2 < _arr2.length; _i2++) { var event = _arr2[_i2]; if (_this[event]) _this.on(event, _this[event].bind(_assertThisInitialized(_this)), { sync: true }); } } return _this; } var _proto = InteractiveMesh.prototype; _proto[Object3.Events.Interaction.Clicked] = function (hitObject) { this.parent.plugin.switchToFeature(); }; return InteractiveMesh; }(THREE.Mesh); var Workpoint = /*#__PURE__*/ function (_THREE$Object3D) { _inheritsLoose(Workpoint, _THREE$Object3D); function Workpoint(makeInteractiv, label) { var _this2; if (makeInteractiv === void 0) { makeInteractiv = true; } _this2 = _THREE$Object3D.call(this) || this; //this.type = 'Workpoint'; //TODO: why this does not work? var sphereGeometry = new THREE.SphereGeometry(sphereRadius, sphereSegments, sphereSegments); var shpereMaterial = new THREE.MeshBasicMaterial({ transparent: true, //TODO: avoid making it transparent! opacity: defaultOpacity, side: THREE.DoubleSide, color: new THREE.Color(sphereColor) }); if (makeInteractiv) { _this2.origin = new InteractiveMesh(sphereGeometry, shpereMaterial); _this2.origin.type = 'Workpoint'; } else { _this2.origin = new THREE.Mesh(sphereGeometry, shpereMaterial); } _this2.add(_this2.origin); if (label) { _this2.caption = createCaption(label, 'black'); _this2.add(_this2.caption); } return _this2; } var _proto2 = Workpoint.prototype; _proto2.updateScale = function updateScale(scale) { this.origin.scale.set(scale, scale, scale); if (this.caption) { var capationScale = scale * 35; this.caption.scale.set(capationScale, capationScale, capationScale); } }; _proto2.setActive = function setActive(value) { if (value) { this.origin.material.opacity = 1; this.updateScale(selectedScale); } else { this.origin.material.opacity = defaultOpacity; this.updateScale(1); } }; return Workpoint; }(THREE.Object3D); export { Workpoint as default };