Geometry Nodes: Operator to wrap a modifier's node group #104546

Merged
Hans Goudey merged 19 commits from HooglyBoogly/blender:geometry-nodes-wrapper-operator into main 2023-02-14 18:22:04 +01:00
Member

As described in #104171, add an operator that creates new node groups that
contain the current node group and named attribute nodes to deal with the
outputs. This saves manual work when moving a high-level modifier to the
node editor for better procedural control.

image

image

image

As described in #104171, add an operator that creates new node groups that contain the current node group and named attribute nodes to deal with the outputs. This saves manual work when moving a high-level modifier to the node editor for better procedural control. ![image](/attachments/3d48acf4-4479-4cf7-a282-8fa599b33f81) ![image](/attachments/5a63535d-156e-4e6a-878b-9f875a2dd706) ![image](/attachments/9a70d5a9-912f-46d5-ba31-2def726db97d)
Hans Goudey added this to the 3.5 milestone 2023-02-09 22:40:41 +01:00
Hans Goudey added the
Module
Nodes & Physics
label 2023-02-09 22:40:41 +01:00
Hans Goudey added 4 commits 2023-02-09 22:40:43 +01:00
Hans Goudey added the
Interest
Geometry Nodes
label 2023-02-09 22:41:01 +01:00
Hans Goudey requested review from Simon Thommes 2023-02-09 22:41:16 +01:00
Hans Goudey requested review from Jacques Lucke 2023-02-09 22:41:24 +01:00
Simon Thommes requested changes 2023-02-10 12:16:22 +01:00
Simon Thommes left a comment
Member

Very nice!

The operator should also assign a sensible name to the node-group that is being created.
If we are fine with the word wrapper (I am), It could be <nodegroup_name>.wrapper.

The name of the operator should probably contain the word node, otherwise I can imagine people being confused what it does and where their modifier went. I'd propose something like Wrap in Node Group or even Convert to Node.

Very nice! The operator should also assign a sensible name to the node-group that is being created. If we are fine with the word `wrapper` (I am), It could be `<nodegroup_name>.wrapper`. The name of the operator should probably contain the word `node`, otherwise I can imagine people being confused what it does and where their modifier went. I'd propose something like `Wrap in Node Group` or even `Convert to Node`.
Hans Goudey added 3 commits 2023-02-10 14:51:57 +01:00
Simon Thommes approved these changes 2023-02-10 18:15:51 +01:00
Simon Thommes left a comment
Member

Seems good to me now!

Seems good to me now!
Jacques Lucke requested changes 2023-02-10 20:49:15 +01:00
@ -8,3 +8,2 @@
def geometry_node_group_empty_new():
group = bpy.data.node_groups.new(data_("Geometry Nodes"), 'GeometryNodeTree')
def geometry_node_group_empty_new(name=data_("Geometry Nodes"), add_link=True):
Member

Better use two separate functions that call a common function instead of adding optional parameters to this one.

Better use two separate functions that call a common function instead of adding optional parameters to this one.
HooglyBoogly marked this conversation as resolved
@ -27,0 +30,4 @@
modifier = context.modifier
else:
modifier = context.object.modifiers.active
if modifier.type != 'NODES':
Member

modifier may be None

modifier may be `None`
HooglyBoogly marked this conversation as resolved
@ -31,10 +41,148 @@ def geometry_modifier_poll(context):
# Test object support for geometry node modifier
if not ob or ob.type not in {'MESH', 'POINTCLOUD', 'VOLUME', 'CURVE', 'FONT', 'CURVES'}:
return False
if not get_context_modifier(context):
Member

Use get_context_modifer(context) is None.

Use `get_context_modifer(context) is None`.
HooglyBoogly marked this conversation as resolved
@ -38,0 +94,4 @@
"""Create a new node group wrapping the modifier's group"""
bl_idname = "object.new_geometry_node_group_wrapper"
bl_label = "Create Wrapper Node Group"
Member

The name is still kind of ugly. Maybe something like Move to Nodes (description: Move inputs and outputs set in the modifier to a new node group) or what Simon suggested.

The name is still kind of ugly. Maybe something like `Move to Nodes` (description: `Move inputs and outputs set in the modifier to a new node group`) or what Simon suggested.
Author
Member

Yeah, good idea!

Yeah, good idea!
HooglyBoogly marked this conversation as resolved
@ -38,0 +121,4 @@
# Copy default values for inputs and create named attribute input nodes.
input_nodes = []
first_geometry_input = None
for input in old_group.inputs:
Member

Avoid using input as variable name because this is a built-in function in Python.

Avoid using `input` as variable name because this is a built-in function in Python.
HooglyBoogly marked this conversation as resolved
@ -38,0 +136,4 @@
elif input.bl_socket_idname == 'NodeSocketGeometry':
if not first_geometry_input:
first_geometry_input = group_node_input
Member

Make sure vscode removes trailing spaces automatically.

Make sure vscode removes trailing spaces automatically.
HooglyBoogly marked this conversation as resolved
@ -38,0 +142,4 @@
# Adjust locations of named attribute input nodes and group input node to make some space.
if input_nodes:
for i, node in enumerate(input_nodes):
node.location[0] = -175
Member

Can you use .x?

Can you use `.x`?
Author
Member

Hmm, yes!

Hmm, yes!
HooglyBoogly marked this conversation as resolved
@ -38,0 +172,4 @@
group_output_node.location[0] = (len(store_nodes) + 1) * 175
group.links.new(first_geometry_output, store_nodes[0].inputs["Geometry"])
for i in range(len(store_nodes))[:-1]:
Member

Seems like you could move the - 1 into range(...).

Seems like you could move the `- 1` into `range(...)`.
HooglyBoogly marked this conversation as resolved
Brecht Van Lommel added this to the Nodes & Physics project 2023-02-13 09:12:40 +01:00
Hans Goudey requested review from Jacques Lucke 2023-02-13 18:09:33 +01:00
Hans Goudey added 8 commits 2023-02-13 18:09:36 +01:00
Jacques Lucke requested changes 2023-02-14 13:54:35 +01:00
@ -22,2 +22,3 @@
group.links.new(output_node.inputs[0], input_node.outputs[0])
if add_link:
group.links.new(output_node.inputs[0], input_node.outputs[0])
Member

Return the input and output node from the function, and move this line into geometry_node_group_empty_new.

Return the input and output node from the function, and move this line into `geometry_node_group_empty_new`.
HooglyBoogly marked this conversation as resolved
@ -38,0 +98,4 @@
class CreateModifierWrapperGroup(Operator):
"""Move inputs and outputs from in the modifier to a new node group"""
bl_idname = "object.new_geometry_node_group_wrapper"
Member

The class name and idname should be updated to respect the new label.

The class name and idname should be updated to respect the new label.
HooglyBoogly marked this conversation as resolved
@ -70,11 +224,7 @@ class NewGeometryNodeTreeAssign(Operator):
return geometry_modifier_poll(context)
Member

This poll function now returns false when there is no modifier, which breaks New button to create a geometry node tree on a new object.

This poll function now returns false when there is no modifier, which breaks `New` button to create a geometry node tree on a new object.
HooglyBoogly marked this conversation as resolved
Hans Goudey added 4 commits 2023-02-14 18:05:15 +01:00
Jacques Lucke approved these changes 2023-02-14 18:16:43 +01:00
Hans Goudey merged commit 5ca65001ea into main 2023-02-14 18:22:04 +01:00
Hans Goudey deleted branch geometry-nodes-wrapper-operator 2023-02-14 18:22:04 +01:00
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
3 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#104546
No description provided.