脱・DeclareSimpleCommand

MayaPluginWizardを使ってプロジェクトを立ち上げると
DeclareSimpleCommandという便利なマクロ一発でプラグイン/コマンドを作成するのに必要なクラスが宣言されてしまう。

DeclareSimpleCommandでは何をしているのか?

このマクロを使わずにちょこっとコードを書いてみる。


#include // プロキシークラス、これが重要
#include
#include


//--------------------------------------------
// コマンド/プラグインはMPxCommandクラスから
// 派生させる
//--------------------------------------------
class TestCommand : public MPxCommand
{
public:
TestCommand();
virtual ~TestCommand();
public:
virtual MStatus doIt(const MArgList& args);
static void* creator();
};

//--------------------------------------------
// コンストラク
//--------------------------------------------
TestCommand::TestCommand()
{
}

//--------------------------------------------
// デストラク
//--------------------------------------------
TestCommand::~TestCommand()
{
}

//--------------------------------------------
// コマンドの処理内容をメインで記述
//--------------------------------------------
MStatus TestCommand::doIt(const MArgList &args)
{
MStatus status = MStatus::kSuccess;
return status;
}

//--------------------------------------------
// Maya側からプラグイン初期化時に呼び出される
// ファクトリー関数。絶対に定義
//--------------------------------------------
void* TestCommand::creator()
{
return new TestCommand();
}


//-----------------------------------------------------
// Maya側でプラグインを登録するために必要な関数なので
// 絶対に定義すること
//-----------------------------------------------------
MStatus initializePlugin(MObject& object)
{
// 関数セットを作成する。
// arg2:ベンダ名 arg3:バージョン番号
MFnPlugin plugin(object,"futa","1.0");

// コマンドを登録する。
// arg1:コマンド名 arg2:コマンドクラスのファクトリ関数
MStatus status = plugin.registerCommand("TestCommand",TestCommand::creator);


return status;
}

//-----------------------------------------------------
// Maya側でプラグインを削除するために必要な関数なので
// 絶対に定義すること
//-----------------------------------------------------
MStatus uninitializePlugin(MObject& object)
{
// 関数セットを作成
MFnPlugin plugin(object);

//initializePlugin()で登録したコマンドを削除する。
// arg1:コマンド名
MStatus status = plugin.deregisterCommand("TestCommand");
return status;
}



DeclareSimpleCommandマクロを使うとこうなる。


#include

//---------------------------------------------------
// クラス宣言、initialize〜uninitialize〜などの
// 定義を一括で行う。詳しくは定義をみてみましょう。
//---------------------------------------------------
DeclareSimpleCommand(TestCommand,"futa","1.0");


//--------------------------------------------
// コマンドの処理内容をメインで記述
//--------------------------------------------
MStatus TestCommand::doIt(const MArgList &args)
{
MStatus status = MStatus::kSuccess;
return status;
}





あら簡単。。。(てか省略されすぎでしょ…)

しかし、いつまでもDeclare〜に頼っていると、
いざクラスの機能を拡張しようとしたときに困りそうなので、今のうちに最基礎部分ぐらいは
空で書けるようにしておきます。orz...