diff --git a/libraries/entities-renderer/src/RenderableEntityItem.h b/libraries/entities-renderer/src/RenderableEntityItem.h index c860b849b8..2697d30de4 100644 --- a/libraries/entities-renderer/src/RenderableEntityItem.h +++ b/libraries/entities-renderer/src/RenderableEntityItem.h @@ -101,7 +101,7 @@ protected: virtual void doRender(RenderArgs* args) = 0; virtual bool isFading() const { return _isFading; } - void updateModelTransformAndBound(); + virtual void updateModelTransformAndBound(); virtual bool isTransparent() const { return _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f : false; } inline bool isValidRenderItem() const { return _renderItemID != Item::INVALID_ITEM_ID; } @@ -124,7 +124,6 @@ signals: protected: template std::shared_ptr asTypedEntity() { return std::static_pointer_cast(_entity); } - static void makeStatusGetters(const EntityItemPointer& entity, Item::Status::Getters& statusGetters); const Transform& getModelTransform() const; @@ -153,7 +152,6 @@ protected: quint64 _created; -private: // The base class relies on comparing the model transform to the entity transform in order // to trigger an update, so the member must not be visible to derived classes as a modifiable // transform diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 9d2ce6fa28..45e718e1d5 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -41,6 +41,20 @@ PolyLineEntityRenderer::PolyLineEntityRenderer(const EntityItemPointer& entity) } } +void PolyLineEntityRenderer::updateModelTransformAndBound() { + bool success = false; + auto newModelTransform = _entity->getTransformToCenter(success); + if (success) { + _modelTransform = newModelTransform; + + auto lineEntity = std::static_pointer_cast(_entity); + AABox bound; + lineEntity->computeTightLocalBoundingBox(bound); + bound.transform(newModelTransform); + _bound = bound; + } +} + void PolyLineEntityRenderer::buildPipelines() { // FIXME: opaque pipelines diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.h b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.h index 9139c260ea..97a45cef19 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.h @@ -25,6 +25,8 @@ class PolyLineEntityRenderer : public TypedEntityRenderer { public: PolyLineEntityRenderer(const EntityItemPointer& entity); + void updateModelTransformAndBound() override; + // FIXME: shouldn't always be transparent: take into account texture and glow virtual bool isTransparent() const override { return true; } diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index 645d2b39f8..fe14ba6925 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -14,6 +14,7 @@ #include #include +#include #include "EntitiesLogging.h" #include "EntityItemProperties.h" @@ -85,7 +86,7 @@ void PolyLineEntityItem::setLinePoints(const QVector& points) { _points = points; _pointsChanged = true; }); - computeAndUpdateDimensionsAndPosition(); + computeAndUpdateDimensions(); } void PolyLineEntityItem::setStrokeWidths(const QVector& strokeWidths) { @@ -93,7 +94,7 @@ void PolyLineEntityItem::setStrokeWidths(const QVector& strokeWidths) { _widths = strokeWidths; _widthsChanged = true; }); - computeAndUpdateDimensionsAndPosition(); + computeAndUpdateDimensions(); } void PolyLineEntityItem::setNormals(const QVector& normals) { @@ -110,7 +111,7 @@ void PolyLineEntityItem::setStrokeColors(const QVector& strokeColors) }); } -void PolyLineEntityItem::computeAndUpdateDimensionsAndPosition() { +void PolyLineEntityItem::computeAndUpdateDimensions() { QVector points; QVector widths; @@ -129,6 +130,32 @@ void PolyLineEntityItem::computeAndUpdateDimensionsAndPosition() { setScaledDimensions(2.0f * (maxHalfDim + maxWidth)); } +void PolyLineEntityItem::computeTightLocalBoundingBox(AABox& localBox) const { + QVector points; + QVector widths; + withReadLock([&] { + points = _points; + widths = _widths; + }); + + if (points.size() > 0) { + Extents extents; + float maxWidth = DEFAULT_LINE_WIDTH; + for (int i = 0; i < points.length(); i++) { + extents.addPoint(points[i]); + if (i < widths.size()) { + maxWidth = glm::max(maxWidth, widths[i]); + } + } + extents.addPoint(extents.minimum - maxWidth * Vectors::ONE); + extents.addPoint(extents.maximum + maxWidth * Vectors::ONE); + + localBox.setBox(extents.minimum, extents.maximum - extents.minimum); + } else { + localBox.setBox(glm::vec3(-0.5f * DEFAULT_LINE_WIDTH), glm::vec3(DEFAULT_LINE_WIDTH)); + } +} + int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args, EntityPropertyFlags& propertyFlags, bool overwriteLocalData, @@ -267,4 +294,4 @@ void PolyLineEntityItem::setFaceCamera(bool faceCamera) { _needsRenderUpdate = _faceCamera != faceCamera; _faceCamera = faceCamera; }); -} \ No newline at end of file +} diff --git a/libraries/entities/src/PolyLineEntityItem.h b/libraries/entities/src/PolyLineEntityItem.h index fc3b085cf1..e68666d75e 100644 --- a/libraries/entities/src/PolyLineEntityItem.h +++ b/libraries/entities/src/PolyLineEntityItem.h @@ -15,7 +15,7 @@ #include "EntityItem.h" class PolyLineEntityItem : public EntityItem { - public: +public: static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties); PolyLineEntityItem(const EntityItemID& entityItemID); @@ -90,10 +90,12 @@ class PolyLineEntityItem : public EntityItem { BoxFace& face, glm::vec3& surfaceNormal, QVariantMap& extraInfo, bool precisionPicking) const override { return false; } + void computeTightLocalBoundingBox(AABox& box) const; + virtual void debugDump() const override; private: - void computeAndUpdateDimensionsAndPosition(); - + void computeAndUpdateDimensions(); + protected: glm::u8vec3 _color; QVector _points;