Skip to content

Commit

Permalink
Merge pull request #698 from agargaro/getScaleVector
Browse files Browse the repository at this point in the history
Replace `extractMatrixScale` with `Vector3.setFromMatrixScale`
  • Loading branch information
gkjohnson authored Aug 26, 2024
2 parents bd391f2 + d12e372 commit 00b2210
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions src/utils/ExtensionUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function acceleratedMeshRaycast( raycaster, intersects ) {
tmpInverseMatrix.copy( this.matrixWorld ).invert();
ray.copy( raycaster.ray ).applyMatrix4( tmpInverseMatrix );

extractMatrixScale( this.matrixWorld, _worldScale );
_worldScale.setFromMatrixScale( this.matrixWorld );
direction.copy( ray.direction ).multiply( _worldScale );

const scaleFactor = direction.length();
Expand Down Expand Up @@ -206,15 +206,3 @@ export function disposeBoundsTree() {
}

}

// https://github.com/mrdoob/three.js/blob/dev/src/math/Matrix4.js#L732
// extracting the scale directly is ~3x faster than using "decompose"
function extractMatrixScale( matrix, target ) {

const te = matrix.elements;
const sx = target.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
const sy = target.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
const sz = target.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
return target.set( sx, sy, sz );

}

0 comments on commit 00b2210

Please sign in to comment.