【发布时间】:2020-08-19 10:40:44
【问题描述】:
我是 Blender 的新手,我很难理解它的关键概念。我正在使用 Blender 2.82 并使用 Python 脚本。我的项目包括使用 Python 执行以下操作:
- 稍微移动对象。
- 使用相机 1、相机 2、相机 3 和相机 4 拍照。
- 重复。
我有一个脚本可以做到这一点。但是,我想在动画循环期间每次更改对象(球体)的位置时保存它,以便以后可以看到我做了什么。当尝试在我的循环中插入动画关键帧时,我的球体似乎没有移动。下面是我的代码。当我删除包含frame_set 和keyframe_insert 的行时,我的球体移动,正如我从渲染图像中看到的那样。我想我混淆了某种概念……任何帮助将不胜感激。这样做的目的是生成我将从放置在一个正在移动的对象周围的四个摄像机获得的图像,以模拟一个动作捕捉系统。
为什么插入关键帧会改变所有正在渲染的图像?
import bpy, bgl, blf,sys
import numpy as np
from bpy import data, ops, props, types, context
cameraNames=''
# Loop all command line arguments and try to find "cameras=east" or similar
for arg in sys.argv:
words=arg.split('=')
if ( words[0] == 'cameras'):
cameraNames = words[1]
sceneKey = bpy.data.scenes.keys()[0]
# Loop all objects and try to find Cameras
bpy.data.scenes[sceneKey].render.image_settings.file_format = 'JPEG'
bpy.data.scenes[sceneKey].cycles.max_bounces=12
bpy.data.scenes[sceneKey].render.tile_x=8
bpy.data.scenes[sceneKey].render.tile_y=8
bpy.data.scenes[sceneKey].cycles.samples = 16
bpy.data.scenes[sceneKey].cycles.caustics_reflective = False
bpy.data.scenes[sceneKey].cycles.caustics_refractive = False
bpy.data.objects['Sphere'].location=[1,1,1]
frame_num=0
for i in range(0,2): #nframes
bpy.context.scene.frame_set(frame_num)
for obj in bpy.data.objects:
# Find cameras that match cameraNames
if ( obj.type =='CAMERA') and ( cameraNames == '' or obj.name.find(cameraNames) != -1) :
# Set Scenes camera and output filename
bpy.data.scenes[sceneKey].camera = obj
bpy.data.scenes[sceneKey].render.filepath = '//'+obj.name+"_"+str(i)
# Render Scene and store the scene
bpy.ops.render.render( write_still=True )
bpy.data.objects['Sphere'].keyframe_insert(data_path="location",index=-1)
frame_num+=1
bpy.data.objects['Sphere'].location=[2,2,1]
【问题讨论】:
标签: python animation render blender keyframe