From 9388ae42128c8ae9430a32ad192ef95c9956edd5 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 14 Apr 2015 14:52:21 -0700 Subject: [PATCH 1/8] fix warning about unused variable --- libraries/render-utils/src/Model.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index b98123803f..22358f7453 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -151,7 +151,7 @@ void Model::RenderPipelineLib::addRenderPipeline(Model::RenderKey key, // create a new RenderPipeline with the same shader side and the mirrorState auto mirrorPipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, mirrorState)); - auto it = insert(value_type(mirrorKey.getRaw(), RenderPipeline(mirrorPipeline, locations))); + insert(value_type(mirrorKey.getRaw(), RenderPipeline(mirrorPipeline, locations))); } } From da9091a99db023f5c2dddc8687aa245fc4be29af Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 14 Apr 2015 14:54:43 -0700 Subject: [PATCH 2/8] remove SHAPE_TYPE_CONVEX_HULL from libs and tests --- libraries/physics/src/ShapeInfoUtil.cpp | 140 ++++-------------------- libraries/physics/src/ShapeInfoUtil.h | 8 +- libraries/shared/src/ShapeInfo.cpp | 20 ++-- libraries/shared/src/ShapeInfo.h | 2 +- tests/physics/src/ShapeInfoTests.cpp | 16 +-- tests/physics/src/ShapeManagerTests.cpp | 16 +-- 6 files changed, 39 insertions(+), 163 deletions(-) diff --git a/libraries/physics/src/ShapeInfoUtil.cpp b/libraries/physics/src/ShapeInfoUtil.cpp index 8900c5a0dc..c6c76a98eb 100644 --- a/libraries/physics/src/ShapeInfoUtil.cpp +++ b/libraries/physics/src/ShapeInfoUtil.cpp @@ -14,107 +14,6 @@ #include "ShapeInfoUtil.h" #include "BulletUtil.h" -int ShapeInfoUtil::toBulletShapeType(int shapeInfoType) { - int bulletShapeType = INVALID_SHAPE_PROXYTYPE; - switch(shapeInfoType) { - case SHAPE_TYPE_BOX: - bulletShapeType = BOX_SHAPE_PROXYTYPE; - break; - case SHAPE_TYPE_SPHERE: - bulletShapeType = SPHERE_SHAPE_PROXYTYPE; - break; - case SHAPE_TYPE_CAPSULE_Y: - bulletShapeType = CAPSULE_SHAPE_PROXYTYPE; - break; - case SHAPE_TYPE_CONVEX_HULL: - bulletShapeType = CONVEX_HULL_SHAPE_PROXYTYPE; - break; - case SHAPE_TYPE_COMPOUND: - bulletShapeType = COMPOUND_SHAPE_PROXYTYPE; - break; - } - return bulletShapeType; -} - -int ShapeInfoUtil::fromBulletShapeType(int bulletShapeType) { - int shapeInfoType = SHAPE_TYPE_NONE; - switch(bulletShapeType) { - case BOX_SHAPE_PROXYTYPE: - shapeInfoType = SHAPE_TYPE_BOX; - break; - case SPHERE_SHAPE_PROXYTYPE: - shapeInfoType = SHAPE_TYPE_SPHERE; - break; - case CAPSULE_SHAPE_PROXYTYPE: - shapeInfoType = SHAPE_TYPE_CAPSULE_Y; - break; - case CONVEX_HULL_SHAPE_PROXYTYPE: - shapeInfoType = SHAPE_TYPE_CONVEX_HULL; - break; - case COMPOUND_SHAPE_PROXYTYPE: - shapeInfoType = SHAPE_TYPE_COMPOUND; - break; - } - return shapeInfoType; -} - -void ShapeInfoUtil::collectInfoFromShape(const btCollisionShape* shape, ShapeInfo& info) { - if (shape) { - int type = ShapeInfoUtil::fromBulletShapeType(shape->getShapeType()); - switch(type) { - case SHAPE_TYPE_BOX: { - const btBoxShape* boxShape = static_cast(shape); - info.setBox(bulletToGLM(boxShape->getHalfExtentsWithMargin())); - } - break; - case SHAPE_TYPE_SPHERE: { - const btSphereShape* sphereShape = static_cast(shape); - info.setSphere(sphereShape->getRadius()); - } - break; - case SHAPE_TYPE_CONVEX_HULL: { - const btConvexHullShape* convexHullShape = static_cast(shape); - const int numPoints = convexHullShape->getNumPoints(); - const btVector3* btPoints = convexHullShape->getUnscaledPoints(); - QVector> points; - QVector childPoints; - for (int i = 0; i < numPoints; i++) { - glm::vec3 point(btPoints->getX(), btPoints->getY(), btPoints->getZ()); - childPoints << point; - } - points << childPoints; - info.setConvexHulls(points); - } - break; - case SHAPE_TYPE_COMPOUND: { - const btCompoundShape* compoundShape = static_cast(shape); - const int numChildShapes = compoundShape->getNumChildShapes(); - QVector> points; - for (int i = 0; i < numChildShapes; i ++) { - const btCollisionShape* childShape = compoundShape->getChildShape(i); - const btConvexHullShape* convexHullShape = static_cast(childShape); - const int numPoints = convexHullShape->getNumPoints(); - const btVector3* btPoints = convexHullShape->getUnscaledPoints(); - - QVector childPoints; - for (int j = 0; j < numPoints; j++) { - glm::vec3 point(btPoints->getX(), btPoints->getY(), btPoints->getZ()); - childPoints << point; - } - points << childPoints; - } - info.setConvexHulls(points); - } - break; - default: { - info.clear(); - } - break; - } - } else { - info.clear(); - } -} btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) { btCollisionShape* shape = NULL; @@ -135,33 +34,34 @@ btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) { shape = new btCapsuleShape(radius, height); } break; - case SHAPE_TYPE_CONVEX_HULL: { - auto hull = new btConvexHullShape(); - const QVector>& points = info.getPoints(); - foreach (glm::vec3 point, points[0]) { - btVector3 btPoint(point[0], point[1], point[2]); - hull->addPoint(btPoint, false); - } - hull->recalcLocalAabb(); - shape = hull; - } - break; case SHAPE_TYPE_COMPOUND: { - auto compound = new btCompoundShape(); const QVector>& points = info.getPoints(); - - btTransform trans; - trans.setIdentity(); - foreach (QVector hullPoints, points) { + uint32_t numSubShapes = info.getNumSubShapes(); + if (numSubShapes == 1) { auto hull = new btConvexHullShape(); - foreach (glm::vec3 point, hullPoints) { + const QVector>& points = info.getPoints(); + foreach (glm::vec3 point, points[0]) { btVector3 btPoint(point[0], point[1], point[2]); hull->addPoint(btPoint, false); } hull->recalcLocalAabb(); - compound->addChildShape (trans, hull); + shape = hull; + } else { + assert(numSubShapes > 1); + auto compound = new btCompoundShape(); + btTransform trans; + trans.setIdentity(); + foreach (QVector hullPoints, points) { + auto hull = new btConvexHullShape(); + foreach (glm::vec3 point, hullPoints) { + btVector3 btPoint(point[0], point[1], point[2]); + hull->addPoint(btPoint, false); + } + hull->recalcLocalAabb(); + compound->addChildShape (trans, hull); + } + shape = compound; } - shape = compound; } break; } diff --git a/libraries/physics/src/ShapeInfoUtil.h b/libraries/physics/src/ShapeInfoUtil.h index 9585161440..39a897019c 100644 --- a/libraries/physics/src/ShapeInfoUtil.h +++ b/libraries/physics/src/ShapeInfoUtil.h @@ -19,16 +19,10 @@ // translates between ShapeInfo and btShape +// TODO: rename this to ShapeFactory namespace ShapeInfoUtil { - // XXX is collectInfoFromShape no longer strictly needed? - void collectInfoFromShape(const btCollisionShape* shape, ShapeInfo& info); - btCollisionShape* createShapeFromInfo(const ShapeInfo& info); - - // TODO? just use bullet shape types everywhere? - int toBulletShapeType(int shapeInfoType); - int fromBulletShapeType(int bulletShapeType); }; #endif // hifi_ShapeInfoUtil_h diff --git a/libraries/shared/src/ShapeInfo.cpp b/libraries/shared/src/ShapeInfo.cpp index 5fe1fc230d..544df35b86 100644 --- a/libraries/shared/src/ShapeInfo.cpp +++ b/libraries/shared/src/ShapeInfo.cpp @@ -37,12 +37,6 @@ void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QString _halfExtents = glm::vec3(radius); break; } - case SHAPE_TYPE_CONVEX_HULL: - _url = QUrl(url); - // halfExtents aren't used by convex-hull or compound convex-hull except as part of - // the generation of the key for the ShapeManager. - _halfExtents = halfExtents; - break; case SHAPE_TYPE_COMPOUND: _url = QUrl(url); _halfExtents = halfExtents; @@ -78,12 +72,8 @@ void ShapeInfo::setEllipsoid(const glm::vec3& halfExtents) { } void ShapeInfo::setConvexHulls(const QVector>& points) { - if (points.size() == 1) { - _type = SHAPE_TYPE_CONVEX_HULL; - } else { - _type = SHAPE_TYPE_COMPOUND; - } _points = points; + _type = (_points.size() > 0) ? SHAPE_TYPE_COMPOUND : SHAPE_TYPE_NONE; _doubleHashKey.clear(); } @@ -95,6 +85,14 @@ void ShapeInfo::setCapsuleY(float radius, float halfHeight) { _doubleHashKey.clear(); } +uint32_t ShapeInfo::getNumSubShapes() const { + if (_type == SHAPE_TYPE_NONE) { + return 0; + } else if (_type == SHAPE_TYPE_COMPOUND) { + return _points.size(); + } + return 1; +} float ShapeInfo::computeVolume() const { const float DEFAULT_VOLUME = 1.0f; float volume = DEFAULT_VOLUME; diff --git a/libraries/shared/src/ShapeInfo.h b/libraries/shared/src/ShapeInfo.h index 4dce121d64..8770ef62c7 100644 --- a/libraries/shared/src/ShapeInfo.h +++ b/libraries/shared/src/ShapeInfo.h @@ -24,7 +24,6 @@ enum ShapeType { SHAPE_TYPE_BOX, SHAPE_TYPE_SPHERE, SHAPE_TYPE_ELLIPSOID, - SHAPE_TYPE_CONVEX_HULL, SHAPE_TYPE_PLANE, SHAPE_TYPE_COMPOUND, SHAPE_TYPE_CAPSULE_X, @@ -52,6 +51,7 @@ public: const glm::vec3& getHalfExtents() const { return _halfExtents; } const QVector>& getPoints() const { return _points; } + uint32_t getNumSubShapes() const; void clearPoints () { _points.clear(); } void appendToPoints (const QVector& newPoints) { _points << newPoints; } diff --git a/tests/physics/src/ShapeInfoTests.cpp b/tests/physics/src/ShapeInfoTests.cpp index bf2a98eb10..ef5bd0be39 100644 --- a/tests/physics/src/ShapeInfoTests.cpp +++ b/tests/physics/src/ShapeInfoTests.cpp @@ -147,9 +147,7 @@ void ShapeInfoTests::testBoxShape() { std::cout << __FILE__ << ":" << __LINE__ << " ERROR: NULL Box shape" << std::endl; } - ShapeInfo otherInfo; - ShapeInfoUtil::collectInfoFromShape(shape, otherInfo); - + ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); if (key.getHash() != otherKey.getHash()) { std::cout << __FILE__ << ":" << __LINE__ @@ -172,9 +170,7 @@ void ShapeInfoTests::testSphereShape() { btCollisionShape* shape = ShapeInfoUtil::createShapeFromInfo(info); - ShapeInfo otherInfo; - ShapeInfoUtil::collectInfoFromShape(shape, otherInfo); - + ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); if (key.getHash() != otherKey.getHash()) { std::cout << __FILE__ << ":" << __LINE__ @@ -198,9 +194,7 @@ void ShapeInfoTests::testCylinderShape() { btCollisionShape* shape = ShapeInfoUtil::createShapeFromInfo(info); - ShapeInfo otherInfo; - ShapeInfoUtil::collectInfoFromShape(shape, otherInfo); - + ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); if (key.getHash() != otherKey.getHash()) { std::cout << __FILE__ << ":" << __LINE__ @@ -225,9 +219,7 @@ void ShapeInfoTests::testCapsuleShape() { btCollisionShape* shape = ShapeInfoUtil::createShapeFromInfo(info); - ShapeInfo otherInfo; - ShapeInfoUtil::collectInfoFromShape(shape, otherInfo); - + ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); if (key.getHash() != otherKey.getHash()) { std::cout << __FILE__ << ":" << __LINE__ diff --git a/tests/physics/src/ShapeManagerTests.cpp b/tests/physics/src/ShapeManagerTests.cpp index d86f296d0e..d2b4ca70fa 100644 --- a/tests/physics/src/ShapeManagerTests.cpp +++ b/tests/physics/src/ShapeManagerTests.cpp @@ -187,9 +187,7 @@ void ShapeManagerTests::addBoxShape() { ShapeManager shapeManager; btCollisionShape* shape = shapeManager.getShape(info); - ShapeInfo otherInfo; - ShapeInfoUtil::collectInfoFromShape(shape, otherInfo); - + ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); if (shape != otherShape) { std::cout << __FILE__ << ":" << __LINE__ @@ -205,9 +203,7 @@ void ShapeManagerTests::addSphereShape() { ShapeManager shapeManager; btCollisionShape* shape = shapeManager.getShape(info); - ShapeInfo otherInfo; - ShapeInfoUtil::collectInfoFromShape(shape, otherInfo); - + ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); if (shape != otherShape) { std::cout << __FILE__ << ":" << __LINE__ @@ -225,9 +221,7 @@ void ShapeManagerTests::addCylinderShape() { ShapeManager shapeManager; btCollisionShape* shape = shapeManager.getShape(info); - ShapeInfo otherInfo; - ShapeInfoUtil::collectInfoFromShape(shape, otherInfo); - + ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); if (shape != otherShape) { std::cout << __FILE__ << ":" << __LINE__ @@ -246,9 +240,7 @@ void ShapeManagerTests::addCapsuleShape() { ShapeManager shapeManager; btCollisionShape* shape = shapeManager.getShape(info); - ShapeInfo otherInfo; - ShapeInfoUtil::collectInfoFromShape(shape, otherInfo); - + ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); if (shape != otherShape) { std::cout << __FILE__ << ":" << __LINE__ From 7da1c518771b6d2d875b68ca6e264bd363777594 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 14 Apr 2015 14:55:42 -0700 Subject: [PATCH 3/8] whoops, missed a file --- libraries/physics/src/ShapeManager.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/physics/src/ShapeManager.cpp b/libraries/physics/src/ShapeManager.cpp index 2a73f5d28f..dd67c2c73a 100644 --- a/libraries/physics/src/ShapeManager.cpp +++ b/libraries/physics/src/ShapeManager.cpp @@ -35,7 +35,7 @@ btCollisionShape* ShapeManager::getShape(const ShapeInfo& info) { // Very small or large objects are not supported. float diagonal = 4.0f * glm::length2(info.getHalfExtents()); const float MIN_SHAPE_DIAGONAL_SQUARED = 3.0e-4f; // 1 cm cube - const float MAX_SHAPE_DIAGONAL_SQUARED = 3.0e6f; // 1000 m cube + //const float MAX_SHAPE_DIAGONAL_SQUARED = 3.0e6f; // 1000 m cube if (diagonal < MIN_SHAPE_DIAGONAL_SQUARED /* || diagonal > MAX_SHAPE_DIAGONAL_SQUARED*/ ) { // qCDebug(physics) << "ShapeManager::getShape -- not making shape due to size" << diagonal; return NULL; @@ -104,11 +104,9 @@ void ShapeManager::collectGarbage() { ShapeReference* shapeRef = _shapeMap.find(key); if (shapeRef && shapeRef->refCount == 0) { // if the shape we're about to delete is compound, delete the children first. - auto shapeType = ShapeInfoUtil::fromBulletShapeType(shapeRef->shape->getShapeType()); - if (shapeType == SHAPE_TYPE_COMPOUND) { + if (shapeRef->shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) { const btCompoundShape* compoundShape = static_cast(shapeRef->shape); const int numChildShapes = compoundShape->getNumChildShapes(); - QVector> points; for (int i = 0; i < numChildShapes; i ++) { const btCollisionShape* childShape = compoundShape->getChildShape(i); delete childShape; From 5b81b5b11b5236247044d065afc080609b084d5a Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 14 Apr 2015 14:56:32 -0700 Subject: [PATCH 4/8] removing SHAPE_TYPE_CONVEX_HULL from entities lib --- .../src/RenderableModelEntityItem.cpp | 86 ++++++++----------- .../src/RenderableModelEntityItem.h | 3 - .../entities/src/EntityItemProperties.cpp | 2 +- libraries/entities/src/ModelEntityItem.cpp | 10 +++ libraries/entities/src/ModelEntityItem.h | 4 +- 5 files changed, 49 insertions(+), 56 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 1d601d1294..3dd8f79fff 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -274,54 +274,50 @@ void RenderableModelEntityItem::setCollisionModelURL(const QString& url) { } } -bool RenderableModelEntityItem::hasCollisionModel() const { - if (_model) { - return ! _model->getCollisionURL().isEmpty(); - } else { - return !_collisionModelURL.isEmpty(); - } -} - -const QString& RenderableModelEntityItem::getCollisionModelURL() const { - // assert (!_model || _collisionModelURL == _model->getCollisionURL().toString()); - return _collisionModelURL; -} - bool RenderableModelEntityItem::isReadyToComputeShape() { + ShapeType type = getShapeType(); + if (type == SHAPE_TYPE_COMPOUND) { - if (!_model) { - return false; // hmm... + if (!_model) { + return false; // hmm... + } + + assert(!_model->getCollisionURL().isEmpty()); + + if (_model->getURL().isEmpty()) { + // we need a render geometry with a scale to proceed, so give up. + return false; + } + + const QSharedPointer collisionNetworkGeometry = _model->getCollisionGeometry(); + const QSharedPointer renderNetworkGeometry = _model->getGeometry(); + + if ((! collisionNetworkGeometry.isNull() && collisionNetworkGeometry->isLoadedWithTextures()) && + (! renderNetworkGeometry.isNull() && renderNetworkGeometry->isLoadedWithTextures())) { + // we have both URLs AND both geometries AND they are both fully loaded. + return true; + } + + // the model is still being downloaded. + std::cout << "adebug still being downloaded" << std::endl; // adebug + return false; } - - if (_model->getCollisionURL().isEmpty()) { - // no collision-model url, so we're ready to compute a shape (of type None). - return true; - } - if (_model->getURL().isEmpty()) { - // we need a render geometry with a scale to proceed, so give up. - return true; - } - - const QSharedPointer collisionNetworkGeometry = _model->getCollisionGeometry(); - const QSharedPointer renderNetworkGeometry = _model->getGeometry(); - - if ((! collisionNetworkGeometry.isNull() && collisionNetworkGeometry->isLoadedWithTextures()) && - (! renderNetworkGeometry.isNull() && renderNetworkGeometry->isLoadedWithTextures())) { - // we have both URLs AND both geometries AND they are both fully loaded. - return true; - } - - // the model is still being downloaded. - return false; + return true; } void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { - if (_model->getCollisionURL().isEmpty() || _model->getURL().isEmpty()) { - info.setParams(getShapeType(), 0.5f * getDimensions()); + ShapeType type = getShapeType(); + if (type != SHAPE_TYPE_COMPOUND) { + ModelEntityItem::computeShapeInfo(info); + info.setParams(_shapeType, 0.5f * getDimensions()); } else { const QSharedPointer collisionNetworkGeometry = _model->getCollisionGeometry(); - const FBXGeometry& collisionGeometry = collisionNetworkGeometry->getFBXGeometry(); + // should never fall in here when collision model not fully loaded + // hence we assert collisionNetworkGeometry is not NULL + assert(!collisionNetworkGeometry.isNull()); + + const FBXGeometry& collisionGeometry = collisionNetworkGeometry->getFBXGeometry(); const QSharedPointer renderNetworkGeometry = _model->getGeometry(); const FBXGeometry& renderGeometry = renderNetworkGeometry->getFBXGeometry(); @@ -415,18 +411,8 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { } glm::vec3 collisionModelDimensions = box.getDimensions(); - info.setParams(getShapeType(), collisionModelDimensions, _collisionModelURL); + info.setParams(_shapeType, collisionModelDimensions, _collisionModelURL); info.setConvexHulls(_points); } } -ShapeType RenderableModelEntityItem::getShapeType() const { - // XXX make hull an option in edit.js ? - if (!_model || _model->getCollisionURL().isEmpty()) { - return _shapeType; - } else if (_points.size() == 1) { - return SHAPE_TYPE_CONVEX_HULL; - } else { - return SHAPE_TYPE_COMPOUND; - } -} diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 9146a04cf8..b632357942 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -53,12 +53,9 @@ public: bool needsToCallUpdate() const; virtual void setCollisionModelURL(const QString& url); - virtual bool hasCollisionModel() const; - virtual const QString& getCollisionModelURL() const; bool isReadyToComputeShape(); void computeShapeInfo(ShapeInfo& info); - ShapeType getShapeType() const; private: void remapTextures(); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index bf2ea640f1..8a25d59f26 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -192,7 +192,7 @@ void buildStringToShapeTypeLookup() { stringToShapeTypeLookup["box"] = SHAPE_TYPE_BOX; stringToShapeTypeLookup["sphere"] = SHAPE_TYPE_SPHERE; stringToShapeTypeLookup["ellipsoid"] = SHAPE_TYPE_ELLIPSOID; - stringToShapeTypeLookup["convex-hull"] = SHAPE_TYPE_CONVEX_HULL; + stringToShapeTypeLookup["convex-hull"] = SHAPE_TYPE_COMPOUND; stringToShapeTypeLookup["plane"] = SHAPE_TYPE_PLANE; stringToShapeTypeLookup["compound"] = SHAPE_TYPE_COMPOUND; stringToShapeTypeLookup["capsule-x"] = SHAPE_TYPE_CAPSULE_X; diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index cdbc3d9441..acee2a594f 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -282,6 +282,16 @@ void ModelEntityItem::updateShapeType(ShapeType type) { } } +// virtual +ShapeType ModelEntityItem::getShapeType() const { + if (_shapeType == SHAPE_TYPE_COMPOUND) { + return hasCollisionModel() ? SHAPE_TYPE_COMPOUND : SHAPE_TYPE_NONE; + } + else { + return _shapeType; + } +} + void ModelEntityItem::setCollisionModelURL(const QString& url) { if (_collisionModelURL != url) { _collisionModelURL = url; diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 9e34de445b..057c5babaf 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -49,7 +49,7 @@ public: virtual void debugDump() const; void updateShapeType(ShapeType type); - virtual ShapeType getShapeType() const { return _shapeType; } + virtual ShapeType getShapeType() const; // TODO: Move these to subclasses, or other appropriate abstraction // getters/setters applicable to models and particles @@ -63,7 +63,7 @@ public: const QString& getModelURL() const { return _modelURL; } static const QString DEFAULT_COLLISION_MODEL_URL; - virtual const QString& getCollisionModelURL() const { return _collisionModelURL; } + const QString& getCollisionModelURL() const { return _collisionModelURL; } bool hasAnimation() const { return !_animationURL.isEmpty(); } static const QString DEFAULT_ANIMATION_URL; From 8623a0606cd48be6fa43ec7095419a40b9a85bc2 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 14 Apr 2015 15:39:24 -0700 Subject: [PATCH 5/8] remove accidentally commited debug code --- libraries/entities-renderer/src/RenderableModelEntityItem.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 3dd8f79fff..c67e1f04e5 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -299,7 +299,6 @@ bool RenderableModelEntityItem::isReadyToComputeShape() { } // the model is still being downloaded. - std::cout << "adebug still being downloaded" << std::endl; // adebug return false; } return true; From aec42cf2dc64935fa22dfc4beb422d207b86c330 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 14 Apr 2015 15:39:49 -0700 Subject: [PATCH 6/8] enforce ShapeType agreement for ModeEntityItem --- libraries/entities/src/ModelEntityItem.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index acee2a594f..e98f784765 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -276,6 +276,16 @@ void ModelEntityItem::debugDump() const { } void ModelEntityItem::updateShapeType(ShapeType type) { + // BEGIN_TEMPORARY_WORKAROUND + // we have allowed inconsistent ShapeType's to be stored in SVO files in the past (this was a bug) + // but we are now enforcing the entity properties to be consistent. To make the possible we're + // introducing a temporary workaround: we will ignore ShapeType updates that conflict with the + // _collisionModelURL. + if (hasCollisionModel()) { + type = SHAPE_TYPE_COMPOUND; + } + // END_TEMPORARY_WORKAROUND + if (type != _shapeType) { _shapeType = type; _dirtyFlags |= EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS; @@ -296,6 +306,7 @@ void ModelEntityItem::setCollisionModelURL(const QString& url) { if (_collisionModelURL != url) { _collisionModelURL = url; _dirtyFlags |= EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS; + _shapeType = _collisionModelURL.isEmpty() ? SHAPE_TYPE_NONE : SHAPE_TYPE_COMPOUND; } } From 21d669f2f13e0395f47e72a32d6e7dbd0771a308 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 16 Apr 2015 12:13:41 -0700 Subject: [PATCH 7/8] use computed shape type --- libraries/entities-renderer/src/RenderableModelEntityItem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index c67e1f04e5..86b0be4dd8 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -308,7 +308,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { ShapeType type = getShapeType(); if (type != SHAPE_TYPE_COMPOUND) { ModelEntityItem::computeShapeInfo(info); - info.setParams(_shapeType, 0.5f * getDimensions()); + info.setParams(type, 0.5f * getDimensions()); } else { const QSharedPointer collisionNetworkGeometry = _model->getCollisionGeometry(); @@ -410,7 +410,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { } glm::vec3 collisionModelDimensions = box.getDimensions(); - info.setParams(_shapeType, collisionModelDimensions, _collisionModelURL); + info.setParams(type, collisionModelDimensions, _collisionModelURL); info.setConvexHulls(_points); } } From 94c6053d5259b07917e99a04c55a79ed2cef823a Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 16 Apr 2015 12:15:03 -0700 Subject: [PATCH 8/8] fix formatting --- libraries/entities/src/ModelEntityItem.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index e98f784765..f95eeea8e4 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -296,8 +296,7 @@ void ModelEntityItem::updateShapeType(ShapeType type) { ShapeType ModelEntityItem::getShapeType() const { if (_shapeType == SHAPE_TYPE_COMPOUND) { return hasCollisionModel() ? SHAPE_TYPE_COMPOUND : SHAPE_TYPE_NONE; - } - else { + } else { return _shapeType; } }