Skip to content

Commit e314cb0

Browse files
committed
Changed some of the matrix.getPosition() to vector.getPositionFromMatrix( matrix ). See mrdoob#2967.
1 parent 0a9132d commit e314cb0

8 files changed

Lines changed: 48 additions & 42 deletions

File tree

examples/js/AudioObject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ THREE.AudioObject = function ( url, volume, playbackRate, loop ) {
110110
oldSoundPosition.copy( soundPosition );
111111
oldCameraPosition.copy( cameraPosition );
112112

113-
soundPosition.copy( this.matrixWorld.getPosition() );
114-
cameraPosition.copy( camera.matrixWorld.getPosition() );
113+
soundPosition.getPositionFromMatrix( this.matrixWorld );
114+
cameraPosition.getPositionFromMatrix( camera.matrixWorld );
115115

116116
soundDelta.subVectors( soundPosition, oldSoundPosition );
117117
cameraDelta.subVectors( cameraPosition, oldCameraPosition );

examples/js/renderers/SVGRenderer.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,16 @@ THREE.SVGRenderer = function () {
230230

231231
function calculateLight( lights, position, normal, color ) {
232232

233-
var l, ll, light, lightColor, lightPosition, amount;
233+
for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
234234

235-
for ( l = 0, ll = lights.length; l < ll; l ++ ) {
236-
237-
light = lights[ l ];
238-
lightColor = light.color;
235+
var light = lights[ l ];
236+
var lightColor = light.color;
239237

240238
if ( light instanceof THREE.DirectionalLight ) {
241239

242-
lightPosition = light.matrixWorld.getPosition().normalize();
240+
var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld ).normalize();
243241

244-
amount = normal.dot( lightPosition );
242+
var amount = normal.dot( lightPosition );
245243

246244
if ( amount <= 0 ) continue;
247245

@@ -253,9 +251,9 @@ THREE.SVGRenderer = function () {
253251

254252
} else if ( light instanceof THREE.PointLight ) {
255253

256-
lightPosition = light.matrixWorld.getPosition();
254+
var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld );
257255

258-
amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() );
256+
var amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() );
259257

260258
if ( amount <= 0 ) continue;
261259

src/core/Projector.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ THREE.Projector = function () {
110110

111111
} else {
112112

113-
_vector3.copy( object.matrixWorld.getPosition() );
113+
_vector3.getPositionFromMatrix( object.matrixWorld );
114114
_vector3.applyProjection( _viewProjectionMatrix );
115115
_object.z = _vector3.z;
116116

@@ -133,7 +133,7 @@ THREE.Projector = function () {
133133

134134
} else {
135135

136-
_vector3.copy( object.matrixWorld.getPosition() );
136+
_vector3.getPositionFromMatrix.copy( object.matrixWorld );
137137
_vector3.applyProjection( _viewProjectionMatrix );
138138
_object.z = _vector3.z;
139139

@@ -152,7 +152,7 @@ THREE.Projector = function () {
152152

153153
} else {
154154

155-
_vector3.copy( object.matrixWorld.getPosition() );
155+
_vector3.getPositionFromMatrix( object.matrixWorld );
156156
_vector3.applyProjection( _viewProjectionMatrix );
157157
_object.z = _vector3.z;
158158

src/core/Raycaster.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
// Checking boundingSphere distance to ray
6161
sphere.set(
6262
object.matrixWorld.getPosition(),
63-
object.geometry.boundingSphere.radius* object.matrixWorld.getMaxScaleOnAxis() );
63+
object.geometry.boundingSphere.radius * object.matrixWorld.getMaxScaleOnAxis() );
6464

6565
if ( ! raycaster.ray.isIntersectionSphere( sphere ) ) {
6666

@@ -86,22 +86,22 @@
8686
inverseMatrix.getInverse( object.matrixWorld );
8787

8888
localRay.copy( raycaster.ray ).transform( inverseMatrix );
89-
89+
9090
for ( var f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
9191

9292
var face = geometry.faces[ f ];
9393

9494
var material = isFaceMaterial === true ? objectMaterials[ face.materialIndex ] : object.material;
9595

9696
if ( material === undefined ) continue;
97-
97+
9898
facePlane.setFromNormalAndCoplanarPoint( face.normal, vertices[face.a] );
9999

100100
var planeDistance = localRay.distanceToPlane( facePlane );
101-
101+
102102
// bail if raycaster and plane are parallel
103103
if ( Math.abs( planeDistance ) < precision ) continue;
104-
104+
105105
// if negative distance, then plane is behind raycaster
106106
if ( planeDistance < 0 ) continue;
107107

@@ -117,7 +117,7 @@
117117

118118
// this can be done using the planeDistance from localRay because localRay wasn't normalized, but ray was
119119
if ( planeDistance < raycaster.near || planeDistance > raycaster.far ) continue;
120-
120+
121121
intersectPoint = localRay.at( planeDistance, intersectPoint ); // passing in intersectPoint avoids a copy
122122

123123
if ( face instanceof THREE.Face3 ) {

src/extras/renderers/plugins/ShadowMapPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ THREE.ShadowMapPlugin = function () {
196196
shadowMatrix = light.shadowMatrix;
197197
shadowCamera = light.shadowCamera;
198198

199-
shadowCamera.position.copy( light.matrixWorld.getPosition() );
199+
shadowCamera.position.getPositionFromMatrix( light.matrixWorld );
200200
shadowCamera.lookAt( light.target.matrixWorld.getPosition() );
201201
shadowCamera.updateMatrixWorld();
202202

src/math/Frustum.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,37 @@ THREE.extend( THREE.Frustum.prototype, {
7070

7171
},
7272

73-
intersectsObject: function ( object ) {
73+
intersectsObject: function () {
7474

75-
// this method is expanded inlined for performance reasons.
76-
var matrix = object.matrixWorld;
77-
var planes = this.planes;
78-
var center = matrix.getPosition();
79-
var negRadius = - object.geometry.boundingSphere.radius * matrix.getMaxScaleOnAxis();
75+
var center = new THREE.Vector3();
8076

81-
for ( var i = 0; i < 6; i ++ ) {
77+
return function ( object ) {
8278

83-
var distance = planes[ i ].distanceToPoint( center );
79+
// this method is expanded inlined for performance reasons.
8480

85-
if( distance < negRadius ) {
81+
var matrix = object.matrixWorld;
82+
var planes = this.planes;
83+
var negRadius = - object.geometry.boundingSphere.radius * matrix.getMaxScaleOnAxis();
8684

87-
return false;
85+
center.getPositionFromMatrix( matrix );
86+
87+
for ( var i = 0; i < 6; i ++ ) {
88+
89+
var distance = planes[ i ].distanceToPoint( center );
90+
91+
if ( distance < negRadius ) {
92+
93+
return false;
94+
95+
}
8896

8997
}
9098

91-
}
99+
return true;
92100

93-
return true;
101+
};
94102

95-
},
103+
}(),
96104

97105
intersectsSphere: function ( sphere ) {
98106

@@ -104,7 +112,7 @@ THREE.extend( THREE.Frustum.prototype, {
104112

105113
var distance = planes[ i ].distanceToPoint( center );
106114

107-
if( distance < negRadius ) {
115+
if ( distance < negRadius ) {
108116

109117
return false;
110118

@@ -122,7 +130,7 @@ THREE.extend( THREE.Frustum.prototype, {
122130

123131
for ( var i = 0; i < 6; i ++ ) {
124132

125-
if( planes[ i ].distanceToPoint( point ) < 0 ) {
133+
if ( planes[ i ].distanceToPoint( point ) < 0 ) {
126134

127135
return false;
128136

@@ -140,4 +148,4 @@ THREE.extend( THREE.Frustum.prototype, {
140148

141149
}
142150

143-
} );
151+
} );

src/math/Vector3.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ THREE.extend( THREE.Vector3.prototype, {
265265

266266
},
267267

268-
applyEuler: function() {
268+
applyEuler: function () {
269269

270270
var q1 = new THREE.Quaternion();
271271

@@ -281,7 +281,7 @@ THREE.extend( THREE.Vector3.prototype, {
281281

282282
}(),
283283

284-
applyAxisAngle: function() {
284+
applyAxisAngle: function () {
285285

286286
var q1 = new THREE.Quaternion();
287287

@@ -432,7 +432,7 @@ THREE.extend( THREE.Vector3.prototype, {
432432

433433
},
434434

435-
negate: function() {
435+
negate: function () {
436436

437437
return this.multiplyScalar( - 1 );
438438

src/renderers/CanvasRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ THREE.CanvasRenderer = function ( parameters ) {
436436

437437
if ( light instanceof THREE.DirectionalLight ) {
438438

439-
var lightPosition = light.matrixWorld.getPosition().normalize();
439+
var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld ).normalize();
440440

441441
var amount = normal.dot( lightPosition );
442442

@@ -448,7 +448,7 @@ THREE.CanvasRenderer = function ( parameters ) {
448448

449449
} else if ( light instanceof THREE.PointLight ) {
450450

451-
var lightPosition = light.matrixWorld.getPosition();
451+
var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld );
452452

453453
var amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() );
454454

0 commit comments

Comments
 (0)