下面我们来实现一个功能简单的结点,该结点只有一个输入接口和一个输出接口(注:一个结点可以有多个输入接口和输出接口),要实现的功能是把输入的数据乘以0.5变成原来的一半,然后输出。
打开MayaPluginWizard,新建一个Dependency Graph Node插件
- //
- // Copyright (C)
- //
- // File: pluginMain.cpp
- //
- // Author: Maya Plug-in Wizard 2.0
- //
- #include "halfScaleNodeNode.h"
- #include
- MStatus initializePlugin( MObject obj )
- //
- // Description:
- // this method is called when the plug-in is loaded into Maya. It
- // registers all of the services that this plug-in provides with
- // Maya.
- //
- // Arguments:
- // obj - a handle to the plug-in object (use MFnPlugin to access it)
- //
- {
- MStatus status;
- MFnPlugin plugin( obj, "", "2010", "Any");
- status = plugin.registerNode( "halfScaleNode", halfScaleNode::id, halfScaleNode::creator,
- halfScaleNode::initialize );
- if (!status) {
- status.perror("registerNode");
- return status;
- }
- return status;
- }
- MStatus uninitializePlugin( MObject obj)
- //
- // Description:
- // this method is called when the plug-in is unloaded from Maya. It
- // deregisters all of the services that it was providing.
- //
- // Arguments:
- // obj - a handle to the plug-in object (use MFnPlugin to access it)
- //
- {
- MStatus status;
- MFnPlugin plugin( obj );
- status = plugin.deregisterNode( halfScaleNode::id );
- if (!status) {
- status.perror("deregisterNode");
- return status;
- }
- return status;
- }
- //
- // Copyright (C)
- //
- // File: pluginMain.cpp
- //
- // Author: Maya Plug-in Wizard 2.0
- //
- #include "halfScaleNodeNode.h"
- #include
- MStatus initializePlugin( MObject obj )
- //
- // Description:
- // this method is called when the plug-in is loaded into Maya. It
- // registers all of the services that this plug-in provides with
- // Maya.
- //
- // Arguments:
- // obj - a handle to the plug-in object (use MFnPlugin to access it)
- //
- {
- MStatus status;
- MFnPlugin plugin( obj, "", "2010", "Any");
- status = plugin.registerNode( "halfScaleNode", halfScaleNode::id, halfScaleNode::creator,
- halfScaleNode::initialize );
- if (!status) {
- status.perror("registerNode");
- return status;
- }
- return status;
- }
- MStatus uninitializePlugin( MObject obj)
- //
- // Description:
- // this method is called when the plug-in is unloaded from Maya. It
- // deregisters all of the services that it was providing.
- //
- // Arguments:
- // obj - a handle to the plug-in object (use MFnPlugin to access it)
- //
- {
- MStatus status;
- MFnPlugin plugin( obj );
- status = plugin.deregisterNode( halfScaleNode::id );
- if (!status) {
- status.perror("deregisterNode");
- return status;
- }
- return status;
- }
halfScaleNodeNode.h
- #ifndef _halfScaleNodeNode
- #define _halfScaleNodeNode
- //
- // Copyright (C)
- //
- // File: halfScaleNodeNode.h
- //
- // Dependency Graph Node: halfScaleNode
- //
- // Author: Maya Plug-in Wizard 2.0
- //
- #include
- #include
- #include
- class halfScaleNode : public MPxNode
- {
- public:
- halfScaleNode();
- virtual ~halfScaleNode();
- virtual MStatus compute( const MPlug& plug, MDataBlock& data );
- static void* creator();
- static MStatus initialize();
- public:
- // There needs to be a MObject handle declared for each attribute that
- // the node will have. These handles are needed for getting and setting
- // the values later.
- //
- static MObject input; // Example input attribute
- static MObject output; // Example output attribute
- // The typeid is a unique 32bit indentifier that describes this node.
- // It is used to save and retrieve nodes of this type from the binary
- // file format. If it is not unique, it will cause file IO problems.
- //
- static MTypeId id;
- };
- #endif
- #ifndef _halfScaleNodeNode
- #define _halfScaleNodeNode
- //
- // Copyright (C)
- //
- // File: halfScaleNodeNode.h
- //
- // Dependency Graph Node: halfScaleNode
- //
- // Author: Maya Plug-in Wizard 2.0
- //
- #include
- #include
- #include
- class halfScaleNode : public MPxNode
- {
- public:
- halfScaleNode();
- virtual ~halfScaleNode();
- virtual MStatus compute( const MPlug& plug, MDataBlock& data );
- static void* creator();
- static MStatus initialize();
- public:
- // There needs to be a MObject handle declared for each attribute that
- // the node will have. These handles are needed for getting and setting
- // the values later.
- //
- static MObject input; // Example input attribute
- static MObject output; // Example output attribute
- // The typeid is a unique 32bit indentifier that describes this node.
- // It is used to save and retrieve nodes of this type from the binary
- // file format. If it is not unique, it will cause file IO problems.
- //
- static MTypeId id;
- };
- #endif