|
|
@@ -1,587 +1,613 @@
|
|
|
-THREE.TransformControls = function ( camera, domElement ) {
|
|
|
+( function () {
|
|
|
|
|
|
- if ( domElement === undefined ) {
|
|
|
+ const _raycaster = new THREE.Raycaster();
|
|
|
|
|
|
- console.warn( 'THREE.TransformControls: The second parameter "domElement" is now mandatory.' );
|
|
|
- domElement = document;
|
|
|
+ const _tempVector = new THREE.Vector3();
|
|
|
|
|
|
- }
|
|
|
+ const _tempVector2 = new THREE.Vector3();
|
|
|
|
|
|
- THREE.Object3D.call( this );
|
|
|
+ const _tempQuaternion = new THREE.Quaternion();
|
|
|
|
|
|
- this.visible = false;
|
|
|
- this.domElement = domElement;
|
|
|
+ const _unit = {
|
|
|
+ X: new THREE.Vector3( 1, 0, 0 ),
|
|
|
+ Y: new THREE.Vector3( 0, 1, 0 ),
|
|
|
+ Z: new THREE.Vector3( 0, 0, 1 )
|
|
|
+ };
|
|
|
+ const _changeEvent = {
|
|
|
+ type: 'change'
|
|
|
+ };
|
|
|
+ const _mouseDownEvent = {
|
|
|
+ type: 'mouseDown'
|
|
|
+ };
|
|
|
+ const _mouseUpEvent = {
|
|
|
+ type: 'mouseUp',
|
|
|
+ mode: null
|
|
|
+ };
|
|
|
+ const _objectChangeEvent = {
|
|
|
+ type: 'objectChange'
|
|
|
+ };
|
|
|
|
|
|
- var _gizmo = new THREE.TransformControlsGizmo();
|
|
|
- this.add( _gizmo );
|
|
|
+ class TransformControls extends THREE.Object3D {
|
|
|
|
|
|
- var _plane = new THREE.TransformControlsPlane();
|
|
|
- this.add( _plane );
|
|
|
+ constructor( camera, domElement ) {
|
|
|
|
|
|
- var scope = this;
|
|
|
+ super();
|
|
|
|
|
|
- // Define properties with getters/setter
|
|
|
- // Setting the defined property will automatically trigger change event
|
|
|
- // Defined properties are passed down to gizmo and plane
|
|
|
+ if ( domElement === undefined ) {
|
|
|
|
|
|
- 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 );
|
|
|
+ console.warn( 'THREE.TransformControls: The second parameter "domElement" is now mandatory.' );
|
|
|
+ domElement = document;
|
|
|
|
|
|
- var changeEvent = { type: 'change' };
|
|
|
- var mouseDownEvent = { type: 'mouseDown' };
|
|
|
- var mouseUpEvent = { type: 'mouseUp', mode: scope.mode };
|
|
|
- var objectChangeEvent = { type: 'objectChange' };
|
|
|
+ }
|
|
|
|
|
|
- // Reusable utility variables
|
|
|
+ this.visible = false;
|
|
|
+ this.domElement = domElement;
|
|
|
|
|
|
- var raycaster = new THREE.Raycaster();
|
|
|
+ const _gizmo = new TransformControlsGizmo();
|
|
|
|
|
|
- function intersectObjectWithRay( object, raycaster, includeInvisible ) {
|
|
|
+ this._gizmo = _gizmo;
|
|
|
+ this.add( _gizmo );
|
|
|
|
|
|
- var allIntersections = raycaster.intersectObject( object, true );
|
|
|
+ const _plane = new TransformControlsPlane();
|
|
|
|
|
|
- for ( var i = 0; i < allIntersections.length; i ++ ) {
|
|
|
+ this._plane = _plane;
|
|
|
+ this.add( _plane );
|
|
|
+ const scope = this; // Defined getter, setter and store for a property
|
|
|
|
|
|
- if ( allIntersections[ i ].object.visible || includeInvisible ) {
|
|
|
+ function defineProperty( propName, defaultValue ) {
|
|
|
|
|
|
- return allIntersections[ i ];
|
|
|
+ let propValue = defaultValue;
|
|
|
+ Object.defineProperty( scope, propName, {
|
|
|
+ get: function () {
|
|
|
|
|
|
- }
|
|
|
+ return propValue !== undefined ? propValue : defaultValue;
|
|
|
|
|
|
- }
|
|
|
+ },
|
|
|
+ set: function ( value ) {
|
|
|
|
|
|
- return false;
|
|
|
+ if ( propValue !== value ) {
|
|
|
|
|
|
- }
|
|
|
+ propValue = value;
|
|
|
+ _plane[ propName ] = value;
|
|
|
+ _gizmo[ propName ] = value;
|
|
|
+ scope.dispatchEvent( {
|
|
|
+ type: propName + '-changed',
|
|
|
+ value: value
|
|
|
+ } );
|
|
|
+ scope.dispatchEvent( _changeEvent );
|
|
|
|
|
|
- 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 pointStart = new THREE.Vector3();
|
|
|
- var pointEnd = new THREE.Vector3();
|
|
|
- var offset = new THREE.Vector3();
|
|
|
- var rotationAxis = new THREE.Vector3();
|
|
|
- var startNorm = new THREE.Vector3();
|
|
|
- var endNorm = new THREE.Vector3();
|
|
|
- var rotationAngle = 0;
|
|
|
-
|
|
|
- var cameraPosition = new THREE.Vector3();
|
|
|
- var cameraQuaternion = new THREE.Quaternion();
|
|
|
- var cameraScale = new THREE.Vector3();
|
|
|
-
|
|
|
- var parentPosition = new THREE.Vector3();
|
|
|
- var parentQuaternion = new THREE.Quaternion();
|
|
|
- var parentQuaternionInv = new THREE.Quaternion();
|
|
|
- var parentScale = new THREE.Vector3();
|
|
|
-
|
|
|
- var worldPositionStart = new THREE.Vector3();
|
|
|
- var worldQuaternionStart = new THREE.Quaternion();
|
|
|
- var worldScaleStart = new THREE.Vector3();
|
|
|
-
|
|
|
- var worldPosition = new THREE.Vector3();
|
|
|
- var worldQuaternion = new THREE.Quaternion();
|
|
|
- var worldQuaternionInv = new THREE.Quaternion();
|
|
|
- var worldScale = new THREE.Vector3();
|
|
|
-
|
|
|
- var eye = new THREE.Vector3();
|
|
|
-
|
|
|
- var positionStart = new THREE.Vector3();
|
|
|
- var quaternionStart = new THREE.Quaternion();
|
|
|
- var scaleStart = 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 );
|
|
|
-
|
|
|
- {
|
|
|
-
|
|
|
- domElement.addEventListener( 'pointerdown', onPointerDown );
|
|
|
- domElement.addEventListener( 'pointermove', onPointerHover );
|
|
|
- scope.domElement.ownerDocument.addEventListener( 'pointerup', onPointerUp );
|
|
|
+ }
|
|
|
+ } );
|
|
|
+ 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
|
|
|
+
|
|
|
+ const worldPosition = new THREE.Vector3();
|
|
|
+ const worldPositionStart = new THREE.Vector3();
|
|
|
+ const worldQuaternion = new THREE.Quaternion();
|
|
|
+ const worldQuaternionStart = new THREE.Quaternion();
|
|
|
+ const cameraPosition = new THREE.Vector3();
|
|
|
+ const cameraQuaternion = new THREE.Quaternion();
|
|
|
+ const pointStart = new THREE.Vector3();
|
|
|
+ const pointEnd = new THREE.Vector3();
|
|
|
+ const rotationAxis = new THREE.Vector3();
|
|
|
+ const rotationAngle = 0;
|
|
|
+ const 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( this );
|
|
|
+ this._onPointerDown = onPointerDown.bind( this );
|
|
|
+ this._onPointerHover = onPointerHover.bind( this );
|
|
|
+ this._onPointerMove = onPointerMove.bind( this );
|
|
|
+ this._onPointerUp = onPointerUp.bind( this );
|
|
|
+ this.domElement.addEventListener( 'pointerdown', this._onPointerDown );
|
|
|
+ this.domElement.addEventListener( 'pointermove', this._onPointerHover );
|
|
|
+ this.domElement.ownerDocument.addEventListener( 'pointerup', this._onPointerUp );
|
|
|
+
|
|
|
+ } // updateMatrixWorld updates key transformation variables
|
|
|
+
|
|
|
+
|
|
|
+ updateMatrixWorld() {
|
|
|
+
|
|
|
+ if ( this.object !== undefined ) {
|
|
|
|
|
|
- }
|
|
|
+ this.object.updateMatrixWorld();
|
|
|
|
|
|
- this.dispose = function () {
|
|
|
+ if ( this.object.parent === null ) {
|
|
|
|
|
|
- domElement.removeEventListener( 'pointerdown', onPointerDown );
|
|
|
- domElement.removeEventListener( 'pointermove', onPointerHover );
|
|
|
- scope.domElement.ownerDocument.removeEventListener( 'pointermove', onPointerMove );
|
|
|
- scope.domElement.ownerDocument.removeEventListener( 'pointerup', onPointerUp );
|
|
|
+ console.error( 'TransformControls: The attached 3D object must be a part of the scene graph.' );
|
|
|
|
|
|
- this.traverse( function ( child ) {
|
|
|
+ } else {
|
|
|
|
|
|
- if ( child.geometry ) child.geometry.dispose();
|
|
|
- if ( child.material ) child.material.dispose();
|
|
|
+ this.object.parent.matrixWorld.decompose( this._parentPosition, this._parentQuaternion, this._parentScale );
|
|
|
|
|
|
- } );
|
|
|
+ }
|
|
|
|
|
|
- };
|
|
|
+ this.object.matrixWorld.decompose( this.worldPosition, this.worldQuaternion, this._worldScale );
|
|
|
|
|
|
- // Set current object
|
|
|
- this.attach = function ( object ) {
|
|
|
+ this._parentQuaternionInv.copy( this._parentQuaternion ).invert();
|
|
|
|
|
|
- this.object = object;
|
|
|
- this.visible = true;
|
|
|
+ this._worldQuaternionInv.copy( this.worldQuaternion ).invert();
|
|
|
|
|
|
- return this;
|
|
|
+ }
|
|
|
|
|
|
- };
|
|
|
+ this.camera.updateMatrixWorld();
|
|
|
+ this.camera.matrixWorld.decompose( this.cameraPosition, this.cameraQuaternion, this._cameraScale );
|
|
|
+ this.eye.copy( this.cameraPosition ).sub( this.worldPosition ).normalize();
|
|
|
+ super.updateMatrixWorld( this );
|
|
|
|
|
|
- // Detatch from object
|
|
|
- this.detach = function () {
|
|
|
+ }
|
|
|
|
|
|
- this.object = undefined;
|
|
|
- this.visible = false;
|
|
|
- this.axis = null;
|
|
|
+ pointerHover( pointer ) {
|
|
|
|
|
|
- return this;
|
|
|
+ if ( this.object === undefined || this.dragging === true ) return;
|
|
|
|
|
|
- };
|
|
|
+ _raycaster.setFromCamera( pointer, this.camera );
|
|
|
|
|
|
- // Defined getter, setter and store for a property
|
|
|
- function defineProperty( propName, defaultValue ) {
|
|
|
+ const intersect = intersectObjectWithRay( this._gizmo.picker[ this.mode ], _raycaster );
|
|
|
|
|
|
- var propValue = defaultValue;
|
|
|
+ if ( intersect ) {
|
|
|
|
|
|
- Object.defineProperty( scope, propName, {
|
|
|
+ this.axis = intersect.object.name;
|
|
|
|
|
|
- get: function () {
|
|
|
+ } else {
|
|
|
|
|
|
- return propValue !== undefined ? propValue : defaultValue;
|
|
|
+ this.axis = null;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- set: function ( value ) {
|
|
|
+ }
|
|
|
|
|
|
- if ( propValue !== value ) {
|
|
|
+ pointerDown( pointer ) {
|
|
|
|
|
|
- propValue = value;
|
|
|
- _plane[ propName ] = value;
|
|
|
- _gizmo[ propName ] = value;
|
|
|
+ if ( this.object === undefined || this.dragging === true || pointer.button !== 0 ) return;
|
|
|
|
|
|
- scope.dispatchEvent( { type: propName + '-changed', value: value } );
|
|
|
- scope.dispatchEvent( changeEvent );
|
|
|
+ if ( this.axis !== null ) {
|
|
|
|
|
|
- }
|
|
|
+ _raycaster.setFromCamera( pointer, this.camera );
|
|
|
|
|
|
- }
|
|
|
+ const planeIntersect = intersectObjectWithRay( this._plane, _raycaster, true );
|
|
|
|
|
|
- } );
|
|
|
+ if ( planeIntersect ) {
|
|
|
|
|
|
- scope[ propName ] = defaultValue;
|
|
|
- _plane[ propName ] = defaultValue;
|
|
|
- _gizmo[ propName ] = defaultValue;
|
|
|
+ let space = this.space;
|
|
|
|
|
|
- }
|
|
|
+ if ( this.mode === 'scale' ) {
|
|
|
|
|
|
- // updateMatrixWorld updates key transformation variables
|
|
|
- this.updateMatrixWorld = function () {
|
|
|
+ space = 'local';
|
|
|
|
|
|
- if ( this.object !== undefined ) {
|
|
|
+ } else if ( this.axis === 'E' || this.axis === 'XYZE' || this.axis === 'XYZ' ) {
|
|
|
|
|
|
- this.object.updateMatrixWorld();
|
|
|
+ space = 'world';
|
|
|
|
|
|
- if ( this.object.parent === null ) {
|
|
|
+ }
|
|
|
|
|
|
- console.error( 'TransformControls: The attached 3D object must be a part of the scene graph.' );
|
|
|
+ if ( space === 'local' && this.mode === 'rotate' ) {
|
|
|
|
|
|
- } else {
|
|
|
+ const snap = this.rotationSnap;
|
|
|
+ if ( this.axis === 'X' && snap ) this.object.rotation.x = Math.round( this.object.rotation.x / snap ) * snap;
|
|
|
+ if ( this.axis === 'Y' && snap ) this.object.rotation.y = Math.round( this.object.rotation.y / snap ) * snap;
|
|
|
+ if ( this.axis === 'Z' && snap ) this.object.rotation.z = Math.round( this.object.rotation.z / snap ) * snap;
|
|
|
|
|
|
- this.object.parent.matrixWorld.decompose( parentPosition, parentQuaternion, parentScale );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ this.object.updateMatrixWorld();
|
|
|
+ this.object.parent.updateMatrixWorld();
|
|
|
|
|
|
- this.object.matrixWorld.decompose( worldPosition, worldQuaternion, worldScale );
|
|
|
+ this._positionStart.copy( this.object.position );
|
|
|
|
|
|
- parentQuaternionInv.copy( parentQuaternion ).invert();
|
|
|
- worldQuaternionInv.copy( worldQuaternion ).invert();
|
|
|
+ this._quaternionStart.copy( this.object.quaternion );
|
|
|
|
|
|
- }
|
|
|
+ this._scaleStart.copy( this.object.scale );
|
|
|
|
|
|
- this.camera.updateMatrixWorld();
|
|
|
- this.camera.matrixWorld.decompose( cameraPosition, cameraQuaternion, cameraScale );
|
|
|
+ this.object.matrixWorld.decompose( this.worldPositionStart, this.worldQuaternionStart, this._worldScaleStart );
|
|
|
+ this.pointStart.copy( planeIntersect.point ).sub( this.worldPositionStart );
|
|
|
|
|
|
- eye.copy( cameraPosition ).sub( worldPosition ).normalize();
|
|
|
+ }
|
|
|
|
|
|
- THREE.Object3D.prototype.updateMatrixWorld.call( this );
|
|
|
+ this.dragging = true;
|
|
|
+ _mouseDownEvent.mode = this.mode;
|
|
|
+ this.dispatchEvent( _mouseDownEvent );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.pointerHover = function ( pointer ) {
|
|
|
+ }
|
|
|
|
|
|
- if ( this.object === undefined || this.dragging === true ) return;
|
|
|
+ pointerMove( pointer ) {
|
|
|
|
|
|
- raycaster.setFromCamera( pointer, this.camera );
|
|
|
+ const axis = this.axis;
|
|
|
+ const mode = this.mode;
|
|
|
+ const object = this.object;
|
|
|
+ let space = this.space;
|
|
|
|
|
|
- var intersect = intersectObjectWithRay( _gizmo.picker[ this.mode ], raycaster );
|
|
|
+ if ( mode === 'scale' ) {
|
|
|
|
|
|
- if ( intersect ) {
|
|
|
+ space = 'local';
|
|
|
|
|
|
- this.axis = intersect.object.name;
|
|
|
+ } else if ( axis === 'E' || axis === 'XYZE' || axis === 'XYZ' ) {
|
|
|
|
|
|
- } else {
|
|
|
+ space = 'world';
|
|
|
|
|
|
- this.axis = null;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( object === undefined || axis === null || this.dragging === false || pointer.button !== - 1 ) return;
|
|
|
|
|
|
- };
|
|
|
+ _raycaster.setFromCamera( pointer, this.camera );
|
|
|
|
|
|
- this.pointerDown = function ( pointer ) {
|
|
|
+ const planeIntersect = intersectObjectWithRay( this._plane, _raycaster, true );
|
|
|
+ if ( ! planeIntersect ) return;
|
|
|
+ this.pointEnd.copy( planeIntersect.point ).sub( this.worldPositionStart );
|
|
|
|
|
|
- if ( this.object === undefined || this.dragging === true || pointer.button !== 0 ) return;
|
|
|
+ if ( mode === 'translate' ) {
|
|
|
|
|
|
- if ( this.axis !== null ) {
|
|
|
+ // Apply translate
|
|
|
+ this._offset.copy( this.pointEnd ).sub( this.pointStart );
|
|
|
|
|
|
- raycaster.setFromCamera( pointer, this.camera );
|
|
|
+ if ( space === 'local' && axis !== 'XYZ' ) {
|
|
|
|
|
|
- var planeIntersect = intersectObjectWithRay( _plane, raycaster, true );
|
|
|
+ this._offset.applyQuaternion( this._worldQuaternionInv );
|
|
|
|
|
|
- if ( planeIntersect ) {
|
|
|
+ }
|
|
|
|
|
|
- var space = this.space;
|
|
|
+ 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 ( this.mode === 'scale' ) {
|
|
|
+ if ( space === 'local' && axis !== 'XYZ' ) {
|
|
|
|
|
|
- space = 'local';
|
|
|
+ this._offset.applyQuaternion( this._quaternionStart ).divide( this._parentScale );
|
|
|
|
|
|
- } else if ( this.axis === 'E' || this.axis === 'XYZE' || this.axis === 'XYZ' ) {
|
|
|
+ } else {
|
|
|
|
|
|
- space = 'world';
|
|
|
+ this._offset.applyQuaternion( this._parentQuaternionInv ).divide( this._parentScale );
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( space === 'local' && this.mode === 'rotate' ) {
|
|
|
+ object.position.copy( this._offset ).add( this._positionStart ); // Apply translation snap
|
|
|
|
|
|
- var snap = this.rotationSnap;
|
|
|
+ if ( this.translationSnap ) {
|
|
|
|
|
|
- if ( this.axis === 'X' && snap ) this.object.rotation.x = Math.round( this.object.rotation.x / snap ) * snap;
|
|
|
- if ( this.axis === 'Y' && snap ) this.object.rotation.y = Math.round( this.object.rotation.y / snap ) * snap;
|
|
|
- if ( this.axis === 'Z' && snap ) this.object.rotation.z = Math.round( this.object.rotation.z / snap ) * snap;
|
|
|
+ if ( space === 'local' ) {
|
|
|
|
|
|
- }
|
|
|
+ object.position.applyQuaternion( _tempQuaternion.copy( this._quaternionStart ).invert() );
|
|
|
|
|
|
- this.object.updateMatrixWorld();
|
|
|
- this.object.parent.updateMatrixWorld();
|
|
|
+ if ( axis.search( 'X' ) !== - 1 ) {
|
|
|
|
|
|
- positionStart.copy( this.object.position );
|
|
|
- quaternionStart.copy( this.object.quaternion );
|
|
|
- scaleStart.copy( this.object.scale );
|
|
|
+ object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
|
|
|
|
|
|
- this.object.matrixWorld.decompose( worldPositionStart, worldQuaternionStart, worldScaleStart );
|
|
|
+ }
|
|
|
|
|
|
- pointStart.copy( planeIntersect.point ).sub( worldPositionStart );
|
|
|
+ if ( axis.search( 'Y' ) !== - 1 ) {
|
|
|
|
|
|
- }
|
|
|
+ object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
|
|
|
|
|
|
- this.dragging = true;
|
|
|
- mouseDownEvent.mode = this.mode;
|
|
|
- this.dispatchEvent( mouseDownEvent );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( axis.search( 'Z' ) !== - 1 ) {
|
|
|
|
|
|
- };
|
|
|
+ object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
|
|
|
|
|
|
- this.pointerMove = function ( pointer ) {
|
|
|
+ }
|
|
|
|
|
|
- var axis = this.axis;
|
|
|
- var mode = this.mode;
|
|
|
- var object = this.object;
|
|
|
- var space = this.space;
|
|
|
+ object.position.applyQuaternion( this._quaternionStart );
|
|
|
|
|
|
- if ( mode === 'scale' ) {
|
|
|
+ }
|
|
|
|
|
|
- space = 'local';
|
|
|
+ if ( space === 'world' ) {
|
|
|
|
|
|
- } else if ( axis === 'E' || axis === 'XYZE' || axis === 'XYZ' ) {
|
|
|
+ if ( object.parent ) {
|
|
|
|
|
|
- space = 'world';
|
|
|
+ object.position.add( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( object === undefined || axis === null || this.dragging === false || pointer.button !== - 1 ) return;
|
|
|
+ if ( axis.search( 'X' ) !== - 1 ) {
|
|
|
|
|
|
- raycaster.setFromCamera( pointer, this.camera );
|
|
|
+ object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
|
|
|
|
|
|
- var planeIntersect = intersectObjectWithRay( _plane, raycaster, true );
|
|
|
+ }
|
|
|
|
|
|
- if ( ! planeIntersect ) return;
|
|
|
+ if ( axis.search( 'Y' ) !== - 1 ) {
|
|
|
|
|
|
- pointEnd.copy( planeIntersect.point ).sub( worldPositionStart );
|
|
|
+ object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
|
|
|
|
|
|
- if ( mode === 'translate' ) {
|
|
|
+ }
|
|
|
|
|
|
- // Apply translate
|
|
|
+ if ( axis.search( 'Z' ) !== - 1 ) {
|
|
|
|
|
|
- offset.copy( pointEnd ).sub( pointStart );
|
|
|
+ object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
|
|
|
|
|
|
- if ( space === 'local' && axis !== 'XYZ' ) {
|
|
|
+ }
|
|
|
|
|
|
- offset.applyQuaternion( worldQuaternionInv );
|
|
|
+ if ( object.parent ) {
|
|
|
|
|
|
- }
|
|
|
+ object.position.sub( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
|
|
|
|
|
|
- if ( axis.indexOf( 'X' ) === - 1 ) offset.x = 0;
|
|
|
- if ( axis.indexOf( 'Y' ) === - 1 ) offset.y = 0;
|
|
|
- if ( axis.indexOf( 'Z' ) === - 1 ) offset.z = 0;
|
|
|
+ }
|
|
|
|
|
|
- if ( space === 'local' && axis !== 'XYZ' ) {
|
|
|
+ }
|
|
|
|
|
|
- offset.applyQuaternion( quaternionStart ).divide( parentScale );
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
+ } else if ( mode === 'scale' ) {
|
|
|
|
|
|
- offset.applyQuaternion( parentQuaternionInv ).divide( parentScale );
|
|
|
+ if ( axis.search( 'XYZ' ) !== - 1 ) {
|
|
|
|
|
|
- }
|
|
|
+ let d = this.pointEnd.length() / this.pointStart.length();
|
|
|
+ if ( this.pointEnd.dot( this.pointStart ) < 0 ) d *= - 1;
|
|
|
|
|
|
- object.position.copy( offset ).add( positionStart );
|
|
|
+ _tempVector2.set( d, d, d );
|
|
|
|
|
|
- // Apply translation snap
|
|
|
+ } else {
|
|
|
|
|
|
- if ( this.translationSnap ) {
|
|
|
+ _tempVector.copy( this.pointStart );
|
|
|
|
|
|
- if ( space === 'local' ) {
|
|
|
+ _tempVector2.copy( this.pointEnd );
|
|
|
|
|
|
- object.position.applyQuaternion( _tempQuaternion.copy( quaternionStart ).invert() );
|
|
|
+ _tempVector.applyQuaternion( this._worldQuaternionInv );
|
|
|
|
|
|
- if ( axis.search( 'X' ) !== - 1 ) {
|
|
|
+ _tempVector2.applyQuaternion( this._worldQuaternionInv );
|
|
|
|
|
|
- object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
|
|
|
+ _tempVector2.divide( _tempVector );
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- if ( axis.search( 'Y' ) !== - 1 ) {
|
|
|
+ if ( axis.search( 'X' ) === - 1 ) {
|
|
|
|
|
|
- object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
|
|
|
+ _tempVector2.x = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( axis.search( 'Z' ) !== - 1 ) {
|
|
|
+ if ( axis.search( 'Y' ) === - 1 ) {
|
|
|
|
|
|
- object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
|
|
|
+ _tempVector2.y = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
- object.position.applyQuaternion( quaternionStart );
|
|
|
+ if ( axis.search( 'Z' ) === - 1 ) {
|
|
|
|
|
|
- }
|
|
|
+ _tempVector2.z = 1;
|
|
|
|
|
|
- if ( space === 'world' ) {
|
|
|
+ }
|
|
|
|
|
|
- if ( object.parent ) {
|
|
|
+ } // Apply scale
|
|
|
|
|
|
- object.position.add( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
|
|
|
|
|
|
- }
|
|
|
+ object.scale.copy( this._scaleStart ).multiply( _tempVector2 );
|
|
|
+
|
|
|
+ if ( this.scaleSnap ) {
|
|
|
|
|
|
if ( axis.search( 'X' ) !== - 1 ) {
|
|
|
|
|
|
- object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
|
|
|
+ object.scale.x = Math.round( object.scale.x / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( axis.search( 'Y' ) !== - 1 ) {
|
|
|
|
|
|
- object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
|
|
|
+ object.scale.y = Math.round( object.scale.y / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( axis.search( 'Z' ) !== - 1 ) {
|
|
|
|
|
|
- object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
|
|
|
+ object.scale.z = Math.round( object.scale.z / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( object.parent ) {
|
|
|
+ }
|
|
|
|
|
|
- object.position.sub( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
|
|
|
+ } else if ( mode === 'rotate' ) {
|
|
|
|
|
|
- }
|
|
|
+ this._offset.copy( this.pointEnd ).sub( this.pointStart );
|
|
|
|
|
|
- }
|
|
|
+ const ROTATION_SPEED = 20 / this.worldPosition.distanceTo( _tempVector.setFromMatrixPosition( this.camera.matrixWorld ) );
|
|
|
|
|
|
- }
|
|
|
+ if ( axis === 'E' ) {
|
|
|
|
|
|
- } else if ( mode === 'scale' ) {
|
|
|
+ this.rotationAxis.copy( this.eye );
|
|
|
+ this.rotationAngle = this.pointEnd.angleTo( this.pointStart );
|
|
|
|
|
|
- if ( axis.search( 'XYZ' ) !== - 1 ) {
|
|
|
+ this._startNorm.copy( this.pointStart ).normalize();
|
|
|
|
|
|
- var d = pointEnd.length() / pointStart.length();
|
|
|
+ this._endNorm.copy( this.pointEnd ).normalize();
|
|
|
|
|
|
- if ( pointEnd.dot( pointStart ) < 0 ) d *= - 1;
|
|
|
+ this.rotationAngle *= this._endNorm.cross( this._startNorm ).dot( this.eye ) < 0 ? 1 : - 1;
|
|
|
|
|
|
- _tempVector2.set( d, d, d );
|
|
|
+ } else if ( axis === 'XYZE' ) {
|
|
|
|
|
|
- } else {
|
|
|
+ this.rotationAxis.copy( this._offset ).cross( this.eye ).normalize();
|
|
|
+ this.rotationAngle = this._offset.dot( _tempVector.copy( this.rotationAxis ).cross( this.eye ) ) * ROTATION_SPEED;
|
|
|
|
|
|
- _tempVector.copy( pointStart );
|
|
|
- _tempVector2.copy( pointEnd );
|
|
|
+ } else if ( axis === 'X' || axis === 'Y' || axis === 'Z' ) {
|
|
|
|
|
|
- _tempVector.applyQuaternion( worldQuaternionInv );
|
|
|
- _tempVector2.applyQuaternion( worldQuaternionInv );
|
|
|
+ this.rotationAxis.copy( _unit[ axis ] );
|
|
|
|
|
|
- _tempVector2.divide( _tempVector );
|
|
|
+ _tempVector.copy( _unit[ axis ] );
|
|
|
|
|
|
- if ( axis.search( 'X' ) === - 1 ) {
|
|
|
+ if ( space === 'local' ) {
|
|
|
|
|
|
- _tempVector2.x = 1;
|
|
|
+ _tempVector.applyQuaternion( this.worldQuaternion );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( axis.search( 'Y' ) === - 1 ) {
|
|
|
+ this.rotationAngle = this._offset.dot( _tempVector.cross( this.eye ).normalize() ) * ROTATION_SPEED;
|
|
|
|
|
|
- _tempVector2.y = 1;
|
|
|
+ } // Apply rotation snap
|
|
|
|
|
|
- }
|
|
|
|
|
|
- if ( axis.search( 'Z' ) === - 1 ) {
|
|
|
+ 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 {
|
|
|
|
|
|
- _tempVector2.z = 1;
|
|
|
+ this.rotationAxis.applyQuaternion( this._parentQuaternionInv );
|
|
|
+ object.quaternion.copy( _tempQuaternion.setFromAxisAngle( this.rotationAxis, this.rotationAngle ) );
|
|
|
+ object.quaternion.multiply( this._quaternionStart ).normalize();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- // Apply scale
|
|
|
+ this.dispatchEvent( _changeEvent );
|
|
|
+ this.dispatchEvent( _objectChangeEvent );
|
|
|
|
|
|
- object.scale.copy( scaleStart ).multiply( _tempVector2 );
|
|
|
+ }
|
|
|
|
|
|
- if ( this.scaleSnap ) {
|
|
|
+ pointerUp( pointer ) {
|
|
|
|
|
|
- if ( axis.search( 'X' ) !== - 1 ) {
|
|
|
+ if ( pointer.button !== 0 ) return;
|
|
|
|
|
|
- object.scale.x = Math.round( object.scale.x / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
|
|
|
+ if ( this.dragging && this.axis !== null ) {
|
|
|
|
|
|
- }
|
|
|
+ _mouseUpEvent.mode = this.mode;
|
|
|
+ this.dispatchEvent( _mouseUpEvent );
|
|
|
|
|
|
- if ( axis.search( 'Y' ) !== - 1 ) {
|
|
|
-
|
|
|
- object.scale.y = Math.round( object.scale.y / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ this.dragging = false;
|
|
|
+ this.axis = null;
|
|
|
|
|
|
- if ( axis.search( 'Z' ) !== - 1 ) {
|
|
|
+ }
|
|
|
|
|
|
- object.scale.z = Math.round( object.scale.z / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
|
|
|
+ dispose() {
|
|
|
|
|
|
- }
|
|
|
+ this.domElement.removeEventListener( 'pointerdown', this._onPointerDown );
|
|
|
+ this.domElement.removeEventListener( 'pointermove', this._onPointerHover );
|
|
|
+ this.domElement.ownerDocument.removeEventListener( 'pointermove', this._onPointerMove );
|
|
|
+ this.domElement.ownerDocument.removeEventListener( 'pointerup', this._onPointerUp );
|
|
|
+ this.traverse( function ( child ) {
|
|
|
|
|
|
- }
|
|
|
+ if ( child.geometry ) child.geometry.dispose();
|
|
|
+ if ( child.material ) child.material.dispose();
|
|
|
|
|
|
- } else if ( mode === 'rotate' ) {
|
|
|
+ } );
|
|
|
|
|
|
- offset.copy( pointEnd ).sub( pointStart );
|
|
|
+ } // Set current object
|
|
|
|
|
|
- var ROTATION_SPEED = 20 / worldPosition.distanceTo( _tempVector.setFromMatrixPosition( this.camera.matrixWorld ) );
|
|
|
|
|
|
- if ( axis === 'E' ) {
|
|
|
+ attach( object ) {
|
|
|
|
|
|
- rotationAxis.copy( eye );
|
|
|
- rotationAngle = pointEnd.angleTo( pointStart );
|
|
|
+ this.object = object;
|
|
|
+ this.visible = true;
|
|
|
+ return this;
|
|
|
|
|
|
- startNorm.copy( pointStart ).normalize();
|
|
|
- endNorm.copy( pointEnd ).normalize();
|
|
|
+ } // Detatch from object
|
|
|
|
|
|
- rotationAngle *= ( endNorm.cross( startNorm ).dot( eye ) < 0 ? 1 : - 1 );
|
|
|
|
|
|
- } else if ( axis === 'XYZE' ) {
|
|
|
+ detach() {
|
|
|
|
|
|
- rotationAxis.copy( offset ).cross( eye ).normalize();
|
|
|
- rotationAngle = offset.dot( _tempVector.copy( rotationAxis ).cross( this.eye ) ) * ROTATION_SPEED;
|
|
|
+ this.object = undefined;
|
|
|
+ this.visible = false;
|
|
|
+ this.axis = null;
|
|
|
+ return this;
|
|
|
|
|
|
- } else if ( axis === 'X' || axis === 'Y' || axis === 'Z' ) {
|
|
|
+ } // TODO: deprecate
|
|
|
|
|
|
- rotationAxis.copy( _unit[ axis ] );
|
|
|
|
|
|
- _tempVector.copy( _unit[ axis ] );
|
|
|
+ getMode() {
|
|
|
|
|
|
- if ( space === 'local' ) {
|
|
|
+ return this.mode;
|
|
|
|
|
|
- _tempVector.applyQuaternion( worldQuaternion );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ setMode( mode ) {
|
|
|
|
|
|
- rotationAngle = offset.dot( _tempVector.cross( eye ).normalize() ) * ROTATION_SPEED;
|
|
|
+ this.mode = mode;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- // Apply rotation snap
|
|
|
+ setTranslationSnap( translationSnap ) {
|
|
|
|
|
|
- if ( this.rotationSnap ) rotationAngle = Math.round( rotationAngle / this.rotationSnap ) * this.rotationSnap;
|
|
|
+ this.translationSnap = translationSnap;
|
|
|
|
|
|
- this.rotationAngle = rotationAngle;
|
|
|
+ }
|
|
|
|
|
|
- // Apply rotate
|
|
|
- if ( space === 'local' && axis !== 'E' && axis !== 'XYZE' ) {
|
|
|
+ setRotationSnap( rotationSnap ) {
|
|
|
|
|
|
- object.quaternion.copy( quaternionStart );
|
|
|
- object.quaternion.multiply( _tempQuaternion.setFromAxisAngle( rotationAxis, rotationAngle ) ).normalize();
|
|
|
+ this.rotationSnap = rotationSnap;
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
|
|
|
- rotationAxis.applyQuaternion( parentQuaternionInv );
|
|
|
- object.quaternion.copy( _tempQuaternion.setFromAxisAngle( rotationAxis, rotationAngle ) );
|
|
|
- object.quaternion.multiply( quaternionStart ).normalize();
|
|
|
+ setScaleSnap( scaleSnap ) {
|
|
|
|
|
|
- }
|
|
|
+ this.scaleSnap = scaleSnap;
|
|
|
|
|
|
}
|
|
|
|
|
|
- this.dispatchEvent( changeEvent );
|
|
|
- this.dispatchEvent( objectChangeEvent );
|
|
|
+ setSize( size ) {
|
|
|
|
|
|
- };
|
|
|
-
|
|
|
- this.pointerUp = function ( pointer ) {
|
|
|
+ this.size = size;
|
|
|
|
|
|
- if ( pointer.button !== 0 ) return;
|
|
|
+ }
|
|
|
|
|
|
- if ( this.dragging && ( this.axis !== null ) ) {
|
|
|
+ setSpace( space ) {
|
|
|
|
|
|
- mouseUpEvent.mode = this.mode;
|
|
|
- this.dispatchEvent( mouseUpEvent );
|
|
|
+ this.space = space;
|
|
|
|
|
|
}
|
|
|
|
|
|
- this.dragging = false;
|
|
|
- this.axis = null;
|
|
|
+ update() {
|
|
|
|
|
|
- };
|
|
|
+ console.warn( 'THREE.TransformControls: update function has no more functionality and therefore has been deprecated.' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- // normalize mouse / touch pointer and remap {x,y} to view space.
|
|
|
+ TransformControls.prototype.isTransformControls = true; // mouse / touch event handlers
|
|
|
|
|
|
function getPointer( event ) {
|
|
|
|
|
|
- if ( scope.domElement.ownerDocument.pointerLockElement ) {
|
|
|
+ if ( this.domElement.ownerDocument.pointerLockElement ) {
|
|
|
|
|
|
return {
|
|
|
x: 0,
|
|
|
@@ -591,10 +617,8 @@ THREE.TransformControls = function ( camera, domElement ) {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
|
|
|
-
|
|
|
- var rect = domElement.getBoundingClientRect();
|
|
|
-
|
|
|
+ const pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
|
|
|
+ const rect = this.domElement.getBoundingClientRect();
|
|
|
return {
|
|
|
x: ( pointer.clientX - rect.left ) / rect.width * 2 - 1,
|
|
|
y: - ( pointer.clientY - rect.top ) / rect.height * 2 + 1,
|
|
|
@@ -605,17 +629,15 @@ THREE.TransformControls = function ( camera, domElement ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // mouse / touch event handlers
|
|
|
-
|
|
|
function onPointerHover( event ) {
|
|
|
|
|
|
- if ( ! scope.enabled ) return;
|
|
|
+ if ( ! this.enabled ) return;
|
|
|
|
|
|
switch ( event.pointerType ) {
|
|
|
|
|
|
case 'mouse':
|
|
|
case 'pen':
|
|
|
- scope.pointerHover( getPointer( event ) );
|
|
|
+ this.pointerHover( this._getPointer( event ) );
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
@@ -624,1040 +646,826 @@ THREE.TransformControls = function ( camera, domElement ) {
|
|
|
|
|
|
function onPointerDown( event ) {
|
|
|
|
|
|
- if ( ! scope.enabled ) return;
|
|
|
-
|
|
|
- scope.domElement.style.touchAction = 'none'; // disable touch scroll
|
|
|
- scope.domElement.ownerDocument.addEventListener( 'pointermove', onPointerMove );
|
|
|
+ if ( ! this.enabled ) return;
|
|
|
+ this.domElement.style.touchAction = 'none'; // disable touch scroll
|
|
|
|
|
|
- scope.pointerHover( getPointer( event ) );
|
|
|
- scope.pointerDown( getPointer( event ) );
|
|
|
+ this.domElement.ownerDocument.addEventListener( 'pointermove', this._onPointerMove );
|
|
|
+ this.pointerHover( this._getPointer( event ) );
|
|
|
+ this.pointerDown( this._getPointer( event ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
function onPointerMove( event ) {
|
|
|
|
|
|
- if ( ! scope.enabled ) return;
|
|
|
-
|
|
|
- scope.pointerMove( getPointer( event ) );
|
|
|
+ if ( ! this.enabled ) return;
|
|
|
+ this.pointerMove( this._getPointer( event ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
function onPointerUp( event ) {
|
|
|
|
|
|
- if ( ! scope.enabled ) return;
|
|
|
-
|
|
|
- scope.domElement.style.touchAction = '';
|
|
|
- scope.domElement.ownerDocument.removeEventListener( 'pointermove', onPointerMove );
|
|
|
-
|
|
|
- scope.pointerUp( getPointer( event ) );
|
|
|
+ if ( ! this.enabled ) return;
|
|
|
+ this.domElement.style.touchAction = '';
|
|
|
+ this.domElement.ownerDocument.removeEventListener( 'pointermove', this._onPointerMove );
|
|
|
+ this.pointerUp( this._getPointer( event ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
- // TODO: deprecate
|
|
|
-
|
|
|
- this.getMode = function () {
|
|
|
-
|
|
|
- return scope.mode;
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- this.setMode = function ( mode ) {
|
|
|
+ function intersectObjectWithRay( object, raycaster, includeInvisible ) {
|
|
|
|
|
|
- scope.mode = mode;
|
|
|
+ const allIntersections = raycaster.intersectObject( object, true );
|
|
|
|
|
|
- };
|
|
|
+ for ( let i = 0; i < allIntersections.length; i ++ ) {
|
|
|
|
|
|
- this.setTranslationSnap = function ( translationSnap ) {
|
|
|
+ if ( allIntersections[ i ].object.visible || includeInvisible ) {
|
|
|
|
|
|
- scope.translationSnap = translationSnap;
|
|
|
+ return allIntersections[ i ];
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- this.setRotationSnap = function ( rotationSnap ) {
|
|
|
+ }
|
|
|
|
|
|
- scope.rotationSnap = rotationSnap;
|
|
|
+ return false;
|
|
|
|
|
|
- };
|
|
|
+ } //
|
|
|
+ // Reusable utility variables
|
|
|
|
|
|
- this.setScaleSnap = function ( scaleSnap ) {
|
|
|
|
|
|
- scope.scaleSnap = scaleSnap;
|
|
|
+ const _tempEuler = new THREE.Euler();
|
|
|
+
|
|
|
+ const _alignVector = new THREE.Vector3( 0, 1, 0 );
|
|
|
|
|
|
- };
|
|
|
+ const _zeroVector = new THREE.Vector3( 0, 0, 0 );
|
|
|
|
|
|
- this.setSize = function ( size ) {
|
|
|
+ const _lookAtMatrix = new THREE.Matrix4();
|
|
|
|
|
|
- scope.size = size;
|
|
|
+ const _tempQuaternion2 = new THREE.Quaternion();
|
|
|
|
|
|
- };
|
|
|
+ const _identityQuaternion = new THREE.Quaternion();
|
|
|
|
|
|
- this.setSpace = function ( space ) {
|
|
|
+ const _dirVector = new THREE.Vector3();
|
|
|
|
|
|
- scope.space = space;
|
|
|
+ const _tempMatrix = new THREE.Matrix4();
|
|
|
|
|
|
- };
|
|
|
+ const _unitX = new THREE.Vector3( 1, 0, 0 );
|
|
|
|
|
|
- this.update = function () {
|
|
|
+ const _unitY = new THREE.Vector3( 0, 1, 0 );
|
|
|
|
|
|
- console.warn( 'THREE.TransformControls: update function has no more functionality and therefore has been deprecated.' );
|
|
|
+ const _unitZ = new THREE.Vector3( 0, 0, 1 );
|
|
|
|
|
|
- };
|
|
|
+ const _v1 = new THREE.Vector3();
|
|
|
|
|
|
-};
|
|
|
+ const _v2 = new THREE.Vector3();
|
|
|
|
|
|
-THREE.TransformControls.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
|
|
|
+ const _v3 = new THREE.Vector3();
|
|
|
|
|
|
- constructor: THREE.TransformControls,
|
|
|
+ class TransformControlsGizmo extends THREE.Object3D {
|
|
|
|
|
|
- isTransformControls: true
|
|
|
+ constructor() {
|
|
|
|
|
|
-} );
|
|
|
+ super();
|
|
|
+ this.type = 'TransformControlsGizmo'; // shared materials
|
|
|
|
|
|
+ const gizmoMaterial = new THREE.MeshBasicMaterial( {
|
|
|
+ depthTest: false,
|
|
|
+ depthWrite: false,
|
|
|
+ transparent: true,
|
|
|
+ side: THREE.DoubleSide,
|
|
|
+ fog: false,
|
|
|
+ toneMapped: false
|
|
|
+ } );
|
|
|
+ const gizmoLineMaterial = new THREE.LineBasicMaterial( {
|
|
|
+ depthTest: false,
|
|
|
+ depthWrite: false,
|
|
|
+ transparent: true,
|
|
|
+ linewidth: 1,
|
|
|
+ fog: false,
|
|
|
+ toneMapped: false
|
|
|
+ } ); // Make unique material for each axis/color
|
|
|
|
|
|
-THREE.TransformControlsGizmo = function () {
|
|
|
+ const matInvisible = gizmoMaterial.clone();
|
|
|
+ matInvisible.opacity = 0.15;
|
|
|
+ const matHelper = gizmoMaterial.clone();
|
|
|
+ matHelper.opacity = 0.33;
|
|
|
+ const matRed = gizmoMaterial.clone();
|
|
|
+ matRed.color.set( 0xff0000 );
|
|
|
+ const matGreen = gizmoMaterial.clone();
|
|
|
+ matGreen.color.set( 0x00ff00 );
|
|
|
+ const matBlue = gizmoMaterial.clone();
|
|
|
+ matBlue.color.set( 0x0000ff );
|
|
|
+ const matWhiteTransparent = gizmoMaterial.clone();
|
|
|
+ matWhiteTransparent.opacity = 0.25;
|
|
|
+ const matYellowTransparent = matWhiteTransparent.clone();
|
|
|
+ matYellowTransparent.color.set( 0xffff00 );
|
|
|
+ const matCyanTransparent = matWhiteTransparent.clone();
|
|
|
+ matCyanTransparent.color.set( 0x00ffff );
|
|
|
+ const matMagentaTransparent = matWhiteTransparent.clone();
|
|
|
+ matMagentaTransparent.color.set( 0xff00ff );
|
|
|
+ const matYellow = gizmoMaterial.clone();
|
|
|
+ matYellow.color.set( 0xffff00 );
|
|
|
+ const matLineRed = gizmoLineMaterial.clone();
|
|
|
+ matLineRed.color.set( 0xff0000 );
|
|
|
+ const matLineGreen = gizmoLineMaterial.clone();
|
|
|
+ matLineGreen.color.set( 0x00ff00 );
|
|
|
+ const matLineBlue = gizmoLineMaterial.clone();
|
|
|
+ matLineBlue.color.set( 0x0000ff );
|
|
|
+ const matLineCyan = gizmoLineMaterial.clone();
|
|
|
+ matLineCyan.color.set( 0x00ffff );
|
|
|
+ const matLineMagenta = gizmoLineMaterial.clone();
|
|
|
+ matLineMagenta.color.set( 0xff00ff );
|
|
|
+ const matLineYellow = gizmoLineMaterial.clone();
|
|
|
+ matLineYellow.color.set( 0xffff00 );
|
|
|
+ const matLineGray = gizmoLineMaterial.clone();
|
|
|
+ matLineGray.color.set( 0x787878 );
|
|
|
+ const matLineYellowTransparent = matLineYellow.clone();
|
|
|
+ matLineYellowTransparent.opacity = 0.25; // reusable geometry
|
|
|
|
|
|
- 'use strict';
|
|
|
+ const arrowGeometry = new THREE.CylinderGeometry( 0, 0.05, 0.2, 12, 1, false );
|
|
|
+ const scaleHandleGeometry = new THREE.BoxGeometry( 0.125, 0.125, 0.125 );
|
|
|
+ const lineGeometry = new THREE.BufferGeometry();
|
|
|
+ lineGeometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) );
|
|
|
|
|
|
- THREE.Object3D.call( this );
|
|
|
+ function CircleGeometry( radius, arc ) {
|
|
|
|
|
|
- this.type = 'TransformControlsGizmo';
|
|
|
+ const geometry = new THREE.BufferGeometry();
|
|
|
+ const vertices = [];
|
|
|
|
|
|
- // shared materials
|
|
|
+ for ( let i = 0; i <= 64 * arc; ++ i ) {
|
|
|
+
|
|
|
+ vertices.push( 0, Math.cos( i / 32 * Math.PI ) * radius, Math.sin( i / 32 * Math.PI ) * radius );
|
|
|
|
|
|
- var gizmoMaterial = new THREE.MeshBasicMaterial( {
|
|
|
- depthTest: false,
|
|
|
- depthWrite: false,
|
|
|
- transparent: true,
|
|
|
- side: THREE.DoubleSide,
|
|
|
- fog: false,
|
|
|
- toneMapped: false
|
|
|
- } );
|
|
|
+ }
|
|
|
|
|
|
- var gizmoLineMaterial = new THREE.LineBasicMaterial( {
|
|
|
- depthTest: false,
|
|
|
- depthWrite: false,
|
|
|
- transparent: true,
|
|
|
- linewidth: 1,
|
|
|
- fog: false,
|
|
|
- toneMapped: false
|
|
|
- } );
|
|
|
+ geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
|
|
|
+ return geometry;
|
|
|
|
|
|
- // Make unique material for each axis/color
|
|
|
+ } // Special geometry for transform helper. If scaled with position vector it spans from [0,0,0] to position
|
|
|
|
|
|
- var matInvisible = gizmoMaterial.clone();
|
|
|
- matInvisible.opacity = 0.15;
|
|
|
|
|
|
- var matHelper = gizmoMaterial.clone();
|
|
|
- matHelper.opacity = 0.33;
|
|
|
+ function TranslateHelperGeometry() {
|
|
|
|
|
|
- var matRed = gizmoMaterial.clone();
|
|
|
- matRed.color.set( 0xff0000 );
|
|
|
+ const geometry = new THREE.BufferGeometry();
|
|
|
+ geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 1, 1 ], 3 ) );
|
|
|
+ return geometry;
|
|
|
|
|
|
- var matGreen = gizmoMaterial.clone();
|
|
|
- matGreen.color.set( 0x00ff00 );
|
|
|
+ } // Gizmo definitions - custom hierarchy definitions for setupGizmo() function
|
|
|
|
|
|
- var matBlue = gizmoMaterial.clone();
|
|
|
- matBlue.color.set( 0x0000ff );
|
|
|
|
|
|
- var matWhiteTransparent = gizmoMaterial.clone();
|
|
|
- matWhiteTransparent.opacity = 0.25;
|
|
|
+ const gizmoTranslate = {
|
|
|
+ X: [[ new THREE.Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, - Math.PI / 2 ], null, 'fwd' ], [ new THREE.Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, Math.PI / 2 ], null, 'bwd' ], [ new THREE.Line( lineGeometry, matLineRed ) ]],
|
|
|
+ Y: [[ new THREE.Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], null, null, 'fwd' ], [ new THREE.Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], [ Math.PI, 0, 0 ], null, 'bwd' ], [ new THREE.Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ]]],
|
|
|
+ Z: [[ new THREE.Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ Math.PI / 2, 0, 0 ], null, 'fwd' ], [ new THREE.Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ - Math.PI / 2, 0, 0 ], null, 'bwd' ], [ new THREE.Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ]]],
|
|
|
+ XYZ: [[ new THREE.Mesh( new THREE.OctahedronGeometry( 0.1, 0 ), matWhiteTransparent.clone() ), [ 0, 0, 0 ], [ 0, 0, 0 ]]],
|
|
|
+ XY: [[ new THREE.Mesh( new THREE.PlaneGeometry( 0.295, 0.295 ), matYellowTransparent.clone() ), [ 0.15, 0.15, 0 ]], [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.18, 0.3, 0 ], null, [ 0.125, 1, 1 ]], [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.3, 0.18, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]],
|
|
|
+ YZ: [[ new THREE.Mesh( new THREE.PlaneGeometry( 0.295, 0.295 ), matCyanTransparent.clone() ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ]], [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.18, 0.3 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]], [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.3, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]],
|
|
|
+ XZ: [[ new THREE.Mesh( new THREE.PlaneGeometry( 0.295, 0.295 ), matMagentaTransparent.clone() ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ]], [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.18, 0, 0.3 ], null, [ 0.125, 1, 1 ]], [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.3, 0, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]]
|
|
|
+ };
|
|
|
+ const pickerTranslate = {
|
|
|
+ X: [[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]],
|
|
|
+ Y: [[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0.6, 0 ]]],
|
|
|
+ Z: [[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ]]],
|
|
|
+ XYZ: [[ new THREE.Mesh( new THREE.OctahedronGeometry( 0.2, 0 ), matInvisible ) ]],
|
|
|
+ XY: [[ new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0.2, 0 ]]],
|
|
|
+ YZ: [[ new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), matInvisible ), [ 0, 0.2, 0.2 ], [ 0, Math.PI / 2, 0 ]]],
|
|
|
+ XZ: [[ new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0, 0.2 ], [ - Math.PI / 2, 0, 0 ]]]
|
|
|
+ };
|
|
|
+ const 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' ]]
|
|
|
+ };
|
|
|
+ const gizmoRotate = {
|
|
|
+ X: [[ new THREE.Line( CircleGeometry( 1, 0.5 ), matLineRed ) ], [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.04, 0 ), matRed ), [ 0, 0, 0.99 ], null, [ 1, 3, 1 ]]],
|
|
|
+ Y: [[ new THREE.Line( CircleGeometry( 1, 0.5 ), matLineGreen ), null, [ 0, 0, - Math.PI / 2 ]], [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.04, 0 ), matGreen ), [ 0, 0, 0.99 ], null, [ 3, 1, 1 ]]],
|
|
|
+ Z: [[ new THREE.Line( CircleGeometry( 1, 0.5 ), matLineBlue ), null, [ 0, Math.PI / 2, 0 ]], [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.04, 0 ), matBlue ), [ 0.99, 0, 0 ], null, [ 1, 3, 1 ]]],
|
|
|
+ E: [[ new THREE.Line( CircleGeometry( 1.25, 1 ), matLineYellowTransparent ), null, [ 0, Math.PI / 2, 0 ]], [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 1.17, 0, 0 ], [ 0, 0, - Math.PI / 2 ], [ 1, 1, 0.001 ]], [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ - 1.17, 0, 0 ], [ 0, 0, Math.PI / 2 ], [ 1, 1, 0.001 ]], [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, - 1.17, 0 ], [ Math.PI, 0, 0 ], [ 1, 1, 0.001 ]], [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, 1.17, 0 ], [ 0, 0, 0 ], [ 1, 1, 0.001 ]]],
|
|
|
+ XYZE: [[ new THREE.Line( CircleGeometry( 1, 1 ), matLineGray ), null, [ 0, Math.PI / 2, 0 ]]]
|
|
|
+ };
|
|
|
+ const helperRotate = {
|
|
|
+ AXIS: [[ new THREE.Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]]
|
|
|
+ };
|
|
|
+ const pickerRotate = {
|
|
|
+ X: [[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ]]],
|
|
|
+ Y: [[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ]]],
|
|
|
+ Z: [[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]],
|
|
|
+ E: [[ new THREE.Mesh( new THREE.TorusGeometry( 1.25, 0.1, 2, 24 ), matInvisible ) ]],
|
|
|
+ XYZE: [[ new THREE.Mesh( new THREE.SphereGeometry( 0.7, 10, 8 ), matInvisible ) ]]
|
|
|
+ };
|
|
|
+ const gizmoScale = {
|
|
|
+ X: [[ new THREE.Mesh( scaleHandleGeometry, matRed ), [ 0.8, 0, 0 ], [ 0, 0, - Math.PI / 2 ]], [ new THREE.Line( lineGeometry, matLineRed ), null, null, [ 0.8, 1, 1 ]]],
|
|
|
+ Y: [[ new THREE.Mesh( scaleHandleGeometry, matGreen ), [ 0, 0.8, 0 ]], [ new THREE.Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ], [ 0.8, 1, 1 ]]],
|
|
|
+ Z: [[ new THREE.Mesh( scaleHandleGeometry, matBlue ), [ 0, 0, 0.8 ], [ Math.PI / 2, 0, 0 ]], [ new THREE.Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ], [ 0.8, 1, 1 ]]],
|
|
|
+ XY: [[ new THREE.Mesh( scaleHandleGeometry, matYellowTransparent ), [ 0.85, 0.85, 0 ], null, [ 2, 2, 0.2 ]], [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.855, 0.98, 0 ], null, [ 0.125, 1, 1 ]], [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.98, 0.855, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]],
|
|
|
+ YZ: [[ new THREE.Mesh( scaleHandleGeometry, matCyanTransparent ), [ 0, 0.85, 0.85 ], null, [ 0.2, 2, 2 ]], [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.855, 0.98 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]], [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.98, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]],
|
|
|
+ XZ: [[ new THREE.Mesh( scaleHandleGeometry, matMagentaTransparent ), [ 0.85, 0, 0.85 ], null, [ 2, 0.2, 2 ]], [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.855, 0, 0.98 ], null, [ 0.125, 1, 1 ]], [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.98, 0, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]],
|
|
|
+ XYZX: [[ new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 1.1, 0, 0 ]]],
|
|
|
+ XYZY: [[ new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 1.1, 0 ]]],
|
|
|
+ XYZZ: [[ new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 0, 1.1 ]]]
|
|
|
+ };
|
|
|
+ const pickerScale = {
|
|
|
+ X: [[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]],
|
|
|
+ Y: [[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0.5, 0 ]]],
|
|
|
+ Z: [[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ]]],
|
|
|
+ XY: [[ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0.85, 0 ], null, [ 3, 3, 0.2 ]]],
|
|
|
+ YZ: [[ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0, 0.85, 0.85 ], null, [ 0.2, 3, 3 ]]],
|
|
|
+ XZ: [[ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0, 0.85 ], null, [ 3, 0.2, 3 ]]],
|
|
|
+ XYZX: [[ new THREE.Mesh( new THREE.BoxGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 1.1, 0, 0 ]]],
|
|
|
+ XYZY: [[ new THREE.Mesh( new THREE.BoxGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 1.1, 0 ]]],
|
|
|
+ XYZZ: [[ new THREE.Mesh( new THREE.BoxGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 0, 1.1 ]]]
|
|
|
+ };
|
|
|
+ const 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 THREE.Object3D with gizmos described in custom hierarchy definition.
|
|
|
|
|
|
- var matYellowTransparent = matWhiteTransparent.clone();
|
|
|
- matYellowTransparent.color.set( 0xffff00 );
|
|
|
+ function setupGizmo( gizmoMap ) {
|
|
|
|
|
|
- var matCyanTransparent = matWhiteTransparent.clone();
|
|
|
- matCyanTransparent.color.set( 0x00ffff );
|
|
|
+ const gizmo = new THREE.Object3D();
|
|
|
|
|
|
- var matMagentaTransparent = matWhiteTransparent.clone();
|
|
|
- matMagentaTransparent.color.set( 0xff00ff );
|
|
|
+ for ( const name in gizmoMap ) {
|
|
|
|
|
|
- var matYellow = gizmoMaterial.clone();
|
|
|
- matYellow.color.set( 0xffff00 );
|
|
|
+ for ( let i = gizmoMap[ name ].length; i --; ) {
|
|
|
|
|
|
- var matLineRed = gizmoLineMaterial.clone();
|
|
|
- matLineRed.color.set( 0xff0000 );
|
|
|
+ const object = gizmoMap[ name ][ i ][ 0 ].clone();
|
|
|
+ const position = gizmoMap[ name ][ i ][ 1 ];
|
|
|
+ const rotation = gizmoMap[ name ][ i ][ 2 ];
|
|
|
+ const scale = gizmoMap[ name ][ i ][ 3 ];
|
|
|
+ const tag = gizmoMap[ name ][ i ][ 4 ]; // name and tag properties are essential for picking and updating logic.
|
|
|
|
|
|
- var matLineGreen = gizmoLineMaterial.clone();
|
|
|
- matLineGreen.color.set( 0x00ff00 );
|
|
|
+ object.name = name;
|
|
|
+ object.tag = tag;
|
|
|
|
|
|
- var matLineBlue = gizmoLineMaterial.clone();
|
|
|
- matLineBlue.color.set( 0x0000ff );
|
|
|
+ if ( position ) {
|
|
|
|
|
|
- var matLineCyan = gizmoLineMaterial.clone();
|
|
|
- matLineCyan.color.set( 0x00ffff );
|
|
|
+ object.position.set( position[ 0 ], position[ 1 ], position[ 2 ] );
|
|
|
|
|
|
- var matLineMagenta = gizmoLineMaterial.clone();
|
|
|
- matLineMagenta.color.set( 0xff00ff );
|
|
|
+ }
|
|
|
|
|
|
- var matLineYellow = gizmoLineMaterial.clone();
|
|
|
- matLineYellow.color.set( 0xffff00 );
|
|
|
+ if ( rotation ) {
|
|
|
|
|
|
- var matLineGray = gizmoLineMaterial.clone();
|
|
|
- matLineGray.color.set( 0x787878 );
|
|
|
+ object.rotation.set( rotation[ 0 ], rotation[ 1 ], rotation[ 2 ] );
|
|
|
|
|
|
- var matLineYellowTransparent = matLineYellow.clone();
|
|
|
- matLineYellowTransparent.opacity = 0.25;
|
|
|
+ }
|
|
|
|
|
|
- // reusable geometry
|
|
|
+ if ( scale ) {
|
|
|
|
|
|
- var arrowGeometry = new THREE.CylinderGeometry( 0, 0.05, 0.2, 12, 1, false );
|
|
|
+ object.scale.set( scale[ 0 ], scale[ 1 ], scale[ 2 ] );
|
|
|
|
|
|
- var scaleHandleGeometry = new THREE.BoxGeometry( 0.125, 0.125, 0.125 );
|
|
|
+ }
|
|
|
|
|
|
- var lineGeometry = new THREE.BufferGeometry();
|
|
|
- lineGeometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) );
|
|
|
+ object.updateMatrix();
|
|
|
+ const 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 );
|
|
|
|
|
|
- var CircleGeometry = function ( radius, arc ) {
|
|
|
+ }
|
|
|
|
|
|
- var geometry = new THREE.BufferGeometry( );
|
|
|
- var vertices = [];
|
|
|
+ }
|
|
|
|
|
|
- for ( var i = 0; i <= 64 * arc; ++ i ) {
|
|
|
+ return gizmo;
|
|
|
|
|
|
- vertices.push( 0, Math.cos( i / 32 * Math.PI ) * radius, Math.sin( i / 32 * Math.PI ) * radius );
|
|
|
+ } // Gizmo creation
|
|
|
|
|
|
- }
|
|
|
|
|
|
- geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
|
|
|
+ this.gizmo = {};
|
|
|
+ this.picker = {};
|
|
|
+ this.helper = {};
|
|
|
+ this.add( this.gizmo[ 'translate' ] = setupGizmo( gizmoTranslate ) );
|
|
|
+ this.add( this.gizmo[ 'rotate' ] = setupGizmo( gizmoRotate ) );
|
|
|
+ this.add( this.gizmo[ 'scale' ] = setupGizmo( gizmoScale ) );
|
|
|
+ this.add( this.picker[ 'translate' ] = setupGizmo( pickerTranslate ) );
|
|
|
+ this.add( this.picker[ 'rotate' ] = setupGizmo( pickerRotate ) );
|
|
|
+ this.add( this.picker[ 'scale' ] = setupGizmo( pickerScale ) );
|
|
|
+ this.add( this.helper[ 'translate' ] = setupGizmo( helperTranslate ) );
|
|
|
+ this.add( this.helper[ 'rotate' ] = setupGizmo( helperRotate ) );
|
|
|
+ this.add( this.helper[ 'scale' ] = setupGizmo( helperScale ) ); // Pickers should be hidden always
|
|
|
|
|
|
- return geometry;
|
|
|
+ this.picker[ 'translate' ].visible = false;
|
|
|
+ this.picker[ 'rotate' ].visible = false;
|
|
|
+ this.picker[ 'scale' ].visible = false;
|
|
|
|
|
|
- };
|
|
|
+ } // updateMatrixWorld will update transformations and appearance of individual handles
|
|
|
|
|
|
- // Special geometry for transform helper. If scaled with position vector it spans from [0,0,0] to position
|
|
|
|
|
|
- var TranslateHelperGeometry = function () {
|
|
|
+ updateMatrixWorld( force ) {
|
|
|
|
|
|
- var geometry = new THREE.BufferGeometry();
|
|
|
+ const space = this.mode === 'scale' ? this.space : 'local'; // scale always oriented to local rotation
|
|
|
|
|
|
- geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 1, 1 ], 3 ) );
|
|
|
+ const quaternion = space === 'local' ? this.worldQuaternion : _identityQuaternion; // Show only gizmos for current transform mode
|
|
|
|
|
|
- return geometry;
|
|
|
+ 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';
|
|
|
+ let 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 );
|
|
|
|
|
|
- };
|
|
|
+ for ( let i = 0; i < handles.length; i ++ ) {
|
|
|
|
|
|
- // Gizmo definitions - custom hierarchy definitions for setupGizmo() function
|
|
|
-
|
|
|
- var gizmoTranslate = {
|
|
|
- X: [
|
|
|
- [ new THREE.Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, - Math.PI / 2 ], null, 'fwd' ],
|
|
|
- [ new THREE.Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, Math.PI / 2 ], null, 'bwd' ],
|
|
|
- [ new THREE.Line( lineGeometry, matLineRed ) ]
|
|
|
- ],
|
|
|
- Y: [
|
|
|
- [ new THREE.Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], null, null, 'fwd' ],
|
|
|
- [ new THREE.Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], [ Math.PI, 0, 0 ], null, 'bwd' ],
|
|
|
- [ new THREE.Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ]]
|
|
|
- ],
|
|
|
- Z: [
|
|
|
- [ new THREE.Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ Math.PI / 2, 0, 0 ], null, 'fwd' ],
|
|
|
- [ new THREE.Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ - Math.PI / 2, 0, 0 ], null, 'bwd' ],
|
|
|
- [ new THREE.Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ]]
|
|
|
- ],
|
|
|
- XYZ: [
|
|
|
- [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.1, 0 ), matWhiteTransparent.clone() ), [ 0, 0, 0 ], [ 0, 0, 0 ]]
|
|
|
- ],
|
|
|
- XY: [
|
|
|
- [ new THREE.Mesh( new THREE.PlaneGeometry( 0.295, 0.295 ), matYellowTransparent.clone() ), [ 0.15, 0.15, 0 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.18, 0.3, 0 ], null, [ 0.125, 1, 1 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.3, 0.18, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]
|
|
|
- ],
|
|
|
- YZ: [
|
|
|
- [ new THREE.Mesh( new THREE.PlaneGeometry( 0.295, 0.295 ), matCyanTransparent.clone() ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.18, 0.3 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.3, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
|
|
|
- ],
|
|
|
- XZ: [
|
|
|
- [ new THREE.Mesh( new THREE.PlaneGeometry( 0.295, 0.295 ), matMagentaTransparent.clone() ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.18, 0, 0.3 ], null, [ 0.125, 1, 1 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.3, 0, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
|
|
|
- ]
|
|
|
- };
|
|
|
+ const handle = handles[ i ]; // hide aligned to camera
|
|
|
|
|
|
- var pickerTranslate = {
|
|
|
- X: [
|
|
|
- [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]
|
|
|
- ],
|
|
|
- Y: [
|
|
|
- [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0.6, 0 ]]
|
|
|
- ],
|
|
|
- Z: [
|
|
|
- [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ]]
|
|
|
- ],
|
|
|
- XYZ: [
|
|
|
- [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.2, 0 ), matInvisible ) ]
|
|
|
- ],
|
|
|
- XY: [
|
|
|
- [ new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0.2, 0 ]]
|
|
|
- ],
|
|
|
- YZ: [
|
|
|
- [ new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), matInvisible ), [ 0, 0.2, 0.2 ], [ 0, Math.PI / 2, 0 ]]
|
|
|
- ],
|
|
|
- XZ: [
|
|
|
- [ new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0, 0.2 ], [ - Math.PI / 2, 0, 0 ]]
|
|
|
- ]
|
|
|
- };
|
|
|
+ handle.visible = true;
|
|
|
+ handle.rotation.set( 0, 0, 0 );
|
|
|
+ handle.position.copy( this.worldPosition );
|
|
|
+ let factor;
|
|
|
|
|
|
- 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' ]
|
|
|
- ]
|
|
|
- };
|
|
|
+ if ( this.camera.isOrthographicCamera ) {
|
|
|
|
|
|
- var gizmoRotate = {
|
|
|
- X: [
|
|
|
- [ new THREE.Line( CircleGeometry( 1, 0.5 ), matLineRed ) ],
|
|
|
- [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.04, 0 ), matRed ), [ 0, 0, 0.99 ], null, [ 1, 3, 1 ]],
|
|
|
- ],
|
|
|
- Y: [
|
|
|
- [ new THREE.Line( CircleGeometry( 1, 0.5 ), matLineGreen ), null, [ 0, 0, - Math.PI / 2 ]],
|
|
|
- [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.04, 0 ), matGreen ), [ 0, 0, 0.99 ], null, [ 3, 1, 1 ]],
|
|
|
- ],
|
|
|
- Z: [
|
|
|
- [ new THREE.Line( CircleGeometry( 1, 0.5 ), matLineBlue ), null, [ 0, Math.PI / 2, 0 ]],
|
|
|
- [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.04, 0 ), matBlue ), [ 0.99, 0, 0 ], null, [ 1, 3, 1 ]],
|
|
|
- ],
|
|
|
- E: [
|
|
|
- [ new THREE.Line( CircleGeometry( 1.25, 1 ), matLineYellowTransparent ), null, [ 0, Math.PI / 2, 0 ]],
|
|
|
- [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 1.17, 0, 0 ], [ 0, 0, - Math.PI / 2 ], [ 1, 1, 0.001 ]],
|
|
|
- [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ - 1.17, 0, 0 ], [ 0, 0, Math.PI / 2 ], [ 1, 1, 0.001 ]],
|
|
|
- [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, - 1.17, 0 ], [ Math.PI, 0, 0 ], [ 1, 1, 0.001 ]],
|
|
|
- [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, 1.17, 0 ], [ 0, 0, 0 ], [ 1, 1, 0.001 ]],
|
|
|
- ],
|
|
|
- XYZE: [
|
|
|
- [ new THREE.Line( CircleGeometry( 1, 1 ), matLineGray ), null, [ 0, Math.PI / 2, 0 ]]
|
|
|
- ]
|
|
|
- };
|
|
|
+ factor = ( this.camera.top - this.camera.bottom ) / this.camera.zoom;
|
|
|
|
|
|
- var helperRotate = {
|
|
|
- AXIS: [
|
|
|
- [ new THREE.Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
|
|
|
- ]
|
|
|
- };
|
|
|
+ } else {
|
|
|
|
|
|
- var pickerRotate = {
|
|
|
- X: [
|
|
|
- [ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ]],
|
|
|
- ],
|
|
|
- Y: [
|
|
|
- [ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ]],
|
|
|
- ],
|
|
|
- Z: [
|
|
|
- [ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
|
|
|
- ],
|
|
|
- E: [
|
|
|
- [ new THREE.Mesh( new THREE.TorusGeometry( 1.25, 0.1, 2, 24 ), matInvisible ) ]
|
|
|
- ],
|
|
|
- XYZE: [
|
|
|
- [ new THREE.Mesh( new THREE.SphereGeometry( 0.7, 10, 8 ), matInvisible ) ]
|
|
|
- ]
|
|
|
- };
|
|
|
+ factor = this.worldPosition.distanceTo( this.cameraPosition ) * Math.min( 1.9 * Math.tan( Math.PI * this.camera.fov / 360 ) / this.camera.zoom, 7 );
|
|
|
|
|
|
- var gizmoScale = {
|
|
|
- X: [
|
|
|
- [ new THREE.Mesh( scaleHandleGeometry, matRed ), [ 0.8, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineRed ), null, null, [ 0.8, 1, 1 ]]
|
|
|
- ],
|
|
|
- Y: [
|
|
|
- [ new THREE.Mesh( scaleHandleGeometry, matGreen ), [ 0, 0.8, 0 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ], [ 0.8, 1, 1 ]]
|
|
|
- ],
|
|
|
- Z: [
|
|
|
- [ new THREE.Mesh( scaleHandleGeometry, matBlue ), [ 0, 0, 0.8 ], [ Math.PI / 2, 0, 0 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ], [ 0.8, 1, 1 ]]
|
|
|
- ],
|
|
|
- XY: [
|
|
|
- [ new THREE.Mesh( scaleHandleGeometry, matYellowTransparent ), [ 0.85, 0.85, 0 ], null, [ 2, 2, 0.2 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.855, 0.98, 0 ], null, [ 0.125, 1, 1 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.98, 0.855, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]
|
|
|
- ],
|
|
|
- YZ: [
|
|
|
- [ new THREE.Mesh( scaleHandleGeometry, matCyanTransparent ), [ 0, 0.85, 0.85 ], null, [ 0.2, 2, 2 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.855, 0.98 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.98, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
|
|
|
- ],
|
|
|
- XZ: [
|
|
|
- [ new THREE.Mesh( scaleHandleGeometry, matMagentaTransparent ), [ 0.85, 0, 0.85 ], null, [ 2, 0.2, 2 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.855, 0, 0.98 ], null, [ 0.125, 1, 1 ]],
|
|
|
- [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.98, 0, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
|
|
|
- ],
|
|
|
- XYZX: [
|
|
|
- [ new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 1.1, 0, 0 ]],
|
|
|
- ],
|
|
|
- XYZY: [
|
|
|
- [ new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 1.1, 0 ]],
|
|
|
- ],
|
|
|
- XYZZ: [
|
|
|
- [ new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 0, 1.1 ]],
|
|
|
- ]
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- var pickerScale = {
|
|
|
- X: [
|
|
|
- [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]
|
|
|
- ],
|
|
|
- Y: [
|
|
|
- [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0.5, 0 ]]
|
|
|
- ],
|
|
|
- Z: [
|
|
|
- [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ]]
|
|
|
- ],
|
|
|
- XY: [
|
|
|
- [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0.85, 0 ], null, [ 3, 3, 0.2 ]],
|
|
|
- ],
|
|
|
- YZ: [
|
|
|
- [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0, 0.85, 0.85 ], null, [ 0.2, 3, 3 ]],
|
|
|
- ],
|
|
|
- XZ: [
|
|
|
- [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0, 0.85 ], null, [ 3, 0.2, 3 ]],
|
|
|
- ],
|
|
|
- XYZX: [
|
|
|
- [ new THREE.Mesh( new THREE.BoxGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 1.1, 0, 0 ]],
|
|
|
- ],
|
|
|
- XYZY: [
|
|
|
- [ new THREE.Mesh( new THREE.BoxGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 1.1, 0 ]],
|
|
|
- ],
|
|
|
- XYZZ: [
|
|
|
- [ new THREE.Mesh( new THREE.BoxGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 0, 1.1 ]],
|
|
|
- ]
|
|
|
- };
|
|
|
+ handle.scale.set( 1, 1, 1 ).multiplyScalar( factor * this.size / 7 ); // TODO: simplify helpers and consider decoupling from gizmo
|
|
|
|
|
|
- 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' ]
|
|
|
- ]
|
|
|
- };
|
|
|
+ if ( handle.tag === 'helper' ) {
|
|
|
|
|
|
- // Creates an Object3D with gizmos described in custom hierarchy definition.
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- var setupGizmo = function ( gizmoMap ) {
|
|
|
+ if ( handle.name === 'AXIS' ) {
|
|
|
|
|
|
- var gizmo = new THREE.Object3D();
|
|
|
+ handle.position.copy( this.worldPositionStart );
|
|
|
+ handle.visible = !! this.axis;
|
|
|
|
|
|
- for ( var name in gizmoMap ) {
|
|
|
+ if ( this.axis === 'X' ) {
|
|
|
|
|
|
- for ( var i = gizmoMap[ name ].length; i --; ) {
|
|
|
+ _tempQuaternion.setFromEuler( _tempEuler.set( 0, 0, 0 ) );
|
|
|
|
|
|
- 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 ];
|
|
|
+ handle.quaternion.copy( quaternion ).multiply( _tempQuaternion );
|
|
|
|
|
|
- // name and tag properties are essential for picking and updating logic.
|
|
|
- object.name = name;
|
|
|
- object.tag = tag;
|
|
|
+ if ( Math.abs( _alignVector.copy( _unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
|
|
|
|
|
|
- if ( position ) {
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- object.position.set( position[ 0 ], position[ 1 ], position[ 2 ] );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( rotation ) {
|
|
|
+ if ( this.axis === 'Y' ) {
|
|
|
|
|
|
- object.rotation.set( rotation[ 0 ], rotation[ 1 ], rotation[ 2 ] );
|
|
|
+ _tempQuaternion.setFromEuler( _tempEuler.set( 0, 0, Math.PI / 2 ) );
|
|
|
|
|
|
- }
|
|
|
+ handle.quaternion.copy( quaternion ).multiply( _tempQuaternion );
|
|
|
|
|
|
- if ( scale ) {
|
|
|
+ if ( Math.abs( _alignVector.copy( _unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
|
|
|
|
|
|
- object.scale.set( scale[ 0 ], scale[ 1 ], scale[ 2 ] );
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- object.updateMatrix();
|
|
|
+ }
|
|
|
|
|
|
- var tempGeometry = object.geometry.clone();
|
|
|
- tempGeometry.applyMatrix4( object.matrix );
|
|
|
- object.geometry = tempGeometry;
|
|
|
- object.renderOrder = Infinity;
|
|
|
+ if ( this.axis === 'Z' ) {
|
|
|
|
|
|
- object.position.set( 0, 0, 0 );
|
|
|
- object.rotation.set( 0, 0, 0 );
|
|
|
- object.scale.set( 1, 1, 1 );
|
|
|
+ _tempQuaternion.setFromEuler( _tempEuler.set( 0, Math.PI / 2, 0 ) );
|
|
|
|
|
|
- gizmo.add( object );
|
|
|
+ handle.quaternion.copy( quaternion ).multiply( _tempQuaternion );
|
|
|
|
|
|
- }
|
|
|
+ if ( Math.abs( _alignVector.copy( _unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
|
|
|
|
|
|
- }
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- return gizmo;
|
|
|
+ }
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- // Reusable utility variables
|
|
|
+ if ( this.axis === 'XYZE' ) {
|
|
|
|
|
|
- var tempVector = new THREE.Vector3( 0, 0, 0 );
|
|
|
- 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 tempQuaternion = new THREE.Quaternion();
|
|
|
- var tempQuaternion2 = new THREE.Quaternion();
|
|
|
- var identityQuaternion = new THREE.Quaternion();
|
|
|
+ _tempQuaternion.setFromEuler( _tempEuler.set( 0, Math.PI / 2, 0 ) );
|
|
|
|
|
|
- var unitX = new THREE.Vector3( 1, 0, 0 );
|
|
|
- var unitY = new THREE.Vector3( 0, 1, 0 );
|
|
|
- var unitZ = new THREE.Vector3( 0, 0, 1 );
|
|
|
+ _alignVector.copy( this.rotationAxis );
|
|
|
|
|
|
- // Gizmo creation
|
|
|
+ handle.quaternion.setFromRotationMatrix( _lookAtMatrix.lookAt( _zeroVector, _alignVector, _unitY ) );
|
|
|
+ handle.quaternion.multiply( _tempQuaternion );
|
|
|
+ handle.visible = this.dragging;
|
|
|
|
|
|
- this.gizmo = {};
|
|
|
- this.picker = {};
|
|
|
- this.helper = {};
|
|
|
+ }
|
|
|
|
|
|
- this.add( this.gizmo[ 'translate' ] = setupGizmo( gizmoTranslate ) );
|
|
|
- this.add( this.gizmo[ 'rotate' ] = setupGizmo( gizmoRotate ) );
|
|
|
- this.add( this.gizmo[ 'scale' ] = setupGizmo( gizmoScale ) );
|
|
|
- this.add( this.picker[ 'translate' ] = setupGizmo( pickerTranslate ) );
|
|
|
- this.add( this.picker[ 'rotate' ] = setupGizmo( pickerRotate ) );
|
|
|
- this.add( this.picker[ 'scale' ] = setupGizmo( pickerScale ) );
|
|
|
- this.add( this.helper[ 'translate' ] = setupGizmo( helperTranslate ) );
|
|
|
- this.add( this.helper[ 'rotate' ] = setupGizmo( helperRotate ) );
|
|
|
- this.add( this.helper[ 'scale' ] = setupGizmo( helperScale ) );
|
|
|
+ if ( this.axis === 'E' ) {
|
|
|
|
|
|
- // Pickers should be hidden always
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- this.picker[ 'translate' ].visible = false;
|
|
|
- this.picker[ 'rotate' ].visible = false;
|
|
|
- this.picker[ 'scale' ].visible = false;
|
|
|
+ }
|
|
|
|
|
|
- // updateMatrixWorld will update transformations and appearance of individual handles
|
|
|
+ } else if ( handle.name === 'START' ) {
|
|
|
|
|
|
- this.updateMatrixWorld = function () {
|
|
|
+ handle.position.copy( this.worldPositionStart );
|
|
|
+ handle.visible = this.dragging;
|
|
|
|
|
|
- var space = this.space;
|
|
|
+ } else if ( handle.name === 'END' ) {
|
|
|
|
|
|
- if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
|
|
|
+ handle.position.copy( this.worldPosition );
|
|
|
+ handle.visible = this.dragging;
|
|
|
|
|
|
- var quaternion = space === 'local' ? this.worldQuaternion : identityQuaternion;
|
|
|
+ } else if ( handle.name === 'DELTA' ) {
|
|
|
|
|
|
- // Show only gizmos for current transform mode
|
|
|
+ handle.position.copy( this.worldPositionStart );
|
|
|
+ handle.quaternion.copy( this.worldQuaternionStart );
|
|
|
|
|
|
- this.gizmo[ 'translate' ].visible = this.mode === 'translate';
|
|
|
- this.gizmo[ 'rotate' ].visible = this.mode === 'rotate';
|
|
|
- this.gizmo[ 'scale' ].visible = this.mode === 'scale';
|
|
|
+ _tempVector.set( 1e-10, 1e-10, 1e-10 ).add( this.worldPositionStart ).sub( this.worldPosition ).multiplyScalar( - 1 );
|
|
|
|
|
|
- this.helper[ 'translate' ].visible = this.mode === 'translate';
|
|
|
- this.helper[ 'rotate' ].visible = this.mode === 'rotate';
|
|
|
- this.helper[ 'scale' ].visible = this.mode === 'scale';
|
|
|
+ _tempVector.applyQuaternion( this.worldQuaternionStart.clone().invert() );
|
|
|
|
|
|
+ handle.scale.copy( _tempVector );
|
|
|
+ handle.visible = this.dragging;
|
|
|
|
|
|
- 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 );
|
|
|
+ } else {
|
|
|
|
|
|
- for ( var i = 0; i < handles.length; i ++ ) {
|
|
|
+ handle.quaternion.copy( quaternion );
|
|
|
|
|
|
- var handle = handles[ i ];
|
|
|
+ if ( this.dragging ) {
|
|
|
|
|
|
- // hide aligned to camera
|
|
|
+ handle.position.copy( this.worldPositionStart );
|
|
|
|
|
|
- handle.visible = true;
|
|
|
- handle.rotation.set( 0, 0, 0 );
|
|
|
- handle.position.copy( this.worldPosition );
|
|
|
+ } else {
|
|
|
|
|
|
- var factor;
|
|
|
+ handle.position.copy( this.worldPosition );
|
|
|
|
|
|
- if ( this.camera.isOrthographicCamera ) {
|
|
|
+ }
|
|
|
|
|
|
- factor = ( this.camera.top - this.camera.bottom ) / this.camera.zoom;
|
|
|
+ if ( this.axis ) {
|
|
|
|
|
|
- } else {
|
|
|
+ handle.visible = this.axis.search( handle.name ) !== - 1;
|
|
|
|
|
|
- factor = this.worldPosition.distanceTo( this.cameraPosition ) * Math.min( 1.9 * Math.tan( Math.PI * this.camera.fov / 360 ) / this.camera.zoom, 7 );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ } // If updating helper, skip rest of the loop
|
|
|
|
|
|
- handle.scale.set( 1, 1, 1 ).multiplyScalar( factor * this.size / 7 );
|
|
|
|
|
|
- // TODO: simplify helpers and consider decoupling from gizmo
|
|
|
+ continue;
|
|
|
|
|
|
- if ( handle.tag === 'helper' ) {
|
|
|
+ } // Align handles to current local or world rotation
|
|
|
|
|
|
- handle.visible = false;
|
|
|
|
|
|
- if ( handle.name === 'AXIS' ) {
|
|
|
+ handle.quaternion.copy( quaternion );
|
|
|
|
|
|
- handle.position.copy( this.worldPositionStart );
|
|
|
- handle.visible = !! this.axis;
|
|
|
+ if ( this.mode === 'translate' || this.mode === 'scale' ) {
|
|
|
|
|
|
- if ( this.axis === 'X' ) {
|
|
|
+ // Hide translate and scale axis facing the camera
|
|
|
+ const AXIS_HIDE_TRESHOLD = 0.99;
|
|
|
+ const PLANE_HIDE_TRESHOLD = 0.2;
|
|
|
+ const AXIS_FLIP_TRESHOLD = 0.0;
|
|
|
|
|
|
- tempQuaternion.setFromEuler( tempEuler.set( 0, 0, 0 ) );
|
|
|
- handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
|
|
|
+ if ( handle.name === 'X' || handle.name === 'XYZX' ) {
|
|
|
|
|
|
- if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
|
|
|
+ if ( Math.abs( _alignVector.copy( _unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
|
|
|
|
|
|
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
handle.visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( this.axis === 'Y' ) {
|
|
|
-
|
|
|
- tempQuaternion.setFromEuler( tempEuler.set( 0, 0, Math.PI / 2 ) );
|
|
|
- handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
|
|
|
+ if ( handle.name === 'Y' || handle.name === 'XYZY' ) {
|
|
|
|
|
|
- if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
|
|
|
+ if ( Math.abs( _alignVector.copy( _unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
|
|
|
|
|
|
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
handle.visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( this.axis === 'Z' ) {
|
|
|
-
|
|
|
- tempQuaternion.setFromEuler( tempEuler.set( 0, Math.PI / 2, 0 ) );
|
|
|
- handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
|
|
|
+ if ( handle.name === 'Z' || handle.name === 'XYZZ' ) {
|
|
|
|
|
|
- if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
|
|
|
+ if ( Math.abs( _alignVector.copy( _unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
|
|
|
|
|
|
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
handle.visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( this.axis === 'XYZE' ) {
|
|
|
+ if ( handle.name === 'XY' ) {
|
|
|
|
|
|
- tempQuaternion.setFromEuler( tempEuler.set( 0, Math.PI / 2, 0 ) );
|
|
|
- alignVector.copy( this.rotationAxis );
|
|
|
- handle.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( zeroVector, alignVector, unitY ) );
|
|
|
- handle.quaternion.multiply( tempQuaternion );
|
|
|
- handle.visible = this.dragging;
|
|
|
+ if ( Math.abs( _alignVector.copy( _unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- if ( this.axis === 'E' ) {
|
|
|
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- handle.visible = false;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
+ if ( handle.name === 'YZ' ) {
|
|
|
|
|
|
- } else if ( handle.name === 'START' ) {
|
|
|
-
|
|
|
- handle.position.copy( this.worldPositionStart );
|
|
|
- handle.visible = this.dragging;
|
|
|
+ if ( Math.abs( _alignVector.copy( _unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
|
|
|
|
|
|
- } else if ( handle.name === 'END' ) {
|
|
|
-
|
|
|
- handle.position.copy( this.worldPosition );
|
|
|
- handle.visible = this.dragging;
|
|
|
-
|
|
|
- } else if ( handle.name === 'DELTA' ) {
|
|
|
-
|
|
|
- handle.position.copy( this.worldPositionStart );
|
|
|
- handle.quaternion.copy( this.worldQuaternionStart );
|
|
|
- tempVector.set( 1e-10, 1e-10, 1e-10 ).add( this.worldPositionStart ).sub( this.worldPosition ).multiplyScalar( - 1 );
|
|
|
- tempVector.applyQuaternion( this.worldQuaternionStart.clone().invert() );
|
|
|
- handle.scale.copy( tempVector );
|
|
|
- handle.visible = this.dragging;
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- handle.quaternion.copy( quaternion );
|
|
|
-
|
|
|
- if ( this.dragging ) {
|
|
|
-
|
|
|
- handle.position.copy( this.worldPositionStart );
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- handle.position.copy( this.worldPosition );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if ( this.axis ) {
|
|
|
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- handle.visible = this.axis.search( handle.name ) !== - 1;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ if ( handle.name === 'XZ' ) {
|
|
|
|
|
|
- // If updating helper, skip rest of the loop
|
|
|
- continue;
|
|
|
+ if ( Math.abs( _alignVector.copy( _unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- // Align handles to current local or world rotation
|
|
|
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- handle.quaternion.copy( quaternion );
|
|
|
+ }
|
|
|
|
|
|
- if ( this.mode === 'translate' || this.mode === 'scale' ) {
|
|
|
+ } // Flip translate and scale axis ocluded behind another axis
|
|
|
|
|
|
- // Hide translate and scale axis facing the camera
|
|
|
|
|
|
- var AXIS_HIDE_TRESHOLD = 0.99;
|
|
|
- var PLANE_HIDE_TRESHOLD = 0.2;
|
|
|
- var AXIS_FLIP_TRESHOLD = 0.0;
|
|
|
+ if ( handle.name.search( 'X' ) !== - 1 ) {
|
|
|
|
|
|
+ if ( _alignVector.copy( _unitX ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
|
|
|
|
|
|
- if ( handle.name === 'X' || handle.name === 'XYZX' ) {
|
|
|
+ if ( handle.tag === 'fwd' ) {
|
|
|
|
|
|
- if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
- handle.visible = false;
|
|
|
+ } else {
|
|
|
|
|
|
- }
|
|
|
+ handle.scale.x *= - 1;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( handle.name === 'Y' || handle.name === 'XYZY' ) {
|
|
|
+ } else if ( handle.tag === 'bwd' ) {
|
|
|
|
|
|
- if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
- handle.visible = false;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ if ( handle.name.search( 'Y' ) !== - 1 ) {
|
|
|
|
|
|
- if ( handle.name === 'Z' || handle.name === 'XYZZ' ) {
|
|
|
+ if ( _alignVector.copy( _unitY ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
|
|
|
|
|
|
- if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
|
|
|
+ if ( handle.tag === 'fwd' ) {
|
|
|
|
|
|
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
- handle.visible = false;
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- }
|
|
|
+ } else {
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- if ( handle.name === 'XY' ) {
|
|
|
+ handle.scale.y *= - 1;
|
|
|
|
|
|
- if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
|
|
|
+ }
|
|
|
|
|
|
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
- handle.visible = false;
|
|
|
+ } else if ( handle.tag === 'bwd' ) {
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if ( handle.name === 'YZ' ) {
|
|
|
-
|
|
|
- if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
- handle.visible = false;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- if ( handle.name === 'XZ' ) {
|
|
|
+ if ( handle.name.search( 'Z' ) !== - 1 ) {
|
|
|
|
|
|
- if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
|
|
|
+ if ( _alignVector.copy( _unitZ ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
|
|
|
|
|
|
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
|
|
|
- handle.visible = false;
|
|
|
+ if ( handle.tag === 'fwd' ) {
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ handle.visible = false;
|
|
|
|
|
|
- // Flip translate and scale axis ocluded behind another axis
|
|
|
+ } else {
|
|
|
|
|
|
- if ( handle.name.search( 'X' ) !== - 1 ) {
|
|
|
+ handle.scale.z *= - 1;
|
|
|
|
|
|
- if ( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
|
|
|
+ }
|
|
|
|
|
|
- if ( handle.tag === 'fwd' ) {
|
|
|
+ } else if ( handle.tag === 'bwd' ) {
|
|
|
|
|
|
handle.visible = false;
|
|
|
|
|
|
- } else {
|
|
|
-
|
|
|
- handle.scale.x *= - 1;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- } else if ( handle.tag === 'bwd' ) {
|
|
|
-
|
|
|
- handle.visible = false;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ } else if ( this.mode === 'rotate' ) {
|
|
|
|
|
|
- if ( handle.name.search( 'Y' ) !== - 1 ) {
|
|
|
+ // Align handles to current local or world rotation
|
|
|
+ _tempQuaternion2.copy( quaternion );
|
|
|
|
|
|
- if ( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
|
|
|
+ _alignVector.copy( this.eye ).applyQuaternion( _tempQuaternion.copy( quaternion ).invert() );
|
|
|
|
|
|
- if ( handle.tag === 'fwd' ) {
|
|
|
+ if ( handle.name.search( 'E' ) !== - 1 ) {
|
|
|
|
|
|
- handle.visible = false;
|
|
|
+ handle.quaternion.setFromRotationMatrix( _lookAtMatrix.lookAt( this.eye, _zeroVector, _unitY ) );
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
|
|
|
- handle.scale.y *= - 1;
|
|
|
+ if ( handle.name === 'X' ) {
|
|
|
|
|
|
- }
|
|
|
+ _tempQuaternion.setFromAxisAngle( _unitX, Math.atan2( - _alignVector.y, _alignVector.z ) );
|
|
|
|
|
|
- } else if ( handle.tag === 'bwd' ) {
|
|
|
+ _tempQuaternion.multiplyQuaternions( _tempQuaternion2, _tempQuaternion );
|
|
|
|
|
|
- handle.visible = false;
|
|
|
+ handle.quaternion.copy( _tempQuaternion );
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- if ( handle.name.search( 'Z' ) !== - 1 ) {
|
|
|
+ if ( handle.name === 'Y' ) {
|
|
|
|
|
|
- if ( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
|
|
|
+ _tempQuaternion.setFromAxisAngle( _unitY, Math.atan2( _alignVector.x, _alignVector.z ) );
|
|
|
|
|
|
- if ( handle.tag === 'fwd' ) {
|
|
|
+ _tempQuaternion.multiplyQuaternions( _tempQuaternion2, _tempQuaternion );
|
|
|
|
|
|
- handle.visible = false;
|
|
|
+ handle.quaternion.copy( _tempQuaternion );
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
|
|
|
- handle.scale.z *= - 1;
|
|
|
+ if ( handle.name === 'Z' ) {
|
|
|
|
|
|
- }
|
|
|
+ _tempQuaternion.setFromAxisAngle( _unitZ, Math.atan2( _alignVector.y, _alignVector.x ) );
|
|
|
|
|
|
- } else if ( handle.tag === 'bwd' ) {
|
|
|
+ _tempQuaternion.multiplyQuaternions( _tempQuaternion2, _tempQuaternion );
|
|
|
|
|
|
- handle.visible = false;
|
|
|
+ handle.quaternion.copy( _tempQuaternion );
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ } // Hide disabled axes
|
|
|
|
|
|
- } else if ( this.mode === 'rotate' ) {
|
|
|
|
|
|
- // Align handles to current local or world rotation
|
|
|
+ handle.visible = handle.visible && ( handle.name.indexOf( 'X' ) === - 1 || this.showX );
|
|
|
+ handle.visible = handle.visible && ( handle.name.indexOf( 'Y' ) === - 1 || this.showY );
|
|
|
+ handle.visible = handle.visible && ( handle.name.indexOf( 'Z' ) === - 1 || this.showZ );
|
|
|
+ handle.visible = handle.visible && ( handle.name.indexOf( 'E' ) === - 1 || this.showX && this.showY && this.showZ ); // highlight selected axis
|
|
|
|
|
|
- tempQuaternion2.copy( quaternion );
|
|
|
- alignVector.copy( this.eye ).applyQuaternion( tempQuaternion.copy( quaternion ).invert() );
|
|
|
+ handle.material._opacity = handle.material._opacity || handle.material.opacity;
|
|
|
+ handle.material._color = handle.material._color || handle.material.color.clone();
|
|
|
+ handle.material.color.copy( handle.material._color );
|
|
|
+ handle.material.opacity = handle.material._opacity;
|
|
|
|
|
|
- if ( handle.name.search( 'E' ) !== - 1 ) {
|
|
|
+ if ( ! this.enabled ) {
|
|
|
|
|
|
- handle.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( this.eye, zeroVector, unitY ) );
|
|
|
+ handle.material.opacity *= 0.5;
|
|
|
+ handle.material.color.lerp( new THREE.Color( 1, 1, 1 ), 0.5 );
|
|
|
|
|
|
- }
|
|
|
+ } else if ( this.axis ) {
|
|
|
|
|
|
- if ( handle.name === 'X' ) {
|
|
|
+ if ( handle.name === this.axis ) {
|
|
|
|
|
|
- tempQuaternion.setFromAxisAngle( unitX, Math.atan2( - alignVector.y, alignVector.z ) );
|
|
|
- tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
|
|
|
- handle.quaternion.copy( tempQuaternion );
|
|
|
+ handle.material.opacity = 1.0;
|
|
|
+ handle.material.color.lerp( new THREE.Color( 1, 1, 1 ), 0.5 );
|
|
|
|
|
|
- }
|
|
|
+ } else if ( this.axis.split( '' ).some( function ( a ) {
|
|
|
|
|
|
- if ( handle.name === 'Y' ) {
|
|
|
+ return handle.name === a;
|
|
|
|
|
|
- tempQuaternion.setFromAxisAngle( unitY, Math.atan2( alignVector.x, alignVector.z ) );
|
|
|
- tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
|
|
|
- handle.quaternion.copy( tempQuaternion );
|
|
|
+ } ) ) {
|
|
|
|
|
|
- }
|
|
|
+ handle.material.opacity = 1.0;
|
|
|
+ handle.material.color.lerp( new THREE.Color( 1, 1, 1 ), 0.5 );
|
|
|
|
|
|
- if ( handle.name === 'Z' ) {
|
|
|
+ } else {
|
|
|
|
|
|
- tempQuaternion.setFromAxisAngle( unitZ, Math.atan2( alignVector.y, alignVector.x ) );
|
|
|
- tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
|
|
|
- handle.quaternion.copy( tempQuaternion );
|
|
|
+ handle.material.opacity *= 0.25;
|
|
|
+ handle.material.color.lerp( new THREE.Color( 1, 1, 1 ), 0.5 );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- // Hide disabled axes
|
|
|
- handle.visible = handle.visible && ( handle.name.indexOf( 'X' ) === - 1 || this.showX );
|
|
|
- handle.visible = handle.visible && ( handle.name.indexOf( 'Y' ) === - 1 || this.showY );
|
|
|
- handle.visible = handle.visible && ( handle.name.indexOf( 'Z' ) === - 1 || this.showZ );
|
|
|
- handle.visible = handle.visible && ( handle.name.indexOf( 'E' ) === - 1 || ( this.showX && this.showY && this.showZ ) );
|
|
|
+ super.updateMatrixWorld( force );
|
|
|
|
|
|
- // highlight selected axis
|
|
|
-
|
|
|
- handle.material._opacity = handle.material._opacity || handle.material.opacity;
|
|
|
- handle.material._color = handle.material._color || handle.material.color.clone();
|
|
|
-
|
|
|
- handle.material.color.copy( handle.material._color );
|
|
|
- handle.material.opacity = handle.material._opacity;
|
|
|
-
|
|
|
- if ( ! this.enabled ) {
|
|
|
-
|
|
|
- handle.material.opacity *= 0.5;
|
|
|
- handle.material.color.lerp( new THREE.Color( 1, 1, 1 ), 0.5 );
|
|
|
+ }
|
|
|
|
|
|
- } else if ( this.axis ) {
|
|
|
+ }
|
|
|
|
|
|
- if ( handle.name === this.axis ) {
|
|
|
+ TransformControlsGizmo.prototype.isTransformControlsGizmo = true; //
|
|
|
|
|
|
- handle.material.opacity = 1.0;
|
|
|
- handle.material.color.lerp( new THREE.Color( 1, 1, 1 ), 0.5 );
|
|
|
+ class TransformControlsPlane extends THREE.Mesh {
|
|
|
|
|
|
- } else if ( this.axis.split( '' ).some( function ( a ) {
|
|
|
+ constructor() {
|
|
|
|
|
|
- return handle.name === a;
|
|
|
+ super( new THREE.PlaneGeometry( 100000, 100000, 2, 2 ), new THREE.MeshBasicMaterial( {
|
|
|
+ visible: false,
|
|
|
+ wireframe: true,
|
|
|
+ side: THREE.DoubleSide,
|
|
|
+ transparent: true,
|
|
|
+ opacity: 0.1,
|
|
|
+ toneMapped: false
|
|
|
+ } ) );
|
|
|
+ this.type = 'TransformControlsPlane';
|
|
|
|
|
|
- } ) ) {
|
|
|
+ }
|
|
|
|
|
|
- handle.material.opacity = 1.0;
|
|
|
- handle.material.color.lerp( new THREE.Color( 1, 1, 1 ), 0.5 );
|
|
|
+ updateMatrixWorld( force ) {
|
|
|
|
|
|
- } else {
|
|
|
+ let space = this.space;
|
|
|
+ this.position.copy( this.worldPosition );
|
|
|
+ if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
|
|
|
|
|
|
- handle.material.opacity *= 0.25;
|
|
|
- handle.material.color.lerp( new THREE.Color( 1, 1, 1 ), 0.5 );
|
|
|
+ _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.
|
|
|
|
|
|
- }
|
|
|
|
|
|
- THREE.Object3D.prototype.updateMatrixWorld.call( this );
|
|
|
+ _alignVector.copy( _v2 );
|
|
|
|
|
|
- };
|
|
|
+ switch ( this.mode ) {
|
|
|
|
|
|
-};
|
|
|
+ case 'translate':
|
|
|
+ case 'scale':
|
|
|
+ switch ( this.axis ) {
|
|
|
|
|
|
-THREE.TransformControlsGizmo.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
|
|
|
+ case 'X':
|
|
|
+ _alignVector.copy( this.eye ).cross( _v1 );
|
|
|
|
|
|
- constructor: THREE.TransformControlsGizmo,
|
|
|
+ _dirVector.copy( _v1 ).cross( _alignVector );
|
|
|
|
|
|
- isTransformControlsGizmo: true
|
|
|
+ break;
|
|
|
|
|
|
-} );
|
|
|
+ case 'Y':
|
|
|
+ _alignVector.copy( this.eye ).cross( _v2 );
|
|
|
|
|
|
+ _dirVector.copy( _v2 ).cross( _alignVector );
|
|
|
|
|
|
-THREE.TransformControlsPlane = function () {
|
|
|
+ break;
|
|
|
|
|
|
- 'use strict';
|
|
|
+ case 'Z':
|
|
|
+ _alignVector.copy( this.eye ).cross( _v3 );
|
|
|
|
|
|
- THREE.Mesh.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 } )
|
|
|
- );
|
|
|
+ _dirVector.copy( _v3 ).cross( _alignVector );
|
|
|
|
|
|
- this.type = 'TransformControlsPlane';
|
|
|
+ break;
|
|
|
|
|
|
- var unitX = new THREE.Vector3( 1, 0, 0 );
|
|
|
- var unitY = new THREE.Vector3( 0, 1, 0 );
|
|
|
- var unitZ = new THREE.Vector3( 0, 0, 1 );
|
|
|
+ case 'XY':
|
|
|
+ _dirVector.copy( _v3 );
|
|
|
|
|
|
- var tempVector = new THREE.Vector3();
|
|
|
- var dirVector = new THREE.Vector3();
|
|
|
- var alignVector = new THREE.Vector3();
|
|
|
- var tempMatrix = new THREE.Matrix4();
|
|
|
- var identityQuaternion = new THREE.Quaternion();
|
|
|
+ break;
|
|
|
|
|
|
- this.updateMatrixWorld = function () {
|
|
|
+ case 'YZ':
|
|
|
+ _dirVector.copy( _v1 );
|
|
|
|
|
|
- var space = this.space;
|
|
|
+ break;
|
|
|
|
|
|
- this.position.copy( this.worldPosition );
|
|
|
+ case 'XZ':
|
|
|
+ _alignVector.copy( _v3 );
|
|
|
|
|
|
- if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
|
|
|
+ _dirVector.copy( _v2 );
|
|
|
|
|
|
- unitX.set( 1, 0, 0 ).applyQuaternion( space === 'local' ? this.worldQuaternion : identityQuaternion );
|
|
|
- unitY.set( 0, 1, 0 ).applyQuaternion( space === 'local' ? this.worldQuaternion : identityQuaternion );
|
|
|
- unitZ.set( 0, 0, 1 ).applyQuaternion( space === 'local' ? this.worldQuaternion : identityQuaternion );
|
|
|
+ break;
|
|
|
|
|
|
- // Align the plane for current transform mode, axis and space.
|
|
|
+ case 'XYZ':
|
|
|
+ case 'E':
|
|
|
+ _dirVector.set( 0, 0, 0 );
|
|
|
|
|
|
- alignVector.copy( unitY );
|
|
|
+ break;
|
|
|
|
|
|
- switch ( this.mode ) {
|
|
|
+ }
|
|
|
|
|
|
- case 'translate':
|
|
|
- case 'scale':
|
|
|
- switch ( this.axis ) {
|
|
|
+ break;
|
|
|
|
|
|
- case 'X':
|
|
|
- alignVector.copy( this.eye ).cross( unitX );
|
|
|
- dirVector.copy( unitX ).cross( alignVector );
|
|
|
- break;
|
|
|
- case 'Y':
|
|
|
- alignVector.copy( this.eye ).cross( unitY );
|
|
|
- dirVector.copy( unitY ).cross( alignVector );
|
|
|
- break;
|
|
|
- case 'Z':
|
|
|
- alignVector.copy( this.eye ).cross( unitZ );
|
|
|
- dirVector.copy( unitZ ).cross( alignVector );
|
|
|
- break;
|
|
|
- case 'XY':
|
|
|
- dirVector.copy( unitZ );
|
|
|
- break;
|
|
|
- case 'YZ':
|
|
|
- dirVector.copy( unitX );
|
|
|
- break;
|
|
|
- case 'XZ':
|
|
|
- alignVector.copy( unitZ );
|
|
|
- dirVector.copy( unitY );
|
|
|
- break;
|
|
|
- case 'XYZ':
|
|
|
- case 'E':
|
|
|
- dirVector.set( 0, 0, 0 );
|
|
|
- break;
|
|
|
+ case 'rotate':
|
|
|
+ default:
|
|
|
+ // special case for rotate
|
|
|
+ _dirVector.set( 0, 0, 0 );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- 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 );
|
|
|
|
|
|
- if ( dirVector.length() === 0 ) {
|
|
|
+ } else {
|
|
|
|
|
|
- // If in rotate mode, make the plane parallel to camera
|
|
|
- this.quaternion.copy( this.cameraQuaternion );
|
|
|
+ _tempMatrix.lookAt( _tempVector.set( 0, 0, 0 ), _dirVector, _alignVector );
|
|
|
|
|
|
- } else {
|
|
|
+ this.quaternion.setFromRotationMatrix( _tempMatrix );
|
|
|
|
|
|
- tempMatrix.lookAt( tempVector.set( 0, 0, 0 ), dirVector, alignVector );
|
|
|
+ }
|
|
|
|
|
|
- this.quaternion.setFromRotationMatrix( tempMatrix );
|
|
|
+ super.updateMatrixWorld( force );
|
|
|
|
|
|
}
|
|
|
|
|
|
- THREE.Object3D.prototype.updateMatrixWorld.call( this );
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
-};
|
|
|
-
|
|
|
-THREE.TransformControlsPlane.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
|
|
|
+ }
|
|
|
|
|
|
- constructor: THREE.TransformControlsPlane,
|
|
|
+ TransformControlsPlane.prototype.isTransformControlsPlane = true;
|
|
|
|
|
|
- isTransformControlsPlane: true
|
|
|
+ THREE.TransformControls = TransformControls;
|
|
|
+ THREE.TransformControlsGizmo = TransformControlsGizmo;
|
|
|
+ THREE.TransformControlsPlane = TransformControlsPlane;
|
|
|
|
|
|
-} );
|
|
|
+} )();
|