Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// c# setWeights(),setWeight()
// http://ueta.hateblo.jp/entry/2015/08/24/102937
private void n(string name, ref MDagPath dp)
{
MSelectionList sellist = new MSelectionList();
MGlobal.getSelectionListByName( name, sellist );
sellist.getDagPath( 0 , dp );
}
private void n(string name, ref MObject mo)
{
MSelectionList sellist = new MSelectionList();
MGlobal.getSelectionListByName( name , sellist );
sellist.getDependNode( 0 , mo );
}
private void TestGetSetWeights()
{
SpeedCount.TimeCountByPerformanceCounter time_getWeights = new SpeedCount.TimeCountByPerformanceCounter();
SpeedCount.TimeCountByPerformanceCounter time_setWeights = new SpeedCount.TimeCountByPerformanceCounter();
SpeedCount.TimeCountByPerformanceCounter time_total = new SpeedCount.TimeCountByPerformanceCounter();
const string SKINCLUSTER = "skinCluster1";
const string MESHSHAPE = "TestMeshShape";
time_total.Start();
// スキンクラスタ取得
MObject skinNode = new MObject();
n( SKINCLUSTER , ref skinNode );
MFnSkinCluster skinFn = new MFnSkinCluster( skinNode );
// シェイプの取得
MDagPath meshPath = new MDagPath();
n( MESHSHAPE , ref meshPath );
MObject meshNode = new MObject( meshPath.node );
// 取得対象の頂点
// 今回はすべての頂点を取得したいので[0,1,2,,,,,MaxVertex]となっている。
MItMeshVertex meshVerItFn = new MItMeshVertex( meshNode );
MIntArray indices = new MIntArray((uint)meshVerItFn.count() , 0 );
for (int i = 0, len = (int)indices.length; i < len; ++i)
{
indices[i] = i;
}
// 指定の頂点をコンポーネントとして取得する
MFnSingleIndexedComponent singleIdComp = new MFnSingleIndexedComponent();
MObject vertexComp = singleIdComp.create( MFn.Type.kMeshVertComponent );
singleIdComp.addElements( indices );
// インフルエンスの数のIntArray
MDagPathArray infDags = new MDagPathArray();
skinFn.influenceObjects( infDags );
MIntArray infIndices = new MIntArray( infDags.length , 0 );
for (int i = 0, len = (int)infDags.length; i < len; ++i)
{
infIndices[i] = (int)skinFn.indexForInfluenceObject(infDags[i]);
}
// すべてのウエイトの値を取得
MDoubleArray weights = new MDoubleArray();
uint infCount = 0;
time_getWeights.Start();
skinFn.getWeights( meshPath, vertexComp, weights, ref infCount );
double get = time_getWeights.ElapsedMilliSec() * 0.001;
MGlobal.displayInfo("C# getWeights() " + get + " s");
// 最初に取得したウエイトを再設定
time_setWeights.Start();
skinFn.setWeights( meshPath , vertexComp , infIndices , weights );
double set = time_setWeights.ElapsedMilliSec() * 0.001;
MGlobal.displayInfo("C# setWeights() " + set + " s");
double total = time_total.ElapsedMilliSec() * 0.001;
MGlobal.displayInfo("C# total time " + total + " s");
MGlobal.displayInfo("C# etc time " + (total - get - set) + " s");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment