この基本的な Maya Hello World C++ ソース コードは、Maya 出力ウィンドウに「Hello World」を出力するプラグインを作成します。
#include <maya/MSimple.h> #include <maya/MIOStream.h> DeclareSimpleCommand( helloWorld, "Autodesk", "2020"); MStatus helloWorld::doIt( const MArgList& ) { cout << "Hello World\n" << endl; return MS::kSuccess; }
このコードをプラグインにコンパイルするには、helloWorld フォルダを作成し、このフォルダにこのコードを helloWorld.cpp というファイル名で保存します。
このプロジェクトの CMakeLists.txt ファイルを作成し、HelloWorld フォルダに保存します。
cmake_minimum_required(VERSION 2.8) set(PROJECT_NAME helloWorld) project(${PROJECT_NAME}) include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake) set(SOURCE_FILES helloWorld.cpp ) set(LIBRARIES OpenMaya Foundation ) build_plugin()
CMake および該当するジェネレータを使用して、コードのプロジェクトをビルドします。
プロジェクトが正常にビルドされたら、CMake を再度使用して、プラグインをビルドします。
cmake --build build
これで、プラグイン マネージャを使用してプラグインを Maya にロードできるようになりました。プラグイン マネージャにアクセスするには、Maya メニューのウィンドウ > 設定/プリファレンス > プラグイン マネージャ(Window > Settings/Preferences > Plug-in Manager)を使用します。
プラグインがロードされたら、Maya コマンド ウィンドウで helloWorld を実行します。
出力が Maya 出力ウィンドウに書き込まれます。
プラグインに渡された引数を使用してあいさつをカスタマイズする機能を持つバージョンも作成できます。
#include <maya/MSimple.h> #include <maya/MIOStream.h> DeclareSimpleCommand( helloWorld, "Autodesk", "2020"); MStatus helloWorld::doIt( const MArgList& args ) { cout << args.asString( 0 ).asChar() << " " << args.asString( 1 ).asChar() << endl; return MS::kSuccess; }
プラグインを再コンパイルする前に、unloadPlugin コマンドを使用してプラグインを Maya からアンロードします。
プラグイン プロジェクトを再作成する必要はありません。必要な作業は、cmake --build build を使用してプラグインを再コンパイルすることだけです。
プラグインを再ロードし、次に示す 2 つの引数を指定して実行します。
あいさつが Maya 出力ウィンドウに出力されます。