From 2299bb7718c51dabb764b9874f4d229c80036b44 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 5 Jul 2017 09:17:06 -0700 Subject: [PATCH] supply minimum shape rather than null --- libraries/physics/src/ShapeManager.cpp | 7 ------- libraries/shared/src/ShapeInfo.cpp | 24 ++++++++++++++++++++---- libraries/shared/src/ShapeInfo.h | 2 ++ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/libraries/physics/src/ShapeManager.cpp b/libraries/physics/src/ShapeManager.cpp index fd3e35d28a..77716f671b 100644 --- a/libraries/physics/src/ShapeManager.cpp +++ b/libraries/physics/src/ShapeManager.cpp @@ -32,13 +32,6 @@ const btCollisionShape* ShapeManager::getShape(const ShapeInfo& info) { if (info.getType() == SHAPE_TYPE_NONE) { return nullptr; } - const float MIN_SHAPE_DIAGONAL_SQUARED = 3.0e-4f; // 1 cm cube - if (4.0f * glm::length2(info.getHalfExtents()) < MIN_SHAPE_DIAGONAL_SQUARED) { - // tiny shapes are not supported - // qCDebug(physics) << "ShapeManager::getShape -- not making shape due to size" << diagonal; - return nullptr; - } - DoubleHashKey key = info.getHash(); ShapeReference* shapeRef = _shapeMap.find(key); if (shapeRef) { diff --git a/libraries/shared/src/ShapeInfo.cpp b/libraries/shared/src/ShapeInfo.cpp index 583bceeaf2..496e94f8bd 100644 --- a/libraries/shared/src/ShapeInfo.cpp +++ b/libraries/shared/src/ShapeInfo.cpp @@ -15,6 +15,9 @@ #include "NumericalConstants.h" // for MILLIMETERS_PER_METER +// Bullet doesn't support arbitrarily small shapes +const float MIN_HALF_EXTENT = 0.005f; // 0.5 cm + void ShapeInfo::clear() { _url.clear(); _pointCollection.clear(); @@ -26,14 +29,20 @@ void ShapeInfo::clear() { } void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QString url) { + _url = ""; _type = type; - _halfExtents = halfExtents; + setHalfExtents(halfExtents); switch(type) { case SHAPE_TYPE_NONE: _halfExtents = glm::vec3(0.0f); break; case SHAPE_TYPE_BOX: - case SHAPE_TYPE_SPHERE: + break; + case SHAPE_TYPE_SPHERE: { + float radius = glm::length(halfExtents) / SQUARE_ROOT_OF_3; + radius = glm::max(radius, MIN_HALF_EXTENT); + _halfExtents = glm::vec3(radius); + } break; case SHAPE_TYPE_COMPOUND: case SHAPE_TYPE_STATIC_MESH: @@ -48,14 +57,15 @@ void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QString void ShapeInfo::setBox(const glm::vec3& halfExtents) { _url = ""; _type = SHAPE_TYPE_BOX; - _halfExtents = halfExtents; + setHalfExtents(halfExtents); _doubleHashKey.clear(); } void ShapeInfo::setSphere(float radius) { _url = ""; _type = SHAPE_TYPE_SPHERE; - _halfExtents = glm::vec3(radius, radius, radius); + radius = glm::max(radius, MIN_HALF_EXTENT); + _halfExtents = glm::vec3(radius); _doubleHashKey.clear(); } @@ -68,6 +78,8 @@ void ShapeInfo::setPointCollection(const ShapeInfo::PointCollection& pointCollec void ShapeInfo::setCapsuleY(float radius, float halfHeight) { _url = ""; _type = SHAPE_TYPE_CAPSULE_Y; + radius = glm::max(radius, MIN_HALF_EXTENT); + halfHeight = glm::max(halfHeight, 0.0f); _halfExtents = glm::vec3(radius, halfHeight, radius); _doubleHashKey.clear(); } @@ -239,3 +251,7 @@ const DoubleHashKey& ShapeInfo::getHash() const { } return _doubleHashKey; } + +void ShapeInfo::setHalfExtents(const glm::vec3& halfExtents) { + _halfExtents = glm::max(halfExtents, glm::vec3(MIN_HALF_EXTENT)); +} diff --git a/libraries/shared/src/ShapeInfo.h b/libraries/shared/src/ShapeInfo.h index 17e4703fc2..0ffdf1310d 100644 --- a/libraries/shared/src/ShapeInfo.h +++ b/libraries/shared/src/ShapeInfo.h @@ -89,6 +89,8 @@ public: const DoubleHashKey& getHash() const; protected: + void setHalfExtents(const glm::vec3& halfExtents); + QUrl _url; // url for model of convex collision hulls PointCollection _pointCollection; TriangleIndices _triangleIndices;