如何使用Python在Blender 2.61中移动相机 [英] How to move a camera in Blender 2.61 with Python

查看:400
本文介绍了如何使用Python在Blender 2.61中移动相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个简单的脚本来使用Python在Blender 2.61中移动相机. 我以为这是一件容易的事,但是Camera对象没有loc等类似属性.

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 something similar.

我只在网上找到Blender 2.49的脚本,但是由于Blender 2.5的巨大API更改,它们不再起作用了.

I only found scripts online for Blender 2.49 but they don't work anymore because of the immense API changes with Blender 2.5.

任何提示,我将不胜感激.

I would appreciate any hints.

推荐答案

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)

这篇关于如何使用Python在Blender 2.61中移动相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆