-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loaders: set .quaternion instead of .rotation #13488
Conversation
@@ -3607,7 +3607,7 @@ THREE.ColladaLoader.prototype = { | |||
|
|||
if ( asset.upAxis === 'Z_UP' ) { | |||
|
|||
scene.rotation.x = - Math.PI / 2; | |||
scene.quaternion.setFromEuler( new THREE.Euler( - Math.PI / 2, 0, 0 ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mugen87 I think new
is OK here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
@@ -1989,7 +1989,7 @@ | |||
|
|||
var rotation = modelNode.Lcl_Rotation.value.map( THREE.Math.degToRad ); | |||
rotation.push( 'ZYX' ); | |||
model.rotation.fromArray( rotation ); | |||
model.quaternion.setFromEuler( new THREE.Euler().fromArray( rotation ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@takahirox @looeee I think new
is OK here, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that looks fine 👍
var currentRotation = new THREE.Quaternion().setFromEuler( model.rotation ); | ||
preRotations.multiply( currentRotation ); | ||
model.rotation.setFromQuaternion( preRotations, 'ZYX' ); | ||
model.quaternion.premultiply( preRotations ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@takahirox @looeee I think this is equivalent to what was intended...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this looks good too 🙂
@@ -140,7 +140,7 @@ THREE.PlayCanvasLoader.prototype = { | |||
object.name = data.name; | |||
|
|||
object.position.fromArray( data.position ); | |||
object.rotation.fromArray( data.rotation ); | |||
object.quaternion.setFromEuler( new THREE.Euler().fromArray( data.rotation ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mugen87 Again, instantiating a new instance may be OK...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -1695,7 +1695,7 @@ THREE.SEA3D.prototype.updateTransform = function ( obj3d, sea ) { | |||
|
|||
// ignore rotation scale | |||
|
|||
obj3d.rotation.setFromRotationMatrix( THREE.SEA3D.identityMatrixScale( mtx ) ); | |||
obj3d.quaternion.setFromRotationMatrix( THREE.SEA3D.identityMatrixScale( mtx ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ping @sunag Should be OK as long as the argument is a pure rotation matrix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ping @sunag opinion??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ping @sunag Should be OK as long as the argument is a pure rotation matrix.
Yes, yes! Looks good
@@ -491,7 +491,7 @@ THREE.SEA3D.Domain.prototype.applyTransform = function ( matrix ) { | |||
// ignore rotation scale | |||
|
|||
mtx.scale( vec.set( 1 / obj3d.scale.x, 1 / obj3d.scale.y, 1 / obj3d.scale.z ) ); | |||
obj3d.rotation.setFromRotationMatrix( mtx ); | |||
obj3d.quaternion.setFromRotationMatrix( mtx ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ping @sunag Perhaps this block of code can be implemented more-simply with this, instead:
obj3d.applyMatrix( matrix );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @WestLangley
I do not know now but I broke my head a little because quaternion is affected in decomposition matrix if scale is not (1,1,1)
https://github.com/WestLangley/three.js/blob/e865ad729f60fe919373a14073a9486c90a92d9c/examples/js/loaders/sea3d/physics/SEA3DAmmoLoader.js#L493
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in AS3(Flash) version for example the decompose matrix scale not influence the quaternion.
How would a (beginner friendly) change of rotation look on an const euler = new THREE.Euler( 0, 1, 0 );
object.setRotationFromEuler ( euler );
euler.set( Math.PI, 1, 0 );
object.setRotationFromEuler ( euler ); etc. ? |
Yes. Also object.rotateX( 0.01 );
object.rotateAxisAngle( axis, angle ); Thing is, it is difficult to reproduce the tumbling effect one gets from object.rotation.x += 0.01;
object.rotation.y += 0.01; There would be some consequences to removing |
Yeah, this was my thought as well. That's used in lots of introductory tutorials. In fact this change would render basically every three.js tutorial and book obsolete, which is something we should definitely consider. |
One could use this pattern in the render loop. It produces the same result. var euler = new THREE.Euler();
euler.x += 0.01;
euler.y += 0.01;
object.setRotationFromEuler( euler ); @mrdoob That method probably should have been called |
Agreed. We can't do everything perfectly all the time... 😆 |
Is this good to go then? |
Yes. This can be merged. :) |
Sweet! |
Thanks! |
Trying this to see what this change looks like... Not too bad, actually.
The idea is that at some point,
Object3d.rotation
may be removed, but theEuler
class would be retained.Feedback requested.