|
|
@@ -1,6 +1,7 @@
|
|
|
import {
|
|
|
BoxGeometry,
|
|
|
BufferGeometry,
|
|
|
+ Controls,
|
|
|
CylinderGeometry,
|
|
|
DoubleSide,
|
|
|
Euler,
|
|
|
@@ -36,32 +37,22 @@ const _mouseDownEvent = { type: 'mouseDown', mode: null };
|
|
|
const _mouseUpEvent = { type: 'mouseUp', mode: null };
|
|
|
const _objectChangeEvent = { type: 'objectChange' };
|
|
|
|
|
|
-class TransformControls extends Object3D {
|
|
|
+class TransformControls extends Controls {
|
|
|
|
|
|
- constructor( camera, domElement ) {
|
|
|
+ constructor( camera, domElement = null ) {
|
|
|
|
|
|
- super();
|
|
|
-
|
|
|
- if ( domElement === undefined ) {
|
|
|
-
|
|
|
- console.warn( 'THREE.TransformControls: The second parameter "domElement" is now mandatory.' );
|
|
|
- domElement = document;
|
|
|
+ super( undefined, domElement );
|
|
|
|
|
|
- }
|
|
|
+ const root = new TransformControlsRoot( this );
|
|
|
+ this._root = root;
|
|
|
|
|
|
- this.isTransformControls = true;
|
|
|
+ const gizmo = new TransformControlsGizmo();
|
|
|
+ this._gizmo = gizmo;
|
|
|
+ root.add( gizmo );
|
|
|
|
|
|
- this.visible = false;
|
|
|
- this.domElement = domElement;
|
|
|
- this.domElement.style.touchAction = 'none'; // disable touch scroll
|
|
|
-
|
|
|
- const _gizmo = new TransformControlsGizmo();
|
|
|
- this._gizmo = _gizmo;
|
|
|
- this.add( _gizmo );
|
|
|
-
|
|
|
- const _plane = new TransformControlsPlane();
|
|
|
- this._plane = _plane;
|
|
|
- this.add( _plane );
|
|
|
+ const plane = new TransformControlsPlane();
|
|
|
+ this._plane = plane;
|
|
|
+ root.add( plane );
|
|
|
|
|
|
const scope = this;
|
|
|
|
|
|
@@ -83,8 +74,8 @@ class TransformControls extends Object3D {
|
|
|
if ( propValue !== value ) {
|
|
|
|
|
|
propValue = value;
|
|
|
- _plane[ propName ] = value;
|
|
|
- _gizmo[ propName ] = value;
|
|
|
+ plane[ propName ] = value;
|
|
|
+ gizmo[ propName ] = value;
|
|
|
|
|
|
scope.dispatchEvent( { type: propName + '-changed', value: value } );
|
|
|
scope.dispatchEvent( _changeEvent );
|
|
|
@@ -96,8 +87,8 @@ class TransformControls extends Object3D {
|
|
|
} );
|
|
|
|
|
|
scope[ propName ] = defaultValue;
|
|
|
- _plane[ propName ] = defaultValue;
|
|
|
- _gizmo[ propName ] = defaultValue;
|
|
|
+ plane[ propName ] = defaultValue;
|
|
|
+ gizmo[ propName ] = defaultValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -172,50 +163,38 @@ class TransformControls extends Object3D {
|
|
|
this._onPointerMove = onPointerMove.bind( this );
|
|
|
this._onPointerUp = onPointerUp.bind( this );
|
|
|
|
|
|
- this.domElement.addEventListener( 'pointerdown', this._onPointerDown );
|
|
|
- this.domElement.addEventListener( 'pointermove', this._onPointerHover );
|
|
|
- this.domElement.addEventListener( 'pointerup', this._onPointerUp );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // updateMatrixWorld updates key transformation variables
|
|
|
- updateMatrixWorld( force ) {
|
|
|
-
|
|
|
- if ( this.object !== undefined ) {
|
|
|
+ if ( domElement !== null ) {
|
|
|
|
|
|
- this.object.updateMatrixWorld();
|
|
|
-
|
|
|
- if ( this.object.parent === null ) {
|
|
|
-
|
|
|
- console.error( 'TransformControls: The attached 3D object must be a part of the scene graph.' );
|
|
|
-
|
|
|
- } else {
|
|
|
+ this.connect();
|
|
|
|
|
|
- this.object.parent.matrixWorld.decompose( this._parentPosition, this._parentQuaternion, this._parentScale );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- this.object.matrixWorld.decompose( this.worldPosition, this.worldQuaternion, this._worldScale );
|
|
|
+ connect() {
|
|
|
|
|
|
- this._parentQuaternionInv.copy( this._parentQuaternion ).invert();
|
|
|
- this._worldQuaternionInv.copy( this.worldQuaternion ).invert();
|
|
|
+ this.domElement.addEventListener( 'pointerdown', this._onPointerDown );
|
|
|
+ this.domElement.addEventListener( 'pointermove', this._onPointerHover );
|
|
|
+ this.domElement.addEventListener( 'pointerup', this._onPointerUp );
|
|
|
|
|
|
- }
|
|
|
+ this.domElement.style.touchAction = 'none'; // disable touch scroll
|
|
|
|
|
|
- this.camera.updateMatrixWorld();
|
|
|
- this.camera.matrixWorld.decompose( this.cameraPosition, this.cameraQuaternion, this._cameraScale );
|
|
|
+ }
|
|
|
|
|
|
- if ( this.camera.isOrthographicCamera ) {
|
|
|
+ disconnect() {
|
|
|
|
|
|
- this.camera.getWorldDirection( this.eye ).negate();
|
|
|
+ this.domElement.removeEventListener( 'pointerdown', this._onPointerDown );
|
|
|
+ this.domElement.removeEventListener( 'pointermove', this._onPointerHover );
|
|
|
+ this.domElement.removeEventListener( 'pointermove', this._onPointerMove );
|
|
|
+ this.domElement.removeEventListener( 'pointerup', this._onPointerUp );
|
|
|
|
|
|
- } else {
|
|
|
+ this.domElement.style.touchAction = 'auto';
|
|
|
|
|
|
- this.eye.copy( this.cameraPosition ).sub( this.worldPosition ).normalize();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ getGizmo() {
|
|
|
|
|
|
- super.updateMatrixWorld( force );
|
|
|
+ return this._root;
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -555,10 +534,7 @@ class TransformControls extends Object3D {
|
|
|
|
|
|
dispose() {
|
|
|
|
|
|
- this.domElement.removeEventListener( 'pointerdown', this._onPointerDown );
|
|
|
- this.domElement.removeEventListener( 'pointermove', this._onPointerHover );
|
|
|
- this.domElement.removeEventListener( 'pointermove', this._onPointerMove );
|
|
|
- this.domElement.removeEventListener( 'pointerup', this._onPointerUp );
|
|
|
+ this.disconnect();
|
|
|
|
|
|
this.traverse( function ( child ) {
|
|
|
|
|
|
@@ -573,7 +549,7 @@ class TransformControls extends Object3D {
|
|
|
attach( object ) {
|
|
|
|
|
|
this.object = object;
|
|
|
- this.visible = true;
|
|
|
+ this._root.visible = true;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
@@ -583,9 +559,10 @@ class TransformControls extends Object3D {
|
|
|
detach() {
|
|
|
|
|
|
this.object = undefined;
|
|
|
- this.visible = false;
|
|
|
this.axis = null;
|
|
|
|
|
|
+ this._root.visible = false;
|
|
|
+
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
@@ -778,6 +755,64 @@ const _v1 = new Vector3();
|
|
|
const _v2 = new Vector3();
|
|
|
const _v3 = new Vector3();
|
|
|
|
|
|
+class TransformControlsRoot extends Object3D {
|
|
|
+
|
|
|
+ constructor( controls ) {
|
|
|
+
|
|
|
+ super();
|
|
|
+
|
|
|
+ this.isTransformControlsRoot = true;
|
|
|
+
|
|
|
+ this.controls = controls;
|
|
|
+ this.visible = false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // updateMatrixWorld updates key transformation variables
|
|
|
+ updateMatrixWorld( force ) {
|
|
|
+
|
|
|
+ const controls = this.controls;
|
|
|
+
|
|
|
+ if ( controls.object !== undefined ) {
|
|
|
+
|
|
|
+ controls.object.updateMatrixWorld();
|
|
|
+
|
|
|
+ if ( controls.object.parent === null ) {
|
|
|
+
|
|
|
+ console.error( 'TransformControls: The attached 3D object must be a part of the scene graph.' );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ controls.object.parent.matrixWorld.decompose( controls._parentPosition, controls._parentQuaternion, controls._parentScale );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ controls.object.matrixWorld.decompose( controls.worldPosition, controls.worldQuaternion, controls._worldScale );
|
|
|
+
|
|
|
+ controls._parentQuaternionInv.copy( controls._parentQuaternion ).invert();
|
|
|
+ controls._worldQuaternionInv.copy( controls.worldQuaternion ).invert();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ controls.camera.updateMatrixWorld();
|
|
|
+ controls.camera.matrixWorld.decompose( controls.cameraPosition, controls.cameraQuaternion, controls._cameraScale );
|
|
|
+
|
|
|
+ if ( controls.camera.isOrthographicCamera ) {
|
|
|
+
|
|
|
+ controls.camera.getWorldDirection( controls.eye ).negate();
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ controls.eye.copy( controls.cameraPosition ).sub( controls.worldPosition ).normalize();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ super.updateMatrixWorld( force );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
class TransformControlsGizmo extends Object3D {
|
|
|
|
|
|
constructor() {
|