Merge pull request #11370 from samcake/blue-bis

Fixing the web surface of the tablet
This commit is contained in:
Sam Gateau 2017-09-15 15:36:55 -07:00 committed by GitHub
commit 512e9432ed
16 changed files with 74 additions and 22 deletions

View file

@ -256,15 +256,46 @@ bool Base3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3
void Base3DOverlay::locationChanged(bool tellPhysics) {
SpatiallyNestable::locationChanged(tellPhysics);
auto itemID = getRenderItemID();
if (render::Item::isValidID(itemID)) {
render::ScenePointer scene = qApp->getMain3DScene();
render::Transaction transaction;
transaction.updateItem(itemID);
scene->enqueueTransaction(transaction);
}
// Force the actual update of the render transform through the notify call
notifyRenderTransformChange();
}
void Base3DOverlay::parentDeleted() {
qApp->getOverlays().deleteOverlay(getOverlayID());
}
void Base3DOverlay::update(float duration) {
// In Base3DOverlay, if its location or bound changed, the renderTrasnformDirty flag is true.
// then the correct transform used for rendering is computed in the update transaction and assigned.
// TODO: Fix the value to be computed in main thread now and passed by value to the render item.
// This is the simplest fix for the web overlay of the tablet for now
if (_renderTransformDirty) {
_renderTransformDirty = false;
auto itemID = getRenderItemID();
if (render::Item::isValidID(itemID)) {
render::ScenePointer scene = qApp->getMain3DScene();
render::Transaction transaction;
transaction.updateItem<Overlay>(itemID, [](Overlay& data) {
auto overlay3D = dynamic_cast<Base3DOverlay*>(&data);
if (overlay3D) {
auto latestTransform = overlay3D->evalRenderTransform();
overlay3D->setRenderTransform(latestTransform);
}
});
scene->enqueueTransaction(transaction);
}
}
}
void Base3DOverlay::notifyRenderTransformChange() const {
_renderTransformDirty = true;
}
Transform Base3DOverlay::evalRenderTransform() const {
return getTransform();
}
void Base3DOverlay::setRenderTransform(const Transform& transform) {
_renderTransform = transform;
}

View file

@ -52,6 +52,10 @@ public:
virtual AABox getBounds() const override = 0;
void update(float deltatime) override;
void notifyRenderTransformChange() const;
void setProperties(const QVariantMap& properties) override;
QVariant getProperty(const QString& property) override;
@ -67,12 +71,18 @@ protected:
virtual void locationChanged(bool tellPhysics = true) override;
virtual void parentDeleted() override;
mutable Transform _renderTransform;
virtual Transform evalRenderTransform() const;
virtual void setRenderTransform(const Transform& transform);
const Transform& getRenderTransform() const { return _renderTransform; }
float _lineWidth;
bool _isSolid;
bool _isDashedLine;
bool _ignoreRayIntersection;
bool _drawInFront;
bool _isGrabbable { false };
mutable bool _renderTransformDirty{ true };
QString _name;
};

View file

@ -85,6 +85,7 @@ void Circle3DOverlay::render(RenderArgs* args) {
}
// FIXME: THe line width of _lineWidth is not supported anymore, we ll need a workaround
// FIXME Start using the _renderTransform instead of calling for Transform from here, do the custom things needed in evalRenderTransform()
auto transform = getTransform();
transform.postScale(glm::vec3(getDimensions(), 1.0f));

View file

@ -54,6 +54,7 @@ void Cube3DOverlay::render(RenderArgs* args) {
glm::vec4 cubeColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
// TODO: handle registration point??
// FIXME Start using the _renderTransform instead of calling for Transform from here, do the custom things needed in evalRenderTransform()
glm::vec3 position = getPosition();
glm::vec3 dimensions = getDimensions();
glm::quat rotation = getRotation();

View file

@ -79,6 +79,7 @@ void Grid3DOverlay::render(RenderArgs* args) {
position += glm::vec3(cameraPosition.x, 0.0f, cameraPosition.z);
}
// FIXME Start using the _renderTransform instead of calling for Transform from here, do the custom things needed in evalRenderTransform()
Transform transform;
transform.setRotation(getRotation());
transform.setScale(glm::vec3(getDimensions(), 1.0f));

View file

@ -117,6 +117,7 @@ void Image3DOverlay::render(RenderArgs* args) {
xColor color = getColor();
float alpha = getAlpha();
// FIXME Start using the _renderTransform instead of calling for Transform from here, do the custom things needed in evalRenderTransform()
Transform transform = getTransform();
bool transformChanged = applyTransformTo(transform, true);
// If the transform is not modified, setting the transform to

View file

@ -132,6 +132,7 @@ void Line3DOverlay::render(RenderArgs* args) {
glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
auto batch = args->_batch;
if (batch) {
// FIXME Start using the _renderTransform instead of calling for Transform and start and end from here, do the custom things needed in evalRenderTransform()
batch->setModelTransform(Transform());
glm::vec3 start = getStart();
glm::vec3 end = getEnd();

View file

@ -281,6 +281,7 @@ ModelOverlay* ModelOverlay::createClone() const {
void ModelOverlay::locationChanged(bool tellPhysics) {
Base3DOverlay::locationChanged(tellPhysics);
// FIXME Start using the _renderTransform instead of calling for Transform and Dimensions from here, do the custom things needed in evalRenderTransform()
if (_model && _model->isActive()) {
_model->setRotation(getRotation());
_model->setTranslation(getPosition());

View file

@ -66,3 +66,11 @@ bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::ve
// FIXME - face and surfaceNormal not being returned
return findRayRectangleIntersection(origin, direction, getRotation(), getPosition(), getDimensions(), distance);
}
Transform Planar3DOverlay::evalRenderTransform() const {
auto transform = getTransform();
if (glm::length2(getDimensions()) != 1.0f) {
transform.postScale(vec3(getDimensions(), 1.0f));
}
return transform;
}

View file

@ -32,7 +32,9 @@ public:
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal) override;
Transform evalRenderTransform() const override;
protected:
glm::vec2 _dimensions;
};

View file

@ -66,6 +66,7 @@ void Rectangle3DOverlay::render(RenderArgs* args) {
auto batch = args->_batch;
if (batch) {
// FIXME Start using the _renderTransform instead of calling for Transform and Dimensions from here, do the custom things needed in evalRenderTransform()
Transform transform;
transform.setTranslation(position);
transform.setRotation(rotation);

View file

@ -33,6 +33,7 @@ void Shape3DOverlay::render(RenderArgs* args) {
const float MAX_COLOR = 255.0f;
glm::vec4 cubeColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
// FIXME Start using the _renderTransform instead of calling for Transform and Dimensions from here, do the custom things needed in evalRenderTransform()
// TODO: handle registration point??
glm::vec3 position = getPosition();
glm::vec3 dimensions = getDimensions();

View file

@ -39,6 +39,7 @@ void Sphere3DOverlay::render(RenderArgs* args) {
auto batch = args->_batch;
if (batch) {
// FIXME Start using the _renderTransform instead of calling for Transform and Dimensions from here, do the custom things needed in evalRenderTransform()
Transform transform = getTransform();
transform.postScale(getDimensions() * SPHERE_OVERLAY_SCALE);
batch->setModelTransform(transform);

View file

@ -96,6 +96,7 @@ void Text3DOverlay::render(RenderArgs* args) {
Q_ASSERT(args->_batch);
auto& batch = *args->_batch;
// FIXME Start using the _renderTransform instead of calling for Transform and Dimensions from here, do the custom things needed in evalRenderTransform()
Transform transform = getTransform();
applyTransformTo(transform, true);
setTransform(transform);

View file

@ -184,6 +184,7 @@ void Web3DOverlay::update(float deltatime) {
// update globalPosition
_webSurface->getSurfaceContext()->setContextProperty("globalPosition", vec3toVariant(getPosition()));
}
Parent::update(deltatime);
}
QString Web3DOverlay::pickURL() {
@ -306,19 +307,6 @@ void Web3DOverlay::render(RenderArgs* args) {
vec2 halfSize = getSize() / 2.0f;
vec4 color(toGlm(getColor()), getAlpha());
Transform transform = getTransform();
// FIXME: applyTransformTo causes tablet overlay to detach from tablet entity.
// Perhaps rather than deleting the following code it should be run only if isFacingAvatar() is true?
/*
applyTransformTo(transform, true);
setTransform(transform);
*/
if (glm::length2(getDimensions()) != 1.0f) {
transform.postScale(vec3(getDimensions(), 1.0f));
}
if (!_texture) {
_texture = gpu::Texture::createExternal(OffscreenQmlSurface::getDiscardLambda());
_texture->setSource(__FUNCTION__);
@ -332,7 +320,8 @@ void Web3DOverlay::render(RenderArgs* args) {
Q_ASSERT(args->_batch);
gpu::Batch& batch = *args->_batch;
batch.setResourceTexture(0, _texture);
batch.setModelTransform(transform);
batch.setModelTransform(getRenderTransform());
auto geometryCache = DependencyManager::get<GeometryCache>();
if (color.a < OPAQUE_ALPHA_THRESHOLD) {
geometryCache->bindWebBrowserProgram(batch, true);

View file

@ -19,8 +19,10 @@ class OffscreenQmlSurface;
class Web3DOverlay : public Billboard3DOverlay {
Q_OBJECT
using Parent = Billboard3DOverlay;
public:
static const QString QML;
static QString const TYPE;
virtual QString getType() const override { return TYPE; }