Skip to main content
 首页 » 编程设计

python之为什么使用 python 旋转在 blender 2.6 中不起作用

2025年05月04日12pengyingh

我是 blender 的新手。 我错过了什么吗?

但是在控制台窗口中键入:bpy.data.objects['Suzanne'].rotation_euler[2] = 1.25 将使模型旋转。

但是下面的代码根本不旋转模型。为什么?

import bpy 
import math 
 
cam = bpy.data.objects['Camera'] 
origin = bpy.data.objects['Suzanne'] 
 
step_count = 5 
bpy.data.scenes["Scene"].cycles.samples=10 
 
for step in range(0, step_count): 
    r = math.pi * step * (360.0 / step_count) / 180.0 
    print(r) 
    origin.rotation_euler[2] = r       # seems not work! 
    fn = '/tmp/mokey_%02d.jpg' % step 
    print(fn) 
    bpy.data.scenes["Scene"].render.filepath = fn 
    bpy.ops.render.render( write_still=True ) 

请您参考如下方法:

您的代码运行良好。我刚刚使用 Blender 2.71 验证了它

但是,blender 中的旋转有一个小缺陷:blender 中有多种可能的旋转模式。只要为特定对象激活了不同的旋转模式,修改欧拉角就不会产生影响。

您可以使用 rotation_mode 成员强制执行正确的旋转模式(有关可能的旋转模式的完整列表,请参阅 the documentation)。
在您的示例中,您可能希望使用 xyz-Euler 角:

origin.rotation_mode = 'XYZ' # Force using euler angles 

这是集成到您的示例中的解决方法:

import bpy 
import math 
 
cam = bpy.data.objects['Camera'] 
origin = bpy.data.objects['Suzanne'] 
 
step_count = 5 
bpy.data.scenes["Scene"].cycles.samples=10 
 
origin.rotation_mode = 'XYZ' # Force the right rotation mode 
 
for step in range(0, step_count): 
    r = math.pi * step * (360.0 / step_count) / 180.0 
    print(r) 
    origin.rotation_euler[2] = r 
    fn = '/home/robert/mokey_%02d.jpg' % step 
    print(fn) 
    bpy.data.scenes["Scene"].render.filepath = fn 
    bpy.ops.render.render( write_still=True )