split xyz

This commit is contained in:
hofee 2024-10-16 00:05:07 +08:00
parent d9f8ac1268
commit 950b1473b2

View File

@ -229,8 +229,36 @@ class BlenderUtils:
output_depth.format.color_mode = 'BW'
output_depth.format.color_depth = '16'
tree.links.new(map_range.outputs[0], output_depth.inputs[0])
# 创建 Separate XYZ 节点来分离法线的 X, Y, Z 分量
separate_xyz = tree.nodes.new('CompositorNodeSeparateXYZ')
# 将法线向量连接到 Separate XYZ 节点
tree.links.new(rl.outputs['Normal'], separate_xyz.inputs[0])
# 创建 Map Range 节点来分别映射 X, Y, Z 分量
map_range_x = tree.nodes.new('CompositorNodeMapRange')
map_range_y = tree.nodes.new('CompositorNodeMapRange')
map_range_z = tree.nodes.new('CompositorNodeMapRange')
# 设置映射范围
for map_range in [map_range_x, map_range_y, map_range_z]:
map_range.inputs['From Min'].default_value = -1
map_range.inputs['From Max'].default_value = 1
map_range.inputs['To Min'].default_value = 0
map_range.inputs['To Max'].default_value = 1
# 分别连接到法线的 X, Y, Z 输出
tree.links.new(separate_xyz.outputs['X'], map_range_x.inputs[0])
tree.links.new(separate_xyz.outputs['Y'], map_range_y.inputs[0])
tree.links.new(separate_xyz.outputs['Z'], map_range_z.inputs[0])
# 合并 X, Y, Z 分量到一个 RGB 输出
combine_rgb = tree.nodes.new('CompositorNodeCombineXYZ')
tree.links.new(map_range_x.outputs[0], combine_rgb.inputs['X'])
tree.links.new(map_range_y.outputs[0], combine_rgb.inputs['Y'])
tree.links.new(map_range_z.outputs[0], combine_rgb.inputs['Z'])
# 输出到文件
output_normal = tree.nodes.new('CompositorNodeOutputFile')
normal_dir = os.path.join(output_dir, "normal")
if not os.path.exists(normal_dir):
@ -240,8 +268,8 @@ class BlenderUtils:
output_normal.format.file_format = 'PNG'
output_normal.format.color_mode = 'RGB'
output_normal.format.color_depth = '8'
tree.links.new(rl.outputs['Normal'], output_normal.inputs[0])
tree.links.new(combine_rgb.outputs[0], output_normal.inputs[0])
bpy.ops.render.render(write_still=True)