SkinWeight Mapが画像じゃ精度がでないのでCSVにしたらうまくいった。
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=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)
"""
CSVPath="C:/Download/Game/AdvansedLocoMotionSystem/AnimMan/SkinWeight_neck01_to_Head/SkinWeight_002simple/render.csv"
import codecs
fout = codecs.open(CSVPath, 'w', 'utf_8')
for i in range(poly_count):
line = str(WeightArray[i])+","
fout.write(line)
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
"""
def csv_to_array(CSVPath):
import codecs
fin = codecs.open(CSVPath, 'r', 'utf_8')
image_arr=[]
for line in fin:
#line=line.replace("\n","")
#line=line.replace("\r","")
#line=line.replace(',','')
lineArr=line.split(',')
for strV in lineArr:
if(strV!=""):
print("strV= "+strV)
floatStrV=float(strV)
image_arr.append(floatStrV)
return image_arr
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"
CSVPath="C:/Download/Game/AdvansedLocoMotionSystem/AnimMan/SkinWeight_neck01_to_Head/SkinWeight_002simple/render.csv"
#image_arr=image_to_array(imagePath)
image_arr = csv_to_array(CSVPath)
print("image_arr= "+str(image_arr))
ArrLeng=len(image_arr)
for i in range(ArrLeng):
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)
元がこう
結果がこれ
ふーばっちりうまくいった様子。やったね!
コメント