mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 09:08:37 +02:00
tighter bounding box when rendering PolyLines
This commit is contained in:
parent
33070b4579
commit
81eaf157a6
5 changed files with 53 additions and 10 deletions
|
@ -101,7 +101,7 @@ protected:
|
||||||
virtual void doRender(RenderArgs* args) = 0;
|
virtual void doRender(RenderArgs* args) = 0;
|
||||||
|
|
||||||
virtual bool isFading() const { return _isFading; }
|
virtual bool isFading() const { return _isFading; }
|
||||||
void updateModelTransformAndBound();
|
virtual void updateModelTransformAndBound();
|
||||||
virtual bool isTransparent() const { return _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f : false; }
|
virtual bool isTransparent() const { return _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f : false; }
|
||||||
inline bool isValidRenderItem() const { return _renderItemID != Item::INVALID_ITEM_ID; }
|
inline bool isValidRenderItem() const { return _renderItemID != Item::INVALID_ITEM_ID; }
|
||||||
|
|
||||||
|
@ -125,7 +125,6 @@ protected:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::shared_ptr<T> asTypedEntity() { return std::static_pointer_cast<T>(_entity); }
|
std::shared_ptr<T> asTypedEntity() { return std::static_pointer_cast<T>(_entity); }
|
||||||
|
|
||||||
|
|
||||||
static void makeStatusGetters(const EntityItemPointer& entity, Item::Status::Getters& statusGetters);
|
static void makeStatusGetters(const EntityItemPointer& entity, Item::Status::Getters& statusGetters);
|
||||||
const Transform& getModelTransform() const;
|
const Transform& getModelTransform() const;
|
||||||
|
|
||||||
|
@ -153,7 +152,6 @@ protected:
|
||||||
|
|
||||||
quint64 _created;
|
quint64 _created;
|
||||||
|
|
||||||
private:
|
|
||||||
// The base class relies on comparing the model transform to the entity transform in order
|
// 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
|
// to trigger an update, so the member must not be visible to derived classes as a modifiable
|
||||||
// transform
|
// transform
|
||||||
|
|
|
@ -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() {
|
void PolyLineEntityRenderer::buildPipelines() {
|
||||||
// FIXME: opaque pipelines
|
// FIXME: opaque pipelines
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ class PolyLineEntityRenderer : public TypedEntityRenderer<PolyLineEntityItem> {
|
||||||
public:
|
public:
|
||||||
PolyLineEntityRenderer(const EntityItemPointer& entity);
|
PolyLineEntityRenderer(const EntityItemPointer& entity);
|
||||||
|
|
||||||
|
void updateModelTransformAndBound() override;
|
||||||
|
|
||||||
// FIXME: shouldn't always be transparent: take into account texture and glow
|
// FIXME: shouldn't always be transparent: take into account texture and glow
|
||||||
virtual bool isTransparent() const override { return true; }
|
virtual bool isTransparent() const override { return true; }
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <ByteCountCoding.h>
|
#include <ByteCountCoding.h>
|
||||||
|
#include <Extents.h>
|
||||||
|
|
||||||
#include "EntitiesLogging.h"
|
#include "EntitiesLogging.h"
|
||||||
#include "EntityItemProperties.h"
|
#include "EntityItemProperties.h"
|
||||||
|
@ -85,7 +86,7 @@ void PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
|
||||||
_points = points;
|
_points = points;
|
||||||
_pointsChanged = true;
|
_pointsChanged = true;
|
||||||
});
|
});
|
||||||
computeAndUpdateDimensionsAndPosition();
|
computeAndUpdateDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
|
void PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
|
||||||
|
@ -93,7 +94,7 @@ void PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
|
||||||
_widths = strokeWidths;
|
_widths = strokeWidths;
|
||||||
_widthsChanged = true;
|
_widthsChanged = true;
|
||||||
});
|
});
|
||||||
computeAndUpdateDimensionsAndPosition();
|
computeAndUpdateDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
|
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<glm::vec3> points;
|
||||||
QVector<float> widths;
|
QVector<float> widths;
|
||||||
|
|
||||||
|
@ -129,6 +130,32 @@ void PolyLineEntityItem::computeAndUpdateDimensionsAndPosition() {
|
||||||
setScaledDimensions(2.0f * (maxHalfDim + maxWidth));
|
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,
|
int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
|
||||||
ReadBitstreamToTreeParams& args,
|
ReadBitstreamToTreeParams& args,
|
||||||
EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
|
EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include "EntityItem.h"
|
#include "EntityItem.h"
|
||||||
|
|
||||||
class PolyLineEntityItem : public EntityItem {
|
class PolyLineEntityItem : public EntityItem {
|
||||||
public:
|
public:
|
||||||
static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
|
static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||||
|
|
||||||
PolyLineEntityItem(const EntityItemID& entityItemID);
|
PolyLineEntityItem(const EntityItemID& entityItemID);
|
||||||
|
@ -90,9 +90,11 @@ class PolyLineEntityItem : public EntityItem {
|
||||||
BoxFace& face, glm::vec3& surfaceNormal,
|
BoxFace& face, glm::vec3& surfaceNormal,
|
||||||
QVariantMap& extraInfo, bool precisionPicking) const override { return false; }
|
QVariantMap& extraInfo, bool precisionPicking) const override { return false; }
|
||||||
|
|
||||||
|
void computeTightLocalBoundingBox(AABox& box) const;
|
||||||
|
|
||||||
virtual void debugDump() const override;
|
virtual void debugDump() const override;
|
||||||
private:
|
private:
|
||||||
void computeAndUpdateDimensionsAndPosition();
|
void computeAndUpdateDimensions();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
glm::u8vec3 _color;
|
glm::u8vec3 _color;
|
||||||
|
|
Loading…
Reference in a new issue