繁体   English   中英

如何通过 Python 脚本为 Blender 材质设置着色器节点属性?

[英]How to set a shader node property for Blender material via Python script?

在此处输入图像描述

以上是我创建的材料。 我将模型从 Blender 导出到 .obj。 从 Python 脚本(我将 Blender 编译为 Python 模块),我导入了我的 .obj 文件。 然后我尝试设置Noise Texture 'W'属性:

import bpy

bpy.ops.import_scene.obj( filepath = PATH_TO_MY_OBJ)
bpy.context.object.name = "obbb"
obj = bpy.data.objects["obbb"]

我的材料称为Material 如何访问Noise Texture节点并更改W的值?

我想通过 python 访问“Noise Texture”节点,这样我就可以随机化“W”属性。

    # accessing the materials
    material = bpy.data.materials.get("Material")
    
    # accessing all the nodes in that material
    nodes = material.node_tree.nodes
            
    # you can find the specific node by it's name
    noise_node = nodes.get("Noise Texture")

    # available inputs of that node
    # print([x.identifier for x in noise_node.inputs])
    # ['Vector', 'W', 'Scale', 'Detail', 'Distortion']

    # change value of "W"
    noise_node.inputs.get("W").default_value = 1

    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM