Refactor: Nodes: Generalize node tree subtypes

This patch generalizes node tree subtypes to be usable for node trees
other than Geometry Nodes. In particular, this:

- Renames SpaceNode.geometry_nodes_type to node_tree_sub_type, which now
  store a tree type-specific enum.
- Renames SpaceNode.geometry_nodes_tool_tree to selected_node_group,
  which now stores any context-less tree of any type.

This breaks the python API due to renaming.

Pull Request: https://projects.blender.org/blender/blender/pulls/144544
This commit is contained in:
Omar Emara
2025-08-21 09:04:13 +02:00
committed by Omar Emara
parent 40f8a36fd5
commit 3d7c8d022e
15 changed files with 60 additions and 49 deletions

View File

@@ -353,11 +353,11 @@ class NewGeometryNodeGroupTool(Operator):
@classmethod
def poll(cls, context):
space = context.space_data
return space and space.type == 'NODE_EDITOR' and space.geometry_nodes_type == 'TOOL'
return space and space.type == 'NODE_EDITOR' and space.node_tree_sub_type == 'TOOL'
def execute(self, context):
group = geometry_node_group_empty_tool_new(context)
context.space_data.geometry_nodes_tool_tree = group
context.space_data.selected_node_group = group
return {'FINISHED'}

View File

@@ -229,7 +229,7 @@ class NODE_MT_geometry_node_GEO_GEOMETRY_READ(Menu):
node_add_menu.add_node_type(layout, "GeometryNodeInputNormal")
node_add_menu.add_node_type(layout, "GeometryNodeInputPosition", search_weight=1.0)
node_add_menu.add_node_type(layout, "GeometryNodeInputRadius")
if context.space_data.geometry_nodes_type == 'TOOL':
if context.space_data.node_tree_sub_type == 'TOOL':
node_add_menu.add_node_type(layout, "GeometryNodeToolSelection")
node_add_menu.add_node_type(layout, "GeometryNodeToolActiveElement")
node_add_menu.draw_assets_for_catalog(layout, "Geometry/Read")
@@ -244,7 +244,7 @@ class NODE_MT_geometry_node_GEO_GEOMETRY_WRITE(Menu):
node_add_menu.add_node_type(layout, "GeometryNodeSetGeometryName")
node_add_menu.add_node_type(layout, "GeometryNodeSetID")
node_add_menu.add_node_type(layout, "GeometryNodeSetPosition", search_weight=1.0)
if context.space_data.geometry_nodes_type == 'TOOL':
if context.space_data.node_tree_sub_type == 'TOOL':
node_add_menu.add_node_type(layout, "GeometryNodeToolSetSelection")
node_add_menu.draw_assets_for_catalog(layout, "Geometry/Write")
@@ -291,7 +291,7 @@ class NODE_MT_geometry_node_GEO_INPUT(Menu):
def draw(self, context):
layout = self.layout
layout.menu("NODE_MT_geometry_node_GEO_INPUT_CONSTANT")
if context.space_data.geometry_nodes_type != 'TOOL':
if context.space_data.node_tree_sub_type != 'TOOL':
layout.menu("NODE_MT_geometry_node_GEO_INPUT_GIZMO")
layout.menu("NODE_MT_geometry_node_GEO_INPUT_GROUP")
layout.menu("NODE_MT_category_import")
@@ -336,7 +336,7 @@ class NODE_MT_geometry_node_GEO_INPUT_SCENE(Menu):
def draw(self, context):
layout = self.layout
if context.space_data.geometry_nodes_type == 'TOOL':
if context.space_data.node_tree_sub_type == 'TOOL':
node_add_menu.add_node_type(layout, "GeometryNodeTool3DCursor")
node_add_menu.add_node_type(layout, "GeometryNodeInputActiveCamera")
node_add_menu.add_node_type_with_outputs(
@@ -358,7 +358,7 @@ class NODE_MT_geometry_node_GEO_INPUT_SCENE(Menu):
node_add_menu.add_node_type(layout, "GeometryNodeCollectionInfo")
node_add_menu.add_node_type(layout, "GeometryNodeImageInfo")
node_add_menu.add_node_type(layout, "GeometryNodeIsViewport")
if context.space_data.geometry_nodes_type == 'TOOL':
if context.space_data.node_tree_sub_type == 'TOOL':
node_add_menu.add_node_type_with_outputs(
context, layout, "GeometryNodeToolMousePosition",
["Mouse X", "Mouse Y", "Region Width", "Region Height"],
@@ -366,7 +366,7 @@ class NODE_MT_geometry_node_GEO_INPUT_SCENE(Menu):
node_add_menu.add_node_type(layout, "GeometryNodeObjectInfo")
node_add_menu.add_node_type_with_outputs(context, layout, "GeometryNodeInputSceneTime", ["Frame", "Seconds"])
node_add_menu.add_node_type(layout, "GeometryNodeSelfObject")
if context.space_data.geometry_nodes_type == 'TOOL':
if context.space_data.node_tree_sub_type == 'TOOL':
node_add_menu.add_node_type_with_outputs(
context, layout, "GeometryNodeViewportTransform",
["Projection", "View", "Is Orthographic"],
@@ -454,7 +454,7 @@ class NODE_MT_geometry_node_GEO_MESH_READ(Menu):
node_add_menu.add_node_type(layout, "GeometryNodeInputMeshFaceArea")
node_add_menu.add_node_type(layout, "GeometryNodeMeshFaceSetBoundaries")
node_add_menu.add_node_type(layout, "GeometryNodeInputMeshFaceNeighbors")
if context.space_data.geometry_nodes_type == 'TOOL':
if context.space_data.node_tree_sub_type == 'TOOL':
node_add_menu.add_node_type(layout, "GeometryNodeToolFaceSet")
node_add_menu.add_node_type(layout, "GeometryNodeInputMeshFaceIsPlanar")
node_add_menu.add_node_type(layout, "GeometryNodeInputShadeSmooth")
@@ -482,7 +482,7 @@ class NODE_MT_geometry_node_GEO_MESH_WRITE(Menu):
def draw(self, context):
layout = self.layout
if context.space_data.geometry_nodes_type == 'TOOL':
if context.space_data.node_tree_sub_type == 'TOOL':
node_add_menu.add_node_type(layout, "GeometryNodeToolSetFaceSet")
node_add_menu.add_node_type(layout, "GeometryNodeSetMeshNormal")
node_add_menu.add_node_type(layout, "GeometryNodeSetShadeSmooth")

View File

@@ -151,11 +151,11 @@ class NODE_HT_header(Header):
row.template_ID(scene, "compositing_node_group", new="node.new_compositing_node_group")
elif snode.tree_type == 'GeometryNodeTree':
layout.prop(snode, "geometry_nodes_type", text="")
layout.prop(snode, "node_tree_sub_type", text="")
NODE_MT_editor_menus.draw_collapsible(context, layout)
layout.separator_spacer()
if snode.geometry_nodes_type == 'MODIFIER':
if snode.node_tree_sub_type == 'MODIFIER':
ob = context.object
row = layout.row()
@@ -172,7 +172,7 @@ class NODE_HT_header(Header):
else:
row.template_ID(snode, "node_tree", new="node.new_geometry_nodes_modifier")
else:
layout.template_ID(snode, "geometry_nodes_tool_tree", new="node.new_geometry_node_group_tool")
layout.template_ID(snode, "selected_node_group", new="node.new_geometry_node_group_tool")
if snode.node_tree:
layout.popover(panel="NODE_PT_geometry_node_tool_object_types", text="Types")
layout.popover(panel="NODE_PT_geometry_node_tool_mode", text="Modes")