Exemplo n.º 1
0
def build_environment_texture_background(world: bpy.types.World,
                                         hdri_path: str,
                                         rotation: float = 0.0) -> None:
    world.use_nodes = True
    node_tree = world.node_tree

    environment_texture_node = node_tree.nodes.new(
        type="ShaderNodeTexEnvironment")
    environment_texture_node.image = bpy.data.images.load(hdri_path)

    mapping_node = node_tree.nodes.new(type="ShaderNodeMapping")
    if bpy.app.version >= (2, 81, 0):
        mapping_node.inputs["Rotation"].default_value = (0.0, 0.0, rotation)
    else:
        mapping_node.rotation[2] = rotation

    tex_coord_node = node_tree.nodes.new(type="ShaderNodeTexCoord")

    node_tree.links.new(tex_coord_node.outputs["Generated"],
                        mapping_node.inputs["Vector"])
    node_tree.links.new(mapping_node.outputs["Vector"],
                        environment_texture_node.inputs["Vector"])
    node_tree.links.new(environment_texture_node.outputs["Color"],
                        node_tree.nodes["Background"].inputs["Color"])

    arrange_nodes(node_tree)
Exemplo n.º 2
0
def set_tex_environment(world: bpy.types.World, path: str):
    # shader node tree
    world.use_nodes = True
    bpysnt = world.node_tree # ShaderNodeTree
    bpysn_texenv = bpysnt.nodes.new(type="ShaderNodeTexEnvironment") # ShaderNodeTexEnvironment
    bpysn_texenv.image = bpy.data.images.load(path)
    bpysn_texcrd = bpysnt.nodes.new(type="ShaderNodeTexCoord")
    bpysnt.links.new(bpysn_texcrd.outputs["Generated"], bpysn_texenv.inputs["Vector"])
    bpysnt.links.new(bpysn_texenv.outputs["Color"], bpysnt.nodes["Background"].inputs["Color"])
Exemplo n.º 3
0
def build_rgb_background(world: bpy.types.World,
                         rgb: Tuple[float, float, float, float] = (0.9, 0.9, 0.9, 1.0),
                         strength: float = 1.0) -> None:
    world.use_nodes = True
    node_tree = world.node_tree

    rgb_node = node_tree.nodes.new(type="ShaderNodeRGB")
    rgb_node.outputs["Color"].default_value = rgb

    node_tree.nodes["Background"].inputs["Strength"].default_value = strength

    node_tree.links.new(rgb_node.outputs["Color"], node_tree.nodes["Background"].inputs["Color"])

    arrange_nodes(node_tree)