简体   繁体   中英

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

在此处输入图像描述

Above is the material I've created. I exported my model to .obj from Blender. From a Python script (I have Blender compiled as a Python Module), I import my .obj file. I then attempt to set the Noise Texture 'W' property:

import bpy

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

My material is called Material . How can I access the Noise Texture node and change the value of W ?

I want to access the 'Noise Texture' node via python, so that I can randomize the 'W' property.

    # 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

    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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