Model.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. namespace anki {
  13. //==============================================================================
  14. // load =
  15. //==============================================================================
  16. void Model::load(const char* filename)
  17. {
  18. try
  19. {
  20. //
  21. // Load
  22. //
  23. using namespace boost::property_tree;
  24. ptree pt_;
  25. read_xml(filename, pt_);
  26. const ptree& pt = pt_.get_child("model");
  27. // modelPatches
  28. BOOST_FOREACH(const ptree::value_type& v, pt.get_child("modelPatches"))
  29. {
  30. const std::string& mesh = v.second.get<std::string>("mesh");
  31. const std::string& material = v.second.get<std::string>("material");
  32. ModelPatch* patch = new ModelPatch(mesh.c_str(), material.c_str());
  33. modelPatches.push_back(patch);
  34. }
  35. if(modelPatches.size() < 1)
  36. {
  37. throw ANKI_EXCEPTION("Zero number of model patches");
  38. }
  39. // Calculate compound bounding volume
  40. visibilityShape = modelPatches[0].getMesh().getVisibilityShape();
  41. for(ModelPatchesContainer::const_iterator it = modelPatches.begin() + 1;
  42. it != modelPatches.end();
  43. ++it)
  44. {
  45. visibilityShape = visibilityShape.getCompoundShape(
  46. (*it).getMesh().getVisibilityShape());
  47. }
  48. }
  49. catch(std::exception& e)
  50. {
  51. throw ANKI_EXCEPTION("Model \"" + filename + "\": " + e.what());
  52. }
  53. }
  54. } // end namespace