mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 21:57:05 +02:00
fix keepAspectRatio, give text entities naturalDimensions
This commit is contained in:
parent
c869554d46
commit
30cf1555e4
3 changed files with 40 additions and 8 deletions
|
@ -59,10 +59,22 @@ void ImageEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPoint
|
||||||
_alpha = entity->getAlpha();
|
_alpha = entity->getAlpha();
|
||||||
_pulseProperties = entity->getPulseProperties();
|
_pulseProperties = entity->getPulseProperties();
|
||||||
|
|
||||||
|
bool nextTextureLoaded = _texture && (_texture->isLoaded() || _texture->isFailed());
|
||||||
if (!_textureIsLoaded) {
|
if (!_textureIsLoaded) {
|
||||||
emit requestRenderUpdate();
|
emit requestRenderUpdate();
|
||||||
|
if (nextTextureLoaded) {
|
||||||
|
float width = _texture->getWidth();
|
||||||
|
float height = _texture->getHeight();
|
||||||
|
glm::vec3 naturalDimensions = glm::vec3(1.0f, 1.0f, 0.01f);
|
||||||
|
if (width < height) {
|
||||||
|
naturalDimensions.x = width / height;
|
||||||
|
} else {
|
||||||
|
naturalDimensions.y = height / width;
|
||||||
|
}
|
||||||
|
entity->setNaturalDimension(naturalDimensions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_textureIsLoaded = _texture && (_texture->isLoaded() || _texture->isFailed());
|
_textureIsLoaded = nextTextureLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapeKey ImageEntityRenderer::getShapeKey() {
|
ShapeKey ImageEntityRenderer::getShapeKey() {
|
||||||
|
@ -100,7 +112,6 @@ void ImageEntityRenderer::doRender(RenderArgs* args) {
|
||||||
transform.setRotation(BillboardModeHelpers::getBillboardRotation(transform.getTranslation(), transform.getRotation(), _billboardMode,
|
transform.setRotation(BillboardModeHelpers::getBillboardRotation(transform.getTranslation(), transform.getRotation(), _billboardMode,
|
||||||
args->_renderMode == RenderArgs::RenderMode::SHADOW_RENDER_MODE ? BillboardModeHelpers::getPrimaryViewFrustumPosition() : args->getViewFrustum().getPosition()));
|
args->_renderMode == RenderArgs::RenderMode::SHADOW_RENDER_MODE ? BillboardModeHelpers::getPrimaryViewFrustumPosition() : args->getViewFrustum().getPosition()));
|
||||||
|
|
||||||
batch->setModelTransform(transform);
|
|
||||||
batch->setResourceTexture(0, _texture->getGPUTexture());
|
batch->setResourceTexture(0, _texture->getGPUTexture());
|
||||||
|
|
||||||
float imageWidth = _texture->getWidth();
|
float imageWidth = _texture->getWidth();
|
||||||
|
@ -125,15 +136,25 @@ void ImageEntityRenderer::doRender(RenderArgs* args) {
|
||||||
fromImage.setHeight(scaleY * _subImage.height());
|
fromImage.setHeight(scaleY * _subImage.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
float maxSize = glm::max(fromImage.width(), fromImage.height());
|
|
||||||
float x = _keepAspectRatio ? fromImage.width() / (2.0f * maxSize) : 0.5f;
|
|
||||||
float y = _keepAspectRatio ? fromImage.height() / (2.0f * maxSize) : 0.5f;
|
|
||||||
|
|
||||||
glm::vec2 texCoordBottomLeft((fromImage.x() + 0.5f) / imageWidth, (fromImage.y() + fromImage.height() - 0.5f) / imageHeight);
|
glm::vec2 texCoordBottomLeft((fromImage.x() + 0.5f) / imageWidth, (fromImage.y() + fromImage.height() - 0.5f) / imageHeight);
|
||||||
glm::vec2 texCoordTopRight((fromImage.x() + fromImage.width() - 0.5f) / imageWidth, (fromImage.y() + 0.5f) / imageHeight);
|
glm::vec2 texCoordTopRight((fromImage.x() + fromImage.width() - 0.5f) / imageWidth, (fromImage.y() + 0.5f) / imageHeight);
|
||||||
|
|
||||||
|
if (_keepAspectRatio) {
|
||||||
|
glm::vec3 scale = transform.getScale();
|
||||||
|
float targetAspectRatio = imageWidth / imageHeight;
|
||||||
|
float currentAspectRatio = scale.x / scale.y;
|
||||||
|
|
||||||
|
if (targetAspectRatio < currentAspectRatio) {
|
||||||
|
scale.x *= targetAspectRatio / currentAspectRatio;
|
||||||
|
} else {
|
||||||
|
scale.y /= targetAspectRatio / currentAspectRatio;
|
||||||
|
}
|
||||||
|
transform.setScale(scale);
|
||||||
|
}
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(
|
DependencyManager::get<GeometryCache>()->renderQuad(
|
||||||
*batch, glm::vec2(-x, -y), glm::vec2(x, y), texCoordBottomLeft, texCoordTopRight,
|
*batch, glm::vec2(-0.5f), glm::vec2(0.5f), texCoordBottomLeft, texCoordTopRight,
|
||||||
color, _geometryId
|
color, _geometryId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ EntityItemProperties ImageEntityItem::getProperties(const EntityPropertyFlags& d
|
||||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(alpha, getAlpha);
|
COPY_ENTITY_PROPERTY_TO_PROPERTIES(alpha, getAlpha);
|
||||||
withReadLock([&] {
|
withReadLock([&] {
|
||||||
_pulseProperties.getProperties(properties);
|
_pulseProperties.getProperties(properties);
|
||||||
|
properties.setNaturalDimensions(_naturalDimensions);
|
||||||
});
|
});
|
||||||
|
|
||||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(imageURL, getImageURL);
|
COPY_ENTITY_PROPERTY_TO_PROPERTIES(imageURL, getImageURL);
|
||||||
|
@ -217,4 +218,10 @@ PulsePropertyGroup ImageEntityItem::getPulseProperties() const {
|
||||||
return resultWithReadLock<PulsePropertyGroup>([&] {
|
return resultWithReadLock<PulsePropertyGroup>([&] {
|
||||||
return _pulseProperties;
|
return _pulseProperties;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImageEntityItem::setNaturalDimension(const glm::vec3& naturalDimensions) const {
|
||||||
|
withWriteLock([&] {
|
||||||
|
_naturalDimensions = naturalDimensions;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -63,6 +63,8 @@ public:
|
||||||
|
|
||||||
PulsePropertyGroup getPulseProperties() const;
|
PulsePropertyGroup getPulseProperties() const;
|
||||||
|
|
||||||
|
void setNaturalDimension(const glm::vec3& naturalDimensions) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
glm::u8vec3 _color;
|
glm::u8vec3 _color;
|
||||||
float _alpha;
|
float _alpha;
|
||||||
|
@ -72,6 +74,8 @@ protected:
|
||||||
bool _emissive { false };
|
bool _emissive { false };
|
||||||
bool _keepAspectRatio { true };
|
bool _keepAspectRatio { true };
|
||||||
QRect _subImage;
|
QRect _subImage;
|
||||||
|
|
||||||
|
mutable glm::vec3 _naturalDimensions;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ImageEntityItem_h
|
#endif // hifi_ImageEntityItem_h
|
||||||
|
|
Loading…
Reference in a new issue