UNPKG

awv3

Version:
185 lines (148 loc) 5.31 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'; //Axis params: var cylinderRadius = 0.84; var cylinderLength = 20; var arrowRadius = cylinderRadius + 0.8; var arrowLength = 7; var colorsAndDirections = [{ name: 'xAxis', dir: [1, 0, 0], color: 0xc23369 }, { name: 'yAxis', dir: [0, 1, 0], color: 0x28d79f }, { name: 'zAxis', dir: [0, 0, 1], color: 0x28b4d7 }]; var defaultOpacity = 0.7; var selectedScale = 0.02; //Origin params: var sphereRadius = 3; var sphereSegments = 32; var sphereColor = 0x444444; 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: ['CSYSHandle'] }); 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 Csys = /*#__PURE__*/ function (_THREE$Object3D) { _inheritsLoose(Csys, _THREE$Object3D); function Csys(makeInteractive, label) { var _this2; if (makeInteractive === void 0) { makeInteractive = true; } _this2 = _THREE$Object3D.call(this) || this; _this2.selected = false; for (var i = 0; i < colorsAndDirections.length; ++i) { var curInfo = colorsAndDirections[i]; var material = new THREE.MeshBasicMaterial({ transparent: true, //TODO: avoid making it transparent! opacity: defaultOpacity, side: THREE.DoubleSide, color: new THREE.Color(curInfo.color) }); var cylinderGeometry = new THREE.CylinderGeometry(cylinderRadius, cylinderRadius, cylinderLength); var axis = new THREE.Mesh(cylinderGeometry, material); axis.position.set(0, cylinderLength / 2, 0); var arrowGeometry = new THREE.CylinderGeometry(0, arrowRadius, arrowLength); var arrow = new THREE.Mesh(arrowGeometry, material); arrow.position.set(0, cylinderLength + arrowLength / 2, 0); axis.updateMatrix(); arrow.updateMatrix(); var mergedGeometry = new THREE.Geometry(); mergedGeometry.merge(axis.geometry, axis.matrix); mergedGeometry.merge(arrow.geometry, arrow.matrix); _this2[curInfo.name] = new THREE.Mesh(mergedGeometry, material); _this2[curInfo.name].quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), new THREE.Vector3().fromArray(curInfo.dir)); _this2.add(_this2[curInfo.name]); } 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 (makeInteractive) { _this2.origin = new InteractiveMesh(sphereGeometry, shpereMaterial); _this2.origin.type = 'CSYSHandle'; } 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 = Csys.prototype; _proto2.updateScale = function updateScale(scale) { this.selected && (scale = selectedScale + scale); //If cSys is selected, it should be bigger then other. this.xAxis.scale.set(scale, scale, scale); this.yAxis.scale.set(scale, scale, scale); this.zAxis.scale.set(scale, scale, scale); var origScale = scale; this.origin.scale.set(origScale, origScale, origScale); if (this.caption) { var captionScale = scale * 35; this.caption.scale.set(captionScale, captionScale, captionScale); } }; _proto2.setActive = function setActive(value) { // Fixes crash when connection disappears .. if (!this.origin.material) return; if (value) { this.origin.material.opacity = 1; this.selected = true; for (var i = 0; i < colorsAndDirections.length; ++i) { var curInfo = colorsAndDirections[i]; this[curInfo.name].material.opacity = 1; } } else { this.origin.material.opacity = defaultOpacity; this.selected = false; for (var _i3 = 0; _i3 < colorsAndDirections.length; ++_i3) { var _curInfo = colorsAndDirections[_i3]; this[_curInfo.name].material.opacity = defaultOpacity; } } }; return Csys; }(THREE.Object3D); export { Csys as default };