|
@@ -39,12 +39,26 @@
|
|
};
|
|
};
|
|
const _endEvent = {
|
|
const _endEvent = {
|
|
type: 'end'
|
|
type: 'end'
|
|
- };
|
|
|
|
|
|
+ }; //global objects that are used in some operations to avoid creating new objects every time (e.g. every time cursor moves)
|
|
|
|
+
|
|
|
|
+ const _v2_1 = new THREE.Vector2();
|
|
|
|
+
|
|
|
|
+ const _v3_1 = new THREE.Vector3();
|
|
|
|
+
|
|
|
|
+ const _v3_2 = new THREE.Vector3();
|
|
|
|
+
|
|
|
|
+ const _m4_1 = new THREE.Matrix4();
|
|
|
|
+
|
|
|
|
+ const _m4_2 = new THREE.Matrix4();
|
|
|
|
+
|
|
|
|
+ const _quat = new THREE.Quaternion();
|
|
|
|
|
|
const _raycaster = new THREE.Raycaster();
|
|
const _raycaster = new THREE.Raycaster();
|
|
|
|
|
|
const _offset = new THREE.Vector3();
|
|
const _offset = new THREE.Vector3();
|
|
|
|
|
|
|
|
+ const _movement = new THREE.Vector3();
|
|
|
|
+
|
|
const _gizmoMatrixStateTemp = new THREE.Matrix4();
|
|
const _gizmoMatrixStateTemp = new THREE.Matrix4();
|
|
|
|
|
|
const _cameraMatrixStateTemp = new THREE.Matrix4();
|
|
const _cameraMatrixStateTemp = new THREE.Matrix4();
|
|
@@ -524,9 +538,9 @@
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
|
|
|
|
|
|
+ _v3_1.setFromMatrixPosition( this._cameraMatrixState );
|
|
|
|
|
|
- const x = this._v3_1.distanceTo( this._gizmos.position );
|
|
|
|
|
|
+ const x = _v3_1.distanceTo( this._gizmos.position );
|
|
|
|
|
|
let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
|
|
let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
|
|
//check min and max distance
|
|
//check min and max distance
|
|
@@ -845,9 +859,9 @@
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- this._v3_1.setFromMatrixPosition(this._gizmoMatrixState);
|
|
|
|
|
|
+ _v3_1.setFromMatrixPosition( this._gizmoMatrixState );
|
|
|
|
|
|
- this.applyTransformMatrix( this.scale( size, this._v3_1 ) );
|
|
|
|
|
|
+ this.applyTransformMatrix( this.scale( size, _v3_1 ) );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -897,9 +911,9 @@
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
|
|
|
|
|
|
+ _v3_1.setFromMatrixPosition( this._cameraMatrixState );
|
|
|
|
|
|
- const x = this._v3_1.distanceTo( this._gizmos.position );
|
|
|
|
|
|
+ const x = _v3_1.distanceTo( this._gizmos.position );
|
|
|
|
|
|
let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
|
|
let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
|
|
//check min and max distance
|
|
//check min and max distance
|
|
@@ -913,14 +927,14 @@
|
|
const newDistance = y / Math.tan( THREE.MathUtils.DEG2RAD * ( newFov / 2 ) );
|
|
const newDistance = y / Math.tan( THREE.MathUtils.DEG2RAD * ( newFov / 2 ) );
|
|
size = x / newDistance;
|
|
size = x / newDistance;
|
|
|
|
|
|
- this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
|
|
|
|
|
|
+ _v3_2.setFromMatrixPosition( this._gizmoMatrixState );
|
|
|
|
|
|
this.setFov( newFov );
|
|
this.setFov( newFov );
|
|
- this.applyTransformMatrix( this.scale( size, this._v3_2, false ) ); //adjusting distance
|
|
|
|
|
|
+ this.applyTransformMatrix( this.scale( size, _v3_2, false ) ); //adjusting distance
|
|
|
|
|
|
_offset.copy( this._gizmos.position ).sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
|
|
_offset.copy( this._gizmos.position ).sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
|
|
|
|
|
|
- this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
|
|
|
|
|
|
+ _m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1132,9 +1146,9 @@
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
|
|
|
|
|
|
+ _v3_2.setFromMatrixPosition( this._gizmoMatrixState );
|
|
|
|
|
|
- rotationPoint = this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ).applyQuaternion( this.camera.quaternion ).multiplyScalar( 1 / this.camera.zoom ).add( this._v3_2 );
|
|
|
|
|
|
+ rotationPoint = this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ).applyQuaternion( this.camera.quaternion ).multiplyScalar( 1 / this.camera.zoom ).add( _v3_2 );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1289,9 +1303,9 @@
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
|
|
|
|
|
|
+ _v3_1.setFromMatrixPosition( this._cameraMatrixState );
|
|
|
|
|
|
- const x = this._v3_1.distanceTo( this._gizmos.position );
|
|
|
|
|
|
+ const x = _v3_1.distanceTo( this._gizmos.position );
|
|
|
|
|
|
let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
|
|
let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
|
|
//check min and max distance
|
|
//check min and max distance
|
|
@@ -1305,14 +1319,14 @@
|
|
const newDistance = y / Math.tan( THREE.MathUtils.DEG2RAD * ( newFov / 2 ) );
|
|
const newDistance = y / Math.tan( THREE.MathUtils.DEG2RAD * ( newFov / 2 ) );
|
|
size = x / newDistance;
|
|
size = x / newDistance;
|
|
|
|
|
|
- this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
|
|
|
|
|
|
+ _v3_2.setFromMatrixPosition( this._gizmoMatrixState );
|
|
|
|
|
|
this.setFov( newFov );
|
|
this.setFov( newFov );
|
|
- this.applyTransformMatrix( this.scale( size, this._v3_2, false ) ); //adjusting distance
|
|
|
|
|
|
+ this.applyTransformMatrix( this.scale( size, _v3_2, false ) ); //adjusting distance
|
|
|
|
|
|
_offset.copy( this._gizmos.position ).sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
|
|
_offset.copy( this._gizmos.position ).sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
|
|
|
|
|
|
- this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
|
|
|
|
|
|
+ _m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
|
|
|
|
|
|
this.dispatchEvent( _changeEvent );
|
|
this.dispatchEvent( _changeEvent );
|
|
|
|
|
|
@@ -1572,11 +1586,11 @@
|
|
|
|
|
|
this._rotationMatrix.extractRotation( this._cameraMatrixState );
|
|
this._rotationMatrix.extractRotation( this._cameraMatrixState );
|
|
|
|
|
|
- this._quat.setFromRotationMatrix( this._rotationMatrix );
|
|
|
|
|
|
+ _quat.setFromRotationMatrix( this._rotationMatrix );
|
|
|
|
|
|
- this._rotationAxis.crossVectors( vec1, vec2 ).applyQuaternion( this._quat );
|
|
|
|
|
|
+ this._rotationAxis.crossVectors( vec1, vec2 ).applyQuaternion( _quat );
|
|
|
|
|
|
- return this._rotationAxis.normalize().clone();
|
|
|
|
|
|
+ return this._rotationAxis.normalize();
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
@@ -1756,21 +1770,21 @@
|
|
|
|
|
|
const canvasRect = canvas.getBoundingClientRect();
|
|
const canvasRect = canvas.getBoundingClientRect();
|
|
|
|
|
|
- this._v2_1.setX( ( cursorX - canvasRect.left ) / canvasRect.width * 2 - 1 );
|
|
|
|
|
|
+ _v2_1.setX( ( cursorX - canvasRect.left ) / canvasRect.width * 2 - 1 );
|
|
|
|
|
|
- this._v2_1.setY( ( canvasRect.bottom - cursorY ) / canvasRect.height * 2 - 1 );
|
|
|
|
|
|
+ _v2_1.setY( ( canvasRect.bottom - cursorY ) / canvasRect.height * 2 - 1 );
|
|
|
|
|
|
- return this._v2_1.clone();
|
|
|
|
|
|
+ return _v2_1;
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
this.getCursorPosition = ( cursorX, cursorY, canvas ) => {
|
|
this.getCursorPosition = ( cursorX, cursorY, canvas ) => {
|
|
|
|
|
|
- this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
|
|
|
|
|
|
+ _v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
|
|
|
|
|
|
- this._v2_1.x *= ( this.camera.right - this.camera.left ) * 0.5;
|
|
|
|
- this._v2_1.y *= ( this.camera.top - this.camera.bottom ) * 0.5;
|
|
|
|
- return this._v2_1.clone();
|
|
|
|
|
|
+ _v2_1.x *= ( this.camera.right - this.camera.left ) * 0.5;
|
|
|
|
+ _v2_1.y *= ( this.camera.top - this.camera.bottom ) * 0.5;
|
|
|
|
+ return _v2_1;
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
@@ -1918,7 +1932,7 @@
|
|
const self = this;
|
|
const self = this;
|
|
this._animationId = window.requestAnimationFrame( function ( t ) {
|
|
this._animationId = window.requestAnimationFrame( function ( t ) {
|
|
|
|
|
|
- self.onFocusAnim( t, point, cameraMatrix, gizmoMatrix.clone() );
|
|
|
|
|
|
+ self.onFocusAnim( t, point, cameraMatrix, gizmoMatrix );
|
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
@@ -1993,7 +2007,7 @@
|
|
|
|
|
|
this.pan = ( p0, p1, adjust = false ) => {
|
|
this.pan = ( p0, p1, adjust = false ) => {
|
|
|
|
|
|
- const movement = p0.clone().sub( p1 );
|
|
|
|
|
|
+ const movement = _movement.copy( p0 ).sub( p1 );
|
|
|
|
|
|
if ( this.camera.isOrthographicCamera ) {
|
|
if ( this.camera.isOrthographicCamera ) {
|
|
|
|
|
|
@@ -2003,22 +2017,22 @@
|
|
} else if ( this.camera.isPerspectiveCamera && adjust ) {
|
|
} else if ( this.camera.isPerspectiveCamera && adjust ) {
|
|
|
|
|
|
//adjust movement amount
|
|
//adjust movement amount
|
|
- this._v3_1.setFromMatrixPosition( this._cameraMatrixState0 ); //camera's initial position
|
|
|
|
|
|
+ _v3_1.setFromMatrixPosition( this._cameraMatrixState0 ); //camera's initial position
|
|
|
|
|
|
|
|
|
|
- this._v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ); //gizmo's initial position
|
|
|
|
|
|
+ _v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ); //gizmo's initial position
|
|
|
|
|
|
|
|
|
|
- const distanceFactor = this._v3_1.distanceTo( this._v3_2 ) / this.camera.position.distanceTo( this._gizmos.position );
|
|
|
|
|
|
+ const distanceFactor = _v3_1.distanceTo( _v3_2 ) / this.camera.position.distanceTo( this._gizmos.position );
|
|
movement.multiplyScalar( 1 / distanceFactor );
|
|
movement.multiplyScalar( 1 / distanceFactor );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- this._v3_1.set( movement.x, movement.y, 0 ).applyQuaternion( this.camera.quaternion );
|
|
|
|
|
|
+ _v3_1.set( movement.x, movement.y, 0 ).applyQuaternion( this.camera.quaternion );
|
|
|
|
|
|
- this._m4_1.makeTranslation( this._v3_1.x, this._v3_1.y, this._v3_1.z );
|
|
|
|
|
|
+ _m4_1.makeTranslation( _v3_1.x, _v3_1.y, _v3_1.z );
|
|
|
|
|
|
- this.setTransformationMatrices( this._m4_1, this._m4_1 );
|
|
|
|
|
|
+ this.setTransformationMatrices( _m4_1, _m4_1 );
|
|
return _transformation;
|
|
return _transformation;
|
|
|
|
|
|
};
|
|
};
|
|
@@ -2067,13 +2081,13 @@
|
|
this._rotationMatrix.makeRotationAxis( axis, - angle ); //rotate camera
|
|
this._rotationMatrix.makeRotationAxis( axis, - angle ); //rotate camera
|
|
|
|
|
|
|
|
|
|
- this._m4_1.makeTranslation( point.x, point.y, point.z );
|
|
|
|
|
|
+ _m4_1.makeTranslation( point.x, point.y, point.z );
|
|
|
|
|
|
- this._m4_1.multiply( this._rotationMatrix );
|
|
|
|
|
|
+ _m4_1.multiply( this._rotationMatrix );
|
|
|
|
|
|
- this._m4_1.multiply( this._translationMatrix );
|
|
|
|
|
|
+ _m4_1.multiply( this._translationMatrix );
|
|
|
|
|
|
- this.setTransformationMatrices( this._m4_1 );
|
|
|
|
|
|
+ this.setTransformationMatrices( _m4_1 );
|
|
return _transformation;
|
|
return _transformation;
|
|
|
|
|
|
};
|
|
};
|
|
@@ -2172,40 +2186,38 @@
|
|
|
|
|
|
this.camera.updateProjectionMatrix();
|
|
this.camera.updateProjectionMatrix();
|
|
|
|
|
|
- this._v3_1.setFromMatrixPosition( this._gizmoMatrixState ); //gizmos position
|
|
|
|
|
|
+ _v3_1.setFromMatrixPosition( this._gizmoMatrixState ); //gizmos position
|
|
//scale gizmos so they appear in the same spot having the same dimension
|
|
//scale gizmos so they appear in the same spot having the same dimension
|
|
|
|
|
|
|
|
|
|
this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
|
|
this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
|
|
|
|
|
|
- this._translationMatrix.makeTranslation( - this._v3_1.x, - this._v3_1.y, - this._v3_1.z );
|
|
|
|
|
|
+ this._translationMatrix.makeTranslation( - _v3_1.x, - _v3_1.y, - _v3_1.z );
|
|
|
|
|
|
- this._m4_2.makeTranslation( this._v3_1.x, this._v3_1.y, this._v3_1.z ).multiply( this._scaleMatrix );
|
|
|
|
|
|
+ _m4_2.makeTranslation( _v3_1.x, _v3_1.y, _v3_1.z ).multiply( this._scaleMatrix );
|
|
|
|
|
|
- this._m4_2.multiply( this._translationMatrix ); //move camera and gizmos to obtain pinch effect
|
|
|
|
|
|
+ _m4_2.multiply( this._translationMatrix ); //move camera and gizmos to obtain pinch effect
|
|
|
|
|
|
|
|
|
|
- _scalePointTemp.sub( this._v3_1 );
|
|
|
|
|
|
+ _scalePointTemp.sub( _v3_1 );
|
|
|
|
|
|
- const amount = _scalePointTemp.clone().multiplyScalar( sizeInverse );
|
|
|
|
|
|
+ _scalePointTemp.multiplyScalar( 1 - sizeInverse );
|
|
|
|
|
|
- _scalePointTemp.sub( amount );
|
|
|
|
|
|
+ _m4_1.makeTranslation( _scalePointTemp.x, _scalePointTemp.y, _scalePointTemp.z );
|
|
|
|
|
|
- this._m4_1.makeTranslation( _scalePointTemp.x, _scalePointTemp.y, _scalePointTemp.z );
|
|
|
|
|
|
+ _m4_2.premultiply( _m4_1 );
|
|
|
|
|
|
- this._m4_2.premultiply( this._m4_1 );
|
|
|
|
-
|
|
|
|
- this.setTransformationMatrices( this._m4_1, this._m4_2 );
|
|
|
|
|
|
+ this.setTransformationMatrices( _m4_1, _m4_2 );
|
|
return _transformation;
|
|
return _transformation;
|
|
|
|
|
|
} else if ( this.camera.isPerspectiveCamera ) {
|
|
} else if ( this.camera.isPerspectiveCamera ) {
|
|
|
|
|
|
- this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
|
|
|
|
|
|
+ _v3_1.setFromMatrixPosition( this._cameraMatrixState );
|
|
|
|
|
|
- this._v3_2.setFromMatrixPosition( this._gizmoMatrixState ); //move camera
|
|
|
|
|
|
+ _v3_2.setFromMatrixPosition( this._gizmoMatrixState ); //move camera
|
|
|
|
|
|
|
|
|
|
- let distance = this._v3_1.distanceTo( _scalePointTemp );
|
|
|
|
|
|
+ let distance = _v3_1.distanceTo( _scalePointTemp );
|
|
|
|
|
|
let amount = distance - distance * sizeInverse; //check min and max distance
|
|
let amount = distance - distance * sizeInverse; //check min and max distance
|
|
|
|
|
|
@@ -2223,36 +2235,36 @@
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- _offset.copy( _scalePointTemp ).sub( this._v3_1 ).normalize().multiplyScalar( amount );
|
|
|
|
|
|
+ _offset.copy( _scalePointTemp ).sub( _v3_1 ).normalize().multiplyScalar( amount );
|
|
|
|
|
|
- this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
|
|
|
|
|
|
+ _m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
|
|
|
|
|
|
if ( scaleGizmos ) {
|
|
if ( scaleGizmos ) {
|
|
|
|
|
|
//scale gizmos so they appear in the same spot having the same dimension
|
|
//scale gizmos so they appear in the same spot having the same dimension
|
|
- const pos = this._v3_2;
|
|
|
|
|
|
+ const pos = _v3_2;
|
|
distance = pos.distanceTo( _scalePointTemp );
|
|
distance = pos.distanceTo( _scalePointTemp );
|
|
amount = distance - distance * sizeInverse;
|
|
amount = distance - distance * sizeInverse;
|
|
|
|
|
|
- _offset.copy( _scalePointTemp ).sub( this._v3_2 ).normalize().multiplyScalar( amount );
|
|
|
|
|
|
+ _offset.copy( _scalePointTemp ).sub( _v3_2 ).normalize().multiplyScalar( amount );
|
|
|
|
|
|
this._translationMatrix.makeTranslation( pos.x, pos.y, pos.z );
|
|
this._translationMatrix.makeTranslation( pos.x, pos.y, pos.z );
|
|
|
|
|
|
this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
|
|
this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
|
|
|
|
|
|
- this._m4_2.makeTranslation( _offset.x, _offset.y, _offset.z ).multiply( this._translationMatrix );
|
|
|
|
|
|
+ _m4_2.makeTranslation( _offset.x, _offset.y, _offset.z ).multiply( this._translationMatrix );
|
|
|
|
|
|
- this._m4_2.multiply( this._scaleMatrix );
|
|
|
|
|
|
+ _m4_2.multiply( this._scaleMatrix );
|
|
|
|
|
|
this._translationMatrix.makeTranslation( - pos.x, - pos.y, - pos.z );
|
|
this._translationMatrix.makeTranslation( - pos.x, - pos.y, - pos.z );
|
|
|
|
|
|
- this._m4_2.multiply( this._translationMatrix );
|
|
|
|
|
|
+ _m4_2.multiply( this._translationMatrix );
|
|
|
|
|
|
- this.setTransformationMatrices( this._m4_1, this._m4_2 );
|
|
|
|
|
|
+ this.setTransformationMatrices( _m4_1, _m4_2 );
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- this.setTransformationMatrices( this._m4_1 );
|
|
|
|
|
|
+ this.setTransformationMatrices( _m4_1 );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2279,23 +2291,23 @@
|
|
|
|
|
|
this._translationMatrix.makeTranslation( - point.x, - point.y, - point.z );
|
|
this._translationMatrix.makeTranslation( - point.x, - point.y, - point.z );
|
|
|
|
|
|
- this._m4_1.makeTranslation( point.x, point.y, point.z );
|
|
|
|
|
|
+ _m4_1.makeTranslation( point.x, point.y, point.z );
|
|
|
|
|
|
- this._m4_1.multiply( this._rotationMatrix );
|
|
|
|
|
|
+ _m4_1.multiply( this._rotationMatrix );
|
|
|
|
|
|
- this._m4_1.multiply( this._translationMatrix );
|
|
|
|
|
|
+ _m4_1.multiply( this._translationMatrix );
|
|
|
|
|
|
- this._v3_1.setFromMatrixPosition( this._gizmoMatrixState ).sub( point ); //vector from rotation center to gizmos position
|
|
|
|
|
|
+ _v3_1.setFromMatrixPosition( this._gizmoMatrixState ).sub( point ); //vector from rotation center to gizmos position
|
|
|
|
|
|
|
|
|
|
- this._v3_2.copy( this._v3_1 ).applyAxisAngle( this._rotationAxis, angle ); //apply rotation
|
|
|
|
|
|
+ _v3_2.copy( _v3_1 ).applyAxisAngle( this._rotationAxis, angle ); //apply rotation
|
|
|
|
|
|
|
|
|
|
- this._v3_2.sub( this._v3_1 );
|
|
|
|
|
|
+ _v3_2.sub( _v3_1 );
|
|
|
|
|
|
- this._m4_2.makeTranslation( this._v3_2.x, this._v3_2.y, this._v3_2.z );
|
|
|
|
|
|
+ _m4_2.makeTranslation( _v3_2.x, _v3_2.y, _v3_2.z );
|
|
|
|
|
|
- this.setTransformationMatrices( this._m4_1, this._m4_2 );
|
|
|
|
|
|
+ this.setTransformationMatrices( _m4_1, _m4_2 );
|
|
return _transformation;
|
|
return _transformation;
|
|
|
|
|
|
};
|
|
};
|
|
@@ -2312,7 +2324,7 @@
|
|
|
|
|
|
if ( intersect[ i ].object.uuid != this._gizmos.uuid && intersect[ i ].face != null ) {
|
|
if ( intersect[ i ].object.uuid != this._gizmos.uuid && intersect[ i ].face != null ) {
|
|
|
|
|
|
- return intersect[ i ].point.clone();
|
|
|
|
|
|
+ return intersect[ i ].point;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2326,38 +2338,38 @@
|
|
|
|
|
|
if ( camera.type == 'OrthographicCamera' ) {
|
|
if ( camera.type == 'OrthographicCamera' ) {
|
|
|
|
|
|
- this._v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
|
|
|
|
|
|
+ _v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
|
|
|
|
|
|
- this._v3_1.set( this._v2_1.x, this._v2_1.y, 0 );
|
|
|
|
|
|
+ _v3_1.set( _v2_1.x, _v2_1.y, 0 );
|
|
|
|
|
|
- const x2 = Math.pow( this._v2_1.x, 2 );
|
|
|
|
- const y2 = Math.pow( this._v2_1.y, 2 );
|
|
|
|
|
|
+ const x2 = Math.pow( _v2_1.x, 2 );
|
|
|
|
+ const y2 = Math.pow( _v2_1.y, 2 );
|
|
const r2 = Math.pow( this._tbRadius, 2 );
|
|
const r2 = Math.pow( this._tbRadius, 2 );
|
|
|
|
|
|
if ( x2 + y2 <= r2 * 0.5 ) {
|
|
if ( x2 + y2 <= r2 * 0.5 ) {
|
|
|
|
|
|
//intersection with sphere
|
|
//intersection with sphere
|
|
- this._v3_1.setZ( Math.sqrt( r2 - ( x2 + y2 ) ) );
|
|
|
|
|
|
+ _v3_1.setZ( Math.sqrt( r2 - ( x2 + y2 ) ) );
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
//intersection with hyperboloid
|
|
//intersection with hyperboloid
|
|
- this._v3_1.setZ( r2 * 0.5 / Math.sqrt( x2 + y2 ) );
|
|
|
|
|
|
+ _v3_1.setZ( r2 * 0.5 / Math.sqrt( x2 + y2 ) );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- return this._v3_1;
|
|
|
|
|
|
+ return _v3_1;
|
|
|
|
|
|
} else if ( camera.type == 'PerspectiveCamera' ) {
|
|
} else if ( camera.type == 'PerspectiveCamera' ) {
|
|
|
|
|
|
//unproject cursor on the near plane
|
|
//unproject cursor on the near plane
|
|
- this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
|
|
|
|
|
|
+ _v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
|
|
|
|
|
|
- this._v3_1.set( this._v2_1.x, this._v2_1.y, - 1 );
|
|
|
|
|
|
+ _v3_1.set( _v2_1.x, _v2_1.y, - 1 );
|
|
|
|
|
|
- this._v3_1.applyMatrix4( camera.projectionMatrixInverse );
|
|
|
|
|
|
+ _v3_1.applyMatrix4( camera.projectionMatrixInverse );
|
|
|
|
|
|
- const rayDir = this._v3_1.clone().normalize(); //unprojected ray direction
|
|
|
|
|
|
+ const rayDir = _v3_2.copy( _v3_1 ).normalize(); //unprojected ray direction
|
|
|
|
|
|
|
|
|
|
const cameraGizmoDistance = camera.position.distanceTo( this._gizmos.position );
|
|
const cameraGizmoDistance = camera.position.distanceTo( this._gizmos.position );
|
|
@@ -2371,13 +2383,13 @@
|
|
// _ _ | _ _ _\ _ _ near plane
|
|
// _ _ | _ _ _\ _ _ near plane
|
|
// l
|
|
// l
|
|
|
|
|
|
- const h = this._v3_1.z;
|
|
|
|
- const l = Math.sqrt( Math.pow( this._v3_1.x, 2 ) + Math.pow( this._v3_1.y, 2 ) );
|
|
|
|
|
|
+ const h = _v3_1.z;
|
|
|
|
+ const l = Math.sqrt( Math.pow( _v3_1.x, 2 ) + Math.pow( _v3_1.y, 2 ) );
|
|
|
|
|
|
if ( l == 0 ) {
|
|
if ( l == 0 ) {
|
|
|
|
|
|
//ray aligned with camera
|
|
//ray aligned with camera
|
|
- rayDir.set( this._v3_1.x, this._v3_1.y, tbRadius );
|
|
|
|
|
|
+ rayDir.set( _v3_1.x, _v3_1.y, tbRadius );
|
|
return rayDir;
|
|
return rayDir;
|
|
|
|
|
|
}
|
|
}
|
|
@@ -2400,17 +2412,17 @@
|
|
if ( delta >= 0 ) {
|
|
if ( delta >= 0 ) {
|
|
|
|
|
|
//intersection with sphere
|
|
//intersection with sphere
|
|
- this._v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
|
|
|
|
|
|
+ _v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
|
|
|
|
|
|
- this._v2_1.setY( m * this._v2_1.x + q );
|
|
|
|
|
|
+ _v2_1.setY( m * _v2_1.x + q );
|
|
|
|
|
|
- const angle = THREE.MathUtils.RAD2DEG * this._v2_1.angle();
|
|
|
|
|
|
+ const angle = THREE.MathUtils.RAD2DEG * _v2_1.angle();
|
|
|
|
|
|
if ( angle >= 45 ) {
|
|
if ( angle >= 45 ) {
|
|
|
|
|
|
//if angle between intersection point and X' axis is >= 45°, return that point
|
|
//if angle between intersection point and X' axis is >= 45°, return that point
|
|
//otherwise, calculate intersection point with hyperboloid
|
|
//otherwise, calculate intersection point with hyperboloid
|
|
- const rayLength = Math.sqrt( Math.pow( this._v2_1.x, 2 ) + Math.pow( cameraGizmoDistance - this._v2_1.y, 2 ) );
|
|
|
|
|
|
+ const rayLength = Math.sqrt( Math.pow( _v2_1.x, 2 ) + Math.pow( cameraGizmoDistance - _v2_1.y, 2 ) );
|
|
rayDir.multiplyScalar( rayLength );
|
|
rayDir.multiplyScalar( rayLength );
|
|
rayDir.z += cameraGizmoDistance;
|
|
rayDir.z += cameraGizmoDistance;
|
|
return rayDir;
|
|
return rayDir;
|
|
@@ -2432,11 +2444,11 @@
|
|
c = - radius2 * 0.5;
|
|
c = - radius2 * 0.5;
|
|
delta = Math.pow( b, 2 ) - 4 * a * c;
|
|
delta = Math.pow( b, 2 ) - 4 * a * c;
|
|
|
|
|
|
- this._v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
|
|
|
|
|
|
+ _v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
|
|
|
|
|
|
- this._v2_1.setY( m * this._v2_1.x + q );
|
|
|
|
|
|
+ _v2_1.setY( m * _v2_1.x + q );
|
|
|
|
|
|
- const rayLength = Math.sqrt( Math.pow( this._v2_1.x, 2 ) + Math.pow( cameraGizmoDistance - this._v2_1.y, 2 ) );
|
|
|
|
|
|
+ const rayLength = Math.sqrt( Math.pow( _v2_1.x, 2 ) + Math.pow( cameraGizmoDistance - _v2_1.y, 2 ) );
|
|
rayDir.multiplyScalar( rayLength );
|
|
rayDir.multiplyScalar( rayLength );
|
|
rayDir.z += cameraGizmoDistance;
|
|
rayDir.z += cameraGizmoDistance;
|
|
return rayDir;
|
|
return rayDir;
|
|
@@ -2449,22 +2461,22 @@
|
|
|
|
|
|
if ( camera.type == 'OrthographicCamera' ) {
|
|
if ( camera.type == 'OrthographicCamera' ) {
|
|
|
|
|
|
- this._v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
|
|
|
|
|
|
+ _v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
|
|
|
|
|
|
- this._v3_1.set( this._v2_1.x, this._v2_1.y, 0 );
|
|
|
|
|
|
+ _v3_1.set( _v2_1.x, _v2_1.y, 0 );
|
|
|
|
|
|
- return this._v3_1.clone();
|
|
|
|
|
|
+ return _v3_1;
|
|
|
|
|
|
} else if ( camera.type == 'PerspectiveCamera' ) {
|
|
} else if ( camera.type == 'PerspectiveCamera' ) {
|
|
|
|
|
|
- this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) ); //unproject cursor on the near plane
|
|
|
|
|
|
+ _v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) ); //unproject cursor on the near plane
|
|
|
|
|
|
|
|
|
|
- this._v3_1.set( this._v2_1.x, this._v2_1.y, - 1 );
|
|
|
|
|
|
+ _v3_1.set( _v2_1.x, _v2_1.y, - 1 );
|
|
|
|
|
|
- this._v3_1.applyMatrix4( camera.projectionMatrixInverse );
|
|
|
|
|
|
+ _v3_1.applyMatrix4( camera.projectionMatrixInverse );
|
|
|
|
|
|
- const rayDir = this._v3_1.clone().normalize(); //unprojected ray direction
|
|
|
|
|
|
+ const rayDir = _v3_2.copy( _v3_1 ).normalize(); //unprojected ray direction
|
|
// camera
|
|
// camera
|
|
// |\
|
|
// |\
|
|
// | \
|
|
// | \
|
|
@@ -2476,13 +2488,13 @@
|
|
// l
|
|
// l
|
|
|
|
|
|
|
|
|
|
- const h = this._v3_1.z;
|
|
|
|
- const l = Math.sqrt( Math.pow( this._v3_1.x, 2 ) + Math.pow( this._v3_1.y, 2 ) );
|
|
|
|
|
|
+ const h = _v3_1.z;
|
|
|
|
+ const l = Math.sqrt( Math.pow( _v3_1.x, 2 ) + Math.pow( _v3_1.y, 2 ) );
|
|
let cameraGizmoDistance;
|
|
let cameraGizmoDistance;
|
|
|
|
|
|
if ( initialDistance ) {
|
|
if ( initialDistance ) {
|
|
|
|
|
|
- cameraGizmoDistance = this._v3_1.setFromMatrixPosition( this._cameraMatrixState0 ).distanceTo( this._v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ) );
|
|
|
|
|
|
+ cameraGizmoDistance = _v3_1.setFromMatrixPosition( this._cameraMatrixState0 ).distanceTo( _v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ) );
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
@@ -2676,14 +2688,7 @@
|
|
this._currentTarget = new THREE.Vector3();
|
|
this._currentTarget = new THREE.Vector3();
|
|
this.radiusFactor = 0.67;
|
|
this.radiusFactor = 0.67;
|
|
this.mouseActions = [];
|
|
this.mouseActions = [];
|
|
- this._mouseOp = null; //global vectors and matrices that are used in some operations to avoid creating new objects every time (e.g. every time cursor moves)
|
|
|
|
-
|
|
|
|
- this._v2_1 = new THREE.Vector2();
|
|
|
|
- this._v3_1 = new THREE.Vector3();
|
|
|
|
- this._v3_2 = new THREE.Vector3();
|
|
|
|
- this._m4_1 = new THREE.Matrix4();
|
|
|
|
- this._m4_2 = new THREE.Matrix4();
|
|
|
|
- this._quat = new THREE.Quaternion(); //transformation matrices
|
|
|
|
|
|
+ this._mouseOp = null; //transformation matrices
|
|
|
|
|
|
this._translationMatrix = new THREE.Matrix4(); //matrix for translation operation
|
|
this._translationMatrix = new THREE.Matrix4(); //matrix for translation operation
|
|
|
|
|
|
@@ -2829,9 +2834,9 @@
|
|
|
|
|
|
if ( transformation.camera != null ) {
|
|
if ( transformation.camera != null ) {
|
|
|
|
|
|
- this._m4_1.copy( this._cameraMatrixState ).premultiply( transformation.camera );
|
|
|
|
|
|
+ _m4_1.copy( this._cameraMatrixState ).premultiply( transformation.camera );
|
|
|
|
|
|
- this._m4_1.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
|
|
|
|
|
|
+ _m4_1.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
|
|
|
|
|
|
this.camera.updateMatrix(); //update camera up vector
|
|
this.camera.updateMatrix(); //update camera up vector
|
|
|
|
|
|
@@ -2845,9 +2850,9 @@
|
|
|
|
|
|
if ( transformation.gizmos != null ) {
|
|
if ( transformation.gizmos != null ) {
|
|
|
|
|
|
- this._m4_1.copy( this._gizmoMatrixState ).premultiply( transformation.gizmos );
|
|
|
|
|
|
+ _m4_1.copy( this._gizmoMatrixState ).premultiply( transformation.gizmos );
|
|
|
|
|
|
- this._m4_1.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
|
|
|
|
|
|
+ _m4_1.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
|
|
|
|
|
|
this._gizmos.updateMatrix();
|
|
this._gizmos.updateMatrix();
|
|
|
|
|
|
@@ -2967,7 +2972,7 @@
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- _transformation.camera = camera.clone();
|
|
|
|
|
|
+ _transformation.camera = camera;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2985,7 +2990,7 @@
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- _transformation.gizmos = gizmos.clone();
|
|
|
|
|
|
+ _transformation.gizmos = gizmos;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|