From 5b81b5b11b5236247044d065afc080609b084d5a Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 14 Apr 2015 14:56:32 -0700 Subject: [PATCH] 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;