我正在嘗試編寫一個自定義腳本來導出場景中的對象與它們的旋轉中心。下面是我的算法看起來像得到旋轉中心:使用其名稱 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步,但我不知道如何將光標捕捉到對象並獲取光標座標。
確實沒有必要捕捉到光標,因爲對象的位置指的是它的中心。謝謝你的時間 :) ! –