- Implemented methods for determining amount of scene that has streamed in. (KRScene::getStreamLevel, KRNode::getStreamLevel, KRModel::getStreamLevel, KRMaterial::getStreamLevel, and KRTexture::getStreamLevel

- Implemented connection between LOD groups and texture streaming, which delays the switch to a new LOD group until the required textures have completed streaming in.
- Corrected bug in KRMaterial that resulted in reflection cube texture names being formatted incorrectly in the mtl file
- Scene graph now requires that lod_group nodes only be contained within lod_set nodes.
- Scene graph  group nodes that do not have a LOD minimum or maximum distance are now stored as "node" rather than as "lod_group" nodes.
- IMPORTANT!  Scenes exported with this version will not be backwards compatible with earlier versions due to the requirement of lod_set nodes.

--HG--
branch : nfb
extra : rebase_source : 1ff640b85338a794841ebbb2bf0087306ff59143
This commit is contained in:
2014-03-10 22:32:49 -07:00
parent 64f1b70545
commit 8a1164c44f
23 changed files with 305 additions and 87 deletions

View File

@@ -7,11 +7,12 @@
//
#include "KRLODSet.h"
#include "KRLODGroup.h"
#include "KRContext.h"
KRLODSet::KRLODSet(KRScene &scene, std::string name) : KRNode(scene, name)
{
m_activeLODGroup = NULL;
}
KRLODSet::~KRLODSet()
@@ -33,3 +34,82 @@ void KRLODSet::loadXML(tinyxml2::XMLElement *e)
{
KRNode::loadXML(e);
}
void KRLODSet::updateLODVisibility(const KRViewport &viewport)
{
if(m_lod_visible) {
KRLODGroup *new_active_lod_group = NULL;
// Upgrade and downgrade LOD groups as needed
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
KRLODGroup *lod_group = dynamic_cast<KRLODGroup *>(*itr);
assert(lod_group != NULL);
if(lod_group->getLODVisibility(viewport)) {
new_active_lod_group = lod_group;
}
}
if(new_active_lod_group == NULL) {
m_activeLODGroup = NULL;
} else if(m_activeLODGroup == NULL) {
m_activeLODGroup = new_active_lod_group;
} else if(new_active_lod_group != m_activeLODGroup) {
if(new_active_lod_group->getStreamLevel(true) >= kraken_stream_level::STREAM_LEVEL_IN_LQ) {
fprintf(stderr, "LOD %s -> %s\n", m_activeLODGroup->getName().c_str(), new_active_lod_group->getName().c_str());
m_activeLODGroup = new_active_lod_group;
} else {
fprintf(stderr, "LOD %s -> %s - waiting for streaming...\n", m_activeLODGroup->getName().c_str(), new_active_lod_group->getName().c_str());
}
}
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
KRNode *child = *itr;
if(child == m_activeLODGroup) {
child->showLOD();
} else {
child->hideLOD();
}
}
KRNode::updateLODVisibility(viewport);
}
}
KRLODGroup *KRLODSet::getActiveLODGroup() const
{
return m_activeLODGroup;
}
void KRLODSet::childDeleted(KRNode *child_node)
{
KRNode::childDeleted(child_node);
if(m_activeLODGroup == child_node) {
m_activeLODGroup = NULL;
}
}
void KRLODSet::hideLOD()
{
KRNode::hideLOD();
m_activeLODGroup = NULL; // Ensure that the streamer will wait for the group to load in next time
}
void KRLODSet::showLOD()
{
// Don't automatically recurse into our children, as only one of those will be activated, by updateLODVisibility
if(!m_lod_visible) {
getScene().notify_sceneGraphCreate(this);
m_lod_visible = true;
}
}
kraken_stream_level KRLODSet::getStreamLevel(bool prime)
{
if(m_activeLODGroup) {
return m_activeLODGroup->getStreamLevel(prime);
} else {
return kraken_stream_level::STREAM_LEVEL_IN_HQ;
}
}