UNPKG

awv3

Version:
63 lines (49 loc) 2.02 kB
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import * as THREE from 'three'; var CylinderRadius = 0.2; var arrowLength = 4; var arrowStartRadius = 0.5; var arrowEndRadius = 0; var axisColor = 0x808080; var Workaxis = /*#__PURE__*/ function (_THREE$Object3D) { _inheritsLoose(Workaxis, _THREE$Object3D); function Workaxis(plugin) { var _this; _this = _THREE$Object3D.call(this) || this; //this.type = 'Workaxis' //TODO: why this does not work? _this.plugin = plugin; var axisData = _this.plugin.getFeatureData(); var cylinderLength = axisData.axisLength - arrowLength; var material = new THREE.MeshBasicMaterial({ transparent: true, //TODO: avoid making it transparent! side: THREE.DoubleSide, color: new THREE.Color(axisColor) }); //create separate meshes 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(arrowEndRadius, arrowStartRadius, arrowLength); var arrow = new THREE.Mesh(arrowGeometry, material); arrow.position.set(0, cylinderLength + arrowLength / 2, 0); //combine them into single mesh axis.updateMatrix(); arrow.updateMatrix(); var mergedGeometry = new THREE.Geometry(); mergedGeometry.merge(axis.geometry, axis.matrix); mergedGeometry.merge(arrow.geometry, arrow.matrix); var mergedMesh = new THREE.Mesh(mergedGeometry, material); //set meta for interaction/hovering mergedMesh.material.meta = { id: plugin.feature, material: { color: material.color.clone() } }; mergedMesh.type = 'Workaxis'; _this.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), new THREE.Vector3().fromArray(axisData.direction)); _this.add(mergedMesh); return _this; } return Workaxis; }(THREE.Object3D); export { Workaxis as default };