Maya2016でSkinWhight Mapのインポートが壊れているので
SkinWeight Mapのエクスポートとインポートを自作してみた。ほんとテスト段階
SkinWeight Map export
def GetSkinCluster(mesh):
history = cmds.listHistory(mesh)
for h in history:
if cmds.objectType(h, isType='skinCluster'):
return h
return None
def GetSkinPercent(SkinCluster,vtx,mJoint):
# vtx[100] の joint1 の weight を取得
skinWeightV=cmds.skinPercent( SkinCluster, vtx, t= mJoint, query=True, value=True)
return skinWeightV
def GetPolyCount(mesh):
return cmds.polyEvaluate(mesh, v=True)
from PySide.QtCore import QByteArray, QBuffer, QIODevice, QFile
from PySide import QtGui
jointName="neckUpper|head"
mesh="Design_model|Mesh|Face_Only_Beauty"
poly_count = GetPolyCount(mesh)
skin_cluster = GetSkinCluster(mesh)
imagePath="C:/Download/Game/AdvansedLocoMotionSystem/AnimMan/SkinWeight_neck01_to_Head/SkinWeight_002simple/render.png"
WeightArray=[]
for i in range(poly_count):
vtx_attr_name = mesh + ".vtx[" + str(i) + "]"
weightV=image_arr[i]
weightV=GetSkinPercent(skin_cluster,vtx_attr_name,jointName)
WeightArray.append(weightV)
print("WeightArray="+str(WeightArray))
lenWeightArr=len(WeightArray)
print("lenWeightArr= "+str(lenWeightArr))
width=lenWeightArr
height=1
#buffer = QImage(pageSize, QImage.Format_ARGB32)
buffer = QtGui.QImage(width,height,QtGui.QImage.Format_ARGB32_Premultiplied)
def setDrowPixels(MyImage,WeightArray,width,height):
for x in range(0, width ):
for y in range(0, height ):
gValue=0
if(y==0):
gValue = WeightArray[x]
else:
gValue = WeightArray[x*y]
print("x= "+str(x)+" y= "+str(y)+" gValue= "+str(gValue))
MyImage.setPixel( x, y, QtGui.QColor( gValue, gValue, gValue ).rgb() )
return MyImage
buffer=setDrowPixels(buffer,WeightArray,width,height)
buffer.save(imagePath)
skinWeight Map import
def GetSkinCluster(mesh):
history = cmds.listHistory(mesh)
for h in history:
if cmds.objectType(h, isType='skinCluster'):
return h
return None
def GetSkinPercent(SkinCluster,vtx,mJoint):
# vtx[100] の joint1 の weight を取得
skinWeightV=cmds.skinPercent( SkinCluster, vtx, t= mJoint, query=True, value=True)
return skinWeightV
def SetSkinPercent(SkinCluster,vtx,mJoint,skinWeightV):
# vtx[100] の weight を. joint を指定して設定
cmds.skinPercent( SkinCluster, vtx, transformValue=[(mJoint, skinWeightV)])
def GetPolyCount(mesh):
return cmds.polyEvaluate(mesh, v=True)
from PySide.QtCore import QByteArray, QBuffer, QIODevice, QFile
from PySide import QtGui
def image_to_array(imagePath):
source = QtGui.QImage(imagePath)
# バイナリとメタデータを読み込み
#bits = source.constBits()
width = source.width()
height = source.height()
print("width= "+str(width))
print("height= "+str(height))
'''
return array of integer 0-255 rgba values
[(r, g, b, a)]
'''
img = QtGui.QImage(width, height, QtGui.QImage.Format.Format_ARGB32)
img.load(imagePath)
colorArray = []
kidoArray=[]
for y in range(height):
for x in range(width):
color = QtGui.QColor()
color.setRgba(img.pixel(x,y))
colorArray.append(color.getRgb())
kidoArray.append(color.getRgb()[0])
return kidoArray
jointName="ALS_Mannequin|root|pelvis|spine_01|spine_02|spine_03|neck_01|head"
mesh="ALS_Mannequin|Mesh|Face_Only_Beauty"
poly_count = GetPolyCount(mesh)
skin_cluster = GetSkinCluster(mesh)
imagePath="C:/Download/Game/AdvansedLocoMotionSystem/AnimMan/SkinWeight_neck01_to_Head/SkinWeight_002simple/render.png"
image_arr=image_to_array(imagePath)
print("image_arr= "+str(image_arr))
for i in range(poly_count):
vtx_attr_name = mesh + ".vtx[" + str(i) + "]"
weightV=image_arr[i]
#SetSkinPercent(skin_cluster,vtx_attr_name,jointName,1)
SetSkinPercent(skin_cluster,vtx_attr_name,jointName,weightV)
元がこれ
結果がこれ 値が飛んじゃってる気がする。 CSVとかのほうがいいかも
なんだかスムージング処理がいるのかもしれない。
■参考にさせてもらった記事
Maya python で, 特定の mesh 頂点の 特定の joint の skin weight の値を取得, 設定する – Qiita
https://qiita.com/syoyo/items/5252ac7244b4f40b2cac
Python API 2.0 MImage
https://forums.autodesk.com/t5/maya-programming/python-api-2-0-mimage/td-p/6340749
Python QImage.fill Examples
コメント