Model.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <boost/property_tree/ptree.hpp>
  2. #include <boost/property_tree/xml_parser.hpp>
  3. #include <boost/lexical_cast.hpp>
  4. #include <boost/assign.hpp>
  5. #include <boost/range/iterator_range.hpp>
  6. #include "anki/resource/Model.h"
  7. #include "anki/resource/Material.h"
  8. #include "anki/resource/Mesh.h"
  9. #include "anki/resource/SkelAnim.h"
  10. #include "anki/resource/MeshData.h"
  11. #include "anki/resource/Skeleton.h"
  12. #include <boost/foreach.hpp>
  13. namespace anki {
  14. //==============================================================================
  15. void Model::load(const char* filename)
  16. {
  17. try
  18. {
  19. //
  20. // Load
  21. //
  22. using namespace boost::property_tree;
  23. ptree pt_;
  24. read_xml(filename, pt_);
  25. const ptree& pt = pt_.get_child("model");
  26. // modelPatches
  27. BOOST_FOREACH(const ptree::value_type& v, pt.get_child("modelPatches"))
  28. {
  29. const std::string& mesh = v.second.get<std::string>("mesh");
  30. const std::string& material = v.second.get<std::string>("material");
  31. ModelPatch* patch = new ModelPatch(mesh.c_str(), material.c_str());
  32. modelPatches.push_back(patch);
  33. }
  34. if(modelPatches.size() < 1)
  35. {
  36. throw ANKI_EXCEPTION("Zero number of model patches");
  37. }
  38. // Calculate compound bounding volume
  39. visibilityShape = modelPatches[0].getMesh().getVisibilityShape();
  40. for(ModelPatchesContainer::const_iterator it = modelPatches.begin() + 1;
  41. it != modelPatches.end();
  42. ++it)
  43. {
  44. visibilityShape = visibilityShape.getCompoundShape(
  45. (*it).getMesh().getVisibilityShape());
  46. }
  47. }
  48. catch(std::exception& e)
  49. {
  50. throw ANKI_EXCEPTION_R("Model \"" + filename + "\"", e);
  51. }
  52. }
  53. } // end namespace