且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Python在Blender 2.61中移动相机

更新时间:2023-02-02 09:21:35

A reddit上友好的用户为我提供了一个正确的解决方案:诀窍是将相机检索为Object,而不是Camera.这样,您可以通过标准方式设置位置并设置关键帧.

A friendly user on reddit pointed me to one correct solution: The trick is to retrieve the camera as an Object, not as a Camera. With this way, you can set the location via the standard way and set keyframes.

如果要设置Camera个特定对象,则必须通过bpy.data.cameras进行检索.

If you want to set Camera specific objects, you have to retrieve it via 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)