From b035c5b082258f3d0e0d24f23d0900d43e3c8580 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 30 Jan 2015 14:16:32 -0800 Subject: [PATCH 1/5] fix for updating moving models --- .../entities-renderer/src/RenderableModelEntityItem.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 699603cb21..7adb857902 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -148,7 +148,8 @@ void RenderableModelEntityItem::render(RenderArgs* args) { } glm::quat rotation = getRotation(); - if (needsToCallUpdate() && _model->isActive()) { + bool movingOrAnimating = isMoving() || isAnimatingSomething(); + if (movingOrAnimating && _model->isActive()) { _model->setScaleToFit(true, dimensions); _model->setSnapModelToRegistrationPoint(true, getRegistrationPoint()); _model->setRotation(rotation); @@ -168,7 +169,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("model->render"); // filter out if not needed to render if (args && (args->_renderMode == RenderArgs::SHADOW_RENDER_MODE)) { - if (isMoving() || isAnimatingSomething()) { + if (movingOrAnimating) { _model->renderInScene(alpha, args); } } else { From 80f6f718d0cfb6da8ce524106ba25af18f0f2a85 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 30 Jan 2015 14:17:29 -0800 Subject: [PATCH 2/5] EntityItem base class now computes shapeInfo --- libraries/entities/src/BoxEntityItem.cpp | 5 ----- libraries/entities/src/BoxEntityItem.h | 2 -- libraries/entities/src/EntityItem.cpp | 19 +++++++++++++++++++ libraries/entities/src/SphereEntityItem.cpp | 6 ------ libraries/entities/src/SphereEntityItem.h | 2 -- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/libraries/entities/src/BoxEntityItem.cpp b/libraries/entities/src/BoxEntityItem.cpp index 25ef2e6aaf..1e8c811122 100644 --- a/libraries/entities/src/BoxEntityItem.cpp +++ b/libraries/entities/src/BoxEntityItem.cpp @@ -96,11 +96,6 @@ void BoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitst APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor()); } -void BoxEntityItem::computeShapeInfo(ShapeInfo& info) const { - glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); - info.setBox(halfExtents); -} - void BoxEntityItem::debugDump() const { quint64 now = usecTimestampNow(); qDebug() << " BOX EntityItem id:" << getEntityItemID() << "---------------------------------------------"; diff --git a/libraries/entities/src/BoxEntityItem.h b/libraries/entities/src/BoxEntityItem.h index 8d68a13158..a9c3e724a7 100644 --- a/libraries/entities/src/BoxEntityItem.h +++ b/libraries/entities/src/BoxEntityItem.h @@ -51,8 +51,6 @@ public: _color[BLUE_INDEX] = value.blue; } - void computeShapeInfo(ShapeInfo& info) const; - virtual void debugDump() const; protected: diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 9012b2e50b..68b5d1bb05 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1022,6 +1022,25 @@ float EntityItem::getRadius() const { void EntityItem::computeShapeInfo(ShapeInfo& info) const { info.clear(); + if (_type == EntityTypes::Sphere) { + glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); + // TODO: support ellipsoid shapes + info.setSphere(halfExtents.x); + } else if (_type == EntityTypes::Box) { + glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); + info.setBox(halfExtents); + } else if (_type == EntityTypes::Model) { + // For first approximation we just boxify all models... but only if they are small enough. + // The limit here is chosen to something that most avatars could not comfortably fit inside + // to prevent houses from getting boxified... we don't want the things inside houses to + // collide with a house as if it were a giant solid block. + const float MAX_SIZE_FOR_BOXIFICATION_HACK = 3.0f; + float diagonal = glm::length(getDimensionsInMeters()); + if (diagonal < MAX_SIZE_FOR_BOXIFICATION_HACK) { + glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); + info.setBox(halfExtents); + } + } } void EntityItem::recalculateCollisionShape() { diff --git a/libraries/entities/src/SphereEntityItem.cpp b/libraries/entities/src/SphereEntityItem.cpp index 181e5851f6..865fb88463 100644 --- a/libraries/entities/src/SphereEntityItem.cpp +++ b/libraries/entities/src/SphereEntityItem.cpp @@ -101,12 +101,6 @@ void SphereEntityItem::recalculateCollisionShape() { _sphereShape.setRadius(largestDiameter / 2.0f); } -void SphereEntityItem::computeShapeInfo(ShapeInfo& info) const { - glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); - // TODO: support ellipsoid shapes - info.setSphere(halfExtents.x); -} - bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking) const { diff --git a/libraries/entities/src/SphereEntityItem.h b/libraries/entities/src/SphereEntityItem.h index f76c9f5600..fdc0b7f866 100644 --- a/libraries/entities/src/SphereEntityItem.h +++ b/libraries/entities/src/SphereEntityItem.h @@ -56,8 +56,6 @@ public: // TODO: implement proper contains for 3D ellipsoid //virtual bool contains(const glm::vec3& point) const; - void computeShapeInfo(ShapeInfo& info) const; - virtual bool supportsDetailedRayIntersection() const { return true; } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, From bc52ba1d291d6c7b41cd3f9dd2f9b233b47d4d4b Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 30 Jan 2015 16:18:50 -0800 Subject: [PATCH 3/5] restore polymorphism for Box and Sphere entities --- libraries/entities/src/BoxEntityItem.cpp | 5 ++++ libraries/entities/src/BoxEntityItem.h | 2 ++ libraries/entities/src/EntityItem.cpp | 26 +++++++-------------- libraries/entities/src/SphereEntityItem.cpp | 6 +++++ libraries/entities/src/SphereEntityItem.h | 2 ++ 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/libraries/entities/src/BoxEntityItem.cpp b/libraries/entities/src/BoxEntityItem.cpp index 1e8c811122..25ef2e6aaf 100644 --- a/libraries/entities/src/BoxEntityItem.cpp +++ b/libraries/entities/src/BoxEntityItem.cpp @@ -96,6 +96,11 @@ void BoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitst APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor()); } +void BoxEntityItem::computeShapeInfo(ShapeInfo& info) const { + glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); + info.setBox(halfExtents); +} + void BoxEntityItem::debugDump() const { quint64 now = usecTimestampNow(); qDebug() << " BOX EntityItem id:" << getEntityItemID() << "---------------------------------------------"; diff --git a/libraries/entities/src/BoxEntityItem.h b/libraries/entities/src/BoxEntityItem.h index a9c3e724a7..8d68a13158 100644 --- a/libraries/entities/src/BoxEntityItem.h +++ b/libraries/entities/src/BoxEntityItem.h @@ -51,6 +51,8 @@ public: _color[BLUE_INDEX] = value.blue; } + void computeShapeInfo(ShapeInfo& info) const; + virtual void debugDump() const; protected: diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 68b5d1bb05..fa9487c6f6 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1021,25 +1021,17 @@ float EntityItem::getRadius() const { } void EntityItem::computeShapeInfo(ShapeInfo& info) const { - info.clear(); - if (_type == EntityTypes::Sphere) { - glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); - // TODO: support ellipsoid shapes - info.setSphere(halfExtents.x); - } else if (_type == EntityTypes::Box) { + // HACK: Default first first approximation is to boxify the entity... but only if it is small enough. + // The limit here is chosen to something that most avatars could not comfortably fit inside + // to prevent houses from getting boxified... we don't want the things inside houses to + // collide with a house as if it were a giant solid block. + const float MAX_SIZE_FOR_BOXIFICATION_HACK = 3.0f; + float diagonal = glm::length(getDimensionsInMeters()); + if (diagonal < MAX_SIZE_FOR_BOXIFICATION_HACK) { glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); info.setBox(halfExtents); - } else if (_type == EntityTypes::Model) { - // For first approximation we just boxify all models... but only if they are small enough. - // The limit here is chosen to something that most avatars could not comfortably fit inside - // to prevent houses from getting boxified... we don't want the things inside houses to - // collide with a house as if it were a giant solid block. - const float MAX_SIZE_FOR_BOXIFICATION_HACK = 3.0f; - float diagonal = glm::length(getDimensionsInMeters()); - if (diagonal < MAX_SIZE_FOR_BOXIFICATION_HACK) { - glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); - info.setBox(halfExtents); - } + } else { + info.clear(); } } diff --git a/libraries/entities/src/SphereEntityItem.cpp b/libraries/entities/src/SphereEntityItem.cpp index 865fb88463..181e5851f6 100644 --- a/libraries/entities/src/SphereEntityItem.cpp +++ b/libraries/entities/src/SphereEntityItem.cpp @@ -101,6 +101,12 @@ void SphereEntityItem::recalculateCollisionShape() { _sphereShape.setRadius(largestDiameter / 2.0f); } +void SphereEntityItem::computeShapeInfo(ShapeInfo& info) const { + glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); + // TODO: support ellipsoid shapes + info.setSphere(halfExtents.x); +} + bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking) const { diff --git a/libraries/entities/src/SphereEntityItem.h b/libraries/entities/src/SphereEntityItem.h index fdc0b7f866..f76c9f5600 100644 --- a/libraries/entities/src/SphereEntityItem.h +++ b/libraries/entities/src/SphereEntityItem.h @@ -56,6 +56,8 @@ public: // TODO: implement proper contains for 3D ellipsoid //virtual bool contains(const glm::vec3& point) const; + void computeShapeInfo(ShapeInfo& info) const; + virtual bool supportsDetailedRayIntersection() const { return true; } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, From 9da6b623a33408b0c25739a00bbfe48ba216e169 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 30 Jan 2015 16:25:35 -0800 Subject: [PATCH 4/5] move shape polymorphism to ModelEntityItem --- libraries/entities/src/EntityItem.cpp | 13 +------------ libraries/entities/src/ModelEntityItem.cpp | 15 +++++++++++++++ libraries/entities/src/ModelEntityItem.h | 1 + 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index fa9487c6f6..9012b2e50b 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1021,18 +1021,7 @@ float EntityItem::getRadius() const { } void EntityItem::computeShapeInfo(ShapeInfo& info) const { - // HACK: Default first first approximation is to boxify the entity... but only if it is small enough. - // The limit here is chosen to something that most avatars could not comfortably fit inside - // to prevent houses from getting boxified... we don't want the things inside houses to - // collide with a house as if it were a giant solid block. - const float MAX_SIZE_FOR_BOXIFICATION_HACK = 3.0f; - float diagonal = glm::length(getDimensionsInMeters()); - if (diagonal < MAX_SIZE_FOR_BOXIFICATION_HACK) { - glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); - info.setBox(halfExtents); - } else { - info.clear(); - } + info.clear(); } void EntityItem::recalculateCollisionShape() { diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 2c3dcd0600..bfab8871a5 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -245,6 +245,21 @@ bool ModelEntityItem::needsToCallUpdate() const { return isAnimatingSomething() ? true : EntityItem::needsToCallUpdate(); } +void ModelEntityItem::computeShapeInfo(ShapeInfo& info) const { + // HACK: Default first first approximation is to boxify the entity... but only if it is small enough. + // The limit here is chosen to something that most avatars could not comfortably fit inside + // to prevent houses from getting boxified... we don't want the things inside houses to + // collide with a house as if it were a giant solid block. + const float MAX_SIZE_FOR_BOXIFICATION_HACK = 3.0f; + float diagonal = glm::length(getDimensionsInMeters()); + if (diagonal < MAX_SIZE_FOR_BOXIFICATION_HACK) { + glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); + info.setBox(halfExtents); + } else { + info.clear(); + } +} + void ModelEntityItem::update(const quint64& now) { // only advance the frame index if we're playing if (getAnimationIsPlaying()) { diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index a607745475..3db2a40db0 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -46,6 +46,7 @@ public: virtual void update(const quint64& now); virtual bool needsToCallUpdate() const; + void computeShapeInfo(ShapeInfo& info) const; virtual void debugDump() const; From a723c748f542864b2b4bfcd183d7b06b24311d93 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 30 Jan 2015 18:08:00 -0800 Subject: [PATCH 5/5] check initialization of _needsInitialSimulation --- libraries/entities-renderer/src/RenderableModelEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 7adb857902..ee81c5b177 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -149,7 +149,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { glm::quat rotation = getRotation(); bool movingOrAnimating = isMoving() || isAnimatingSomething(); - if (movingOrAnimating && _model->isActive()) { + if ((movingOrAnimating || _needsInitialSimulation) && _model->isActive()) { _model->setScaleToFit(true, dimensions); _model->setSnapModelToRegistrationPoint(true, getRegistrationPoint()); _model->setRotation(rotation);