KnickKnack

Scene hierarchy traversing application

Sep 30th, 2016
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define APPID 1234567
  2.  
  3. #include <windows.h>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. #include "default_alien_overloads.h"
  8. using namespace melange;
  9.  
  10. //----------------------------------------------------------------------------------------
  11. /// Implementation of GetWriterInfo to return the exchange / external application ID and name.
  12. /// @param[in] id                   Application ID.
  13. /// @param[in] appname                  Application string name.
  14. //----------------------------------------------------------------------------------------
  15. void GetWriterInfo(Int32 &id, String &appname);
  16.  
  17. //----------------------------------------------------------------------------------------
  18. /// Recursive helper function to traverse the hierarchy under a passed object.
  19. /// @param[in] baseObj                  The current object.
  20. /// @param[in] spacer                   String taking care of the spacing the output.
  21. /// @param[in] nestinglevel             The counter to the hierarchy level.
  22. //----------------------------------------------------------------------------------------
  23. void IterateOverObject(BaseObject* baseObj = nullptr, String spacer = "", Int32 nestingLevel = 0);
  24.  
  25.  
  26. void GetWriterInfo(Int32 &id, String &appname)
  27. {
  28.     id = APPID;
  29.     appname = "SceneHierarchy";
  30. }
  31.  
  32. void IterateOverObject(BaseObject* baseObj /*= nullptr*/, String spacer /*= ""*/, Int32 nestingLevel /*= 0*/)
  33. {
  34.     if (nullptr == baseObj)
  35.         return;
  36.  
  37.     BaseObject *currentObjPtr = baseObj;
  38.  
  39.     String objName = baseObj->GetName();
  40.     cout << spacer.GetCStringCopy(STRINGENCODING_UTF8) << objName.GetCStringCopy(STRINGENCODING_UTF8) << "["<< nestingLevel <<"]"<<endl;
  41.    
  42.     spacer += "+";
  43.     nestingLevel++;
  44.  
  45.     currentObjPtr = baseObj->GetDown();
  46.     while (currentObjPtr)
  47.     {
  48.         IterateOverObject(currentObjPtr, spacer, nestingLevel);
  49.         currentObjPtr = currentObjPtr->GetNext();
  50.     }
  51. }
  52.  
  53. int main(int argc, Char* argv[])
  54. {
  55.     // Path to the scene to scan.
  56.     const String file = "SceneHierarchy.c4d";
  57.  
  58.     // Load the scene document.
  59.     BaseDocument *c4dDoc = LoadDocument(file, SCENEFILTER_OBJECTS);
  60.     if (!c4dDoc)
  61.         return -1;
  62.  
  63.     BaseObject* currentObj = c4dDoc->GetFirstObject();
  64.  
  65.     while (currentObj)
  66.     {
  67.         IterateOverObject(currentObj, " ", 0);
  68.         cout << endl;
  69.         currentObj = currentObj->GetNext();
  70.     }
  71.  
  72.     return 0;
  73. }
RAW Paste Data