MAYA插件入门 之二(转载)_huadingjin_新浪博客

         下面我们来实现一个功能简单的结点,该结点只有一个输入接口和一个输出接口(注:一个结点可以有多个输入接口和输出接口),要实现的功能是把输入的数据乘以0.5变成原来的一半,然后输出。

         打开MayaPluginWizard,新建一个Dependency Graph Node插件

halfScaleNode

 

 

[cpp]  view plain copy
  1. //   
  2. // Copyright (C)    
  3. //    
  4. // File: pluginMain.cpp   
  5. //   
  6. // Author: Maya Plug-in Wizard 2.0   
  7. //   
  8.   
  9. #include "halfScaleNodeNode.h"   
  10.   
  11. #include    
  12.   
  13. MStatus initializePlugin( MObject obj )  
  14. //   
  15. //  Description:   
  16. //      this method is called when the plug-in is loaded into Maya.  It    
  17. //      registers all of the services that this plug-in provides with    
  18. //      Maya.   
  19. //   
  20. //  Arguments:   
  21. //      obj - a handle to the plug-in object (use MFnPlugin to access it)   
  22. //   
  23. {   
  24.     MStatus   status;  
  25.     MFnPlugin plugin( obj, """2010""Any");  
  26.   
  27.     status = plugin.registerNode( "halfScaleNode", halfScaleNode::id, halfScaleNode::creator,  
  28.                                   halfScaleNode::initialize );  
  29.     if (!status) {  
  30.         status.perror("registerNode");  
  31.         return status;  
  32.     }  
  33.   
  34.     return status;  
  35. }  
  36.   
  37. MStatus uninitializePlugin( MObject obj)  
  38. //   
  39. //  Description:   
  40. //      this method is called when the plug-in is unloaded from Maya. It    
  41. //      deregisters all of the services that it was providing.   
  42. //   
  43. //  Arguments:   
  44. //      obj - a handle to the plug-in object (use MFnPlugin to access it)   
  45. //   
  46. {  
  47.     MStatus   status;  
  48.     MFnPlugin plugin( obj );  
  49.   
  50.     status = plugin.deregisterNode( halfScaleNode::id );  
  51.     if (!status) {  
  52.         status.perror("deregisterNode");  
  53.         return status;  
  54.     }  
  55.   
  56.     return status;  
  57. }  
[cpp]  view plain copy
  1. //  
  2. // Copyright (C)   
  3. //   
  4. // File: pluginMain.cpp  
  5. //  
  6. // Author: Maya Plug-in Wizard 2.0  
  7. //  
  8.   
  9. #include "halfScaleNodeNode.h"  
  10.   
  11. #include   
  12.   
  13. MStatus initializePlugin( MObject obj )  
  14. //  
  15. //  Description:  
  16. //      this method is called when the plug-in is loaded into Maya.  It   
  17. //      registers all of the services that this plug-in provides with   
  18. //      Maya.  
  19. //  
  20. //  Arguments:  
  21. //      obj - a handle to the plug-in object (use MFnPlugin to access it)  
  22. //  
  23. {   
  24.     MStatus   status;  
  25.     MFnPlugin plugin( obj, """2010""Any");  
  26.   
  27.     status = plugin.registerNode( "halfScaleNode", halfScaleNode::id, halfScaleNode::creator,  
  28.                                   halfScaleNode::initialize );  
  29.     if (!status) {  
  30.         status.perror("registerNode");  
  31.         return status;  
  32.     }  
  33.   
  34.     return status;  
  35. }  
  36.   
  37. MStatus uninitializePlugin( MObject obj)  
  38. //  
  39. //  Description:  
  40. //      this method is called when the plug-in is unloaded from Maya. It   
  41. //      deregisters all of the services that it was providing.  
  42. //  
  43. //  Arguments:  
  44. //      obj - a handle to the plug-in object (use MFnPlugin to access it)  
  45. //  
  46. {  
  47.     MStatus   status;  
  48.     MFnPlugin plugin( obj );  
  49.   
  50.     status = plugin.deregisterNode( halfScaleNode::id );  
  51.     if (!status) {  
  52.         status.perror("deregisterNode");  
  53.         return status;  
  54.     }  
  55.   
  56.     return status;  
  57. }  


 

halfScaleNodeNode.h

[cpp]  view plain copy
  1. #ifndef _halfScaleNodeNode   
  2. #define _halfScaleNodeNode   
  3. //   
  4. // Copyright (C)    
  5. //    
  6. // File: halfScaleNodeNode.h   
  7. //   
  8. // Dependency Graph Node: halfScaleNode   
  9. //   
  10. // Author: Maya Plug-in Wizard 2.0   
  11. //   
  12.   
  13. #include    
  14. #include    
  15. #include     
  16.   
  17.    
  18. class halfScaleNode : public MPxNode  
  19. {  
  20. public:  
  21.                         halfScaleNode();  
  22.     virtual             ~halfScaleNode();   
  23.   
  24.     virtual MStatus     compute( const MPlug& plug, MDataBlock& data );  
  25.   
  26.     static  void*       creator();  
  27.     static  MStatus     initialize();  
  28.   
  29. public:  
  30.   
  31.     // There needs to be a MObject handle declared for each attribute that   
  32.     // the node will have.  These handles are needed for getting and setting   
  33.     // the values later.   
  34.     //   
  35.     static  MObject     input;      // Example input attribute   
  36.     static  MObject     output;     // Example output attribute   
  37.   
  38.   
  39.     // The typeid is a unique 32bit indentifier that describes this node.   
  40.     // It is used to save and retrieve nodes of this type from the binary   
  41.     // file format.  If it is not unique, it will cause file IO problems.   
  42.     //   
  43.     static  MTypeId     id;  
  44. };  
  45.   
  46. #endif  
[cpp]  view plain copy
  1. #ifndef _halfScaleNodeNode  
  2. #define _halfScaleNodeNode  
  3. //  
  4. // Copyright (C)   
  5. //   
  6. // File: halfScaleNodeNode.h  
  7. //  
  8. // Dependency Graph Node: halfScaleNode  
  9. //  
  10. // Author: Maya Plug-in Wizard 2.0  
  11. //  
  12.   
  13. #include   
  14. #include   
  15. #include    
  16.   
  17.    
  18. class halfScaleNode : public MPxNode  
  19. {  
  20. public:  
  21.                         halfScaleNode();  
  22.     virtual             ~halfScaleNode();   
  23.   
  24.     virtual MStatus     compute( const MPlug& plug, MDataBlock& data );  
  25.   
  26.     static  void*       creator();  
  27.     static  MStatus     initialize();  
  28.   
  29. public:  
  30.   
  31.     // There needs to be a MObject handle declared for each attribute that  
  32.     // the node will have.  These handles are needed for getting and setting  
  33.     // the values later.  
  34.     //  
  35.     static  MObject     input;      // Example input attribute  
  36.     static  MObject     output;     // Example output attribute  
  37.   
  38.   
  39.     // The typeid is a unique 32bit indentifier that describes this node.  
  40.     // It is used to save and retrieve nodes of this type from the binary  
  41.     // file format.  If it is not unique, it will cause file IO problems.  
  42.     //  
  43.     static  MTypeId     id;  
  44. };  
  45.   
  46. #endif  


 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值