Skip to content

Commit a7d80a0

Browse files
authored
Merge pull request #15996 from WestLangley/dev-unproject
Vector3.unproject(): Avoid computing inverse
2 parents e185122 + 89c39cc commit a7d80a0

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

src/helpers/CameraHelper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ CameraHelper.prototype.update = function () {
158158

159159
var w = 1, h = 1;
160160

161-
// we need just camera projection matrix
161+
// we need just camera projection matrix inverse
162162
// world matrix must be identity
163163

164-
camera.projectionMatrix.copy( this.camera.projectionMatrix );
164+
camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
165165

166166
// center / target
167167

src/math/Vector3.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { _Math } from './Math.js';
2-
import { Matrix4 } from './Matrix4.js';
32
import { Quaternion } from './Quaternion.js';
43

54
/**
@@ -318,17 +317,11 @@ Object.assign( Vector3.prototype, {
318317

319318
},
320319

321-
unproject: function () {
320+
unproject: function ( camera ) {
322321

323-
var matrix = new Matrix4();
322+
return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
324323

325-
return function unproject( camera ) {
326-
327-
return this.applyMatrix4( matrix.getInverse( camera.projectionMatrix ) ).applyMatrix4( camera.matrixWorld );
328-
329-
};
330-
331-
}(),
324+
},
332325

333326
transformDirection: function ( m ) {
334327

0 commit comments

Comments
 (0)