|
44 | 44 | const _raycaster = new THREE.Raycaster(); |
45 | 45 |
|
46 | 46 | const _offset = new THREE.Vector3(); |
| 47 | + |
| 48 | + const _gizmoMatrixStateTemp = new THREE.Matrix4(); |
| 49 | + |
| 50 | + const _cameraMatrixStateTemp = new THREE.Matrix4(); |
| 51 | + |
| 52 | + const _scalePointTemp = new THREE.Vector3(); |
47 | 53 | /** |
48 | 54 | * |
49 | 55 | * @param {Camera} camera Virtual camera used in the scene |
|
567 | 573 |
|
568 | 574 | }; |
569 | 575 |
|
570 | | - this.onKeyDown = event => { |
571 | | - |
572 | | - if ( event.key == 'c' ) { |
573 | | - |
574 | | - if ( event.ctrlKey || event.metaKey ) { |
575 | | - |
576 | | - this.copyState(); |
577 | | - |
578 | | - } |
579 | | - |
580 | | - } else if ( event.key == 'v' ) { |
581 | | - |
582 | | - if ( event.ctrlKey || event.metaKey ) { |
583 | | - |
584 | | - this.pasteState(); |
585 | | - |
586 | | - } |
587 | | - |
588 | | - } |
589 | | - |
590 | | - }; |
591 | | - |
592 | 576 | this.onSinglePanStart = ( event, operation ) => { |
593 | 577 |
|
594 | 578 | if ( this.enabled ) { |
|
1621 | 1605 |
|
1622 | 1606 | this._translationMatrix.makeTranslation( _offset.x, _offset.y, _offset.z ); |
1623 | 1607 |
|
1624 | | - const gizmoStateTemp = this._gizmoMatrixState.clone(); |
| 1608 | + _gizmoMatrixStateTemp.copy( this._gizmoMatrixState ); |
1625 | 1609 |
|
1626 | 1610 | this._gizmoMatrixState.premultiply( this._translationMatrix ); |
1627 | 1611 |
|
1628 | 1612 | this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale ); |
1629 | 1613 |
|
1630 | | - const cameraStateTemp = this._cameraMatrixState.clone(); |
| 1614 | + _cameraMatrixStateTemp.copy( this._cameraMatrixState ); |
1631 | 1615 |
|
1632 | 1616 | this._cameraMatrixState.premultiply( this._translationMatrix ); |
1633 | 1617 |
|
|
1640 | 1624 |
|
1641 | 1625 | } |
1642 | 1626 |
|
1643 | | - this._gizmoMatrixState.copy( gizmoStateTemp ); |
| 1627 | + this._gizmoMatrixState.copy( _gizmoMatrixStateTemp ); |
1644 | 1628 |
|
1645 | | - this._cameraMatrixState.copy( cameraStateTemp ); |
| 1629 | + this._cameraMatrixState.copy( _cameraMatrixStateTemp ); |
1646 | 1630 |
|
1647 | 1631 | }; |
1648 | 1632 |
|
|
2163 | 2147 |
|
2164 | 2148 | this.scale = ( size, point, scaleGizmos = true ) => { |
2165 | 2149 |
|
2166 | | - const scalePoint = point.clone(); |
| 2150 | + _scalePointTemp.copy( point ); |
| 2151 | + |
2167 | 2152 | let sizeInverse = 1 / size; |
2168 | 2153 |
|
2169 | 2154 | if ( this.camera.isOrthographicCamera ) { |
|
2199 | 2184 | this._m4_2.multiply( this._translationMatrix ); //move camera and gizmos to obtain pinch effect |
2200 | 2185 |
|
2201 | 2186 |
|
2202 | | - scalePoint.sub( this._v3_1 ); |
2203 | | - const amount = scalePoint.clone().multiplyScalar( sizeInverse ); |
2204 | | - scalePoint.sub( amount ); |
| 2187 | + _scalePointTemp.sub( this._v3_1 ); |
| 2188 | + |
| 2189 | + const amount = _scalePointTemp.clone().multiplyScalar( sizeInverse ); |
| 2190 | + |
| 2191 | + _scalePointTemp.sub( amount ); |
2205 | 2192 |
|
2206 | | - this._m4_1.makeTranslation( scalePoint.x, scalePoint.y, scalePoint.z ); |
| 2193 | + this._m4_1.makeTranslation( _scalePointTemp.x, _scalePointTemp.y, _scalePointTemp.z ); |
2207 | 2194 |
|
2208 | 2195 | this._m4_2.premultiply( this._m4_1 ); |
2209 | 2196 |
|
|
2217 | 2204 | this._v3_2.setFromMatrixPosition( this._gizmoMatrixState ); //move camera |
2218 | 2205 |
|
2219 | 2206 |
|
2220 | | - let distance = this._v3_1.distanceTo( scalePoint ); |
| 2207 | + let distance = this._v3_1.distanceTo( _scalePointTemp ); |
2221 | 2208 |
|
2222 | 2209 | let amount = distance - distance * sizeInverse; //check min and max distance |
2223 | 2210 |
|
|
2235 | 2222 |
|
2236 | 2223 | } |
2237 | 2224 |
|
2238 | | - _offset.copy( scalePoint ).sub( this._v3_1 ).normalize().multiplyScalar( amount ); |
| 2225 | + _offset.copy( _scalePointTemp ).sub( this._v3_1 ).normalize().multiplyScalar( amount ); |
2239 | 2226 |
|
2240 | 2227 | this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z ); |
2241 | 2228 |
|
2242 | 2229 | if ( scaleGizmos ) { |
2243 | 2230 |
|
2244 | 2231 | //scale gizmos so they appear in the same spot having the same dimension |
2245 | 2232 | const pos = this._v3_2; |
2246 | | - distance = pos.distanceTo( scalePoint ); |
| 2233 | + distance = pos.distanceTo( _scalePointTemp ); |
2247 | 2234 | amount = distance - distance * sizeInverse; |
2248 | 2235 |
|
2249 | | - _offset.copy( scalePoint ).sub( this._v3_2 ).normalize().multiplyScalar( amount ); |
| 2236 | + _offset.copy( _scalePointTemp ).sub( this._v3_2 ).normalize().multiplyScalar( amount ); |
2250 | 2237 |
|
2251 | 2238 | this._translationMatrix.makeTranslation( pos.x, pos.y, pos.z ); |
2252 | 2239 |
|
|
2827 | 2814 | this.domElement.addEventListener( 'wheel', this.onWheel ); |
2828 | 2815 | this.domElement.addEventListener( 'pointerdown', this.onPointerDown ); |
2829 | 2816 | this.domElement.addEventListener( 'pointercancel', this.onPointerCancel ); |
2830 | | - window.addEventListener( 'keydown', this.onKeyDown ); |
2831 | 2817 | window.addEventListener( 'resize', this.onWindowResize ); |
2832 | 2818 |
|
2833 | 2819 | } //listeners |
|
0 commit comments