1.摄像机“Camera”在一个名叫“渲染”的集合中
2.代码:
import bpy # 设置输出路径和文件名 output_path = "/path/to/output/" # 替换为你的输出路径 filename = "rendered_animation" # 输出文件的前缀 # 获取名为“渲染”的集合 render_collection_name = "渲染" render_collection = None for collection in bpy.data.collections: if collection.name == render_collection_name: render_collection = collection break # 打印集合信息 if render_collection: print(f"找到集合: {render_collection_name}") else: print(f"未找到集合: {render_collection_name}") # 如果找到了集合,尝试在其中获取名为“Camera”的对象 if render_collection: camera_object = render_collection.objects.get("Camera") if camera_object and camera_object.type == 'CAMERA': # 设置摄像机对象为场景的默认摄像机 bpy.context.scene.camera = camera_object print(f"设置默认摄像机: {camera_object.name}") else: print("未找到摄像机或对象类型不是摄像机") # 设置渲染的帧范围 bpy.context.scene.frame_start = 1 bpy.context.scene.frame_end = 100 # 假设动画有100帧 print(f"设置帧范围从 {bpy.context.scene.frame_start} 到 {bpy.context.scene.frame_end}") # 设置渲染输出路径,使用格式化字符串 bpy.context.scene.render.filepath = f"{output_path}/{filename}_帧_" # 设置文件格式和路径 print(f"设置输出路径: {bpy.context.scene.render.filepath}") # 启用渲染 bpy.ops.render.render(animation=True, write_still=False) print("开始动画渲染") # 渲染每一帧 for i in range(bpy.context.scene.frame_start, bpy.context.scene.frame_end + 1): bpy.context.scene.frame_set(i) bpy.ops.render.render(animation=False, write_still=True) print(f"第{i}帧渲染完成。") print("渲染全部完成。")
输出文件的路径:C:\path\to\output
标签:render,python,scene,collection,print,api,context,bpy,blender From: https://www.cnblogs.com/jingzaixin/p/18158437