我是搅拌机的新手。 我错过了什么吗?
然而在控制台窗口中键入: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 )
答案 0 :(得分:1)
您的代码完美无缺。我刚刚使用Blender 2.71
验证了它然而,搅拌机中的旋转有一个小缺陷:搅拌机中有多种可能的旋转模式。只要为特定对象激活不同的旋转模式,修改欧拉角就不起作用。
您可以使用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 )