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:
@@ -141,6 +141,8 @@ void KRModel::loadModel() {
|
|||||||
m_bones = bones;
|
m_bones = bones;
|
||||||
getScene().notify_sceneGraphModify(this);
|
getScene().notify_sceneGraphModify(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
invalidateBounds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,22 +476,26 @@ KRScene &KRNode::getScene() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KRAABB KRNode::getBounds() {
|
KRAABB KRNode::getBounds() {
|
||||||
KRAABB bounds = KRAABB::Zero();
|
if(!m_boundsValid) {
|
||||||
|
KRAABB bounds = KRAABB::Zero();
|
||||||
|
|
||||||
bool first_child = true;
|
bool first_child = true;
|
||||||
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
||||||
KRNode *child = (*itr);
|
KRNode *child = (*itr);
|
||||||
if(child->getBounds() != KRAABB::Zero()) {
|
if(child->getBounds() != KRAABB::Zero()) {
|
||||||
if(first_child) {
|
if(first_child) {
|
||||||
first_child = false;
|
first_child = false;
|
||||||
bounds = child->getBounds();
|
bounds = child->getBounds();
|
||||||
} else {
|
} else {
|
||||||
bounds.encapsulate(child->getBounds());
|
bounds.encapsulate(child->getBounds());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_bounds = bounds;
|
||||||
|
m_boundsValid = true;
|
||||||
}
|
}
|
||||||
|
return m_bounds;
|
||||||
return 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user