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. Qt DesignerでサクッとGUI作っちゃおう!

    2021-06-27

  2. Hello! GLSL Shader!

    2024-04-06

  3. 長さを固定するスライドチェーンリグを作る

    2021-04-05

  4. Maya Python API 2.0 応用編『最近接頂点スナップツールを作る』

    2021-05-07

コメント

ページ上部へ戻る