(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "three"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("three")); } else { var mod = { exports: {} }; factory(mod.exports, global.three); global.TransformControls = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _three) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.TransformControlsPlane = _exports.TransformControlsGizmo = _exports.TransformControls = void 0; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var _raycaster = new _three.Raycaster(); var _tempVector = new _three.Vector3(); var _tempVector2 = new _three.Vector3(); var _tempQuaternion = new _three.Quaternion(); var _unit = { X: new _three.Vector3(1, 0, 0), Y: new _three.Vector3(0, 1, 0), Z: new _three.Vector3(0, 0, 1) }; var _changeEvent = { type: 'change' }; var _mouseDownEvent = { type: 'mouseDown' }; var _mouseUpEvent = { type: 'mouseUp', mode: null }; var _objectChangeEvent = { type: 'objectChange' }; var TransformControls = /*#__PURE__*/function (_Object3D) { _inherits(TransformControls, _Object3D); var _super = _createSuper(TransformControls); function TransformControls(camera, domElement) { var _this; _classCallCheck(this, TransformControls); _this = _super.call(this); if (domElement === undefined) { console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'); domElement = document; } _this.visible = false; _this.domElement = domElement; _this.domElement.style.touchAction = 'none'; // disable touch scroll var _gizmo = new TransformControlsGizmo(); _this._gizmo = _gizmo; _this.add(_gizmo); var _plane = new TransformControlsPlane(); _this._plane = _plane; _this.add(_plane); var scope = _assertThisInitialized(_this); // Defined getter, setter and store for a property function defineProperty(propName, defaultValue) { var propValue = defaultValue; Object.defineProperty(scope, propName, { get: function get() { return propValue !== undefined ? propValue : defaultValue; }, set: function set(value) { if (propValue !== value) { propValue = value; _plane[propName] = value; _gizmo[propName] = value; scope.dispatchEvent({ type: propName + '-changed', value: value }); scope.dispatchEvent(_changeEvent); } } }); scope[propName] = defaultValue; _plane[propName] = defaultValue; _gizmo[propName] = defaultValue; } // Define properties with getters/setter // Setting the defined property will automatically trigger change event // Defined properties are passed down to gizmo and plane defineProperty('camera', camera); defineProperty('object', undefined); defineProperty('enabled', true); defineProperty('axis', null); defineProperty('mode', 'translate'); defineProperty('translationSnap', null); defineProperty('rotationSnap', null); defineProperty('scaleSnap', null); defineProperty('space', 'world'); defineProperty('size', 1); defineProperty('dragging', false); defineProperty('showX', true); defineProperty('showY', true); defineProperty('showZ', true); // Reusable utility variables var worldPosition = new _three.Vector3(); var worldPositionStart = new _three.Vector3(); var worldQuaternion = new _three.Quaternion(); var worldQuaternionStart = new _three.Quaternion(); var cameraPosition = new _three.Vector3(); var cameraQuaternion = new _three.Quaternion(); var pointStart = new _three.Vector3(); var pointEnd = new _three.Vector3(); var rotationAxis = new _three.Vector3(); var rotationAngle = 0; var eye = new _three.Vector3(); // TODO: remove properties unused in plane and gizmo defineProperty('worldPosition', worldPosition); defineProperty('worldPositionStart', worldPositionStart); defineProperty('worldQuaternion', worldQuaternion); defineProperty('worldQuaternionStart', worldQuaternionStart); defineProperty('cameraPosition', cameraPosition); defineProperty('cameraQuaternion', cameraQuaternion); defineProperty('pointStart', pointStart); defineProperty('pointEnd', pointEnd); defineProperty('rotationAxis', rotationAxis); defineProperty('rotationAngle', rotationAngle); defineProperty('eye', eye); _this._offset = new _three.Vector3(); _this._startNorm = new _three.Vector3(); _this._endNorm = new _three.Vector3(); _this._cameraScale = new _three.Vector3(); _this._parentPosition = new _three.Vector3(); _this._parentQuaternion = new _three.Quaternion(); _this._parentQuaternionInv = new _three.Quaternion(); _this._parentScale = new _three.Vector3(); _this._worldScaleStart = new _three.Vector3(); _this._worldQuaternionInv = new _three.Quaternion(); _this._worldScale = new _three.Vector3(); _this._positionStart = new _three.Vector3(); _this._quaternionStart = new _three.Quaternion(); _this._scaleStart = new _three.Vector3(); _this._getPointer = getPointer.bind(_assertThisInitialized(_this)); _this._onPointerDown = onPointerDown.bind(_assertThisInitialized(_this)); _this._onPointerHover = onPointerHover.bind(_assertThisInitialized(_this)); _this._onPointerMove = onPointerMove.bind(_assertThisInitialized(_this)); _this._onPointerUp = onPointerUp.bind(_assertThisInitialized(_this)); _this.domElement.addEventListener('pointerdown', _this._onPointerDown); _this.domElement.addEventListener('pointermove', _this._onPointerHover); _this.domElement.addEventListener('pointerup', _this._onPointerUp); return _this; } // updateMatrixWorld updates key transformation variables _createClass(TransformControls, [{ key: "updateMatrixWorld", value: function updateMatrixWorld() { if (this.object !== undefined) { this.object.updateMatrixWorld(); if (this.object.parent === null) { console.error('TransformControls: The attached 3D object must be a part of the scene graph.'); } else { this.object.parent.matrixWorld.decompose(this._parentPosition, this._parentQuaternion, this._parentScale); } this.object.matrixWorld.decompose(this.worldPosition, this.worldQuaternion, this._worldScale); this._parentQuaternionInv.copy(this._parentQuaternion).invert(); this._worldQuaternionInv.copy(this.worldQuaternion).invert(); } this.camera.updateMatrixWorld(); this.camera.matrixWorld.decompose(this.cameraPosition, this.cameraQuaternion, this._cameraScale); this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(); _get(_getPrototypeOf(TransformControls.prototype), "updateMatrixWorld", this).call(this, this); } }, { key: "pointerHover", value: function pointerHover(pointer) { if (this.object === undefined || this.dragging === true) return; _raycaster.setFromCamera(pointer, this.camera); var intersect = intersectObjectWithRay(this._gizmo.picker[this.mode], _raycaster); if (intersect) { this.axis = intersect.object.name; } else { this.axis = null; } } }, { key: "pointerDown", value: function pointerDown(pointer) { if (this.object === undefined || this.dragging === true || pointer.button !== 0) return; if (this.axis !== null) { _raycaster.setFromCamera(pointer, this.camera); var planeIntersect = intersectObjectWithRay(this._plane, _raycaster, true); if (planeIntersect) { this.object.updateMatrixWorld(); this.object.parent.updateMatrixWorld(); this._positionStart.copy(this.object.position); this._quaternionStart.copy(this.object.quaternion); this._scaleStart.copy(this.object.scale); this.object.matrixWorld.decompose(this.worldPositionStart, this.worldQuaternionStart, this._worldScaleStart); this.pointStart.copy(planeIntersect.point).sub(this.worldPositionStart); } this.dragging = true; _mouseDownEvent.mode = this.mode; this.dispatchEvent(_mouseDownEvent); } } }, { key: "pointerMove", value: function pointerMove(pointer) { var axis = this.axis; var mode = this.mode; var object = this.object; var space = this.space; if (mode === 'scale') { space = 'local'; } else if (axis === 'E' || axis === 'XYZE' || axis === 'XYZ') { space = 'world'; } if (object === undefined || axis === null || this.dragging === false || pointer.button !== -1) return; _raycaster.setFromCamera(pointer, this.camera); var planeIntersect = intersectObjectWithRay(this._plane, _raycaster, true); if (!planeIntersect) return; this.pointEnd.copy(planeIntersect.point).sub(this.worldPositionStart); if (mode === 'translate') { // Apply translate this._offset.copy(this.pointEnd).sub(this.pointStart); if (space === 'local' && axis !== 'XYZ') { this._offset.applyQuaternion(this._worldQuaternionInv); } if (axis.indexOf('X') === -1) this._offset.x = 0; if (axis.indexOf('Y') === -1) this._offset.y = 0; if (axis.indexOf('Z') === -1) this._offset.z = 0; if (space === 'local' && axis !== 'XYZ') { this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale); } else { this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale); } object.position.copy(this._offset).add(this._positionStart); // Apply translation snap if (this.translationSnap) { if (space === 'local') { object.position.applyQuaternion(_tempQuaternion.copy(this._quaternionStart).invert()); if (axis.search('X') !== -1) { object.position.x = Math.round(object.position.x / this.translationSnap) * this.translationSnap; } if (axis.search('Y') !== -1) { object.position.y = Math.round(object.position.y / this.translationSnap) * this.translationSnap; } if (axis.search('Z') !== -1) { object.position.z = Math.round(object.position.z / this.translationSnap) * this.translationSnap; } object.position.applyQuaternion(this._quaternionStart); } if (space === 'world') { if (object.parent) { object.position.add(_tempVector.setFromMatrixPosition(object.parent.matrixWorld)); } if (axis.search('X') !== -1) { object.position.x = Math.round(object.position.x / this.translationSnap) * this.translationSnap; } if (axis.search('Y') !== -1) { object.position.y = Math.round(object.position.y / this.translationSnap) * this.translationSnap; } if (axis.search('Z') !== -1) { object.position.z = Math.round(object.position.z / this.translationSnap) * this.translationSnap; } if (object.parent) { object.position.sub(_tempVector.setFromMatrixPosition(object.parent.matrixWorld)); } } } } else if (mode === 'scale') { if (axis.search('XYZ') !== -1) { var d = this.pointEnd.length() / this.pointStart.length(); if (this.pointEnd.dot(this.pointStart) < 0) d *= -1; _tempVector2.set(d, d, d); } else { _tempVector.copy(this.pointStart); _tempVector2.copy(this.pointEnd); _tempVector.applyQuaternion(this._worldQuaternionInv); _tempVector2.applyQuaternion(this._worldQuaternionInv); _tempVector2.divide(_tempVector); if (axis.search('X') === -1) { _tempVector2.x = 1; } if (axis.search('Y') === -1) { _tempVector2.y = 1; } if (axis.search('Z') === -1) { _tempVector2.z = 1; } } // Apply scale object.scale.copy(this._scaleStart).multiply(_tempVector2); if (this.scaleSnap) { if (axis.search('X') !== -1) { object.scale.x = Math.round(object.scale.x / this.scaleSnap) * this.scaleSnap || this.scaleSnap; } if (axis.search('Y') !== -1) { object.scale.y = Math.round(object.scale.y / this.scaleSnap) * this.scaleSnap || this.scaleSnap; } if (axis.search('Z') !== -1) { object.scale.z = Math.round(object.scale.z / this.scaleSnap) * this.scaleSnap || this.scaleSnap; } } } else if (mode === 'rotate') { this._offset.copy(this.pointEnd).sub(this.pointStart); var ROTATION_SPEED = 20 / this.worldPosition.distanceTo(_tempVector.setFromMatrixPosition(this.camera.matrixWorld)); if (axis === 'E') { this.rotationAxis.copy(this.eye); this.rotationAngle = this.pointEnd.angleTo(this.pointStart); this._startNorm.copy(this.pointStart).normalize(); this._endNorm.copy(this.pointEnd).normalize(); this.rotationAngle *= this._endNorm.cross(this._startNorm).dot(this.eye) < 0 ? 1 : -1; } else if (axis === 'XYZE') { this.rotationAxis.copy(this._offset).cross(this.eye).normalize(); this.rotationAngle = this._offset.dot(_tempVector.copy(this.rotationAxis).cross(this.eye)) * ROTATION_SPEED; } else if (axis === 'X' || axis === 'Y' || axis === 'Z') { this.rotationAxis.copy(_unit[axis]); _tempVector.copy(_unit[axis]); if (space === 'local') { _tempVector.applyQuaternion(this.worldQuaternion); } this.rotationAngle = this._offset.dot(_tempVector.cross(this.eye).normalize()) * ROTATION_SPEED; } // Apply rotation snap if (this.rotationSnap) this.rotationAngle = Math.round(this.rotationAngle / this.rotationSnap) * this.rotationSnap; // Apply rotate if (space === 'local' && axis !== 'E' && axis !== 'XYZE') { object.quaternion.copy(this._quaternionStart); object.quaternion.multiply(_tempQuaternion.setFromAxisAngle(this.rotationAxis, this.rotationAngle)).normalize(); } else { this.rotationAxis.applyQuaternion(this._parentQuaternionInv); object.quaternion.copy(_tempQuaternion.setFromAxisAngle(this.rotationAxis, this.rotationAngle)); object.quaternion.multiply(this._quaternionStart).normalize(); } } this.dispatchEvent(_changeEvent); this.dispatchEvent(_objectChangeEvent); } }, { key: "pointerUp", value: function pointerUp(pointer) { if (pointer.button !== 0) return; if (this.dragging && this.axis !== null) { _mouseUpEvent.mode = this.mode; this.dispatchEvent(_mouseUpEvent); } this.dragging = false; this.axis = null; } }, { key: "dispose", value: function dispose() { this.domElement.removeEventListener('pointerdown', this._onPointerDown); this.domElement.removeEventListener('pointermove', this._onPointerHover); this.domElement.removeEventListener('pointermove', this._onPointerMove); this.domElement.removeEventListener('pointerup', this._onPointerUp); this.traverse(function (child) { if (child.geometry) child.geometry.dispose(); if (child.material) child.material.dispose(); }); } // Set current object }, { key: "attach", value: function attach(object) { this.object = object; this.visible = true; return this; } // Detatch from object }, { key: "detach", value: function detach() { this.object = undefined; this.visible = false; this.axis = null; return this; } }, { key: "getRaycaster", value: function getRaycaster() { return _raycaster; } // TODO: deprecate }, { key: "getMode", value: function getMode() { return this.mode; } }, { key: "setMode", value: function setMode(mode) { this.mode = mode; } }, { key: "setTranslationSnap", value: function setTranslationSnap(translationSnap) { this.translationSnap = translationSnap; } }, { key: "setRotationSnap", value: function setRotationSnap(rotationSnap) { this.rotationSnap = rotationSnap; } }, { key: "setScaleSnap", value: function setScaleSnap(scaleSnap) { this.scaleSnap = scaleSnap; } }, { key: "setSize", value: function setSize(size) { this.size = size; } }, { key: "setSpace", value: function setSpace(space) { this.space = space; } }, { key: "update", value: function update() { console.warn('THREE.TransformControls: update function has no more functionality and therefore has been deprecated.'); } }]); return TransformControls; }(_three.Object3D); _exports.TransformControls = TransformControls; TransformControls.prototype.isTransformControls = true; // mouse / touch event handlers function getPointer(event) { if (this.domElement.ownerDocument.pointerLockElement) { return { x: 0, y: 0, button: event.button }; } else { var rect = this.domElement.getBoundingClientRect(); return { x: (event.clientX - rect.left) / rect.width * 2 - 1, y: -(event.clientY - rect.top) / rect.height * 2 + 1, button: event.button }; } } function onPointerHover(event) { if (!this.enabled) return; switch (event.pointerType) { case 'mouse': case 'pen': this.pointerHover(this._getPointer(event)); break; } } function onPointerDown(event) { if (!this.enabled) return; this.domElement.setPointerCapture(event.pointerId); this.domElement.addEventListener('pointermove', this._onPointerMove); this.pointerHover(this._getPointer(event)); this.pointerDown(this._getPointer(event)); } function onPointerMove(event) { if (!this.enabled) return; this.pointerMove(this._getPointer(event)); } function onPointerUp(event) { if (!this.enabled) return; this.domElement.releasePointerCapture(event.pointerId); this.domElement.removeEventListener('pointermove', this._onPointerMove); this.pointerUp(this._getPointer(event)); } function intersectObjectWithRay(object, raycaster, includeInvisible) { var allIntersections = raycaster.intersectObject(object, true); for (var i = 0; i < allIntersections.length; i++) { if (allIntersections[i].object.visible || includeInvisible) { return allIntersections[i]; } } return false; } // // Reusable utility variables var _tempEuler = new _three.Euler(); var _alignVector = new _three.Vector3(0, 1, 0); var _zeroVector = new _three.Vector3(0, 0, 0); var _lookAtMatrix = new _three.Matrix4(); var _tempQuaternion2 = new _three.Quaternion(); var _identityQuaternion = new _three.Quaternion(); var _dirVector = new _three.Vector3(); var _tempMatrix = new _three.Matrix4(); var _unitX = new _three.Vector3(1, 0, 0); var _unitY = new _three.Vector3(0, 1, 0); var _unitZ = new _three.Vector3(0, 0, 1); var _v1 = new _three.Vector3(); var _v2 = new _three.Vector3(); var _v3 = new _three.Vector3(); var TransformControlsGizmo = /*#__PURE__*/function (_Object3D2) { _inherits(TransformControlsGizmo, _Object3D2); var _super2 = _createSuper(TransformControlsGizmo); function TransformControlsGizmo() { var _this2; _classCallCheck(this, TransformControlsGizmo); _this2 = _super2.call(this); _this2.type = 'TransformControlsGizmo'; // shared materials var gizmoMaterial = new _three.MeshBasicMaterial({ depthTest: false, depthWrite: false, fog: false, toneMapped: false, transparent: true }); var gizmoLineMaterial = new _three.LineBasicMaterial({ depthTest: false, depthWrite: false, fog: false, toneMapped: false, transparent: true }); // Make unique material for each axis/color var matInvisible = gizmoMaterial.clone(); matInvisible.opacity = 0.15; var matHelper = gizmoLineMaterial.clone(); matHelper.opacity = 0.5; var matRed = gizmoMaterial.clone(); matRed.color.setHex(0xff0000); var matGreen = gizmoMaterial.clone(); matGreen.color.setHex(0x00ff00); var matBlue = gizmoMaterial.clone(); matBlue.color.setHex(0x0000ff); var matRedTransparent = gizmoMaterial.clone(); matRedTransparent.color.setHex(0xff0000); matRedTransparent.opacity = 0.5; var matGreenTransparent = gizmoMaterial.clone(); matGreenTransparent.color.setHex(0x00ff00); matGreenTransparent.opacity = 0.5; var matBlueTransparent = gizmoMaterial.clone(); matBlueTransparent.color.setHex(0x0000ff); matBlueTransparent.opacity = 0.5; var matWhiteTransparent = gizmoMaterial.clone(); matWhiteTransparent.opacity = 0.25; var matYellowTransparent = gizmoMaterial.clone(); matYellowTransparent.color.setHex(0xffff00); matYellowTransparent.opacity = 0.25; var matYellow = gizmoMaterial.clone(); matYellow.color.setHex(0xffff00); var matGray = gizmoMaterial.clone(); matGray.color.setHex(0x787878); // reusable geometry var arrowGeometry = new _three.CylinderGeometry(0, 0.04, 0.1, 12); arrowGeometry.translate(0, 0.05, 0); var scaleHandleGeometry = new _three.BoxGeometry(0.08, 0.08, 0.08); scaleHandleGeometry.translate(0, 0.04, 0); var lineGeometry = new _three.BufferGeometry(); lineGeometry.setAttribute('position', new _three.Float32BufferAttribute([0, 0, 0, 1, 0, 0], 3)); var lineGeometry2 = new _three.CylinderGeometry(0.0075, 0.0075, 0.5, 3); lineGeometry2.translate(0, 0.25, 0); function CircleGeometry(radius, arc) { var geometry = new _three.TorusGeometry(radius, 0.0075, 3, 64, arc * Math.PI * 2); geometry.rotateY(Math.PI / 2); geometry.rotateX(Math.PI / 2); return geometry; } // Special geometry for transform helper. If scaled with position vector it spans from [0,0,0] to position function TranslateHelperGeometry() { var geometry = new _three.BufferGeometry(); geometry.setAttribute('position', new _three.Float32BufferAttribute([0, 0, 0, 1, 1, 1], 3)); return geometry; } // Gizmo definitions - custom hierarchy definitions for setupGizmo() function var gizmoTranslate = { X: [[new _three.Mesh(arrowGeometry, matRed), [0.5, 0, 0], [0, 0, -Math.PI / 2]], [new _three.Mesh(arrowGeometry, matRed), [-0.5, 0, 0], [0, 0, Math.PI / 2]], [new _three.Mesh(lineGeometry2, matRed), [0, 0, 0], [0, 0, -Math.PI / 2]]], Y: [[new _three.Mesh(arrowGeometry, matGreen), [0, 0.5, 0]], [new _three.Mesh(arrowGeometry, matGreen), [0, -0.5, 0], [Math.PI, 0, 0]], [new _three.Mesh(lineGeometry2, matGreen)]], Z: [[new _three.Mesh(arrowGeometry, matBlue), [0, 0, 0.5], [Math.PI / 2, 0, 0]], [new _three.Mesh(arrowGeometry, matBlue), [0, 0, -0.5], [-Math.PI / 2, 0, 0]], [new _three.Mesh(lineGeometry2, matBlue), null, [Math.PI / 2, 0, 0]]], XYZ: [[new _three.Mesh(new _three.OctahedronGeometry(0.1, 0), matWhiteTransparent.clone()), [0, 0, 0]]], XY: [[new _three.Mesh(new _three.BoxGeometry(0.15, 0.15, 0.01), matBlueTransparent.clone()), [0.15, 0.15, 0]]], YZ: [[new _three.Mesh(new _three.BoxGeometry(0.15, 0.15, 0.01), matRedTransparent.clone()), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]], XZ: [[new _three.Mesh(new _three.BoxGeometry(0.15, 0.15, 0.01), matGreenTransparent.clone()), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]] }; var pickerTranslate = { X: [[new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0.3, 0, 0], [0, 0, -Math.PI / 2]], [new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [-0.3, 0, 0], [0, 0, Math.PI / 2]]], Y: [[new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0.3, 0]], [new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, -0.3, 0], [0, 0, Math.PI]]], Z: [[new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, 0.3], [Math.PI / 2, 0, 0]], [new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, -0.3], [-Math.PI / 2, 0, 0]]], XYZ: [[new _three.Mesh(new _three.OctahedronGeometry(0.2, 0), matInvisible)]], XY: [[new _three.Mesh(new _three.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0.15, 0]]], YZ: [[new _three.Mesh(new _three.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]], XZ: [[new _three.Mesh(new _three.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]] }; var helperTranslate = { START: [[new _three.Mesh(new _three.OctahedronGeometry(0.01, 2), matHelper), null, null, null, 'helper']], END: [[new _three.Mesh(new _three.OctahedronGeometry(0.01, 2), matHelper), null, null, null, 'helper']], DELTA: [[new _three.Line(TranslateHelperGeometry(), matHelper), null, null, null, 'helper']], X: [[new _three.Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']], Y: [[new _three.Line(lineGeometry, matHelper.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], 'helper']], Z: [[new _three.Line(lineGeometry, matHelper.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], 'helper']] }; var gizmoRotate = { XYZE: [[new _three.Mesh(CircleGeometry(0.5, 1), matGray), null, [0, Math.PI / 2, 0]]], X: [[new _three.Mesh(CircleGeometry(0.5, 0.5), matRed)]], Y: [[new _three.Mesh(CircleGeometry(0.5, 0.5), matGreen), null, [0, 0, -Math.PI / 2]]], Z: [[new _three.Mesh(CircleGeometry(0.5, 0.5), matBlue), null, [0, Math.PI / 2, 0]]], E: [[new _three.Mesh(CircleGeometry(0.75, 1), matYellowTransparent), null, [0, Math.PI / 2, 0]]] }; var helperRotate = { AXIS: [[new _three.Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']] }; var pickerRotate = { XYZE: [[new _three.Mesh(new _three.SphereGeometry(0.25, 10, 8), matInvisible)]], X: [[new _three.Mesh(new _three.TorusGeometry(0.5, 0.1, 4, 24), matInvisible), [0, 0, 0], [0, -Math.PI / 2, -Math.PI / 2]]], Y: [[new _three.Mesh(new _three.TorusGeometry(0.5, 0.1, 4, 24), matInvisible), [0, 0, 0], [Math.PI / 2, 0, 0]]], Z: [[new _three.Mesh(new _three.TorusGeometry(0.5, 0.1, 4, 24), matInvisible), [0, 0, 0], [0, 0, -Math.PI / 2]]], E: [[new _three.Mesh(new _three.TorusGeometry(0.75, 0.1, 2, 24), matInvisible)]] }; var gizmoScale = { X: [[new _three.Mesh(scaleHandleGeometry, matRed), [0.5, 0, 0], [0, 0, -Math.PI / 2]], [new _three.Mesh(lineGeometry2, matRed), [0, 0, 0], [0, 0, -Math.PI / 2]], [new _three.Mesh(scaleHandleGeometry, matRed), [-0.5, 0, 0], [0, 0, Math.PI / 2]]], Y: [[new _three.Mesh(scaleHandleGeometry, matGreen), [0, 0.5, 0]], [new _three.Mesh(lineGeometry2, matGreen)], [new _three.Mesh(scaleHandleGeometry, matGreen), [0, -0.5, 0], [0, 0, Math.PI]]], Z: [[new _three.Mesh(scaleHandleGeometry, matBlue), [0, 0, 0.5], [Math.PI / 2, 0, 0]], [new _three.Mesh(lineGeometry2, matBlue), [0, 0, 0], [Math.PI / 2, 0, 0]], [new _three.Mesh(scaleHandleGeometry, matBlue), [0, 0, -0.5], [-Math.PI / 2, 0, 0]]], XY: [[new _three.Mesh(new _three.BoxGeometry(0.15, 0.15, 0.01), matBlueTransparent), [0.15, 0.15, 0]]], YZ: [[new _three.Mesh(new _three.BoxGeometry(0.15, 0.15, 0.01), matRedTransparent), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]], XZ: [[new _three.Mesh(new _three.BoxGeometry(0.15, 0.15, 0.01), matGreenTransparent), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]], XYZ: [[new _three.Mesh(new _three.BoxGeometry(0.1, 0.1, 0.1), matWhiteTransparent.clone())]] }; var pickerScale = { X: [[new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0.3, 0, 0], [0, 0, -Math.PI / 2]], [new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [-0.3, 0, 0], [0, 0, Math.PI / 2]]], Y: [[new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0.3, 0]], [new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, -0.3, 0], [0, 0, Math.PI]]], Z: [[new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, 0.3], [Math.PI / 2, 0, 0]], [new _three.Mesh(new _three.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, -0.3], [-Math.PI / 2, 0, 0]]], XY: [[new _three.Mesh(new _three.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0.15, 0]]], YZ: [[new _three.Mesh(new _three.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]], XZ: [[new _three.Mesh(new _three.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]], XYZ: [[new _three.Mesh(new _three.BoxGeometry(0.2, 0.2, 0.2), matInvisible), [0, 0, 0]]] }; var helperScale = { X: [[new _three.Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']], Y: [[new _three.Line(lineGeometry, matHelper.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], 'helper']], Z: [[new _three.Line(lineGeometry, matHelper.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], 'helper']] }; // Creates an Object3D with gizmos described in custom hierarchy definition. function setupGizmo(gizmoMap) { var gizmo = new _three.Object3D(); for (var name in gizmoMap) { for (var i = gizmoMap[name].length; i--;) { var object = gizmoMap[name][i][0].clone(); var position = gizmoMap[name][i][1]; var rotation = gizmoMap[name][i][2]; var scale = gizmoMap[name][i][3]; var tag = gizmoMap[name][i][4]; // name and tag properties are essential for picking and updating logic. object.name = name; object.tag = tag; if (position) { object.position.set(position[0], position[1], position[2]); } if (rotation) { object.rotation.set(rotation[0], rotation[1], rotation[2]); } if (scale) { object.scale.set(scale[0], scale[1], scale[2]); } object.updateMatrix(); var tempGeometry = object.geometry.clone(); tempGeometry.applyMatrix4(object.matrix); object.geometry = tempGeometry; object.renderOrder = Infinity; object.position.set(0, 0, 0); object.rotation.set(0, 0, 0); object.scale.set(1, 1, 1); gizmo.add(object); } } return gizmo; } // Gizmo creation _this2.gizmo = {}; _this2.picker = {}; _this2.helper = {}; _this2.add(_this2.gizmo['translate'] = setupGizmo(gizmoTranslate)); _this2.add(_this2.gizmo['rotate'] = setupGizmo(gizmoRotate)); _this2.add(_this2.gizmo['scale'] = setupGizmo(gizmoScale)); _this2.add(_this2.picker['translate'] = setupGizmo(pickerTranslate)); _this2.add(_this2.picker['rotate'] = setupGizmo(pickerRotate)); _this2.add(_this2.picker['scale'] = setupGizmo(pickerScale)); _this2.add(_this2.helper['translate'] = setupGizmo(helperTranslate)); _this2.add(_this2.helper['rotate'] = setupGizmo(helperRotate)); _this2.add(_this2.helper['scale'] = setupGizmo(helperScale)); // Pickers should be hidden always _this2.picker['translate'].visible = false; _this2.picker['rotate'].visible = false; _this2.picker['scale'].visible = false; return _this2; } // updateMatrixWorld will update transformations and appearance of individual handles _createClass(TransformControlsGizmo, [{ key: "updateMatrixWorld", value: function updateMatrixWorld(force) { var _this3 = this; var space = this.mode === 'scale' ? 'local' : this.space; // scale always oriented to local rotation var quaternion = space === 'local' ? this.worldQuaternion : _identityQuaternion; // Show only gizmos for current transform mode this.gizmo['translate'].visible = this.mode === 'translate'; this.gizmo['rotate'].visible = this.mode === 'rotate'; this.gizmo['scale'].visible = this.mode === 'scale'; this.helper['translate'].visible = this.mode === 'translate'; this.helper['rotate'].visible = this.mode === 'rotate'; this.helper['scale'].visible = this.mode === 'scale'; var handles = []; handles = handles.concat(this.picker[this.mode].children); handles = handles.concat(this.gizmo[this.mode].children); handles = handles.concat(this.helper[this.mode].children); var _loop = function _loop(i) { var handle = handles[i]; // hide aligned to camera handle.visible = true; handle.rotation.set(0, 0, 0); handle.position.copy(_this3.worldPosition); var factor = void 0; if (_this3.camera.isOrthographicCamera) { factor = (_this3.camera.top - _this3.camera.bottom) / _this3.camera.zoom; } else { factor = _this3.worldPosition.distanceTo(_this3.cameraPosition) * Math.min(1.9 * Math.tan(Math.PI * _this3.camera.fov / 360) / _this3.camera.zoom, 7); } handle.scale.set(1, 1, 1).multiplyScalar(factor * _this3.size / 4); // TODO: simplify helpers and consider decoupling from gizmo if (handle.tag === 'helper') { handle.visible = false; if (handle.name === 'AXIS') { handle.position.copy(_this3.worldPositionStart); handle.visible = !!_this3.axis; if (_this3.axis === 'X') { _tempQuaternion.setFromEuler(_tempEuler.set(0, 0, 0)); handle.quaternion.copy(quaternion).multiply(_tempQuaternion); if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(_this3.eye)) > 0.9) { handle.visible = false; } } if (_this3.axis === 'Y') { _tempQuaternion.setFromEuler(_tempEuler.set(0, 0, Math.PI / 2)); handle.quaternion.copy(quaternion).multiply(_tempQuaternion); if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(_this3.eye)) > 0.9) { handle.visible = false; } } if (_this3.axis === 'Z') { _tempQuaternion.setFromEuler(_tempEuler.set(0, Math.PI / 2, 0)); handle.quaternion.copy(quaternion).multiply(_tempQuaternion); if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(_this3.eye)) > 0.9) { handle.visible = false; } } if (_this3.axis === 'XYZE') { _tempQuaternion.setFromEuler(_tempEuler.set(0, Math.PI / 2, 0)); _alignVector.copy(_this3.rotationAxis); handle.quaternion.setFromRotationMatrix(_lookAtMatrix.lookAt(_zeroVector, _alignVector, _unitY)); handle.quaternion.multiply(_tempQuaternion); handle.visible = _this3.dragging; } if (_this3.axis === 'E') { handle.visible = false; } } else if (handle.name === 'START') { handle.position.copy(_this3.worldPositionStart); handle.visible = _this3.dragging; } else if (handle.name === 'END') { handle.position.copy(_this3.worldPosition); handle.visible = _this3.dragging; } else if (handle.name === 'DELTA') { handle.position.copy(_this3.worldPositionStart); handle.quaternion.copy(_this3.worldQuaternionStart); _tempVector.set(1e-10, 1e-10, 1e-10).add(_this3.worldPositionStart).sub(_this3.worldPosition).multiplyScalar(-1); _tempVector.applyQuaternion(_this3.worldQuaternionStart.clone().invert()); handle.scale.copy(_tempVector); handle.visible = _this3.dragging; } else { handle.quaternion.copy(quaternion); if (_this3.dragging) { handle.position.copy(_this3.worldPositionStart); } else { handle.position.copy(_this3.worldPosition); } if (_this3.axis) { handle.visible = _this3.axis.search(handle.name) !== -1; } } // If updating helper, skip rest of the loop return "continue"; } // Align handles to current local or world rotation handle.quaternion.copy(quaternion); if (_this3.mode === 'translate' || _this3.mode === 'scale') { // Hide translate and scale axis facing the camera var AXIS_HIDE_TRESHOLD = 0.99; var PLANE_HIDE_TRESHOLD = 0.2; if (handle.name === 'X') { if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(_this3.eye)) > AXIS_HIDE_TRESHOLD) { handle.scale.set(1e-10, 1e-10, 1e-10); handle.visible = false; } } if (handle.name === 'Y') { if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(_this3.eye)) > AXIS_HIDE_TRESHOLD) { handle.scale.set(1e-10, 1e-10, 1e-10); handle.visible = false; } } if (handle.name === 'Z') { if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(_this3.eye)) > AXIS_HIDE_TRESHOLD) { handle.scale.set(1e-10, 1e-10, 1e-10); handle.visible = false; } } if (handle.name === 'XY') { if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(_this3.eye)) < PLANE_HIDE_TRESHOLD) { handle.scale.set(1e-10, 1e-10, 1e-10); handle.visible = false; } } if (handle.name === 'YZ') { if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(_this3.eye)) < PLANE_HIDE_TRESHOLD) { handle.scale.set(1e-10, 1e-10, 1e-10); handle.visible = false; } } if (handle.name === 'XZ') { if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(_this3.eye)) < PLANE_HIDE_TRESHOLD) { handle.scale.set(1e-10, 1e-10, 1e-10); handle.visible = false; } } } else if (_this3.mode === 'rotate') { // Align handles to current local or world rotation _tempQuaternion2.copy(quaternion); _alignVector.copy(_this3.eye).applyQuaternion(_tempQuaternion.copy(quaternion).invert()); if (handle.name.search('E') !== -1) { handle.quaternion.setFromRotationMatrix(_lookAtMatrix.lookAt(_this3.eye, _zeroVector, _unitY)); } if (handle.name === 'X') { _tempQuaternion.setFromAxisAngle(_unitX, Math.atan2(-_alignVector.y, _alignVector.z)); _tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion); handle.quaternion.copy(_tempQuaternion); } if (handle.name === 'Y') { _tempQuaternion.setFromAxisAngle(_unitY, Math.atan2(_alignVector.x, _alignVector.z)); _tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion); handle.quaternion.copy(_tempQuaternion); } if (handle.name === 'Z') { _tempQuaternion.setFromAxisAngle(_unitZ, Math.atan2(_alignVector.y, _alignVector.x)); _tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion); handle.quaternion.copy(_tempQuaternion); } } // Hide disabled axes handle.visible = handle.visible && (handle.name.indexOf('X') === -1 || _this3.showX); handle.visible = handle.visible && (handle.name.indexOf('Y') === -1 || _this3.showY); handle.visible = handle.visible && (handle.name.indexOf('Z') === -1 || _this3.showZ); handle.visible = handle.visible && (handle.name.indexOf('E') === -1 || _this3.showX && _this3.showY && _this3.showZ); // highlight selected axis handle.material._color = handle.material._color || handle.material.color.clone(); handle.material._opacity = handle.material._opacity || handle.material.opacity; handle.material.color.copy(handle.material._color); handle.material.opacity = handle.material._opacity; if (_this3.enabled && _this3.axis) { if (handle.name === _this3.axis) { handle.material.color.setHex(0xffff00); handle.material.opacity = 1.0; } else if (_this3.axis.split('').some(function (a) { return handle.name === a; })) { handle.material.color.setHex(0xffff00); handle.material.opacity = 1.0; } } }; for (var i = 0; i < handles.length; i++) { var _ret = _loop(i); if (_ret === "continue") continue; } _get(_getPrototypeOf(TransformControlsGizmo.prototype), "updateMatrixWorld", this).call(this, force); } }]); return TransformControlsGizmo; }(_three.Object3D); _exports.TransformControlsGizmo = TransformControlsGizmo; TransformControlsGizmo.prototype.isTransformControlsGizmo = true; // var TransformControlsPlane = /*#__PURE__*/function (_Mesh) { _inherits(TransformControlsPlane, _Mesh); var _super3 = _createSuper(TransformControlsPlane); function TransformControlsPlane() { var _this4; _classCallCheck(this, TransformControlsPlane); _this4 = _super3.call(this, new _three.PlaneGeometry(100000, 100000, 2, 2), new _three.MeshBasicMaterial({ visible: false, wireframe: true, side: _three.DoubleSide, transparent: true, opacity: 0.1, toneMapped: false })); _this4.type = 'TransformControlsPlane'; return _this4; } _createClass(TransformControlsPlane, [{ key: "updateMatrixWorld", value: function updateMatrixWorld(force) { var space = this.space; this.position.copy(this.worldPosition); if (this.mode === 'scale') space = 'local'; // scale always oriented to local rotation _v1.copy(_unitX).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion); _v2.copy(_unitY).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion); _v3.copy(_unitZ).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion); // Align the plane for current transform mode, axis and space. _alignVector.copy(_v2); switch (this.mode) { case 'translate': case 'scale': switch (this.axis) { case 'X': _alignVector.copy(this.eye).cross(_v1); _dirVector.copy(_v1).cross(_alignVector); break; case 'Y': _alignVector.copy(this.eye).cross(_v2); _dirVector.copy(_v2).cross(_alignVector); break; case 'Z': _alignVector.copy(this.eye).cross(_v3); _dirVector.copy(_v3).cross(_alignVector); break; case 'XY': _dirVector.copy(_v3); break; case 'YZ': _dirVector.copy(_v1); break; case 'XZ': _alignVector.copy(_v3); _dirVector.copy(_v2); break; case 'XYZ': case 'E': _dirVector.set(0, 0, 0); break; } break; case 'rotate': default: // special case for rotate _dirVector.set(0, 0, 0); } if (_dirVector.length() === 0) { // If in rotate mode, make the plane parallel to camera this.quaternion.copy(this.cameraQuaternion); } else { _tempMatrix.lookAt(_tempVector.set(0, 0, 0), _dirVector, _alignVector); this.quaternion.setFromRotationMatrix(_tempMatrix); } _get(_getPrototypeOf(TransformControlsPlane.prototype), "updateMatrixWorld", this).call(this, force); } }]); return TransformControlsPlane; }(_three.Mesh); _exports.TransformControlsPlane = TransformControlsPlane; TransformControlsPlane.prototype.isTransformControlsPlane = true; });