【blender】material.node_tree.nodes[“Principled BSDF“]没找到

在使用bpy编写代码的时候,出现报错

RuntimeError: 错误: Python: Traceback (most recent call last):
  File "c:\Users\ASUS\.vscode\extensions\jacqueslucke.blender-development-0.0.25\pythonFiles\include\blender_vscode\operators\script_runner.py", line 17, in execute
    runpy.run_path(self.filepath, init_globals={"CTX": ctx})
  File "D:\Software\blender-3.6.18-windows-x64\3.6\python\lib\runpy.py", line 289, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "D:\Software\blender-3.6.18-windows-x64\3.6\python\lib\runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "D:\Software\blender-3.6.18-windows-x64\3.6\python\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "e:\blender_project\doorway.py", line 47, in <module>
    bsdf = material.node_tree.nodes["Principled BSDF"]
KeyError: 'bpy_prop_collection[key]: key "Principled BSDF" not found'
位置: D:\Software\blender-3.6.18-windows-x64\3.6\scripts\modules\bpy\ops.py:111

错误代码行:

   # 创建材质并添加纹理
   material = bpy.data.materials.new(name=f"{asset_id}_Material")
   material.use_nodes = True
   bsdf = material.node_tree.nodes["Principled BSDF"] # 这一行出错

   # 加载纹理图像
   texture_image = bpy.data.images.load(texture_path)
   
   # 创建纹理节点
   texture_node = material.node_tree.nodes.new(type='ShaderNodeTexImage')
   texture_node.image = texture_image
   material.node_tree.links.new(bsdf.inputs['Base Color'], texture_node.outputs['Color'])

gpt给出的回答是不存在"Principled BSDF"节点,根据gpt修改了代码,相当于创建了"Principled BSDF"节点再继续操作(这里就不给出了),随后查看blender,发现在blender着色器中查看会发现有两个"原点BSDF"节点。

在这里插入图片描述
直观一点,在info中查看,会发现中文设置下"Principled BSDF"变成了"原点BSDF"。

突然意思到我的blender语言设置成了中文,怪不得一开始找不到"Principled BSDF",把blender语言修改为英文之后,使用原来的代码就跑通了orz。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值