python - Blender插件中的自定义节点套接字和CustomSocketInterface
问题描述
我正在使用 Blender 2.79,但 Blender 2.8+ 可能运行相同
最初,我使用 NodeSocket 子类作为自定义套接字,但最终我得到了这个错误AttributeError: 'NodeSocketInterface' object has no attribute 'draw_color'
。其他人也有default_value
不存在的问题NodeSocketInterface
。
我如何使用这个NodeSocketInterface
类?
解决方案
这是由于没有注册NodeSocketInterface
. 注册子类时,会自动创建一个没有所需方法/属性NodeSocket
的虚拟对象。NodeSocketInterface
我基于对 Blender 源代码的理解编写了以下代码,它适用于将 aCustomSocketInterface
关联到 a CustomSocket
:
# 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)
推荐阅读
- javascript - 在所有标签中查找单词并在 jQuery 中替换它
- python - 在 Python 中使用 openCV 对矩阵执行 blob 检测
- css - 来自侧边栏关闭(X)图标的警报模式
- asp.net - 为什么我的身份验证状态提供程序不起作用?
- r - 在 R 中复制记录并为每个重复记录输入具有不同值的新列
- c++ - 如何将代码分成多个.cpp文件C++
- c# - 带有实体框架的 Blazor webassembly 失败,并显示“不支持 ContentType;支持的类型是 'application/json'”
- node.js - 在作为firebase函数运行的快速应用程序中获取完整的url——包括函数名?
- word-wrap - iText7 html 到 pdf 不能打断长词
- git - 阻止 git 跟踪临时打开的 Microsoft Office 文件