Completed implementation of Model LOD system

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40117
This commit is contained in:
kearwood
2012-10-05 02:23:00 +00:00
parent 2fd05171b7
commit 7f7651efbd
10 changed files with 157 additions and 39 deletions

View File

@@ -52,6 +52,23 @@ KRModel::KRModel(KRContext &context, std::string name) : KRResource(context, nam
m_materials.clear();
m_uniqueMaterials.clear();
m_pData = new KRDataBlock();
m_lodCoverage = 100; // Default to being the full detail mesh; not an LOD level
m_lodBaseName = name;
size_t last_underscore_pos = name.find_last_of('_');
if(last_underscore_pos != std::string::npos) {
// Found an underscore
std::string suffix = name.substr(last_underscore_pos + 1);
if(suffix.find_first_of("lod") == 0) {
std::string lod_level_string = suffix.substr(3);
char *end = NULL;
int c = (int)strtol(suffix.c_str(), &end, 10);
if(m_lodCoverage < 0 || m_lodCoverage > 100 || *end != '\0') {
m_lodCoverage = c;
m_lodBaseName = name.substr(0, last_underscore_pos - 1);
}
}
}
}
KRModel::KRModel(KRContext &context, std::string name, KRDataBlock *data) : KRResource(context, name) {
@@ -59,6 +76,7 @@ KRModel::KRModel(KRContext &context, std::string name, KRDataBlock *data) : KRRe
m_materials.clear();
m_uniqueMaterials.clear();
m_pData = new KRDataBlock();
m_lodCoverage = 100;
loadPack(data);
}
@@ -434,3 +452,17 @@ void KRModel::clearBuffers() {
m_submeshes.clear();
}
int KRModel::getLODCoverage() const {
return m_lodCoverage;
}
std::string KRModel::getLODBaseName() const {
return m_lodBaseName;
}
// Predicate used with std::sort to sort by highest detail model first, decending to lowest detail LOD model
bool KRModel::lod_sort_predicate(const KRModel *m1, const KRModel *m2)
{
return m1->m_lodCoverage > m2->m_lodCoverage;
}