From 2ece568f09a479fdedba69c4811ee10254abf78f Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Fri, 27 Nov 2020 15:04:56 -0800 Subject: [PATCH] fixing up simple-compound logic --- .../src/RenderableModelEntityItem.cpp | 25 +++++++++++++++---- .../src/RenderableModelEntityItem.h | 3 +++ libraries/entities/src/ModelEntityItem.cpp | 16 +++++++----- libraries/entities/src/ModelEntityItem.h | 1 - 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 392d2a748c..d6b7313ae7 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -250,8 +250,12 @@ bool RenderableModelEntityItem::findDetailedParabolaIntersection(const glm::vec3 face, surfaceNormal, extraInfo, precisionPicking, false); } +QString RenderableModelEntityItem::getCollisionShapeURL() const { + return getShapeType() == SHAPE_TYPE_COMPOUND ? getCompoundShapeURL() : getModelURL(); +} + void RenderableModelEntityItem::fetchCollisionGeometryResource() { - _collisionGeometryResource = DependencyManager::get()->getCollisionGeometryResource(getCompoundShapeURL()); + _collisionGeometryResource = DependencyManager::get()->getCollisionGeometryResource(getCollisionShapeURL()); if (_collisionGeometryResource) { if (_collisionGeometryResource->isLoaded()) { markDirtyFlags(Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS); @@ -276,10 +280,10 @@ void RenderableModelEntityItem::setShapeType(ShapeType type) { ModelEntityItem::setShapeType(type); auto shapeType = getShapeType(); if (shapeType == SHAPE_TYPE_COMPOUND || shapeType == SHAPE_TYPE_SIMPLE_COMPOUND) { - if (!_collisionGeometryResource && !getCompoundShapeURL().isEmpty()) { + if (!_collisionGeometryResource && !getCollisionShapeURL().isEmpty()) { fetchCollisionGeometryResource(); } - } else if (_collisionGeometryResource && !getCompoundShapeURL().isEmpty()) { + } else if (_collisionGeometryResource) { // the compoundURL has been set but the shapeType does not agree _collisionGeometryResource.reset(); } @@ -290,7 +294,18 @@ void RenderableModelEntityItem::setCompoundShapeURL(const QString& url) { ModelEntityItem::setCompoundShapeURL(url); if (url != currentCompoundShapeURL && !url.isEmpty()) { auto shapeType = getShapeType(); - if (shapeType == SHAPE_TYPE_COMPOUND || shapeType == SHAPE_TYPE_SIMPLE_COMPOUND) { + if (shapeType == SHAPE_TYPE_COMPOUND) { + fetchCollisionGeometryResource(); + } + } +} + +void RenderableModelEntityItem::setModelURL(const QString& url) { + auto currentModelURL = getModelURL(); + ModelEntityItem::setModelURL(url); + if (url != currentModelURL && !url.isEmpty()) { + auto shapeType = getShapeType(); + if (shapeType == SHAPE_TYPE_SIMPLE_COMPOUND) { fetchCollisionGeometryResource(); } } @@ -300,7 +315,7 @@ bool RenderableModelEntityItem::isReadyToComputeShape() const { auto model = getModel(); auto shapeType = getShapeType(); if (shapeType == SHAPE_TYPE_COMPOUND || shapeType == SHAPE_TYPE_SIMPLE_COMPOUND) { - auto shapeURL = getCompoundShapeURL(); + auto shapeURL = getCollisionShapeURL(); // we need a render geometry with a scale to proceed if (model && !model->getURL().isEmpty() && !shapeURL.isEmpty() && _dimensionsInitialized && model->isLoaded()) { if (!_collisionGeometryResource) { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 09c07b3b84..4501f6d88c 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -75,6 +75,7 @@ public: virtual void setShapeType(ShapeType type) override; virtual void setCompoundShapeURL(const QString& url) override; + virtual void setModelURL(const QString& url) override; virtual bool isReadyToComputeShape() const override; virtual void computeShapeInfo(ShapeInfo& shapeInfo) override; @@ -119,6 +120,8 @@ private: bool readyToAnimate() const; void fetchCollisionGeometryResource(); + QString getCollisionShapeURL() const; + GeometryResource::Pointer _collisionGeometryResource; std::vector _jointMap; QVariantMap _originalTextures; diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 8c3a729e41..4716db6a41 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -254,25 +254,29 @@ void ModelEntityItem::debugDump() const { } void ModelEntityItem::setShapeType(ShapeType type) { + bool changed = false; + uint32_t flags = 0; withWriteLock([&] { if (type != _shapeType) { if (type == SHAPE_TYPE_STATIC_MESH && _dynamic) { // dynamic and STATIC_MESH are incompatible // since the shape is being set here we clear the dynamic bit _dynamic = false; - _flags |= Simulation::DIRTY_MOTION_TYPE; + flags = Simulation::DIRTY_MOTION_TYPE; } _shapeType = type; - _flags |= Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS; + flags |= Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS; + changed = true; } }); + + if (changed) { + markDirtyFlags(flags); + locationChanged(); + } } ShapeType ModelEntityItem::getShapeType() const { - return computeTrueShapeType(); -} - -ShapeType ModelEntityItem::computeTrueShapeType() const { ShapeType type = resultWithReadLock([&] { return _shapeType; }); if (type == SHAPE_TYPE_STATIC_MESH && _dynamic) { // dynamic is incompatible with STATIC_MESH diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index b6d577dff0..b835b48d13 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -122,7 +122,6 @@ public: private: void setAnimationSettings(const QString& value); // only called for old bitstream format bool applyNewAnimationProperties(AnimationPropertyGroup newProperties); - ShapeType computeTrueShapeType() const; protected: void resizeJointArrays(int newSize);