[英]How to move a camera in Blender 2.61 with Python
我正在寻找一个简单的脚本来使用Python在Blender 2.61中移动相机。 我认为这将是一项简单的任务,但Camera对象没有loc或类似的属性。
我只在线发现了Blender 2.49的脚本,但由于Blender 2.5的API变化很大,它们不再起作用了。
我会很感激任何提示。
furtelwart的答案非常有用。 我做了一些挖掘,所以你也可以设置一些关于相机和渲染的其他非常有用的属性。
import bpy
tx = 0.0
ty = 0.0
tz = 80.0
rx = 0.0
ry = 0.0
rz = 0.0
fov = 50.0
pi = 3.14159265
scene = bpy.data.scenes["Scene"]
# Set render resolution
scene.render.resolution_x = 480
scene.render.resolution_y = 359
# Set camera fov in degrees
scene.camera.data.angle = fov*(pi/180.0)
# Set camera rotation in euler angles
scene.camera.rotation_mode = 'XYZ'
scene.camera.rotation_euler[0] = rx*(pi/180.0)
scene.camera.rotation_euler[1] = ry*(pi/180.0)
scene.camera.rotation_euler[2] = rz*(pi/180.0)
# Set camera translation
scene.camera.location.x = tx
scene.camera.location.y = ty
scene.camera.location.z = tz
我正在使用此脚本进行批量渲染。 您可以在此处查看: http : //code.google.com/p/encuadro/source/browse/renders/marker/model/marker_a4.py
稍后将对其进行改进以获取命令行参数。 我是python和blender的新手所以这可能是一种业余爱好者,但它确实有效。
reddit上的友好用户向我指出了一个正确的解决方案:诀窍是将相机检索为Object
,而不是Camera
。 通过这种方式,您可以通过标准方式设置位置并设置关键帧。
如果要设置Camera
特定对象,则必须通过bpy.data.cameras
检索它。
import bpy
if(len(bpy.data.cameras) == 1):
obj = bpy.data.objects['Camera'] # bpy.types.Camera
obj.location.x = 0.0
obj.location.y = -10.0
obj.location.z = 10.0
obj.keyframe_insert(data_path="location", frame=10.0)
obj.location.x = 10.0
obj.location.y = 0.0
obj.location.z = 5.0
obj.keyframe_insert(data_path="location", frame=20.0)
也许本页底部的摄像机装备可能是一个不错的起点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.