# Geometry Nodes: new Axes to Rotation node #104416

Merged
Jacques Lucke merged 32 commits from JacquesLucke/blender:axis-to-euler into main 2024-05-08 13:34:26 +02:00
Member

This adds a new Axes to Rotation node which creates a new rotation. In many cases, the primary and secondary axis inputs are a normal and tangent of a mesh or curve. This provides a simpler and more direct way to create this rotation compared to using two Align Euler to Vector nodes.

This more direct way of computing the rotation also allows us to optimize the case better.

The node rotates one axis (X, Y or Z) to the given primary axis direction. Then it rotates around that primary direction to align the second axis to the given secondary direction. Ideally, both input axes are orthogonal. However, the node still creates the "best" rotation when they are not orthogonal. If one or the axes is zero or both are (close to) parallel, the resulting rotation is unstable. There is not too much the node can do to make it more stable.

This adds a new `Axes to Rotation` node which creates a new rotation. In many cases, the primary and secondary axis inputs are a normal and tangent of a mesh or curve. This provides a simpler and more direct way to create this rotation compared to using two `Align Euler to Vector` nodes. This more direct way of computing the rotation also allows us to optimize the case better. The node rotates one axis (X, Y or Z) to the given primary axis direction. Then it rotates around that primary direction to align the second axis to the given secondary direction. Ideally, both input axes are orthogonal. However, the node still creates the "best" rotation when they are not orthogonal. If one or the axes is zero or both are (close to) parallel, the resulting rotation is unstable. There is not too much the node can do to make it more stable. ![image](/attachments/931d41ab-1673-4cb6-8125-f851f966e421)
106 KiB
14 KiB
14 KiB
added 12 commits 2023-02-07 18:34:19 +01:00
Differential Revision: https://developer.blender.org/D17109
added 1 commit 2023-02-07 18:38:32 +01:00
requested review from Hans Goudey 2023-02-07 19:24:05 +01:00
requested review from Simon Thommes 2023-02-07 19:25:40 +01:00
reviewed 2023-02-07 20:46:52 +01:00
left a comment
Member

The code looks relatively straightforward. Assuming this works for Simon, this looks good to go.

The code looks relatively straightforward. Assuming this works for Simon, this looks good to go.
 @ -9901,0 +9922,4 @@ RNA_def_property_ui_text( prop, "Secondary Axis", "Axis that is aligned as good as possible given the alignment of the primary axis");
Member

as good -> as well

`as good` -> `as well`
 @ -0,0 +38,4 @@ uiItemR(layout, ptr, "secondary_axis", UI_ITEM_R_EXPAND, nullptr, ICON_NONE); if (storage.primary_axis == storage.secondary_axis) { uiItemL(layout, N_("Must not be equal"), ICON_ERROR);
Member

Must not be equal -> Axes must not be equal

Just reads a bit better IMO

`Must not be equal` -> `Axes must not be equal` Just reads a bit better IMO
 @ -0,0 +70,4 @@ /* Through cancellation this will set the last axis to be the one that's neither the primary * nor secondary axis. */ tertiary_axis_ = (0 + 1 + 2) - primary_axis - secondary_axis;
Member

Ooh, clever!

Ooh, clever!
 @ -0,0 +94,4 @@ const float tertiary_factor = invert_tertiary ? -1.0f : 1.0f; for (const int64_t i : mask) { float3 primary = math::normalize(primaries[i]);
Member

Not asking for any changes here, but it would be nice if we could build function nodes with multiple multi-functions. In this case we could split the normalization of primaries and secondaries to separate functions. Later on we could implement an optimization pass that removes sequential normalization functions.

I guess that might be possible with some improvements to NodeMultiFunctionBuilder?

Not asking for any changes here, but it would be nice if we could build function nodes with multiple multi-functions. In this case we could split the normalization of `primaries` and `secondaries` to separate functions. Later on we could implement an optimization pass that removes sequential normalization functions. I guess that might be possible with some improvements to `NodeMultiFunctionBuilder`?
approved these changes 2023-02-07 21:12:54 +01:00
left a comment
Member

.

.
changed title from Geometry Nodes: new Axis to Euler node to Geometry Nodes: New Axis to Euler node 2023-02-08 12:40:30 +01:00
changed title from Geometry Nodes: New Axis to Euler node to Geometry Nodes: new Axis to Euler node 2023-02-08 12:40:43 +01:00
requested changes 2023-02-10 12:36:53 +01:00
Dismissed
left a comment
Member

Seems good to me overall I tested some corner cases, where I think the behaviour could be different.

When primary and secondary axis are parallel, it should probably ignore the secondary axis entirely. At least I don't see a reason, why it would have any particular impact.

When using only the secondary axis as an input it would make sense to me to rotate first around what is selected as primary axis. Right now it seems a bit random to me, not sure of the logic behind it right now.

e.g. this shouldn't result in any rotation imo

Seems good to me overall I tested some corner cases, where I think the behaviour could be different. When primary and secondary axis are parallel, it should probably ignore the secondary axis entirely. At least I don't see a reason, why it would have any particular impact. When using only the secondary axis as an input it would make sense to me to rotate first around what is selected as primary axis. Right now it seems a bit random to me, not sure of the logic behind it right now. e.g. this shouldn't result in any rotation imo ![image](/attachments/a8d55d6e-aaff-42bd-8857-e8314efa8fe1)
28 KiB
added this to the Nodes & Physics project 2023-02-13 09:19:22 +01:00
added this to the 4.0 milestone 2023-06-15 20:31:00 +02:00
requested changes 2023-06-15 20:31:45 +02:00
left a comment
Member

With the rotation socket in 4.0, we have another opportunity to add this node. But it needs to be updated for that.

With the rotation socket in 4.0, we have another opportunity to add this node. But it needs to be updated for that.
added 2 commits 2023-12-12 20:48:56 +01:00
added 1 commit 2023-12-12 20:49:39 +01:00
added 1 commit 2023-12-12 20:51:10 +01:00
removed this from the 4.0 milestone 2023-12-12 20:52:15 +01:00
Member

What about default values for inputs:

• Primary Axis: 1.0, 0.0, 0.0.
• Secondary Axis: 0.0, 1.0, 0.0.

This will let to use this node in simple cases without additional value nodes (or maybe better to not hide values of inputs?).

What about default values for inputs: - `Primary Axis`: `1.0, 0.0, 0.0`. - `Secondary Axis`: `0.0, 1.0, 0.0`. This will let to use this node in simple cases without additional value nodes (or maybe better to not hide values of inputs?).
added 6 commits 2024-02-14 16:18:29 +01:00
changed title from Geometry Nodes: new Axis to Euler node to Geometry Nodes: new Axes to Rotation node 2024-02-15 11:31:10 +01:00
added 1 commit 2024-02-22 19:01:29 +01:00
added 3 commits 2024-02-22 19:33:41 +01:00
Author
Member

When primary and secondary axis are parallel, it should probably ignore the secondary axis entirely. At least I don't see a reason, why it would have any particular impact.

This is somewhat tricky. Due to floating point math, it's hard to distinguish the case when both are parallel reliably. We'd have to use some epsilon, which might not work in all cases and can potentially also have undesired effects. The case when both are (almost) parallel is just very unstable, not sure if we can prevent that in practice.

When using only the secondary axis as an input it would make sense to me to rotate first around what is selected as primary axis. Right now it seems a bit random to me, not sure of the logic behind it right now.
e.g. this shouldn't result in any rotation imo

I think this resulted in a rotation because the default for the primary axis was the X axis. Now I changed it so that by default the node does nothing. So the setup in your image should also do nothing then. I also made both inputs non-hidden again. Seems wrong to hide inputs whose values are important and that can make sense to modify manually.

> When primary and secondary axis are parallel, it should probably ignore the secondary axis entirely. At least I don't see a reason, why it would have any particular impact. This is somewhat tricky. Due to floating point math, it's hard to distinguish the case when both are parallel reliably. We'd have to use some epsilon, which might not work in all cases and can potentially also have undesired effects. The case when both are (almost) parallel is just very unstable, not sure if we can prevent that in practice. > When using only the secondary axis as an input it would make sense to me to rotate first around what is selected as primary axis. Right now it seems a bit random to me, not sure of the logic behind it right now. > e.g. this shouldn't result in any rotation imo I think this resulted in a rotation because the default for the primary axis was the X axis. Now I changed it so that by default the node does nothing. So the setup in your image should also do nothing then. I also made both inputs non-hidden again. Seems wrong to hide inputs whose values are important and that can make sense to modify manually.
approved these changes 2024-02-23 17:36:09 +01:00
left a comment
Member

I'm happy with the code now. No strong opinion, but didn't we talk about hiding the value of the first vector but not the second?

I'm happy with the code now. No strong opinion, but didn't we talk about hiding the value of the first vector but not the second?
 @ -0,0 +1,180 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */
Member

Author
Member

No strong opinion, but didn't we talk about hiding the value of the first vector but not the second?

Yeah, we did. However, I changed my mind on that because of the Simon's screenshot. This wouldn't have been an issue if the input value is not hidden.

> No strong opinion, but didn't we talk about hiding the value of the first vector but not the second? Yeah, we did. However, I changed my mind on that because of the Simon's screenshot. This wouldn't have been an issue if the input value is not hidden.
added 2 commits 2024-02-26 12:18:17 +01:00
Some checks failed
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
cd12ea9073
Author
Member

@blender-bot build

@blender-bot build
reviewed 2024-04-27 15:50:36 +02:00
 @ -0,0 +124,4 @@ mat[primary_axis_.as_int()] = primary; mat[secondary_axis_.as_int()] = secondary; mat[tertiary_axis_.as_int()] = tertiary_factor * tertiary; BLI_assert(math::is_orthonormal(mat));
Member

I getting this assertion for just 2 vectors.

I getting this assertion for just 2 vectors.
Author
Member

Can you provide a concrete example where you get this error?

Can you provide a concrete example where you get this error?
Member

If without build, this was something like that\ (probably mesh can be arbirtary)

If without build, this was something like that\ (probably mesh can be arbirtary) ![image](/attachments/d4362bf7-95e1-4314-b2dc-08b1c3b33793)
113 KiB
Author
Member

Can't reproduce it right now, it would be really useful if you could provide a .blend file..

Can't reproduce it right now, it would be really useful if you could provide a .blend file..
Member

Also cant reproduce this now\

Also cant reproduce this now\
reviewed 2024-04-27 16:41:21 +02:00
 @ -0,0 +35,4 @@ uiItemR(layout, ptr, "secondary_axis", UI_ITEM_R_EXPAND, nullptr, ICON_NONE); if (node.custom1 == node.custom2) { uiItemL(layout, N_("Axes must not be equal"), ICON_ERROR);
Member

Still think its might be better to display error in node header as usual werning. Currently this message is not displayed on node group body for nested nodes.

Still think its might be better to display error in node header as usual werning. Currently this message is not displayed on node group body for nested nodes.
Author
Member

I moved it to an overlay. Report it as a proper error is a bit tricky right now, but also not super urgent I think. It's not something that can be triggered by group inputs.

I moved it to an overlay. Report it as a proper error is a bit tricky right now, but also not super urgent I think. It's not something that can be triggered by group inputs.
added 1 commit 2024-05-07 12:34:11 +02:00
added 1 commit 2024-05-07 12:45:34 +02:00
reviewed 2024-05-07 13:10:08 +02:00
 @ -0,0 +31,4 @@ static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr) { const bNode &node = *static_cast(ptr->data);
Member

Now unused.

Now unused.
added 1 commit 2024-05-07 13:35:54 +02:00
requested review from Simon Thommes 2024-05-07 13:43:24 +02:00
approved these changes 2024-05-08 12:59:46 +02:00
left a comment
Member

Looks good to me, I agree with the decision to expose both axes fully

Looks good to me, I agree with the decision to expose both axes fully
referenced this issue from a commit 2024-05-08 13:34:26 +02:00
merged commit 25c134fd08 into main 2024-05-08 13:34:26 +02:00
deleted branch axis-to-euler 2024-05-08 13:34:30 +02:00
First-time contributor

I just tried this out, and I couldn't be happier with how it came together! It's a game changer, thank you for implementing this. :)

I just tried this out, and I couldn't be happier with how it came together! It's a game changer, thank you for implementing this. :)
No reviewers
No Milestone
No project
No Assignees
5 Participants