Blender插件中的自定义节点套接字和自定义SocketInterface

2024-10-01 05:05:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是Blender 2.79,但Blender 2.8+的操作方式可能相同

Example for custom nodes

最初,我使用NodeSocket子类作为自定义套接字,但最终我得到了这个错误AttributeError: 'NodeSocketInterface' object has no attribute 'draw_color'。其他人也有default_value不在NodeSocketInterface的问题

如何使用这个NodeSocketInterface


Tags: noforobjectexample错误custom方式attribute
1条回答
网友
1楼 · 发布于 2024-10-01 05:05:33

这是因为没有注册NodeSocketInterface。注册NodeSocket子类时,没有所需方法/属性的伪NodeSocketInterfaceautomatically created

我在理解Blender源代码的基础上编写了以下代码,它用于注册与CustomSocket关联的CustomSocketInterface

# Blender 2.79
# (bl_idname defaults to class names if not set)

class CustomSocketInterface(bpy.types.NodeSocketInterface):
    bl_socket_idname = 'CustomSocket' # required, Blender will complain if it is missing
    # those are (at least) used under Interface in N-menu in
    # node editor when viewing a node group, for input and output sockets
    def draw(self, context, layout):
        pass
    def draw_color(self, context):
        return (0,1,1,1)

class CustomSocket(bpy.types.NodeSocket):
    def draw(self, context, layout, node, text):
        pass
    def draw_color(self, context, node):
        return (0,1,1,1)
...
# register (didn't try but order should matter)
    bpy.utils.register_class(CustomSocketInterface)
    bpy.utils.register_class(CustomSocket)

相关问题 更多 >