Skip to content
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

Merged
merged 1 commit into from
Mar 7, 2018

Conversation

WestLangley
Copy link
Collaborator

@WestLangley WestLangley commented Mar 3, 2018

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 the Euler class would be retained.

Feedback requested.

@@ -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 ) );
Copy link
Collaborator Author

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...

Copy link
Collaborator

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 ) );
Copy link
Collaborator Author

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.

Copy link
Collaborator

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 );
Copy link
Collaborator Author

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...

Copy link
Collaborator

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 ) );
Copy link
Collaborator Author

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...

Copy link
Collaborator

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 ) );
Copy link
Collaborator Author

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ping @sunag opinion??

Copy link
Collaborator

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 );
Copy link
Collaborator Author

@WestLangley WestLangley Mar 3, 2018

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 );

Copy link
Collaborator

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

Copy link
Collaborator

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.

@looeee
Copy link
Collaborator

looeee commented Mar 7, 2018

Object3d.rotation may be removed, but the Euler class would be retained

How would a (beginner friendly) change of rotation look on an Object3D after this change?
Would you need to do do something like:

const euler = new THREE.Euler( 0, 1, 0 );
object.setRotationFromEuler ( euler );

euler.set( Math.PI, 1, 0 );
object.setRotationFromEuler ( euler );

etc. ?

@WestLangley
Copy link
Collaborator Author

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 Object3D.rotation.

@looeee
Copy link
Collaborator

looeee commented Mar 7, 2018

Thing is, it is difficult to reproduce the tumbling effect...

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.

@WestLangley
Copy link
Collaborator Author

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 setOrientationFromEuler(). Oh, well...

@mrdoob
Copy link
Owner

mrdoob commented Mar 7, 2018

@mrdoob That method probably should have been called setOrientationFromEuler(). Oh, well...

Agreed. We can't do everything perfectly all the time... 😆

@mrdoob mrdoob added this to the r91 milestone Mar 7, 2018
@mrdoob
Copy link
Owner

mrdoob commented Mar 7, 2018

Is this good to go then?

@WestLangley
Copy link
Collaborator Author

Yes. This can be merged. :)

@mrdoob
Copy link
Owner

mrdoob commented Mar 7, 2018

Sweet!

@mrdoob mrdoob merged commit ac3b5be into mrdoob:dev Mar 7, 2018
@mrdoob
Copy link
Owner

mrdoob commented Mar 7, 2018

Thanks!

@WestLangley WestLangley deleted the dev-loaders_quat branch March 7, 2018 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants