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

Refactored Node3D rotation modes #54084

Merged
merged 1 commit into from
Oct 25, 2021

Conversation

reduz
Copy link
Member

@reduz reduz commented Oct 21, 2021

  • Made the Basis euler orders indexed via enum.
  • Node3D has a new rotation_order property to choose Euler rotation order.
  • Node3D has also a rotation_mode property to choose between Euler, Quaternion and Basis

rotation_mode

Exposing these modes as well as the order makes Godot a lot friendlier for animators, which can choose the best way to interpolate rotations. The quaternion property is also very handy for tweening without Gimbal lock.
The new Basis mode makes the (exposed) transform property obsolete, so it was removed (can still be accessed by code of course).

@reduz reduz requested review from a team as code owners October 21, 2021 17:10
@reduz reduz force-pushed the node3d-rotation-options branch from 997853d to 6625ac3 Compare October 21, 2021 17:21
@reduz reduz requested a review from a team as a code owner October 21, 2021 17:21
@fire
Copy link
Member

fire commented Oct 21, 2021

As part of the animation team, animators can't read quaternions and rotation modes helps key the proper rotations.

Looks good!

Will need to wait for tests.

@reduz
Copy link
Member Author

reduz commented Oct 21, 2021

@fire It is true that animators can't read quaternions. In fact, I don't think anyone really can, but having a quaternion exposed property is great for doing Gimbal-Lock free interpolation (simply add a key in the rotation). I think in a subsequent PR we could have something like a ball you can turn or something like this for editing quaternions but I think its out of the scope of this PR.

Copy link
Contributor

@lyuma lyuma left a comment

Choose a reason for hiding this comment

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

@fire looked at this too.

Using Hide Whitespace, we validated that the code in set_euler and get_euler is identical to before.

It looks great. I was just curious about the DIRTY_VECTORS case.

Also small nit, but is there any reason to do variant accessors using VariantInternalAccessor<Basis::EulerOrder> rather than the VARIANT_ACCESSOR_NUMBER(Basis::EulerOrder) macro?

data.scale = data.local_transform.basis.get_scale();
data.dirty &= ~DIRTY_VECTORS;
} else {
data.rotation = Basis::from_euler(data.rotation, data.rotation_order).get_euler_normalized(order);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this calculating a new Basis matrix using Basis::from_euler() when data.local_transform.basis already exists?

Is this to avoid introducing error when scale is 0 or non-uniform?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is because local_transform may be dirty (invalid)

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

@reduz reduz force-pushed the node3d-rotation-options branch from 6625ac3 to 0ea457e Compare October 25, 2021 12:09
@akien-mga
Copy link
Member

A GDScript test is now failing:

modules/gdscript/tests/gdscript_test_runner.cpp:179: ERROR: CHECK( result.passed ) is NOT correct!
  values: CHECK( false )
  logged: "/Users/runner/work/godot/godot/modules/gdscript/tests/scripts/runtime/features/stringify.gd"
          "GDTEST_ANALYZER_ERROR
No constructor of \"Basis\" matches the signature \"Basis(Vector3)\".
"

@reduz reduz force-pushed the node3d-rotation-options branch from 0ea457e to e4b872c Compare October 25, 2021 13:34
@reduz reduz requested a review from a team as a code owner October 25, 2021 13:34
@reduz
Copy link
Member Author

reduz commented Oct 25, 2021

@akien-mga nice we have this now, let me see if I can fix it

@akien-mga
Copy link
Member

Now it passes tests, just needs an update to the docs: https://github.com/godotengine/godot/runs/3997580689?check_suite_focus=true

* Made the Basis euler orders indexed via enum.
* Node3D has a new rotation_order property to choose Euler rotation order.
* Node3D has also a rotation_mode property to choose between Euler, Quaternion and Basis

Exposing these modes as well as the order makes Godot a lot friendlier for animators, which can choose the best way to interpolate rotations.
The new *Basis* mode makes the (exposed) transform property obsolete, so it was removed (can still be accessed by code of course).
@reduz reduz force-pushed the node3d-rotation-options branch from e4b872c to d03b7fb Compare October 25, 2021 17:34
@akien-mga akien-mga merged commit d98a636 into godotengine:master Oct 25, 2021
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants