Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1119 lines
37 KiB

  1. //======= Copyright � 1996-2006, Valve Corporation, All rights reserved. ======
  2. //
  3. // Purpose: Utility classes for creating, registering & deregistering
  4. // Maya MPx* derived classes
  5. //
  6. //=============================================================================
  7. #ifndef VSMAYAMPXFACTORY_H
  8. #define VSMAYAMPXFACTORY_H
  9. #if defined( _WIN32 )
  10. #pragma once
  11. #endif
  12. #include <maya/MPxCommand.h>
  13. #include <maya/MPxDeformerNode.h>
  14. #include <maya/MPxDragAndDropBehavior.h>
  15. #include <maya/MPxFileTranslator.h>
  16. #include <maya/MPxLocatorNode.h>
  17. #include <maya/MPxNode.h>
  18. #include <maya/MPxSurfaceShape.h>
  19. #include <maya/MPxSurfaceShapeUI.h>
  20. #include <maya/MPxToolCommand.h>
  21. #include <maya/MPxTransform.h>
  22. #include <maya/MPxTransformationMatrix.h>
  23. #include <maya/MSyntax.h>
  24. #if MAYA_API_VERSION >= 200800
  25. #include <maya/MPxImageFile.h>
  26. #endif //MAYA_API_VERSION >= 200800
  27. //-----------------------------------------------------------------------------
  28. //
  29. // Forward declarations
  30. //
  31. //-----------------------------------------------------------------------------
  32. class MFnPlugin;
  33. namespace ValveMaya
  34. {
  35. class CMSyntaxHelp;
  36. }
  37. //=============================================================================
  38. //
  39. // Base class for Maya MPx factories
  40. //
  41. //=============================================================================
  42. class CVsMayaMPxFactoryBase
  43. {
  44. public:
  45. // Registers all MPx derived things that have been allocated
  46. static MStatus RegisterEverything( MFnPlugin &pluginFn );
  47. // Deregisters all MPx derived things that have been allocated
  48. static MStatus DeregisterEverything( MFnPlugin &pluginFn );
  49. // Displays a list of stuff in the plugin
  50. static void DisplaySummary( const MString &pluginName );
  51. // Types of things the MPxFactory can create
  52. enum Type
  53. {
  54. // NOTE: Ensure this list of enums stays in sync with GetTypeName() array
  55. kCommand,
  56. kFileTranslator,
  57. kDependencyNode,
  58. kShaderNode,
  59. kTransform,
  60. kLocatorNode,
  61. kImageFile,
  62. // Insert new ones above here
  63. kUnknown
  64. };
  65. void Enable( bool bEnabled ) { m_bEnabled = bEnabled; }
  66. bool IsEnabled() const { return m_bEnabled; }
  67. protected:
  68. // Constructor
  69. CVsMayaMPxFactoryBase();
  70. private:
  71. // The next factory
  72. CVsMayaMPxFactoryBase* m_pNextFactory;
  73. // The starting factory
  74. static CVsMayaMPxFactoryBase *s_pFirstFactory;
  75. // Register the thing associated with this factory
  76. virtual MStatus Register( MFnPlugin &pluginFn ) const = 0;
  77. // Deregister the thing associated with this factory
  78. virtual MStatus Deregister( MFnPlugin &pluginFn ) const = 0;
  79. // Everything has a name
  80. virtual const MString &GetName() const = 0;
  81. // Everything has a description
  82. virtual const MString &GetDesc() const = 0;
  83. // Everything has a type
  84. virtual Type GetType() const = 0;
  85. // Everything has a type (map types to names)
  86. MString GetTypeName() const;
  87. // Whether this factory is enabled or not
  88. bool m_bEnabled;
  89. };
  90. //-----------------------------------------------------------------------------
  91. //
  92. // Templatized helpers for creating MPx derived classes
  93. //
  94. //-----------------------------------------------------------------------------
  95. template< class T >
  96. class CVsMayaMPxFactory : public CVsMayaMPxFactoryBase
  97. {
  98. private:
  99. // Register the thing associated with this factory
  100. virtual MStatus Register( MFnPlugin &pluginFn ) const
  101. {
  102. return T::Register( pluginFn );
  103. }
  104. // Deregister the thing associated with this factory
  105. virtual MStatus Deregister( MFnPlugin &pluginFn ) const
  106. {
  107. return T::Deregister( pluginFn );
  108. }
  109. virtual const MString &GetName() const
  110. {
  111. return T::s_name;
  112. }
  113. virtual const MString &GetDesc() const
  114. {
  115. return T::s_desc;
  116. }
  117. virtual Type GetType() const
  118. {
  119. return T::GetType();
  120. }
  121. };
  122. //============================================================================
  123. //
  124. // Base class for Valve Maya commands ( CVsMayaMPxCommand )
  125. //
  126. //============================================================================
  127. class CVsMayaMPxCommand : public MPxCommand
  128. {
  129. public:
  130. virtual const MString &GetName() const { return m_nullStr; }
  131. virtual const MString &GetDesc() const { return m_nullStr; }
  132. protected:
  133. // Derived classes must specify this to override syntax
  134. virtual void SpecifySyntax( MSyntax &mSyntax, ValveMaya::CMSyntaxHelp &help );
  135. ValveMaya::CMSyntaxHelp *GetSyntaxHelp() { return m_pSyntaxHelp; }
  136. private:
  137. ValveMaya::CMSyntaxHelp *m_pSyntaxHelp;
  138. static MStatus Register(
  139. MFnPlugin &pluginFn,
  140. const MString &name,
  141. MCreatorFunction creatorFunction,
  142. MCreateSyntaxFunction createSyntaxFunction = NULL );
  143. static MStatus Deregister( MFnPlugin &pluginFn, const MString &name );
  144. template < class T > friend class CVsMayaMPxCommandDecorator;
  145. MString m_nullStr;
  146. };
  147. //-----------------------------------------------------------------------------
  148. //
  149. // Decorator class for Valve Maya commands ( CVsMayaMPxCommandDecorator )
  150. //
  151. //-----------------------------------------------------------------------------
  152. template < class T >
  153. class CVsMayaMPxCommandDecorator : public T
  154. {
  155. public:
  156. static const MString &Name() { return s_name; };
  157. static const MString &Desc() { return s_desc; };
  158. virtual const MString &GetName() const { return Name(); };
  159. virtual const MString &GetDesc() const { return Desc(); };
  160. static CVsMayaMPxFactoryBase::Type GetType() { return CVsMayaMPxFactoryBase::kCommand; }
  161. private:
  162. friend class CVsMayaMPxFactoryBase;
  163. template < class U > friend class CVsMayaMPxFactory;
  164. // These should be const but it's not because the CVsMayaMPxFactoryCommand class
  165. // only knows its name and therefore it's description at runtime
  166. static MString s_name;
  167. static MString s_desc;
  168. static ValveMaya::CMSyntaxHelp s_mSyntaxHelp; // Keeps track of command line flags
  169. static void *Create()
  170. {
  171. CVsMayaMPxCommandDecorator *pDecorator = new CVsMayaMPxCommandDecorator< T >;
  172. pDecorator->m_pSyntaxHelp = &s_mSyntaxHelp;
  173. return pDecorator;
  174. }
  175. static MSyntax CreateSyntax()
  176. {
  177. // Maya will simply never call this unless the 'hasSyntax()' virtual returns true
  178. // doesn't matter if a syntaxCreator is registered or not, and an empty
  179. // MSyntax is fine too. Also note the return is by value and not reference.
  180. // Also... even when Maya does call this, it is only ever called once, the
  181. // first time Maya needs to know what the syntax is (when the command is
  182. // invoked or when help cmd is done
  183. MSyntax mSyntax;
  184. T().SpecifySyntax( mSyntax, s_mSyntaxHelp );
  185. return mSyntax;
  186. }
  187. static MStatus Register( MFnPlugin &pluginFn )
  188. {
  189. return T::Register( pluginFn, s_name, Create, T().hasSyntax() ? CreateSyntax : NULL );
  190. }
  191. static MStatus Deregister( MFnPlugin &pluginFn )
  192. {
  193. return T::Deregister( pluginFn, s_name );
  194. }
  195. };
  196. //============================================================================
  197. //
  198. // Base class for Valve Maya commands ( CVsMayaMPxToolCommand )
  199. //
  200. //============================================================================
  201. class CVsMayaMPxToolCommand : public MPxToolCommand
  202. {
  203. public:
  204. virtual const MString &GetName() const { return m_nullStr; }
  205. virtual const MString &GetDesc() const { return m_nullStr; }
  206. protected:
  207. // Derived classes must specify this to override syntax
  208. virtual void SpecifySyntax( MSyntax &mSyntax, ValveMaya::CMSyntaxHelp &help );
  209. ValveMaya::CMSyntaxHelp *GetSyntaxHelp() { return m_pSyntaxHelp; }
  210. private:
  211. ValveMaya::CMSyntaxHelp *m_pSyntaxHelp;
  212. static MStatus Register(
  213. MFnPlugin &pluginFn,
  214. const MString &name,
  215. MCreatorFunction creatorFunction,
  216. MCreateSyntaxFunction createSyntaxFunction = NULL );
  217. static MStatus Deregister( MFnPlugin &pluginFn, const MString &name );
  218. template < class T > friend class CVsMayaMPxToolCommandDecorator;
  219. MString m_nullStr;
  220. };
  221. //-----------------------------------------------------------------------------
  222. //
  223. // Decorator class for Valve Maya commands ( CVsMayaMPxToolCommandDecorator )
  224. //
  225. //-----------------------------------------------------------------------------
  226. template < class T >
  227. class CVsMayaMPxToolCommandDecorator : public T
  228. {
  229. public:
  230. static const MString &Name() { return s_name; };
  231. static const MString &Desc() { return s_desc; };
  232. virtual const MString &GetName() const { return Name(); };
  233. virtual const MString &GetDesc() const { return Desc(); };
  234. static CVsMayaMPxFactoryBase::Type GetType() { return CVsMayaMPxFactoryBase::kCommand; }
  235. private:
  236. friend class CVsMayaMPxFactoryBase;
  237. template < class U > friend class CVsMayaMPxFactory;
  238. // These should be const but it's not because the CVsMayaMPxFactoryCommand class
  239. // only knows its name and therefore it's description at runtime
  240. static MString s_name;
  241. static MString s_desc;
  242. static ValveMaya::CMSyntaxHelp s_mSyntaxHelp; // Keeps track of command line flags
  243. static void *Create()
  244. {
  245. CVsMayaMPxToolCommandDecorator *pDecorator = new CVsMayaMPxToolCommandDecorator< T >;
  246. pDecorator->m_pSyntaxHelp = &s_mSyntaxHelp;
  247. return pDecorator;
  248. }
  249. static MSyntax CreateSyntax()
  250. {
  251. // Maya will simply never call this unless the 'hasSyntax()' virtual returns true
  252. // doesn't matter if a syntaxCreator is registered or not, and an empty
  253. // MSyntax is fine too. Also note the return is by value and not reference.
  254. // Also... even when Maya does call this, it is only ever called once, the
  255. // first time Maya needs to know what the syntax is (when the command is
  256. // invoked or when help cmd is done
  257. MSyntax mSyntax;
  258. T().SpecifySyntax( mSyntax, s_mSyntaxHelp );
  259. return mSyntax;
  260. }
  261. static MStatus Register( MFnPlugin &pluginFn )
  262. {
  263. return T::Register( pluginFn, s_name, Create, T().hasSyntax() ? CreateSyntax : NULL );
  264. }
  265. static MStatus Deregister( MFnPlugin &pluginFn )
  266. {
  267. return T::Deregister( pluginFn, s_name );
  268. }
  269. };
  270. //=============================================================================
  271. //
  272. // Base class for Valve Maya file translators ( CVsMayaMPxFileTranslator )
  273. //
  274. //=============================================================================
  275. class CVsMayaMPxFileTranslator : public MPxFileTranslator
  276. {
  277. public:
  278. virtual const MString &GetName() const = 0;
  279. virtual const MString &GetGUIName() const = 0;
  280. protected:
  281. static MStatus Register(
  282. MFnPlugin &pluginFn,
  283. const MString &name,
  284. const MString &guiName,
  285. MCreatorFunction creatorFunction );
  286. static MStatus Deregister(
  287. MFnPlugin &pluginFn,
  288. const MString &name );
  289. };
  290. //-----------------------------------------------------------------------------
  291. //
  292. // Decorator class for Valve Maya file translators ( CVsMayaMPxFileTranslatorDecorator )
  293. //
  294. //-----------------------------------------------------------------------------
  295. template < class T >
  296. class CVsMayaMPxFileTranslatorDecorator : public T
  297. {
  298. public:
  299. virtual const MString &GetName() const { return s_name; };
  300. virtual const MString &GetGUIName() const { return s_guiName; };
  301. virtual const MString &GetDesc() const { return s_desc; };
  302. static CVsMayaMPxFactoryBase::Type GetType() { return CVsMayaMPxFactoryBase::kFileTranslator; }
  303. private:
  304. template < class U > friend class CVsMayaMPxFactory;
  305. static const MString s_name;
  306. static const MString s_desc;
  307. static const MString s_guiName;
  308. static void *Create()
  309. {
  310. return new CVsMayaMPxFileTranslatorDecorator< T >;
  311. }
  312. static MStatus Register( MFnPlugin &pluginFn )
  313. {
  314. return T::Register( pluginFn, s_name, s_guiName, Create );
  315. }
  316. static MStatus Deregister( MFnPlugin &pluginFn )
  317. {
  318. return T::Deregister( pluginFn, s_guiName );
  319. }
  320. };
  321. //=============================================================================
  322. //
  323. // Base class for Valve Maya Dependency Nodes ( CVsMayaMPxNode )
  324. //
  325. //============================================================================
  326. class CVsMayaMPxNode : public MPxNode
  327. {
  328. public:
  329. virtual const MString &GetName() const = 0;
  330. protected:
  331. static MStatus Register(
  332. MFnPlugin &pluginFn,
  333. const MString &name,
  334. const MTypeId &mTypeId,
  335. MCreatorFunction creatorFunction,
  336. MInitializeFunction initFunction,
  337. const MString &classification );
  338. static MStatus Deregister(
  339. MFnPlugin &pluginFn,
  340. const MTypeId &mTypeId );
  341. };
  342. //-----------------------------------------------------------------------------
  343. //
  344. // Decorator class for Valve Maya nodes ( CVsMayaMPxNodeDecorator )
  345. //
  346. //-----------------------------------------------------------------------------
  347. template < class T >
  348. class CVsMayaMPxNodeDecorator : public T
  349. {
  350. public:
  351. static const MString &Name() { return s_name; };
  352. virtual const MString &GetName() const { return Name(); };
  353. virtual const MString &GetDesc() const { return s_desc; };
  354. static CVsMayaMPxFactoryBase::Type GetType()
  355. {
  356. return s_classification.length() ? CVsMayaMPxFactoryBase::kShaderNode : CVsMayaMPxFactoryBase::kDependencyNode;
  357. }
  358. private:
  359. template < class U > friend class CVsMayaMPxFactory;
  360. static const MString s_name;
  361. static const MString s_desc;
  362. static const MTypeId s_mTypeId;
  363. static const MInitializeFunction s_mInitializeFunction;
  364. static const MString s_classification;
  365. static void *Create()
  366. {
  367. return new CVsMayaMPxNodeDecorator< T >;
  368. }
  369. static MStatus Register( MFnPlugin &pluginFn )
  370. {
  371. return T::Register( pluginFn, s_name, s_mTypeId, Create, s_mInitializeFunction, s_classification );
  372. }
  373. static MStatus Deregister( MFnPlugin &pluginFn )
  374. {
  375. return T::Deregister( pluginFn, s_mTypeId );
  376. }
  377. };
  378. //=============================================================================
  379. //
  380. // Base class for Valve Maya Transform Nodes ( CVsMayaMPxTransform )
  381. //
  382. //============================================================================
  383. class CVsMayaMPxTransform : public MPxTransform
  384. {
  385. public:
  386. virtual const MString &GetName() const = 0;
  387. protected:
  388. #if MAYA_API_VERSION >= 200900
  389. static MStatus Register(
  390. MFnPlugin &pluginFn,
  391. const MString &name,
  392. const MTypeId &mTypeId,
  393. MCreatorFunction creatorFunction,
  394. MInitializeFunction initFunction,
  395. MCreateXformMatrixFunction xformCreatorFunction = MPxTransformationMatrix::creator,
  396. const MTypeId &xformMTypeId = MPxTransformationMatrix::baseTransformationMatrixId,
  397. const MString *classification = NULL );
  398. #else // #if MAYA_API_VERSION >= 200900
  399. static MStatus Register(
  400. MFnPlugin &pluginFn,
  401. const MString &name,
  402. const MTypeId &mTypeId,
  403. MCreatorFunction creatorFunction,
  404. MInitializeFunction initFunction,
  405. MCreatorFunction xformCreatorFunction = MPxTransformationMatrix::creator,
  406. const MTypeId &xformMTypeId = MPxTransformationMatrix::baseTransformationMatrixId,
  407. const MString *classification = NULL );
  408. #endif // #if MAYA_API_VERSION >= 200900
  409. static MStatus Deregister(
  410. MFnPlugin &pluginFn,
  411. const MTypeId &mTypeId );
  412. };
  413. //-----------------------------------------------------------------------------
  414. //
  415. // Decorator class for Valve Maya commands ( CVsMayaMPxCommandDecorator )
  416. //
  417. //-----------------------------------------------------------------------------
  418. template < class T >
  419. class CVsMayaMPxTransformDecorator : public T
  420. {
  421. public:
  422. static const MString &Name() { return s_name; };
  423. virtual const MString &GetName() const { return Name(); };
  424. virtual const MString &GetDesc() const { return s_desc; };
  425. static CVsMayaMPxFactoryBase::Type GetType() { return CVsMayaMPxFactoryBase::kTransform; }
  426. private:
  427. template < class U > friend class CVsMayaMPxFactory;
  428. static const MString s_name;
  429. static const MString s_desc;
  430. static const MTypeId s_mTypeId;
  431. static const MInitializeFunction s_mInitializeFunction;
  432. #if MAYA_API_VERSION >= 200900
  433. static const MCreateXformMatrixFunction s_xformMCreatorFunction;
  434. #else // #if MAYA_API_VERSION >= 200900
  435. static const MCreatorFunction s_xformMCreatorFunction;
  436. #endif // #if MAYA_API_VERSION >= 200900
  437. static const MTypeId s_xformMTypeId;
  438. static void *Create()
  439. {
  440. return new CVsMayaMPxTransformDecorator< T >;
  441. }
  442. static MStatus Register( MFnPlugin &pluginFn )
  443. {
  444. return T::Register( pluginFn, s_name, s_mTypeId, Create, s_mInitializeFunction, s_xformMCreatorFunction, s_xformMTypeId );
  445. }
  446. static MStatus Deregister( MFnPlugin &pluginFn )
  447. {
  448. return T::Deregister( pluginFn, s_mTypeId );
  449. }
  450. };
  451. //=============================================================================
  452. //
  453. // Base class for Valve Maya Locator Nodes ( CVsMayaMPxLocatorNode )
  454. //
  455. //============================================================================
  456. class CVsMayaMPxLocatorNode : public MPxLocatorNode
  457. {
  458. public:
  459. virtual const MString &GetName() const = 0;
  460. protected:
  461. static MStatus Register(
  462. MFnPlugin &pluginFn,
  463. const MString &name,
  464. const MTypeId &mTypeId,
  465. MCreatorFunction creatorFunction,
  466. MInitializeFunction initFunction );
  467. static MStatus Deregister(
  468. MFnPlugin &pluginFn,
  469. const MTypeId &mTypeId );
  470. };
  471. //-----------------------------------------------------------------------------
  472. //
  473. // Decorator class for Valve Maya nodes ( CVsMayaMPxLocatorNodeDecorator )
  474. //
  475. //-----------------------------------------------------------------------------
  476. template < class T >
  477. class CVsMayaMPxLocatorNodeDecorator : public T
  478. {
  479. public:
  480. static const MString &Name() { return s_name; };
  481. virtual const MString &GetName() const { return Name(); };
  482. virtual const MString &GetDesc() const { return s_desc; };
  483. static CVsMayaMPxFactoryBase::Type GetType()
  484. {
  485. return CVsMayaMPxFactoryBase::kLocatorNode;
  486. }
  487. private:
  488. template < class U > friend class CVsMayaMPxFactory;
  489. static const MString s_name;
  490. static const MString s_desc;
  491. static const MTypeId s_mTypeId;
  492. static const MInitializeFunction s_mInitializeFunction;
  493. static void *Create()
  494. {
  495. return new CVsMayaMPxLocatorNodeDecorator< T >;
  496. }
  497. static MStatus Register( MFnPlugin &pluginFn )
  498. {
  499. return T::Register( pluginFn, s_name, s_mTypeId, Create, s_mInitializeFunction );
  500. }
  501. static MStatus Deregister( MFnPlugin &pluginFn )
  502. {
  503. return T::Deregister( pluginFn, s_mTypeId );
  504. }
  505. };
  506. //=============================================================================
  507. //
  508. // Base class for Valve Maya Drag And Drop Behaviors ( CVsMayaMPxDragAndDropBehavior )
  509. //
  510. //============================================================================
  511. class CVsMayaMPxDragAndDropBehavior : public MPxDragAndDropBehavior
  512. {
  513. public:
  514. virtual const MString &GetName() const = 0;
  515. protected:
  516. static MStatus Register(
  517. MFnPlugin &pluginFn,
  518. const MString &name,
  519. MCreatorFunction creatorFunction );
  520. static MStatus Deregister(
  521. MFnPlugin &pluginFn,
  522. const MString &name );
  523. };
  524. //-----------------------------------------------------------------------------
  525. //
  526. // Decorator class for Valve Maya drag and drop behaviors ( CVsMayaMPxDragAndDropBehavior )
  527. //
  528. //-----------------------------------------------------------------------------
  529. template < class T >
  530. class CVsMayaMPxDragAndDropBehaviorDecorator : public T
  531. {
  532. public:
  533. static const MString &Name() { return s_name; };
  534. virtual const MString &GetName() const { return Name(); };
  535. virtual const MString &GetDesc() const { return s_desc; };
  536. static CVsMayaMPxFactoryBase::Type GetType()
  537. {
  538. return CVsMayaMPxFactoryBase::kLocatorNode;
  539. }
  540. private:
  541. template < class U > friend class CVsMayaMPxFactory;
  542. static const MString s_name;
  543. static const MString s_desc;
  544. static const MInitializeFunction s_mInitializeFunction;
  545. static void *Create()
  546. {
  547. return new CVsMayaMPxDragAndDropBehaviorDecorator< T >;
  548. }
  549. static MStatus Register( MFnPlugin &pluginFn )
  550. {
  551. return T::Register( pluginFn, s_name, Create );
  552. }
  553. static MStatus Deregister( MFnPlugin &pluginFn )
  554. {
  555. return T::Deregister( pluginFn, s_name );
  556. }
  557. };
  558. //=============================================================================
  559. //
  560. // Base class for Valve Maya Shape Nodes ( CVsMayaMPxShapeNode )
  561. //
  562. //============================================================================
  563. class CVsMayaMPxShapeNode : public MPxSurfaceShape
  564. {
  565. public:
  566. virtual const MString &GetName() const = 0;
  567. protected:
  568. static MStatus Register(
  569. MFnPlugin &pluginFn,
  570. const MString &name,
  571. const MTypeId &mTypeId,
  572. MCreatorFunction creatorFunction,
  573. MInitializeFunction initFunction,
  574. MCreatorFunction uiCreatorFunction );
  575. static MStatus Deregister(
  576. MFnPlugin &pluginFn,
  577. const MTypeId &mTypeId );
  578. };
  579. //-----------------------------------------------------------------------------
  580. //
  581. // Decorator class for Valve Maya shape nodes ( CVsMayaMPxShapeNodeDecorator )
  582. //
  583. //-----------------------------------------------------------------------------
  584. template < class T, class U >
  585. class CVsMayaMPxShapeNodeDecorator : public T
  586. {
  587. public:
  588. static const MString &Name() { return s_name; };
  589. virtual const MString &GetName() const { return Name(); };
  590. virtual const MString &GetDesc() const { return s_desc; };
  591. static CVsMayaMPxFactoryBase::Type GetType()
  592. {
  593. return CVsMayaMPxFactoryBase::kLocatorNode;
  594. }
  595. private:
  596. template < class U > friend class CVsMayaMPxFactory;
  597. static const MString s_name;
  598. static const MString s_desc;
  599. static const MTypeId s_mTypeId;
  600. static const MInitializeFunction s_mInitializeFunction;
  601. static const MCreatorFunction s_uiCreatorFunction;
  602. static void *Create()
  603. {
  604. return new CVsMayaMPxShapeNodeDecorator< T, U >;
  605. }
  606. static void *CreateUI()
  607. {
  608. return new U;
  609. }
  610. static MStatus Register( MFnPlugin &pluginFn )
  611. {
  612. return T::Register( pluginFn, s_name, s_mTypeId, Create, s_mInitializeFunction, CreateUI );
  613. }
  614. static MStatus Deregister( MFnPlugin &pluginFn )
  615. {
  616. return T::Deregister( pluginFn, s_mTypeId );
  617. }
  618. };
  619. #if MAYA_API_VERSION >= 200800
  620. //=============================================================================
  621. //
  622. // Base class for Valve Maya Image File Types ( CVsMayaMPxImageFile )
  623. //
  624. //============================================================================
  625. class CVsMayaMPxImageFile : public MPxImageFile
  626. {
  627. public:
  628. virtual const MString &GetName() const = 0;
  629. protected:
  630. static MStatus Register(
  631. MFnPlugin &pluginFn,
  632. const MString &name,
  633. MCreatorFunction creatorFunction,
  634. const MStringArray &extensions );
  635. static MStatus Deregister(
  636. MFnPlugin &pluginFn,
  637. const MString &name );
  638. };
  639. //-----------------------------------------------------------------------------
  640. //
  641. // Decorator class for Valve Maya Image Files ( CVsMayaMPxImageFileDecorator )
  642. //
  643. //-----------------------------------------------------------------------------
  644. template < class T >
  645. class CVsMayaMPxImageFileDecorator : public T
  646. {
  647. public:
  648. static const MString &Name() { return s_name; };
  649. virtual const MString &GetName() const { return Name(); };
  650. virtual const MString &GetDesc() const { return s_desc; };
  651. static CVsMayaMPxFactoryBase::Type GetType()
  652. {
  653. return CVsMayaMPxFactoryBase::kImageFile;
  654. }
  655. private:
  656. template < class T > friend class CVsMayaMPxFactory;
  657. static const MString s_name;
  658. static const MString s_desc;
  659. static const MStringArray s_extensions;
  660. static const MCreatorFunction s_creatorFunction;
  661. static void *Create()
  662. {
  663. return new CVsMayaMPxImageFileDecorator< T >;
  664. }
  665. static MStatus Register( MFnPlugin &pluginFn )
  666. {
  667. return T::Register( pluginFn, s_name, Create, s_extensions );
  668. }
  669. static MStatus Deregister( MFnPlugin &pluginFn )
  670. {
  671. return T::Deregister( pluginFn, s_name );
  672. }
  673. };
  674. //-----------------------------------------------------------------------------
  675. // Helper macro to instantiate an image file
  676. //-----------------------------------------------------------------------------
  677. #define INSTALL_MAYA_MPXIMAGEFILE( _class, _name, _extensions, _desc ) \
  678. const MString CVsMayaMPxImageFileDecorator< _class >::s_name( #_name ); \
  679. const MString CVsMayaMPxImageFileDecorator< _class >::s_desc( _desc ); \
  680. const MStringArray CVsMayaMPxImageFileDecorator< _class >::s_extensions( _extensions ); \
  681. static CVsMayaMPxFactory< CVsMayaMPxImageFileDecorator< _class > > s_##_name##_Factory
  682. #endif // MAYA_API_VERSION >= 200800
  683. //=============================================================================
  684. //
  685. // Base class for Valve Maya Dependency Nodes ( CVsMayaMPxNode )
  686. //
  687. //============================================================================
  688. class CVsMayaMPxDeformerNode : public MPxDeformerNode
  689. {
  690. public:
  691. virtual const MString &GetName() const = 0;
  692. protected:
  693. static MStatus Register(
  694. MFnPlugin &pluginFn,
  695. const MString &name,
  696. const MTypeId &mTypeId,
  697. MCreatorFunction creatorFunction,
  698. MInitializeFunction initFunction,
  699. const MString &classification );
  700. static MStatus Deregister(
  701. MFnPlugin &pluginFn,
  702. const MTypeId &mTypeId );
  703. };
  704. //-----------------------------------------------------------------------------
  705. //
  706. // Decorator class for Valve Maya nodes ( CVsMayaMPxDeformerNodeDecorator )
  707. //
  708. //-----------------------------------------------------------------------------
  709. template < class T >
  710. class CVsMayaMPxDeformerNodeDecorator : public T
  711. {
  712. public:
  713. static const MString &Name() { return s_name; };
  714. virtual const MString &GetName() const { return Name(); };
  715. virtual const MString &GetDesc() const { return s_desc; };
  716. static CVsMayaMPxFactoryBase::Type GetType()
  717. {
  718. return s_classification.length() ? CVsMayaMPxFactoryBase::kShaderNode : CVsMayaMPxFactoryBase::kDependencyNode;
  719. }
  720. private:
  721. template < class U > friend class CVsMayaMPxFactory;
  722. static const MString s_name;
  723. static const MString s_desc;
  724. static const MTypeId s_mTypeId;
  725. static const MInitializeFunction s_mInitializeFunction;
  726. static const MString s_classification;
  727. static void *Create()
  728. {
  729. return new CVsMayaMPxDeformerNodeDecorator< T >;
  730. }
  731. static MStatus Register( MFnPlugin &pluginFn )
  732. {
  733. return T::Register( pluginFn, s_name, s_mTypeId, Create, s_mInitializeFunction, s_classification );
  734. }
  735. static MStatus Deregister( MFnPlugin &pluginFn )
  736. {
  737. return T::Deregister( pluginFn, s_mTypeId );
  738. }
  739. };
  740. //=============================================================================
  741. //
  742. // Helper Macros
  743. //
  744. //=============================================================================
  745. //-----------------------------------------------------------------------------
  746. // Helper macro to instantiate a command
  747. //-----------------------------------------------------------------------------
  748. #define INSTALL_MAYA_MPXCOMMAND( _class, _name, _desc ) \
  749. MString CVsMayaMPxCommandDecorator< _class >::s_name( #_name ); \
  750. MString CVsMayaMPxCommandDecorator< _class >::s_desc( _desc ); \
  751. ValveMaya::CMSyntaxHelp CVsMayaMPxCommandDecorator< _class >::s_mSyntaxHelp; \
  752. static CVsMayaMPxFactory< CVsMayaMPxCommandDecorator< _class > > s_##_name##_Factory
  753. //-----------------------------------------------------------------------------
  754. // Helper macro to instantiate a command
  755. //-----------------------------------------------------------------------------
  756. #define INSTALL_MAYA_MPXTOOLCOMMAND( _class, _name, _desc ) \
  757. MString CVsMayaMPxToolCommandDecorator< _class >::s_name( #_name ); \
  758. MString CVsMayaMPxToolCommandDecorator< _class >::s_desc( _desc ); \
  759. ValveMaya::CMSyntaxHelp CVsMayaMPxToolCommandDecorator< _class >::s_mSyntaxHelp; \
  760. static CVsMayaMPxFactory< CVsMayaMPxToolCommandDecorator< _class > > s_##_name##_Factory
  761. //-----------------------------------------------------------------------------
  762. // Helper macro to instantiate a translator
  763. //-----------------------------------------------------------------------------
  764. #define INSTALL_MAYA_MPXFILETRANSLATOR( _class, _name, _guiName, _desc ) \
  765. const MString CVsMayaMPxFileTranslatorDecorator< _class >::s_name( #_name ); \
  766. const MString CVsMayaMPxFileTranslatorDecorator< _class >::s_desc( _desc ); \
  767. const MString CVsMayaMPxFileTranslatorDecorator< _class >::s_guiName( _guiName ); \
  768. static CVsMayaMPxFactory< CVsMayaMPxFileTranslatorDecorator< _class > > s_##_name##_Factory
  769. //-----------------------------------------------------------------------------
  770. // Helper macro to instantiate a regular dependency node
  771. //-----------------------------------------------------------------------------
  772. #define INSTALL_MAYA_MPXNODE( _class, _name, _typeId, _initializeFunction, _desc ) \
  773. const MString CVsMayaMPxNodeDecorator< _class >::s_name( #_name ); \
  774. const MString CVsMayaMPxNodeDecorator< _class >::s_desc( _desc ); \
  775. const MTypeId CVsMayaMPxNodeDecorator< _class >::s_mTypeId( _typeId ); \
  776. const MInitializeFunction CVsMayaMPxNodeDecorator< _class >::s_mInitializeFunction( _initializeFunction ); \
  777. const MString CVsMayaMPxNodeDecorator< _class >::s_classification( "" ); \
  778. static CVsMayaMPxFactory< CVsMayaMPxNodeDecorator< _class > > s_##_name##_Factory
  779. //-----------------------------------------------------------------------------
  780. // Helper macro to instantiate a shader dependency node
  781. //-----------------------------------------------------------------------------
  782. #define INSTALL_MAYA_MPXSHADERNODE( _class, _name, _typeId, _initializeFunction, _classification, _desc ) \
  783. const MString CVsMayaMPxNodeDecorator< _class >::s_name( #_name ); \
  784. const MString CVsMayaMPxNodeDecorator< _class >::s_desc( _desc ); \
  785. const MTypeId CVsMayaMPxNodeDecorator< _class >::s_mTypeId( _typeId ); \
  786. const MInitializeFunction CVsMayaMPxNodeDecorator< _class >::s_mInitializeFunction( _initializeFunction ); \
  787. const MString CVsMayaMPxNodeDecorator< _class >::s_classification( _classification ); \
  788. static CVsMayaMPxFactory< CVsMayaMPxNodeDecorator< _class > > s_##_name##_Factory
  789. //-----------------------------------------------------------------------------
  790. // Helper macro to instantiate a transform node
  791. //-----------------------------------------------------------------------------
  792. #if MAYA_API_VERSION >= 200900
  793. #define INSTALL_MAYA_MPXTRANSFORM( _class, _name, _typeId, _initializeFunction, _desc ) \
  794. const MString CVsMayaMPxTransformDecorator< _class >::s_name( #_name ); \
  795. const MString CVsMayaMPxTransformDecorator< _class >::s_desc( _desc ); \
  796. const MTypeId CVsMayaMPxTransformDecorator< _class >::s_mTypeId( _typeId ); \
  797. const MInitializeFunction CVsMayaMPxTransformDecorator< _class >::s_mInitializeFunction( _initializeFunction ); \
  798. const MCreateXformMatrixFunction CVsMayaMPxTransformDecorator< _class >::s_xformMCreatorFunction( MPxTransformationMatrix::creator ); \
  799. const MTypeId CVsMayaMPxTransformDecorator< _class >::s_xformMTypeId( MPxTransformationMatrix::baseTransformationMatrixId ); \
  800. static CVsMayaMPxFactory< CVsMayaMPxTransformDecorator< _class > > s_##_name##_Factory
  801. #else // #if MAYA_API_VERSION >= 200900
  802. #define INSTALL_MAYA_MPXTRANSFORM( _class, _name, _typeId, _initializeFunction, _desc ) \
  803. const MString CVsMayaMPxTransformDecorator< _class >::s_name( #_name ); \
  804. const MString CVsMayaMPxTransformDecorator< _class >::s_desc( _desc ); \
  805. const MTypeId CVsMayaMPxTransformDecorator< _class >::s_mTypeId( _typeId ); \
  806. const MInitializeFunction CVsMayaMPxTransformDecorator< _class >::s_mInitializeFunction( _initializeFunction ); \
  807. const MCreatorFunction CVsMayaMPxTransformDecorator< _class >::s_xformMCreatorFunction( MPxTransformationMatrix::creator ); \
  808. const MTypeId CVsMayaMPxTransformDecorator< _class >::s_xformMTypeId( MPxTransformationMatrix::baseTransformationMatrixId ); \
  809. static CVsMayaMPxFactory< CVsMayaMPxTransformDecorator< _class > > s_##_name##_Factory
  810. #endif // #if MAYA_API_VERSION >= 200900
  811. //-----------------------------------------------------------------------------
  812. // Helper macro to instantiate a transform node with a custom transformation matrix
  813. // TODO: Make CVsMayaMPxTransformationMatrix and create the MCreatorFunction for the user
  814. //-----------------------------------------------------------------------------
  815. #if MAYA_API_VERSION >= 200900
  816. #define INSTALL_MAYA_MPXTRANSFORM_WITHMATRIX( _class, _name, _typeId, _initializeFunction, _xformCreatorFunction, _xformTypeId, _desc ) \
  817. const MString CVsMayaMPxTransformDecorator< _class >::s_name( #_name ); \
  818. const MString CVsMayaMPxTransformDecorator< _class >::s_desc( _desc ); \
  819. const MTypeId CVsMayaMPxTransformDecorator< _class >::s_mTypeId( _typeId ); \
  820. const MInitializeFunction CVsMayaMPxTransformDecorator< _class >::s_mInitializeFunction( _initializeFunction ); \
  821. const MCreateXformMatrixFunction CVsMayaMPxTransformDecorator< _class >::s_xformMCreatorFunction( _xformCreatorFunction ); \
  822. const MTypeId CVsMayaMPxTransformDecorator< _class >::s_xformMTypeId( _xformTypeId ); \
  823. static CVsMayaMPxFactory< CVsMayaMPxTransformDecorator< _class > > s_##_name##_Factory
  824. #else // #if MAYA_API_VERSION >= 200900
  825. #define INSTALL_MAYA_MPXTRANSFORM_WITHMATRIX( _class, _name, _typeId, _initializeFunction, _xformCreatorFunction, _xformTypeId, _desc ) \
  826. const MString CVsMayaMPxTransformDecorator< _class >::s_name( #_name ); \
  827. const MString CVsMayaMPxTransformDecorator< _class >::s_desc( _desc ); \
  828. const MTypeId CVsMayaMPxTransformDecorator< _class >::s_mTypeId( _typeId ); \
  829. const MInitializeFunction CVsMayaMPxTransformDecorator< _class >::s_mInitializeFunction( _initializeFunction ); \
  830. const MCreatorFunction CVsMayaMPxTransformDecorator< _class >::s_xformMCreatorFunction( _xformCreatorFunction ); \
  831. const MTypeId CVsMayaMPxTransformDecorator< _class >::s_xformMTypeId( _xformTypeId ); \
  832. static CVsMayaMPxFactory< CVsMayaMPxTransformDecorator< _class > > s_##_name##_Factory
  833. #endif // #if MAYA_API_VERSION >= 200900
  834. //-----------------------------------------------------------------------------
  835. // Helper macro to instantiate a locator node
  836. //-----------------------------------------------------------------------------
  837. #define INSTALL_MAYA_MPXLOCATORNODE( _class, _name, _typeId, _initializeFunction, _desc ) \
  838. const MString CVsMayaMPxLocatorNodeDecorator< _class >::s_name( #_name ); \
  839. const MString CVsMayaMPxLocatorNodeDecorator< _class >::s_desc( _desc ); \
  840. const MTypeId CVsMayaMPxLocatorNodeDecorator< _class >::s_mTypeId( _typeId ); \
  841. const MInitializeFunction CVsMayaMPxLocatorNodeDecorator< _class >::s_mInitializeFunction( _initializeFunction ); \
  842. static CVsMayaMPxFactory< CVsMayaMPxLocatorNodeDecorator< _class > > s_##_name##_Factory
  843. //-----------------------------------------------------------------------------
  844. // Helper macro to instantiate a drag and drop behavior
  845. //-----------------------------------------------------------------------------
  846. #define INSTALL_MAYA_MPXDRAGANDDROPBEHAVIOR( _class, _name, _desc ) \
  847. const MString CVsMayaMPxDragAndDropBehaviorDecorator< _class >::s_name( #_name ); \
  848. const MString CVsMayaMPxDragAndDropBehaviorDecorator< _class >::s_desc( _desc ); \
  849. static CVsMayaMPxFactory< CVsMayaMPxDragAndDropBehaviorDecorator< _class > > s_##_name##_Factory
  850. //-----------------------------------------------------------------------------
  851. // Helper macro to instantiate a shape node
  852. //-----------------------------------------------------------------------------
  853. #define INSTALL_MAYA_MPXSHAPENODE( _class, _name, _typeId, _initializeFunction, _uiClass, _desc ) \
  854. const MString CVsMayaMPxShapeNodeDecorator< _class, _uiClass >::s_name( #_name ); \
  855. const MString CVsMayaMPxShapeNodeDecorator< _class, _uiClass >::s_desc( _desc ); \
  856. const MTypeId CVsMayaMPxShapeNodeDecorator< _class, _uiClass >::s_mTypeId( _typeId ); \
  857. const MInitializeFunction CVsMayaMPxShapeNodeDecorator< _class, _uiClass >::s_mInitializeFunction( _initializeFunction ); \
  858. static CVsMayaMPxFactory< CVsMayaMPxShapeNodeDecorator< _class, _uiClass > > s_##_name##_Factory
  859. //-----------------------------------------------------------------------------
  860. // Helper macro to instantiate a deformer dependency node
  861. //-----------------------------------------------------------------------------
  862. #define INSTALL_MAYA_MPXDEFORMERNODE( _class, _name, _typeId, _initializeFunction, _desc ) \
  863. const MString CVsMayaMPxDeformerNodeDecorator< _class >::s_name( #_name ); \
  864. const MString CVsMayaMPxDeformerNodeDecorator< _class >::s_desc( _desc ); \
  865. const MTypeId CVsMayaMPxDeformerNodeDecorator< _class >::s_mTypeId( _typeId ); \
  866. const MInitializeFunction CVsMayaMPxDeformerNodeDecorator< _class >::s_mInitializeFunction( _initializeFunction ); \
  867. const MString CVsMayaMPxDeformerNodeDecorator< _class >::s_classification( "" ); \
  868. static CVsMayaMPxFactory< CVsMayaMPxDeformerNodeDecorator< _class > > s_##_name##_Factory
  869. #endif // VSMAYAMPXFACTORY_H