diff --git a/libraries/models/src/ModelTreeElement.cpp b/libraries/models/src/ModelTreeElement.cpp index 4929edb484..3caaf3a14c 100644 --- a/libraries/models/src/ModelTreeElement.cpp +++ b/libraries/models/src/ModelTreeElement.cpp @@ -95,6 +95,11 @@ bool ModelTreeElement::bestFitModelBounds(const ModelItem& model) const { if (_box.contains(clampedMin) && _box.contains(clampedMax)) { int childForMinimumPoint = getMyChildContainingPoint(clampedMin); int childForMaximumPoint = getMyChildContainingPoint(clampedMax); + + // if this is a really small box, then it's close enough! + if (_box.getScale() <= SMALLEST_REASONABLE_OCTREE_ELEMENT_SCALE) { + return true; + } // If I contain both the minimum and maximum point, but two different children of mine // contain those points, then I am the best fit for that model if (childForMinimumPoint != childForMaximumPoint) { diff --git a/libraries/octree/src/OctreeElement.cpp b/libraries/octree/src/OctreeElement.cpp index 0462a3b53d..90938ddff3 100644 --- a/libraries/octree/src/OctreeElement.cpp +++ b/libraries/octree/src/OctreeElement.cpp @@ -1412,6 +1412,11 @@ OctreeElement* OctreeElement::getOrCreateChildElementContaining(const AABox& box if (!child) { child = addChildAtIndex(childIndex); } + + // if we've made a really small child, then go ahead and use that one. + if (child->getScale() <= SMALLEST_REASONABLE_OCTREE_ELEMENT_SCALE) { + return child; + } // Now that we have the child to recurse down, let it answer the original question... return child->getOrCreateChildElementContaining(box); diff --git a/libraries/octree/src/OctreeElement.h b/libraries/octree/src/OctreeElement.h index 2485e49797..3b056fa789 100644 --- a/libraries/octree/src/OctreeElement.h +++ b/libraries/octree/src/OctreeElement.h @@ -32,6 +32,8 @@ class OctreePacketData; class ReadBitstreamToTreeParams; class VoxelSystem; +const float SMALLEST_REASONABLE_OCTREE_ELEMENT_SCALE = (1.0f / TREE_SCALE) / 10000.0f; // 1/10,000th of a meter + // Callers who want delete hook callbacks should implement this class class OctreeElementDeleteHook { public: