一段时间以来,我一直在思考如何连接我在搅拌机中制作的材料的两个着色节点,我一直在谷歌搜索,但我似乎无法思考如何连接它们。下面的最后两行代码是我最好的尝试。希望有人能像我一样看穿这个疯狂的物体。
class WM_OT_textOpBasic(bpy.types.Operator):
"""Creates the Base Planet"""
bl_idname = "wm.textopbasic"
bl_label = " Text Tool Operator"
def execute(self, context):
bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=6, radius=1.0, calc_uvs=True, enter_editmode=False, align='WORLD', location=(0.0, 0.0, 0.0), rotation=(0.0, 0.0, 0.0), scale=(1.0, 1.0, 1.0))
planet = bpy.context.selected_objects[0]
planet.name = "Planet"
planet_material = bpy.data.materials.get("planet material")
if planet_material is None:
# create material
planet_material = bpy.data.materials.new(name="planet material")
planet.data.materials.append(planet_material)
planet_material.use_nodes = True
nodes = planet_material.node_tree.nodes
ColorRamp1 = nodes.new('ShaderNodeValToRGB')
ColorRamp1.location = -400,100
ColorRamp2 = nodes.new('ShaderNodeValToRGB')
ColorRamp2.location = -700,100
ColorRamp3 = nodes.new('ShaderNodeValToRGB')
ColorRamp3.location = -1000,100
Noise1 = nodes.new('ShaderNodeTexNoise')
Noise1.location = -1100,300
Noise2 = nodes.new('ShaderNodeTexNoise')
Noise2.location = -900,300
Bump = nodes.new('ShaderNodeBump')
Bump.location = -150,-150
planet.active_material.node_tree.links.new(Noise1.outputs[0],Noise2.inputs[1])
planet_material.node_tree.links(Noise1.outputs[0],Noise2.inputs[1])
```发布于 2022-08-21 00:15:42
您的问题没有指定节点的确切配置,但这段代码显示了它的工作原理。
import bpy
bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=6, radius=1.0, calc_uvs=True, enter_editmode=False, align='WORLD', location=(0.0, 0.0, 0.0), rotation=(0.0, 0.0, 0.0), scale=(1.0, 1.0, 1.0))
planet = bpy.context.selected_objects[0]
planet.name = "Planet"
planet_material = bpy.data.materials.get("planet material")
if planet_material is None:
# create material
planet_material = bpy.data.materials.new(name="planet material")
planet.data.materials.append(planet_material)
planet_material.use_nodes = True
if planet_material.node_tree:
planet_material.node_tree.links.clear()
planet_material.node_tree.nodes.clear()
nodes = planet_material.node_tree.nodes
links = planet_material.node_tree.links
ColorRamp1 = nodes.new('ShaderNodeValToRGB')
ColorRamp1.location = -400,100
Noise1 = nodes.new('ShaderNodeTexNoise')
Noise1.location = -1100,300
output = nodes.new(type='ShaderNodeOutputMaterial') # you need an output node to display
links.new(Noise1.outputs[0], ColorRamp1.inputs[0]) # Noise1.output[0] just takes the start node of noise one at spot 0, ColorRamp1.inputs[0] is the input spot for the noise again at spot 0
links.new(Noise1.outputs[0], output.inputs[1])
links.new(ColorRamp1.outputs[0], output.inputs[1])
planet.data.materials.append(planet_material)https://stackoverflow.com/questions/72469526
复制相似问题