Skip to content

Commit a16a9f6

Browse files
committed
complete Euler class, update examples, update Object3D, update unit tests.
1 parent 4ff0959 commit a16a9f6

16 files changed

Lines changed: 103 additions & 250 deletions

examples/css3d_molecules.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@
433433

434434
var objMatrix = new THREE.Matrix4().makeRotationAxis( axis.normalize(), radians );
435435
object.matrix = objMatrix;
436-
object.rotation.setEulerFromRotationMatrix( object.matrix, object.eulerOrder );
436+
object.rotation.setFromRotationMatrix( object.matrix, object.rotation.order );
437437

438438
object.matrixAutoUpdate = false;
439439
object.updateMatrix();
@@ -453,7 +453,7 @@
453453
joint.position.lerp( end, 0.5 );
454454

455455
joint.matrix.copy( objMatrix );
456-
joint.rotation.setEulerFromRotationMatrix( joint.matrix, joint.eulerOrder );
456+
joint.rotation.setFromRotationMatrix( joint.matrix, joint.rotation.order );
457457

458458
joint.matrixAutoUpdate = false;
459459
joint.updateMatrix();

examples/js/controls/FlyControls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ THREE.FlyControls = function ( object, domElement ) {
199199
this.object.quaternion.multiply( this.tmpQuaternion );
200200

201201
// expose the rotation vector for convenience
202-
this.object.rotation.setEulerFromQuaternion( this.object.quaternion, this.object.eulerOrder );
202+
this.object.rotation.setFromQuaternion( this.object.quaternion, this.object.rotation.order );
203203

204204

205205
};

examples/js/controls/TransformControls.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
379379

380380
this.object.updateMatrixWorld();
381381
worldPosition.getPositionFromMatrix( this.object.matrixWorld );
382-
worldRotation.setEulerFromRotationMatrix( tempMatrix.extractRotation(this.object.matrixWorld ));
382+
worldRotation.setFromRotationMatrix( tempMatrix.extractRotation(this.object.matrixWorld ));
383383

384384
this.camera.updateMatrixWorld();
385385
camPosition.getPositionFromMatrix( this.camera.matrixWorld );
386-
camRotation.setEulerFromRotationMatrix( tempMatrix.extractRotation( this.camera.matrixWorld ));
386+
camRotation.setFromRotationMatrix( tempMatrix.extractRotation( this.camera.matrixWorld ));
387387

388388
scale = worldPosition.distanceTo( camPosition ) / 6 * this.scale;
389389
this.gizmo.position.copy( worldPosition )
@@ -399,7 +399,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
399399
if ( name.search('E') != -1 ){
400400

401401
lookAtMatrix.lookAt( camPosition, worldPosition, tempVector.set( 0, 1, 0 ));
402-
object.rotation.setEulerFromRotationMatrix( lookAtMatrix );
402+
object.rotation.setFromRotationMatrix( lookAtMatrix );
403403

404404
} else {
405405

@@ -431,7 +431,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
431431

432432
}
433433

434-
object.rotation.setEulerFromQuaternion( tempQuaternion );
434+
object.rotation.setFromQuaternion( tempQuaternion );
435435

436436
} else if ( this.space == 'world' ) {
437437

@@ -789,7 +789,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
789789
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionE );
790790
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
791791

792-
scope.object.rotation.setEulerFromQuaternion( tempQuaternion );
792+
scope.object.rotation.setFromQuaternion( tempQuaternion );
793793

794794
} else if ( scope.active == "RXYZE" ) {
795795

@@ -802,7 +802,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
802802
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
803803
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
804804

805-
scope.object.rotation.setEulerFromQuaternion( tempQuaternion );
805+
scope.object.rotation.setFromQuaternion( tempQuaternion );
806806

807807
} else if ( scope.space == 'local' ) {
808808

@@ -822,7 +822,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
822822
if ( scope.active == "RY" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionY );
823823
if ( scope.active == "RZ" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionZ );
824824

825-
scope.object.rotation.setEulerFromQuaternion( quaternionXYZ );
825+
scope.object.rotation.setFromQuaternion( quaternionXYZ );
826826

827827
} else if ( scope.space == 'world' ) {
828828

@@ -842,7 +842,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
842842

843843
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
844844

845-
scope.object.rotation.setEulerFromQuaternion( tempQuaternion );
845+
scope.object.rotation.setFromQuaternion( tempQuaternion );
846846

847847
}
848848

examples/webgl_geometry_extrude_splines.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@
380380
if (!lookAhead)
381381
lookAt.copy( pos ).add( dir );
382382
splineCamera.matrix.lookAt(splineCamera.position, lookAt, normal);
383-
splineCamera.rotation.setEulerFromRotationMatrix( splineCamera.matrix, splineCamera.eulerOrder );
383+
splineCamera.rotation.setFromRotationMatrix( splineCamera.matrix, splineCamera.rotation.order );
384384

385385
cameraHelper.update();
386386

examples/webgl_multiple_windows.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
dst.up.copy( src.up );
193193
dst.position.copy( src.position );
194194
dst.scale.copy( src.scale );
195-
dst.eulerOrder = src.eulerOrder;
195+
dst.rotation.copy( src.rotation );
196196
dst.quaternion.copy( src.quaternion );
197197

198198
};

src/cameras/Camera.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ THREE.Camera.prototype.lookAt = function () {
3333

3434
} else {
3535

36-
this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder );
36+
this.rotation.setFromRotationMatrix( m1, this.rotation.Order );
3737

3838
}
3939

src/core/Object3D.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ THREE.Object3D = function () {
1717
this.up = new THREE.Vector3( 0, 1, 0 );
1818

1919
this.position = new THREE.Vector3();
20-
this.rotation = new THREE.Vector3();
21-
this.eulerOrder = THREE.Object3D.defaultEulerOrder;
20+
this.rotation = new THREE.Euler();
2221
this.scale = new THREE.Vector3( 1, 1, 1 );
2322

2423
this.renderDepth = null;
@@ -75,7 +74,7 @@ THREE.Object3D.prototype = {
7574

7675
} else {
7776

78-
this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder );
77+
this.rotation.setFromRotationMatrix( m1, this.rotation.order );
7978

8079
}
8180

@@ -101,10 +100,10 @@ THREE.Object3D.prototype = {
101100

102101
} else {
103102

104-
q2.setFromEuler( this.rotation, this.eulerOrder );
103+
q2.setFromEuler( this.rotation );
105104
q2.multiply( q1 );
106105

107-
this.rotation.setEulerFromQuaternion( q2, this.eulerOrder );
106+
this.rotation.setFromQuaternion( q2, this.rotation.order );
108107

109108
}
110109

@@ -131,7 +130,7 @@ THREE.Object3D.prototype = {
131130

132131
} else {
133132

134-
v1.applyEuler( this.rotation, this.eulerOrder );
133+
v1.applyEuler( this.rotation );
135134

136135
}
137136

@@ -220,7 +219,7 @@ THREE.Object3D.prototype = {
220219

221220
} else {
222221

223-
this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder );
222+
this.rotation.setFromRotationMatrix( m1, this.rotation.order );
224223

225224
}
226225

@@ -398,7 +397,7 @@ THREE.Object3D.prototype = {
398397

399398
if ( this.useQuaternion === false ) {
400399

401-
this.matrix.makeFromPositionEulerScale( this.position, this.rotation, this.eulerOrder, this.scale );
400+
this.matrix.makeFromPositionEulerScale( this.position, this.rotation, this.scale );
402401

403402
} else {
404403

@@ -451,8 +450,7 @@ THREE.Object3D.prototype = {
451450
object.up.copy( this.up );
452451

453452
object.position.copy( this.position );
454-
if ( object.rotation instanceof THREE.Vector3 ) object.rotation.copy( this.rotation ); // because of Sprite madness
455-
object.eulerOrder = this.eulerOrder;
453+
if ( object.rotation instanceof THREE.Euler ) object.rotation.copy( this.rotation ); // because of Sprite madness
456454
object.scale.copy( this.scale );
457455

458456
object.renderDepth = this.renderDepth;
Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
/**
2+
* @author mrdoob / http://mrdoob.com/
3+
* @author WestLangley / http://github.com/WestLangley
24
* @author bhouston / http://exocortex.com
35
*/
46

5-
THREE.Euler3 = function ( x, y, z, order ) {
7+
THREE.Euler = function ( x, y, z, order ) {
68

79
this.x = x || 0;
810
this.y = y || 0;
911
this.z = z || 0;
10-
this.order = order || "XYZ";
12+
this.order = order || THREE.Euler.DefaultOrder;
1113

1214
};
1315

14-
THREE.Euler3.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
16+
THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
1517

16-
THREE.Euler3.prototype = {
18+
THREE.Euler.DefaultOrder = 'XYZ';
1719

18-
constructor: THREE.Euler3,
20+
THREE.Euler.prototype = {
21+
22+
constructor: THREE.Euler,
1923

2024
set: function ( x, y, z, order ) {
2125

@@ -226,30 +230,50 @@ THREE.Euler3.prototype = {
226230
clamp: function() {
227231

228232
// todo
233+
console.error( "ERROR: Euler.clamp() is not yet implemented.");
229234

230235
},
231236

232237
reorder: function( newOrder ) {
233238

234239
// todo.
240+
console.error( "ERROR: Euler.reorder() is not yet implemented.");
235241

236242
},
237243

238244
alternativeSolution: function() {
239245

240246
// todo.
247+
console.error( "ERROR: Euler.alternativeSolution() is not yet implemented.");
248+
249+
},
250+
251+
fromArray: function ( array ) {
252+
253+
this.x = array[ 0 ];
254+
this.y = array[ 1 ];
255+
this.z = array[ 2 ];
256+
this.order = array[ 3 ];
257+
258+
return this;
259+
260+
},
261+
262+
toArray: function () {
263+
264+
return [ this.x, this.y, this.z, this.order ];
241265

242266
},
243267

244-
equals: function ( e ) {
268+
equals: function ( rotation ) {
245269

246-
return ( ( e.x === this.x ) && ( e.y === this.y ) && ( e.z === this.z ) && ( e.order === this.order ) );
270+
return ( ( rotation.x === this.x ) && ( rotation.y === this.y ) && ( rotation.z === this.z ) && ( rotation.order === this.order ) );
247271

248272
},
249273

250274
clone: function () {
251275

252-
return new THREE.Euler3( this.x, this.y, this.z, this.order );
276+
return new THREE.Euler( this.x, this.y, this.z, this.order );
253277

254278
}
255279

src/math/Matrix4.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,20 @@ THREE.Matrix4.prototype = {
126126

127127
}(),
128128

129-
setRotationFromEuler: function ( v, order ) {
129+
makeRotationFromEuler: function ( rotation ) {
130130

131-
console.warn( 'DEPRECATED: Matrix4\'s .setRotationFromEuler() has been deprecated in favor of makeRotationFromEuler. Please update your code.' );
132-
133-
return this.makeRotationFromEuler( v, order );
134-
135-
},
136-
137-
makeRotationFromEuler: function ( v, order ) {
131+
if( typeof rotation['order'] === undefined ) {
132+
console.error( 'ERROR: Matrix\'s .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order. Please update your code.' );
133+
}
138134

139135
var te = this.elements;
140136

141-
var x = v.x, y = v.y, z = v.z;
137+
var x = rotation.x, y = rotation.y, z = rotation.z;
142138
var a = Math.cos( x ), b = Math.sin( x );
143139
var c = Math.cos( y ), d = Math.sin( y );
144140
var e = Math.cos( z ), f = Math.sin( z );
145141

146-
if ( order === undefined || order === 'XYZ' ) {
142+
if ( rotation.order === undefined || rotation.order === 'XYZ' ) {
147143

148144
var ae = a * e, af = a * f, be = b * e, bf = b * f;
149145

@@ -159,7 +155,7 @@ THREE.Matrix4.prototype = {
159155
te[6] = be + af * d;
160156
te[10] = a * c;
161157

162-
} else if ( order === 'YXZ' ) {
158+
} else if ( rotation.order === 'YXZ' ) {
163159

164160
var ce = c * e, cf = c * f, de = d * e, df = d * f;
165161

@@ -175,7 +171,7 @@ THREE.Matrix4.prototype = {
175171
te[6] = df + ce * b;
176172
te[10] = a * c;
177173

178-
} else if ( order === 'ZXY' ) {
174+
} else if ( rotation.order === 'ZXY' ) {
179175

180176
var ce = c * e, cf = c * f, de = d * e, df = d * f;
181177

@@ -191,7 +187,7 @@ THREE.Matrix4.prototype = {
191187
te[6] = b;
192188
te[10] = a * c;
193189

194-
} else if ( order === 'ZYX' ) {
190+
} else if ( rotation.order === 'ZYX' ) {
195191

196192
var ae = a * e, af = a * f, be = b * e, bf = b * f;
197193

@@ -207,7 +203,7 @@ THREE.Matrix4.prototype = {
207203
te[6] = b * c;
208204
te[10] = a * c;
209205

210-
} else if ( order === 'YZX' ) {
206+
} else if ( rotation.order === 'YZX' ) {
211207

212208
var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
213209

@@ -223,7 +219,7 @@ THREE.Matrix4.prototype = {
223219
te[6] = ad * f + bc;
224220
te[10] = ac - bd * f;
225221

226-
} else if ( order === 'XZY' ) {
222+
} else if ( rotation.order === 'XZY' ) {
227223

228224
var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
229225

@@ -843,9 +839,13 @@ THREE.Matrix4.prototype = {
843839

844840
},
845841

846-
makeFromPositionEulerScale: function ( position, rotation, eulerOrder, scale ) {
842+
makeFromPositionEulerScale: function ( position, rotation, scale ) {
843+
844+
if( typeof rotation['order'] === undefined ) {
845+
console.error( 'ERROR: Matrix4\'s .makeFromPositionEulerScale() now expects a Euler rotation rather than a Vector3 and order. Please update your code.' );
846+
}
847847

848-
this.makeRotationFromEuler( rotation, eulerOrder );
848+
this.makeRotationFromEuler( rotation );
849849
this.scale( scale );
850850
this.setPosition( position );
851851

0 commit comments

Comments
 (0)