2012-01-14 172 views
10

我正在寻找一个简单的脚本来在Blender 2.61中使用Python移动摄像机。 我认为这将是一件容易的事,但Camera对象没有像loc或类似的东西。如何使用Python在Blender 2.61中移动摄像机

我只在Blender 2.49上发现了线上脚本,但由于Blender 2.5发生了巨大的API变化,他们不再工作了。

我会很感激任何提示。

回答

6

A friendly user on 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) 
10

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的新手,所以这可能是一种业余爱好者,但它很有用。

+0

请检查我最近的问题,在python脚本中的命令行参数,因为我有一些麻烦。也许你可以帮忙。谢谢! http://stackoverflow.com/questions/10667314/python-script-with-arguments-for-command-line-blender – roho 2012-05-19 17:21:58

+0

这是有帮助的;谢谢。 – Clay 2012-07-06 19:10:27

相关问题