目录
生成遮罩层,并且渲染保存:
import bpy
import os
bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]
bpy.ops.object.delete()
bpy.ops.import_scene.obj(filepath=r"F:\bjl_1.obj")
bpy.context.scene.render.image_settings.file_format = 'PNG'
# 渲染场景并保存结果
bpy.context.scene.render.filepath = r'c://tmp//out.png'
bpy.ops.render.render(write_still=True)
# 创建蓝色遮罩材质
obj = bpy.context.selected_objects[0]
materials = obj.data.materials
override_nodes = []
for mat in materials:
if mat.use_nodes:
nodes = mat.node_tree.nodes
links = mat.node_tree.links
output_node = nodes.get("Material Output")
# 创建 Mix Shader 节点
mix_node &