tighter bounding box when rendering PolyLines

This commit is contained in:
Andrew Meadows 2019-08-19 17:06:46 -07:00
parent 33070b4579
commit 81eaf157a6
5 changed files with 53 additions and 10 deletions

View file

@ -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<typename T>
std::shared_ptr<T> asTypedEntity() { return std::static_pointer_cast<T>(_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

View file

@ -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<PolyLineEntityItem>(_entity);
AABox bound;
lineEntity->computeTightLocalBoundingBox(bound);
bound.transform(newModelTransform);
_bound = bound;
}
}
void PolyLineEntityRenderer::buildPipelines() {
// FIXME: opaque pipelines

View file

@ -25,6 +25,8 @@ class PolyLineEntityRenderer : public TypedEntityRenderer<PolyLineEntityItem> {
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; }

View file

@ -14,6 +14,7 @@
#include <QDebug>
#include <ByteCountCoding.h>
#include <Extents.h>
#include "EntitiesLogging.h"
#include "EntityItemProperties.h"
@ -85,7 +86,7 @@ void PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
_points = points;
_pointsChanged = true;
});
computeAndUpdateDimensionsAndPosition();
computeAndUpdateDimensions();
}
void PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
@ -93,7 +94,7 @@ void PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
_widths = strokeWidths;
_widthsChanged = true;
});
computeAndUpdateDimensionsAndPosition();
computeAndUpdateDimensions();
}
void PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
@ -110,7 +111,7 @@ void PolyLineEntityItem::setStrokeColors(const QVector<glm::vec3>& strokeColors)
});
}
void PolyLineEntityItem::computeAndUpdateDimensionsAndPosition() {
void PolyLineEntityItem::computeAndUpdateDimensions() {
QVector<glm::vec3> points;
QVector<float> widths;
@ -129,6 +130,32 @@ void PolyLineEntityItem::computeAndUpdateDimensionsAndPosition() {
setScaledDimensions(2.0f * (maxHalfDim + maxWidth));
}
void PolyLineEntityItem::computeTightLocalBoundingBox(AABox& localBox) const {
QVector<glm::vec3> points;
QVector<float> 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;
});
}
}

View file

@ -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<glm::vec3> _points;