pierovdfn

Panda3D Virtual Files and TinyXML

Apr 26th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. /**
  2.  * A modified version of the Panda Hello World to
  3.  * try Panda's Multifiles with TinyXML library.
  4.  */
  5.  
  6. // Panda3D
  7. #include "pandaFramework.h"
  8. #include "pandaSystem.h"
  9. #include "virtualFile.h"
  10. #include "virtualFileSystem.h"
  11.  
  12. // TinyXML
  13. #define TIXML_USE_STL
  14. #include "tinyxml.h"
  15.  
  16. PandaFramework framework;
  17.  
  18. /*
  19. First of all, create the multifile:
  20.  
  21. multify -ep "password" -cf asdf.mf demo.xml panda-model.egg
  22.  
  23. Where
  24. password -> The password
  25. asdf.mf -> The multifile name
  26. panda-model.egg -> The panda
  27. demo.xml -> This XML file:
  28.  
  29. <?xml version="1.0" encoding="UTF-8" ?>
  30. <foo>
  31.     <asd>Hello world</asd>
  32.     <fgh />
  33.     <bar></bar>
  34. </foo>
  35.  
  36.  */
  37.  
  38. int main(int argc, char *argv[]) {
  39.     //open a new window framework
  40.   framework.open_framework(argc, argv);
  41.     //set the window title to My Panda3D Window
  42.   framework.set_window_title("My Panda3D Window");
  43.     //open the window
  44.   WindowFramework *window = framework.open_window();
  45.  
  46.   //here is room for your own code
  47.   VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
  48.   if(vfs->mount("./asdf.mf", "./mount", VirtualFileSystem::MF_read_only, "password"))
  49.   {
  50.     TiXmlDocument doc;
  51.     doc.Parse(vfs->read_file("./mount/demo.xml", false).c_str(), 0, TIXML_ENCODING_UTF8);
  52.  
  53.     TiXmlElement * root = doc.RootElement();
  54.     root->SetAttribute("parsed", "yes");
  55.  
  56.     doc.SaveFile("demo2.xml");
  57.  
  58.     NodePath environ = window->load_model(framework.get_models(), "mount/panda-model.egg");
  59.     // Reparent the model to render.
  60.     environ.reparent_to(window->get_render());
  61.     // Apply scale and position transforms to the model.
  62.     environ.set_scale(0.25, 0.25, 0.25);
  63.     environ.set_pos(-8, 42, 0);
  64.   }
  65.  
  66.     //do the main loop, equal to run() in python
  67.   framework.main_loop();
  68.     //close the window framework
  69.   framework.close_framework();
  70.   return (0);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment