From c8cccc5ec7a87c2d2d54140683445f32c5d91191 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Fri, 28 Sep 2018 14:28:57 -0700 Subject: [PATCH] Fix "good" collision not subdividing OBJ meshes by group --- .../src/RenderableModelEntityItem.cpp | 28 +++++++++++++------ libraries/entities/src/ModelEntityItem.cpp | 4 +++ libraries/entities/src/ModelEntityItem.h | 3 ++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 3a01650a04..3660fd625d 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -307,7 +307,7 @@ bool RenderableModelEntityItem::findDetailedParabolaIntersection(const glm::vec3 } void RenderableModelEntityItem::getCollisionGeometryResource() { - QUrl hullURL(getCompoundShapeURL()); + QUrl hullURL(getCollisionShapeURL()); QUrlQuery queryArgs(hullURL); queryArgs.addQueryItem("collision-hull", ""); hullURL.setQuery(queryArgs); @@ -316,8 +316,9 @@ void RenderableModelEntityItem::getCollisionGeometryResource() { void RenderableModelEntityItem::setShapeType(ShapeType type) { ModelEntityItem::setShapeType(type); - if (getShapeType() == SHAPE_TYPE_COMPOUND) { - if (!_compoundShapeResource && !getCompoundShapeURL().isEmpty()) { + auto shapeType = getShapeType(); + if (shapeType == SHAPE_TYPE_COMPOUND || shapeType == SHAPE_TYPE_SIMPLE_COMPOUND) { + if (!_compoundShapeResource && !getCollisionShapeURL().isEmpty()) { getCollisionGeometryResource(); } } else if (_compoundShapeResource && !getCompoundShapeURL().isEmpty()) { @@ -344,8 +345,11 @@ bool RenderableModelEntityItem::isReadyToComputeShape() const { ShapeType type = getShapeType(); auto model = getModel(); - if (type == SHAPE_TYPE_COMPOUND) { - if (!model || getCompoundShapeURL().isEmpty()) { + auto shapeType = getShapeType(); + if (shapeType == SHAPE_TYPE_COMPOUND || shapeType == SHAPE_TYPE_SIMPLE_COMPOUND) { + auto shapeURL = getCollisionShapeURL(); + + if (!model || shapeURL.isEmpty()) { return false; } @@ -355,7 +359,7 @@ bool RenderableModelEntityItem::isReadyToComputeShape() const { } if (model->isLoaded()) { - if (!getCompoundShapeURL().isEmpty() && !_compoundShapeResource) { + if (!shapeURL.isEmpty() && !_compoundShapeResource) { const_cast(this)->getCollisionGeometryResource(); } @@ -510,7 +514,15 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) { return; } - auto& meshes = model->getGeometry()->getMeshes(); + std::vector> compoundMeshes; + if (type == SHAPE_TYPE_SIMPLE_COMPOUND) { + auto& fbxMeshes = _compoundShapeResource->getFBXGeometry().meshes; + compoundMeshes.reserve(fbxMeshes.size()); + for (auto& fbxMesh : fbxMeshes) { + compoundMeshes.push_back(fbxMesh._mesh); + } + } + auto& meshes = (type == SHAPE_TYPE_SIMPLE_COMPOUND ? compoundMeshes : model->getGeometry()->getMeshes()); int32_t numMeshes = (int32_t)(meshes.size()); const int MAX_ALLOWED_MESH_COUNT = 1000; @@ -744,7 +756,7 @@ bool RenderableModelEntityItem::shouldBePhysical() const { auto model = getModel(); // If we have a model, make sure it hasn't failed to download. // If it has, we'll report back that we shouldn't be physical so that physics aren't held waiting for us to be ready. - if (model && getShapeType() == SHAPE_TYPE_COMPOUND && model->didCollisionGeometryRequestFail()) { + if (model && (getShapeType() == SHAPE_TYPE_COMPOUND || getShapeType() == SHAPE_TYPE_SIMPLE_COMPOUND) && model->didCollisionGeometryRequestFail()) { return false; } else if (model && getShapeType() != SHAPE_TYPE_NONE && model->didVisualGeometryRequestFail()) { return false; diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index f006692415..b1a02a18b6 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -554,6 +554,10 @@ QString ModelEntityItem::getCompoundShapeURL() const { return _compoundShapeURL.get(); } +QString ModelEntityItem::getCollisionShapeURL() const { + return getShapeType() == SHAPE_TYPE_COMPOUND ? getCompoundShapeURL() : getModelURL(); +} + void ModelEntityItem::setColor(const rgbColor& value) { withWriteLock([&] { memcpy(_color, value, sizeof(_color)); diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index ef758b9dde..93517c465d 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -70,6 +70,9 @@ public: static const QString DEFAULT_COMPOUND_SHAPE_URL; QString getCompoundShapeURL() const; + // Returns the URL used for the collision shape + QString getCollisionShapeURL() const; + void setColor(const rgbColor& value); void setColor(const xColor& value);