How to move a camera in Blender 2.61 with Python

后端 未结 3 628
臣服心动
臣服心动 2021-02-04 07:57

I\'m searching for a simple script to move a camera in Blender 2.61 with Python. I thought this would be an easy task, but the Camera object has no properties like loc or someth

3条回答
  •  佛祖请我去吃肉
    2021-02-04 08:16

    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.

    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)
    

提交回复
热议问题