Maya C++ 入門② | 単純なコマンドプラグインを作成しよう!

今回は、Maya APIを使って単純なコマンドプラグインを作成してみましょう。
前回はマクロを使ったコマンドプラグインの登録でした。
今回はマクロではなく自前で実装していきましょう。MPxCommandというのを使います。

管理人がYouTubeで解説!

サンプルコード:MpxCommandでコマンドプラグインを1つ登録する

#include <maya/MGlobal.h>
#include <maya/MArgList.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxCommand.h>

class helloCommandA : public MPxCommand
{
public:
	MStatus doIt(const MArgList&);
	static void* creator();
};

MStatus helloCommandA::doIt(const MArgList&) {
	MGlobal::displayInfo("helloCommandAの処理");
	return MS::kSuccess;
}

void* helloCommandA::creator() {
	return new helloCommandA();
}

MStatus initializePlugin(MObject obj)
{
	MFnPlugin plugin(obj, "TECH ART ONLINE", "1.0", "Any");
	plugin.registerCommand("helloCommandA", helloCommandA::creator);
	return MS::kSuccess;
}
MStatus uninitializePlugin(MObject obj)
{
	MFnPlugin plugin(obj);
	plugin.deregisterCommand("helloCommandA");
	return MS::kSuccess;
}

サンプルコード:MpxCommandでコマンドプラグインを2つ登録する

#include <maya/MGlobal.h>
#include <maya/MArgList.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxCommand.h>

/* 1個目のプラグイン---------------------------------------------------------*/

class helloCommandA : public MPxCommand
{
public:
	MStatus doIt(const MArgList&);
	static void* creator();
};

MStatus helloCommandA::doIt(const MArgList&) {
	return MS::kSuccess;
}

void* helloCommandA::creator() {
  MGlobal::displayInfo("helloCommandAの処理");
	return new helloCommandA();
}

/* 2個目のプラグイン---------------------------------------------------------*/

class helloCommandB : public MPxCommand
{
public:
	MStatus doIt(const MArgList&);
	static void* creator();
};

MStatus helloCommandB::doIt(const MArgList&) {
  MGlobal::displayInfo("helloCommandBの処理");
	return MS::kSuccess;
}

void* helloCommandB::creator() {
	return new helloCommandB();
}

/* それらをロード/アンロードする---------------------------------------------------------*/

MStatus initializePlugin(MObject obj)
{
	MFnPlugin plugin(obj, "TECH ART ONLINE", "1.0", "Any");
	plugin.registerCommand("helloCommandA", helloCommandA::creator);
	plugin.registerCommand("helloCommandB", helloCommandB::creator);
	
	return MS::kSuccess;
}
MStatus uninitializePlugin(MObject obj)
{
	MFnPlugin plugin(obj);
	plugin.deregisterCommand("helloCommandA");
	plugin.deregisterCommand("helloCommandB");
	return MS::kSuccess;
}

関連記事

  1. アーティストのためのMaya Python入門 番外編「可変長引数の基本とMayaでの使い方について」

    2020-11-17

  2. Maya Python API 2.0 入門編『最近接頂点の取得』

    2021-05-06

  3. アーティストのためのMaya Python入門 第18回「例外処理の基本を抑えよう!try/except/else/finally」

    2022-01-24

  4. ShrinkWrap & Wrapを使ったジオメトリのデカール

    2020-11-11

コメント

ABOUT

テクニカルアーティストの為のまとめサイトです。

本サイトでは、『YouTube ✕ Blog』を中心に
情報発信をしていきます。

また、テクニカルアーティストとしての様々な
ライフハック記事も投稿予定です。

限定情報会員

PATREONでは、限定情報やサンプルファイルの配布も行っています。登録頂けると更新頑張れます。支援の方よろしくお願いします。


免責事項

本ウェブサイト内で公開している全ての情報の有用性や安全性については当方は一切の保証を与えるものではありません。
利用したことによって引き起こる直接および間接的な損害に対して当方は一切責任を負うものではありません。
全て自己責任でご使用ください。

3DCGBOOK出版

BOOTHで技術書を販売利しております。







スポンサー

ページ上部へ戻る