Geometry Nodes: Convert four nodes to use rotation socket #111482

Merged
Hans Goudey merged 19 commits from HooglyBoogly/blender:geometry-nodes-use-rotation-type into main 2023-11-15 18:56:08 +01:00
Member

Convert the vector socket from four nodes to a rotation socket, adding
versioning to insert the conversion nodes and change the default values
where necessary.

  • Distribute Points on Faces
  • Instance on Points
  • Rotate Instances
  • Transform Geometry

Using rotation sockets disallows implicit conversions from vectors,
which helps avoid some common mistakes. It can also be faster,
since converting to and from Euler rotations is slow. For best
performance, the automatically added nodes should be removed.

This change is not forward compatible with 3.6, and socket values
are lost when opening 4.1 files in 4.0. The correct socket types are
added back in old versions, though newly added conversion nodes
may have to be removed.


image

Convert the vector socket from four nodes to a rotation socket, adding versioning to insert the conversion nodes and change the default values where necessary. - Distribute Points on Faces - Instance on Points - Rotate Instances - Transform Geometry Using rotation sockets disallows implicit conversions from vectors, which helps avoid some common mistakes. It can also be faster, since converting to and from Euler rotations is slow. For best performance, the automatically added nodes should be removed. This change is not forward compatible with 3.6, and socket values are lost when opening 4.1 files in 4.0. The correct socket types are added back in old versions, though newly added conversion nodes may have to be removed. --- ![image](/attachments/f6c295b3-a59f-4108-9216-895247367f28)
164 KiB
Hans Goudey added 1 commit 2023-08-24 18:08:16 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
f5c9bb5960
Geometry Nodes: Convert four nodes to use rotation socket
Convert the vector socket from four nodes to a rotation socket, adding
versioning to insert the conversion nodes and change the default values
where necessary.
- Distribute Points on Faces
- Instance on Points
- Rotate Instances
- Transform Geometry

Using rotation sockets disallows implicit conversions from vectors,
which helps avoid some common mistakes. It can also be faster,
since converting to and from Euler rotations is slow. For best
performance, the automatically added nodes should be removed.

Note that this change is not forward compatible with 3.6.
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added this to the 4.0 milestone 2023-08-24 18:11:47 +02:00
Hans Goudey requested review from Lukas Tönne 2023-08-24 18:12:23 +02:00
Hans Goudey requested review from Jacques Lucke 2023-08-24 18:12:24 +02:00
Hans Goudey added this to the Nodes & Physics project 2023-08-24 18:12:32 +02:00
Iliya Katushenock reviewed 2023-08-24 18:19:04 +02:00
@ -423,0 +427,4 @@
socket.type = SOCK_ROTATION;
STRNCPY(socket.idname, "NodeSocketRotation");
auto *old_value = static_cast<bNodeSocketValueVector *>(socket.default_value);
auto *new_value = MEM_new<bNodeSocketValueRotation>(__func__);

nodes::update_node_declaration_and_sockets ?

`nodes::update_node_declaration_and_sockets` ?
Author
Member

That won't convert the default value. And I'd also rather not call a relatively higher level function like that in versioning code, since it makes it more difficult to change in the future.

That won't convert the default value. And I'd also rather not call a relatively higher level function like that in versioning code, since it makes it more difficult to change in the future.

Default values can be copied separately, but I'm surprised it's okay to do it manually when declarations already exist...

Default values can be copied separately, but I'm surprised it's okay to do it manually when declarations already exist...
mod_moder marked this conversation as resolved

Attached file is crash when opened.

Attached file is crash when opened.
Hans Goudey added 2 commits 2023-08-24 20:00:24 +02:00
Author
Member

I think the most recent commit should fix the issues with your file, thanks.

I think the most recent commit should fix the issues with your file, thanks.
Author
Member

@blender-bot build

@blender-bot build
Member

I think we can only do this once we have the ability to create random rotations in one node, and to combine rotations (or if we actually do allow the implicit conversion between vector and euler).

Without those things, we make some very common workflows harder (like initializing every instance with a random rotation). Not to mention that this also breaks a very large number of tutorials that are meant for beginners.

I think we can only do this once we have the ability to create random rotations in one node, and to combine rotations (or if we actually do allow the implicit conversion between vector and euler). Without those things, we make some very common workflows harder (like initializing every instance with a random rotation). Not to mention that this also breaks a very large number of tutorials that are meant for beginners.
Member

I think we can only do this once we have the ability to create random rotations in one node[...]

There is an open PR that does just this, but it's rolled into the existing Random Value node. Do we want it changed to be it's own "Random Rotation" node? #109846

> I think we can only do this once we have the ability to create random rotations in one node[...] There is an open PR that does just this, but it's rolled into the existing Random Value node. Do we want it changed to be it's own "Random Rotation" node? https://projects.blender.org/blender/blender/pulls/109846
Member

Agree with Jacques, the patch would be fine on its own but it needs a better plan for compatibility and ease of use with existing nodes.

I'd be ok with implicit conversions interpreting any vector as an euler and convert that to a quaternion. The alternative would be a straightforward (x,y,z) -> (x,y,z,0) conversion plus normalization, but that doesn't give very intuitive rotations and the normalization makes it rather useless for math purposes ("Combine Rotation" must be used for that).

Agree with Jacques, the patch would be fine on its own but it needs a better plan for compatibility and ease of use with existing nodes. I'd be ok with implicit conversions interpreting any vector as an euler and convert that to a quaternion. The alternative would be a straightforward `(x,y,z)` -> `(x,y,z,0)` conversion plus normalization, but that doesn't give very intuitive rotations and the normalization makes it rather useless for math purposes ("Combine Rotation" must be used for that).
Hans Goudey added 1 commit 2023-10-03 00:06:03 +02:00
Hans Goudey added 7 commits 2023-11-15 11:28:49 +01:00
Author
Member

There are now implicit conversions from floats and vectors to rotations, using the old Euler behavior. Those are the only implicit conversions though-- others seem unnecessary at best, and a confusing waste of time at worst.

There are now implicit conversions from floats and vectors to rotations, using the old Euler behavior. Those are the only implicit conversions though-- others seem unnecessary at best, and a confusing waste of time at worst.
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added 1 commit 2023-11-15 15:42:49 +01:00
Jacques Lucke requested changes 2023-11-15 16:48:43 +01:00
@ -426,2 +438,4 @@
add_implicit_conversion<ColorGeometry4b, ColorGeometry4f, byte_color_to_color>(conversions);
add_implicit_conversion<float, math::Quaternion, float_to_quaternion>(conversions);
add_implicit_conversion<float3, math::Quaternion, float3_to_quaternion>(conversions);
Member

Also add rotation to float3 implicit conversion.

Also add rotation to float3 implicit conversion.
HooglyBoogly marked this conversation as resolved
@ -836,0 +855,4 @@
/* Make versioning idempotent. */
continue;
}
bNode *convert = nodeAddNode(nullptr, &ntree, "FunctionNodeEulerToRotation");
Member

Don't insert new node if the implicit conversion works as well.

Don't insert new node if the implicit conversion works as well.
HooglyBoogly marked this conversation as resolved
@ -33,2 +32,3 @@
static bool use_translate(const math::Quaternion &rotation, const float3 scale)
{
if (compare_ff(math::length_squared(rotation), 0.0f, 1e-9f) != 1) {
if (math::angle_between(rotation, math::Quaternion::identity()).radian() > 1e-7f) {
Member

Can this use math::angle_of?

Can this use `math::angle_of`?
Author
Member

Yes, good to know about that!

Yes, good to know about that!
HooglyBoogly marked this conversation as resolved
Hans Goudey added 3 commits 2023-11-15 16:58:05 +01:00
Hans Goudey added 1 commit 2023-11-15 17:00:34 +01:00
Hans Goudey requested review from Jacques Lucke 2023-11-15 17:00:36 +01:00
Hans Goudey added 1 commit 2023-11-15 17:07:15 +01:00
Jacques Lucke reviewed 2023-11-15 17:33:54 +01:00
@ -836,0 +853,4 @@
}
if (ELEM(link->fromsock->type, SOCK_VECTOR, SOCK_FLOAT) &&
link->fromnode->type != NODE_REROUTE) {
/* No need to add the conversion node when impicit conversions will work. */
Member

typo

typo
Author
Member

Hmm, sorry, where is the typo?

Hmm, sorry, where is the typo?
Member

impicit

`impicit`
HooglyBoogly marked this conversation as resolved
Hans Goudey added 1 commit 2023-11-15 17:53:21 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
b16f5824a9
Fix typo
Jacques Lucke approved these changes 2023-11-15 18:06:30 +01:00
Jacques Lucke left a comment
Member

@blender-bot build

@blender-bot build
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added 1 commit 2023-11-15 18:23:46 +01:00
Hans Goudey merged commit 600a133521 into main 2023-11-15 18:56:08 +01:00
Hans Goudey deleted branch geometry-nodes-use-rotation-type 2023-11-15 18:56:09 +01:00
First-time contributor

@HooglyBoogly Random Value node still doesn't have Rotation type. Do you have plans to add it? in would be nice to have random rotation output

@HooglyBoogly Random Value node still doesn't have Rotation type. Do you have plans to add it? in would be nice to have random rotation output
Author
Member

For that we'll probably add a node group asset. Random rotations are a fair bit more complex than the other data types in the random value node.

For that we'll probably add a node group asset. Random rotations are a fair bit more complex than the other data types in the random value node.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#111482
No description provided.