【发布时间】:2016-05-24 08:59:15
【问题描述】:
我正在尝试编写一个自定义脚本来导出场景中的对象及其旋转中心。这是我的算法获得旋转中心的样子: 1-使用名称选择对象,然后调用 2-将光标捕捉到对象(中心) 3- 获取鼠标坐标 4- 写鼠标坐标
import bpy
sce = bpy.context.scene
ob_list = sce.objects
path = 'C:\\Users\\bestc\\Dropbox\\NetBeansProjects\\MoonlightWanderer\\res\\Character\\player.dat'
# Now copy the coordinate of the mouse as center of rotation
try:
outfile = open(path, 'w')
for ob in ob_list:
if ob.name != "Camera" and ob.name != "Lamp":
ob.select = True
bpy.ops.view3d.snap_cursor_to_selected()
mouseX, mouseY, mouseZ = bpy.ops.view3d.cursor_location
# write object name, coords, center of rotation and rotation followed by a newline
outfile.write( "%s\n" % (ob.name))
x, y, z = ob.location # unpack the ob.loc tuple for printing
x2, y2, z2 = ob.rotation_euler # unpack the ob.rot tuple for printing
outfile.write( "%f %f %f %f %f\n" % (y, z, mouseY, mouseZ, y2) )
#outfile.close()
except Exception as e:
print ("Oh no! something went wrong:", e)
else:
if outfile: outfile.close()
print("done writing")`enter code here`
显然问题出在第 2 步和第 3 步,但我不知道如何将光标捕捉到对象并获取光标坐标。
【问题讨论】:
标签: python-3.x blender