From f9be7dda363af106a904ddc16b0ed53851af682a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 17 Mar 2015 18:55:13 -0700 Subject: [PATCH] bump shape stuff from ModelEntityItem down to RenderableModelEntityItem --- .../src/RenderableModelEntityItem.cpp | 49 +++++++++++++++++++ .../src/RenderableModelEntityItem.h | 10 +++- libraries/entities/CMakeLists.txt | 2 +- libraries/entities/src/ModelEntityItem.cpp | 46 ----------------- libraries/entities/src/ModelEntityItem.h | 15 ------ 5 files changed, 59 insertions(+), 63 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 75c9f07881..7e57323d68 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -266,4 +266,53 @@ bool RenderableModelEntityItem::findDetailedRayIntersection(const glm::vec3& ori return _model->findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, extraInfo, precisionPicking); } +bool RenderableModelEntityItem::isReadyToComputeShape() { + if (_collisionModelURL == "") { + // no model url, so we're ready to compute a shape. + return true; + } + if (! _collisionNetworkGeometry.isNull() && _collisionNetworkGeometry->isLoadedWithTextures()) { + // we have a _collisionModelURL AND a _collisionNetworkGeometry AND it's fully loaded. + return true; + } + + if (_collisionNetworkGeometry.isNull()) { + // we have a _collisionModelURL but we don't yet have a _collisionNetworkGeometry. + _collisionNetworkGeometry = + DependencyManager::get()->getGeometry(_collisionModelURL, QUrl(), false, false); + + if (! _collisionNetworkGeometry.isNull() && _collisionNetworkGeometry->isLoadedWithTextures()) { + // shortcut in case it's already loaded. + return true; + } + } + + // the model is still being downloaded. + return false; +} + +void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { + if (_collisionModelURL == "") { + info.setParams(getShapeType(), 0.5f * getDimensions()); + } else { + const FBXGeometry& fbxGeometry = _collisionNetworkGeometry->getFBXGeometry(); + + _points.clear(); + foreach (const FBXMesh& mesh, fbxGeometry.meshes) { + _points << mesh.vertices; + } + + info.setParams(getShapeType(), 0.5f * getDimensions(), NULL, _collisionModelURL); + info.setConvexHull(_points); + } +} + +ShapeType RenderableModelEntityItem::getShapeType() const { + // XXX make hull an option in edit.js ? + if (_collisionModelURL != "") { + return SHAPE_TYPE_CONVEX_HULL; + } else { + return _shapeType; + } +} diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 65cded0207..6d50a52a95 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -30,7 +30,8 @@ public: _needsInitialSimulation(true), _needsModelReload(true), _myRenderer(NULL), - _originalTexturesRead(false) { } + _originalTexturesRead(false), + _collisionNetworkGeometry(QSharedPointer()) { } virtual ~RenderableModelEntityItem(); @@ -52,6 +53,10 @@ public: bool needsToCallUpdate() const; + bool isReadyToComputeShape(); + void computeShapeInfo(ShapeInfo& info); + ShapeType getShapeType() const; + private: void remapTextures(); @@ -62,6 +67,9 @@ private: QString _currentTextures; QStringList _originalTextures; bool _originalTexturesRead; + + QSharedPointer _collisionNetworkGeometry; + QVector _points; }; #endif // hifi_RenderableModelEntityItem_h diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index d8c316aba6..e57bcf67fa 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -13,4 +13,4 @@ find_package(Bullet REQUIRED) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) -link_hifi_libraries(avatars shared octree gpu model fbx networking animation render-utils) +link_hifi_libraries(avatars shared octree gpu model fbx networking animation) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 4e8223cfab..ce009988b1 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -17,7 +17,6 @@ #include "EntityTree.h" #include "EntityTreeElement.h" #include "ModelEntityItem.h" -#include "GeometryCache.h" #include "ResourceCache.h" const QString ModelEntityItem::DEFAULT_MODEL_URL = QString(""); @@ -35,8 +34,6 @@ EntityItem* ModelEntityItem::factory(const EntityItemID& entityID, const EntityI ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID, properties) { - _collisionNetworkGeometry = QSharedPointer(); - _type = EntityTypes::Model; setProperties(properties); _lastAnimated = usecTimestampNow(); @@ -415,46 +412,3 @@ QString ModelEntityItem::getAnimationSettings() const { QString jsonByteString(jsonByteArray); return jsonByteString; } - - -bool ModelEntityItem::isReadyToComputeShape() { - if (_collisionModelURL == "") { - // no model url, so we're ready to compute a shape. - return true; - } - - if (! _collisionNetworkGeometry.isNull() && _collisionNetworkGeometry->isLoadedWithTextures()) { - // we have a _collisionModelURL AND a _collisionNetworkGeometry AND it's fully loaded. - return true; - } - - if (_collisionNetworkGeometry.isNull()) { - // we have a _collisionModelURL but we don't yet have a _collisionNetworkGeometry. - _collisionNetworkGeometry = - DependencyManager::get()->getGeometry(_collisionModelURL, QUrl(), false, false); - - if (! _collisionNetworkGeometry.isNull() && _collisionNetworkGeometry->isLoadedWithTextures()) { - // shortcut in case it's already loaded. - return true; - } - } - - // the model is still being downloaded. - return false; -} - -void ModelEntityItem::computeShapeInfo(ShapeInfo& info) { - if (_collisionModelURL == "") { - info.setParams(getShapeType(), 0.5f * getDimensions()); - } else { - const FBXGeometry& fbxGeometry = _collisionNetworkGeometry->getFBXGeometry(); - - _points.clear(); - foreach (const FBXMesh& mesh, fbxGeometry.meshes) { - _points << mesh.vertices; - } - - info.setParams(getShapeType(), 0.5f * getDimensions(), NULL, _collisionModelURL); - info.setConvexHull(_points); - } -} diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 5a1592b0a1..3bd414ec6e 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -51,17 +51,7 @@ public: virtual bool needsToCallUpdate() const; virtual void debugDump() const; - virtual void computeShapeInfo(ShapeInfo& info); - void updateShapeType(ShapeType type); - virtual ShapeType getShapeType() const { - // XXX make hull an option in edit.js ? - if (_collisionModelURL != "") { - return SHAPE_TYPE_CONVEX_HULL; - } else { - return _shapeType; - } - } // TODO: Move these to subclasses, or other appropriate abstraction // getters/setters applicable to models and particles @@ -132,8 +122,6 @@ public: static void cleanupLoadedAnimations(); - bool isReadyToComputeShape(); - protected: bool isAnimatingSomething() const; @@ -156,9 +144,6 @@ protected: static Animation* getAnimation(const QString& url); static QMap _loadedAnimations; static AnimationCache _animationCache; - - QSharedPointer _collisionNetworkGeometry; - QVector _points; }; #endif // hifi_ModelEntityItem_h