Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
matt77hias committed Apr 24, 2017
1 parent e1e30a1 commit 9c4e26d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
27 changes: 10 additions & 17 deletions MAGE/MAGE/src/model/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,18 @@ namespace mage {
return;
}

Material material(MAGE_MDL_PART_DEFAULT_MATERIAL);
bool early_quit = false;
if (model_part.material != MAGE_MDL_PART_DEFAULT_MATERIAL) {

desc.ForEachMaterial([&](const Material &submaterial) {
if (early_quit) {
return;
}

if (submaterial.m_name == model_part.material) {
material = submaterial;
early_quit = true;
}
});
Material material(*desc.GetMaterial(model_part.material));
ShadedMaterial shaded_material(shader, material);
SharedPtr< Model > submodel(new Model(model_part, m_mesh, shaded_material));
mapping[model_part.child] = SubModelPair(submodel, model_part.parent);
}
else {
Material material(MAGE_MDL_PART_DEFAULT_MATERIAL);
ShadedMaterial shaded_material(shader, material);
SharedPtr< Model > submodel(new Model(model_part, m_mesh, shaded_material));
mapping[model_part.child] = SubModelPair(submodel, model_part.parent);
}

ShadedMaterial shaded_material(shader, material);
SharedPtr< Model > submodel(new Model(model_part, m_mesh, shaded_material));
mapping[model_part.child] = SubModelPair(submodel, model_part.parent);
});

for (map< string, SubModelPair >::const_iterator it = mapping.cbegin(); it != mapping.cend(); ++it) {
Expand Down
18 changes: 18 additions & 0 deletions MAGE/MAGE/src/model/model_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@
//-----------------------------------------------------------------------------
namespace mage {

const Material *ModelDescriptor::GetMaterial(const string &name) const {
for (vector< Material >::const_iterator it = m_materials.cbegin(); it != m_materials.cend(); ++it) {
if (it->m_name == name) {
return &(*it);
}
}
return nullptr;
}

const ModelPart *ModelDescriptor::GetModelPart(const string &name) const {
for (vector< ModelPart >::const_iterator it = m_model_parts.cbegin(); it != m_model_parts.cend(); ++it) {
if (it->child == name) {
return &(*it);
}
}
return nullptr;
}

ID3D11Device2 *GetModelRenderingDevice() {
return GetRenderingDevice();
}
Expand Down
2 changes: 2 additions & 0 deletions MAGE/MAGE/src/model/model_descriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ namespace mage {
return m_mesh;
}

const Material *GetMaterial(const string &name) const;
template< typename ActionT >
void ForEachMaterial(ActionT action) const;
const ModelPart *GetModelPart(const string &name) const;
template< typename ActionT >
void ForEachModelPart(ActionT action) const;

Expand Down

0 comments on commit 9c4e26d

Please sign in to comment.