|
|
@@ -118,27 +118,42 @@ void Model::load(const char* filename)
|
|
|
//
|
|
|
// Sanity checks
|
|
|
//
|
|
|
- if(skelAnims.size() > 0 && !hasSkeleton())
|
|
|
+ try
|
|
|
{
|
|
|
- throw MDL_EXCEPTION("You have skeleton animations but no skeleton");
|
|
|
- }
|
|
|
+ if(skelAnims.size() > 0 && !hasSkeleton())
|
|
|
+ {
|
|
|
+ throw EXCEPTION("You have skeleton animations but no skeleton");
|
|
|
+ }
|
|
|
|
|
|
- for(uint i = 0; i < skelAnims.size(); i++)
|
|
|
- {
|
|
|
- if(skelAnims[i]->bones.size() != skeleton->bones.size())
|
|
|
+ for(uint i = 0; i < skelAnims.size(); i++)
|
|
|
{
|
|
|
- throw MDL_EXCEPTION("SkelAnim \"" + skelAnims[i]->getRsrcName() + "\" and Skeleton \"" +
|
|
|
- skeleton->getRsrcName() + "\" dont have equal bone count");
|
|
|
+ // Bone number problem
|
|
|
+ if(skelAnims[i]->bones.size() != skeleton->bones.size())
|
|
|
+ {
|
|
|
+ throw EXCEPTION("SkelAnim \"" + skelAnims[i]->getRsrcName() + "\" and Skeleton \"" +
|
|
|
+ skeleton->getRsrcName() + "\" dont have equal bone count");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //
|
|
|
- // Create VAOs
|
|
|
- //
|
|
|
- for(Vec<SubModel>::iterator it = subModels.begin(); it != subModels.end(); it++)
|
|
|
+ for(uint i = 0; i < subModels.size(); i++)
|
|
|
+ {
|
|
|
+ if(hasSkeleton())
|
|
|
+ {
|
|
|
+ if(!subModels[i].hasHwSkinning())
|
|
|
+ {
|
|
|
+ throw EXCEPTION("SubModel " + boost::lexical_cast<std::string>(i) + " material does not have HW skinning");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!subModels[i].hasHwSkinning())
|
|
|
+ {
|
|
|
+ throw EXCEPTION("SubModel " + boost::lexical_cast<std::string>(i) + " DP material does not have HW skinning");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(std::exception& e)
|
|
|
{
|
|
|
- createVao(*it->material, *it->mesh, *it, it->vao);
|
|
|
- createVao(*it->dpMaterial, *it->mesh, *it, it->dpVao);
|
|
|
+ throw MDL_EXCEPTION(e.what());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -168,20 +183,71 @@ void Model::parseSubModel(Scanner& scanner)
|
|
|
|
|
|
// Load the stuff
|
|
|
subModels.push_back(SubModel());
|
|
|
- SubModel& subModel = subModels.back();
|
|
|
+ subModels.back().load(mesh.c_str(), material.c_str(), dpMaterial.c_str());
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//======================================================================================================================
|
|
|
+// hasHwSkinning =
|
|
|
+//======================================================================================================================
|
|
|
+bool Model::SubModel::hasHwSkinning() const
|
|
|
+{
|
|
|
+ return material->hasHWSkinning();
|
|
|
+}
|
|
|
|
|
|
- subModel.mesh.loadRsrc(mesh.c_str());
|
|
|
- subModel.material.loadRsrc(material.c_str());
|
|
|
- subModel.dpMaterial.loadRsrc(dpMaterial.c_str());
|
|
|
|
|
|
- /// @todo Sanity checks. See MeshNode.cpp
|
|
|
+//======================================================================================================================
|
|
|
+// load =
|
|
|
+//======================================================================================================================
|
|
|
+void Model::SubModel::load(const char* meshFName, const char* mtlFName, const char* dpMtlFName)
|
|
|
+{
|
|
|
+ //
|
|
|
+ // Load
|
|
|
+ //
|
|
|
+ mesh.loadRsrc(meshFName);
|
|
|
+ material.loadRsrc(mtlFName);
|
|
|
+ dpMaterial.loadRsrc(dpMtlFName);
|
|
|
+
|
|
|
+ //
|
|
|
+ // Sanity checks
|
|
|
+ //
|
|
|
+ #define EXCEPTION_INCOMPATIBLE_RSRCS(x, y) \
|
|
|
+ EXCEPTION("Resource \"" + x->getRsrcName() + "\" and \"" + y->getRsrcName() + "\" are incompatible")
|
|
|
+
|
|
|
+ // if mtl needs tex coords then mesh should have
|
|
|
+ if(material->hasTexCoords() && !mesh->hasTexCoords())
|
|
|
+ {
|
|
|
+ throw EXCEPTION_INCOMPATIBLE_RSRCS(material, mesh);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(dpMaterial->hasTexCoords() && !mesh->hasTexCoords())
|
|
|
+ {
|
|
|
+ throw EXCEPTION_INCOMPATIBLE_RSRCS(dpMaterial, mesh);
|
|
|
+ }
|
|
|
+
|
|
|
+ // if mtl needs weights then mesh should have
|
|
|
+ if(material->hasHWSkinning() && !mesh->hasVertWeights())
|
|
|
+ {
|
|
|
+ throw EXCEPTION_INCOMPATIBLE_RSRCS(material, mesh);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(dpMaterial->hasHWSkinning() && !mesh->hasVertWeights())
|
|
|
+ {
|
|
|
+ throw EXCEPTION_INCOMPATIBLE_RSRCS(dpMaterial, mesh);
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ // VAOs
|
|
|
+ //
|
|
|
+ createVao(*material, *mesh, *this, vao);
|
|
|
+ createVao(*dpMaterial, *mesh, *this, dpVao);
|
|
|
}
|
|
|
|
|
|
|
|
|
//======================================================================================================================
|
|
|
// createVao =
|
|
|
//======================================================================================================================
|
|
|
-void Model::createVao(const Material& mtl, const Mesh& mesh, SubModel& subModel, Vao*& vao)
|
|
|
+void Model::SubModel::createVao(const Material& mtl, const Mesh& mesh, SubModel& subModel, Vao*& vao)
|
|
|
{
|
|
|
vao = new Vao(&subModel);
|
|
|
|