Advertisement
gr4ph0s

C4D material sharing GvNodeMaster sample

Oct 4th, 2017
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. // Graphos 05/10/207
  2. // example of c4d material that store a GvNodeMaster and how to share it using BaseContainer message
  3. // Usage example http://recordit.co/fJlz8Dnf3Y
  4. // Python script => https://pastebin.com/CFrpTfrY
  5.  
  6. #include <c4d_graphview.h>
  7. #include "c4d.h"
  8. #include "c4d_symbols.h"
  9. #include "msimplematerial.h"
  10. #include "customgui_matpreview.h"
  11. #include "main.h"
  12.  
  13. // be sure to use a unique ID obtained from www.plugincafe.com
  14. #define ID_SIMPLEMAT 1001164
  15.  
  16. class RedShiftMaterial : public MaterialData
  17. {
  18.     INSTANCEOF(SimpleMaterial, MaterialData)
  19.  
  20. private:
  21.     GvWorld* world;
  22.     GvNodeMaster* NodeMaster;
  23.  
  24. public:
  25.     virtual Bool Init(GeListNode* node);
  26.     virtual void Free(GeListNode *node);
  27.     virtual Bool Message(GeListNode* node, Int32 type, void* data);
  28.  
  29.     static NodeData* Alloc(void) { return NewObjClear(RedShiftMaterial); }
  30. };
  31.  
  32. Bool RedShiftMaterial::Init(GeListNode* node)
  33. {
  34.     world = GvGetWorld();
  35.     NodeMaster = world->AllocNodeMaster((BaseList2D*)node, false, true);
  36.     return true;
  37. }
  38.  
  39. void RedShiftMaterial::Free(GeListNode* node)
  40. {
  41.     world->FreeNodeMaster(NodeMaster);
  42.     NodeMaster = nullptr;
  43.     world = nullptr;
  44. }
  45.  
  46.  
  47. Bool RedShiftMaterial::Message(GeListNode* node, Int32 type, void* data)
  48. {
  49.     switch (type)
  50.     {
  51.     case MSG_BASECONTAINER:
  52.     {
  53.         BaseContainer* bc = (BaseContainer*)data;
  54.         bc->SetLink(0, NodeMaster);
  55.         return true;
  56.         break;
  57.     }
  58.     }
  59.  
  60.     return true;
  61. }
  62.  
  63.  
  64. Bool RegisterSimpleMaterial(void)
  65. {
  66.     String name = GeGetDefaultFilename(DEFAULTFILENAME_SHADER_VOLUME) + GeLoadString(IDS_SIMPLEMATERIAL);   // place in default Shader section
  67.  
  68.     // add a preview scene that can only be selected in the Simple Material's preview
  69.     AddUserPreviewScene(GeGetPluginResourcePath() + String("scene") + String("Stairs.c4d"), ID_SIMPLEMAT, nullptr);
  70.  
  71.     return RegisterMaterialPlugin(ID_SIMPLEMAT, name, 0, RedShiftMaterial::Alloc, "Msimplematerial", 0);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement