@@ -111,6 +111,26 @@ namespace MWRender
111111 return {};
112112 }
113113 }
114+
115+ // Retrieve pre-computed template radius from node user data, or compute fallback
116+ // to ensure robustness in case radius wasn't pre-computed
117+ float getTemplateRadius (const osg::Node* node)
118+ {
119+ if (!node)
120+ return 0 .0f ;
121+
122+ const auto * userDataContainer = node->getUserDataContainer ();
123+ if (!userDataContainer || userDataContainer->getNumUserObjects () == 0 )
124+ return node->getBound ().radius (); // Fallback: compute if not cached
125+
126+ // First user object should be the template radius FloatValueObject
127+ if (const auto * floatValue = dynamic_cast <const osg::FloatValueObject*>(
128+ userDataContainer->getUserObject (0 )))
129+ return floatValue->getValue ();
130+
131+ // Fallback: compute radius if not cached as expected
132+ return node->getBound ().radius ();
133+ }
114134 }
115135
116136 osg::ref_ptr<osg::Node> ObjectPaging::getChunk (float size, const osg::Vec2f& center, unsigned char /* lod*/ ,
@@ -794,7 +814,9 @@ namespace MWRender
794814 continue ;
795815 }
796816
797- const float radius2 = cnode->getBound ().radius2 () * ref.mScale * ref.mScale ;
817+ // Use pre-computed template radius to avoid expensive getBound() traversal
818+ const float templateRadius = getTemplateRadius (cnode);
819+ const float radius2 = templateRadius * templateRadius * ref.mScale * ref.mScale ;
798820 if (radius2 < dSqr * minSize * minSize && !activeGrid)
799821 {
800822 std::lock_guard<std::mutex> lock (mSizeCacheMutex );
@@ -844,8 +866,10 @@ namespace MWRender
844866 {
845867 const PagedCellRef& ref = *refPtr;
846868
869+ // Use pre-computed template radius for merge decision culling
870+ const float templateRadius = getTemplateRadius (cnode);
847871 if (!activeGrid && minSizeMerged != minSize
848- && cnode-> getBound (). radius2 () * ref.mScale * ref.mScale
872+ && templateRadius * templateRadius * ref.mScale * ref.mScale
849873 < (viewPoint - ref.mPosition ).length2 () * minSizeMerged * minSizeMerged)
850874 continue ;
851875
0 commit comments