KRNode::getBounds() now caches the calculated bounds and invalidates the cache as needed.

This improves speed of Octree generation.

--HG--
branch : nfb
This commit is contained in:
2014-03-25 22:40:31 -07:00
parent c6f6260df4
commit 827ad1eb7b
3 changed files with 33 additions and 14 deletions

View File

@@ -141,6 +141,8 @@ void KRModel::loadModel() {
m_bones = bones; m_bones = bones;
getScene().notify_sceneGraphModify(this); getScene().notify_sceneGraphModify(this);
} }
invalidateBounds();
} }
} }
} }

View File

@@ -65,6 +65,7 @@ KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getCont
m_activePoseMatrix = KRMat4(); m_activePoseMatrix = KRMat4();
m_lod_visible = false; m_lod_visible = false;
m_scale_compensation = false; m_scale_compensation = false;
m_boundsValid = false;
m_lastRenderFrame = -1000; m_lastRenderFrame = -1000;
for(int i=0; i < KRENGINE_NODE_ATTRIBUTE_COUNT; i++) { for(int i=0; i < KRENGINE_NODE_ATTRIBUTE_COUNT; i++) {
@@ -108,7 +109,7 @@ bool KRNode::getScaleCompensation()
void KRNode::childDeleted(KRNode *child_node) void KRNode::childDeleted(KRNode *child_node)
{ {
m_childNodes.erase(child_node); m_childNodes.erase(child_node);
// InvalidateBounds(); invalidateBounds();
getScene().notify_sceneGraphModify(this); getScene().notify_sceneGraphModify(this);
} }
@@ -475,6 +476,7 @@ KRScene &KRNode::getScene() {
} }
KRAABB KRNode::getBounds() { KRAABB KRNode::getBounds() {
if(!m_boundsValid) {
KRAABB bounds = KRAABB::Zero(); KRAABB bounds = KRAABB::Zero();
bool first_child = true; bool first_child = true;
@@ -490,7 +492,10 @@ KRAABB KRNode::getBounds() {
} }
} }
return bounds; m_bounds = bounds;
m_boundsValid = true;
}
return m_bounds;
} }
void KRNode::invalidateModelMatrix() void KRNode::invalidateModelMatrix()
@@ -503,7 +508,7 @@ void KRNode::invalidateModelMatrix()
child->invalidateModelMatrix(); child->invalidateModelMatrix();
} }
// InvalidateBounds invalidateBounds();
getScene().notify_sceneGraphModify(this); getScene().notify_sceneGraphModify(this);
} }
@@ -949,3 +954,11 @@ kraken_stream_level KRNode::getStreamLevel(bool prime)
return stream_level; return stream_level;
} }
void KRNode::invalidateBounds() const
{
m_boundsValid = false;
if(m_parentNode) {
m_parentNode->invalidateBounds();
}
}

View File

@@ -110,6 +110,7 @@ public:
void setWorldRotation(const KRVector3 &v); void setWorldRotation(const KRVector3 &v);
virtual KRAABB getBounds(); virtual KRAABB getBounds();
void invalidateBounds() const;
const KRMat4 &getModelMatrix(); const KRMat4 &getModelMatrix();
const KRMat4 &getInverseModelMatrix(); const KRMat4 &getInverseModelMatrix();
const KRMat4 &getBindPoseMatrix(); const KRMat4 &getBindPoseMatrix();
@@ -216,6 +217,9 @@ private:
bool m_activePoseMatrixValid; bool m_activePoseMatrixValid;
bool m_inverseBindPoseMatrixValid; bool m_inverseBindPoseMatrixValid;
mutable KRAABB m_bounds;
mutable bool m_boundsValid;
std::string m_name; std::string m_name;