Nodes: Panels integration with blend files and UI

Part 3/3 of #109135, #110272

Switch to new node group interfaces and deprecate old DNA and API.
This completes support for panels in node drawing and in node group
interface declarations in particular.

The new node group interface DNA and RNA code has been added in parts
1 and 2 (#110885, #110952) but has not be enabled yet. This commit
completes the integration by
* enabling the new RNA API
* using the new API in UI
* read/write new interfaces from blend files
* add versioning for backward compatibility
* add forward-compatible writing code to reconstruct old interfaces

All places accessing node group interface declarations should now be
using the new API. A runtime cache has been added that allows simple
linear access to socket inputs and outputs even when a panel hierarchy
is used.

Old DNA has been deprecated and should only be accessed for versioning
(inputs/outputs renamed to inputs_legacy/outputs_legacy to catch
errors). Versioning code ensures both backward and forward
compatibility of existing files.

The API for old interfaces is removed. The new API is very similar but
is defined on the `ntree.interface` instead of the `ntree` directly.
Breaking change notifications and detailed instructions for migrating
will be added.

A python test has been added for the node group API functions. This
includes new functionality such as creating panels and moving items
between different levels.

This patch does not yet contain panel representations in the modifier
UI. This has been tested in a separate branch and will be added with a
later PR (#108565).

Pull Request: https://projects.blender.org/blender/blender/pulls/111348
This commit is contained in:
Lukas Tönne
2023-08-30 12:37:21 +02:00
parent f77fdbff8a
commit e071288ab2
65 changed files with 4302 additions and 3473 deletions

View File

@@ -1,5 +1,5 @@
import bpy
from bpy.types import NodeTree, Node, NodeSocket
from bpy.types import NodeTree, Node, NodeSocket, NodeTreeInterfaceSocket
# Implementation of custom nodes from Python
@@ -25,19 +25,9 @@ class MyCustomSocket(NodeSocket):
# Label for nice name display
bl_label = "Custom Node Socket"
# Enum items list
my_items = (
('DOWN', "Down", "Where your feet are"),
('UP', "Up", "Where your head should be"),
('LEFT', "Left", "Not right"),
('RIGHT', "Right", "Not left"),
)
my_enum_prop: bpy.props.EnumProperty(
name="Direction",
description="Just an example",
items=my_items,
default='UP',
input_value: bpy.props.FloatProperty(
name="Value",
description="Value when the socket is not connected",
)
# Optional function for drawing the socket input value
@@ -45,13 +35,35 @@ class MyCustomSocket(NodeSocket):
if self.is_output or self.is_linked:
layout.label(text=text)
else:
layout.prop(self, "my_enum_prop", text=text)
layout.prop(self, "input_value", text=text)
# Socket color
def draw_color(self, context, node):
@classmethod
def draw_color_simple(cls):
return (1.0, 0.4, 0.216, 0.5)
# Customizable interface properties to generate a socket from.
class MyCustomInterfaceSocket(NodeTreeInterfaceSocket):
# The type of socket that is generated.
bl_socket_idname = 'CustomSocketType'
default_value: bpy.props.FloatProperty(default=1.0, description="Default input value for new sockets",)
def draw(self, context, layout):
# Display properties of the interface.
layout.prop(self, "default_value")
# Set properties of newly created sockets
def init_socket(self, node, socket, data_path):
socket.input_value = self.default_value
# Use an existing socket to initialize the group interface
def from_socket(self, node, socket):
# Current value of the socket becomes the default
self.default_value = socket.input_value
# Mix-in class for all custom nodes in this tree type.
# Defines a poll function to enable instantiation.
class MyCustomTreeNode:
@@ -163,6 +175,7 @@ node_categories = [
classes = (
MyCustomTree,
MyCustomSocket,
MyCustomInterfaceSocket,
MyCustomNode,
)