Last active
October 9, 2016 20:28
-
-
Save utatsuya/f0b0b36c077d9497743e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c++ setWeights(),setWeight() | |
// http://ueta.hateblo.jp/entry/2015/08/24/102937 | |
// | |
// usage:command plugin | |
// | |
void n(MString name, MDagPath &dp){ | |
MSelectionList sellist; | |
MGlobal::getSelectionListByName( name , sellist ); | |
sellist.getDagPath( 0 , dp ); | |
} | |
void n(MString name, MObject &mo){ | |
MSelectionList sellist; | |
MGlobal::getSelectionListByName( name , sellist ); | |
sellist.getDependNode( 0 , mo ); | |
} | |
void printTime(MString msg, double time){ | |
MString log("C++ "); | |
log += msg + " " + time + " s"; | |
MGlobal::displayInfo(log); | |
} | |
MStatus TestGetSetWeights::doIt(const MArgList& args) | |
{ | |
const MString SKINCLUSTER = "skinCluster1"; | |
const MString MESHSHAPE = "TestMeshShape"; | |
DWORD start, end, get_s, get_e, set_s, set_e; | |
start = timeGetTime(); | |
// スキンクラスタ取得 | |
MObject skinNode = MObject::kNullObj; | |
n( SKINCLUSTER , skinNode ); | |
MFnSkinCluster skinFn( skinNode ); | |
// シェイプの取得 | |
MDagPath meshPath; | |
n( MESHSHAPE , meshPath ); | |
MObject meshNode( meshPath.node() ); | |
// 取得対象の頂点 | |
// 今回はすべての頂点を取得したいので[0,1,2,,,,,MaxVertex]となっている。 | |
MItMeshVertex meshVerItFn( meshNode ); | |
MIntArray indices( meshVerItFn.count() , 0 ); | |
for (int i = 0, len = indices.length(); i < len; ++i){ | |
indices[i] = i; | |
} | |
// 指定の頂点をコンポーネントとして取得する | |
MFnSingleIndexedComponent singleIdComp; | |
MObject vertexComp = singleIdComp.create( MFn::kMeshVertComponent ); | |
singleIdComp.addElements( indices ); | |
// インフルエンスの数のIntArray | |
MDagPathArray infDags; | |
skinFn.influenceObjects( infDags ); | |
MIntArray infIndices( infDags.length() , 0 ); | |
for (int i = 0, len = infDags.length(); i < len; ++i){ | |
infIndices[i] = skinFn.indexForInfluenceObject( infDags[i] ); | |
} | |
// すべてのウエイトの値を取得 | |
MDoubleArray weights; | |
uint infCount; | |
get_s = timeGetTime(); | |
skinFn.getWeights(meshPath, vertexComp, weights, infCount); | |
get_e = timeGetTime(); | |
printTime("getWeights()", ( get_e - get_s ) * 0.001 ); | |
// 最初に取得したウエイトを再設定 | |
set_s = timeGetTime(); | |
skinFn.setWeights(meshPath, vertexComp, infIndices, weights); | |
set_e = timeGetTime(); | |
printTime("setWeights()", (set_e - set_s) * 0.001 ); | |
end = timeGetTime(); | |
printTime("total time ", (end - start) * 0.001 ); | |
printTime("etc time ", ((end - start) - (get_e - get_s) - (set_e - set_s )) * 0.001 ); | |
return MS::kSuccess; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment