diff --git a/examples/sit.js b/examples/sit.js index c157d4854d..0f4b199855 100644 --- a/examples/sit.js +++ b/examples/sit.js @@ -255,13 +255,24 @@ function update(deltaTime){ } frame++; } + + var locationChanged = false; + if (location.hostname != oldHost) { + print("Changed domain"); + for (model in models) { + removeIndicators(models[model]); + } + oldHost = location.hostname; + locationChanged = true; + } - if (MyAvatar.position.x != avatarOldPosition.x && - MyAvatar.position.y != avatarOldPosition.y && - MyAvatar.position.z != avatarOldPosition.z) { + if (MyAvatar.position.x != avatarOldPosition.x || + MyAvatar.position.y != avatarOldPosition.y || + MyAvatar.position.z != avatarOldPosition.z || + locationChanged) { avatarOldPosition = MyAvatar.position; - var SEARCH_RADIUS = 10; + var SEARCH_RADIUS = 50; var foundModels = Models.findModels(MyAvatar.position, SEARCH_RADIUS); // Let's remove indicator that got out of radius for (model in models) { @@ -274,7 +285,10 @@ function update(deltaTime){ for (var i = 0; i < foundModels.length; ++i) { var model = foundModels[i]; if (typeof(models[model.id]) == "undefined") { - addIndicators(model); + model.properties = Models.getModelProperties(model); + if (Vec3.distance(model.properties.position, MyAvatar.position) < SEARCH_RADIUS) { + addIndicators(model); + } } } @@ -283,9 +297,9 @@ function update(deltaTime){ } } } +var oldHost = location.hostname; function addIndicators(modelID) { - modelID.properties = Models.getModelProperties(modelID); if (modelID.properties.sittingPoints.length > 0) { for (var i = 0; i < modelID.properties.sittingPoints.length; ++i) { modelID.properties.sittingPoints[i].indicator = new SeatIndicator(modelID.properties, i); diff --git a/interface/src/ui/overlays/BillboardOverlay.cpp b/interface/src/ui/overlays/BillboardOverlay.cpp index e7d5cef3be..7d85d54fef 100644 --- a/interface/src/ui/overlays/BillboardOverlay.cpp +++ b/interface/src/ui/overlays/BillboardOverlay.cpp @@ -17,10 +17,11 @@ BillboardOverlay::BillboardOverlay() : _fromImage(-1,-1,-1,-1), _scale(1.0f), _isFacingAvatar(true) { + _isLoaded = false; } void BillboardOverlay::render() { - if (!_visible) { + if (!_visible || !_isLoaded) { return; } @@ -85,16 +86,7 @@ void BillboardOverlay::render() { ((float)_fromImage.y() + (float)_fromImage.height()) / (float)_size.height()); glVertex2f(-x, y); } glEnd(); - } else { - glColor4f(0.5f, 0.5f, 0.5f, 1.0f); - glBegin(GL_QUADS); { - glVertex2f(-1.0f, -1.0f); - glVertex2f(1.0f, -1.0f); - glVertex2f(1.0f, 1.0f); - glVertex2f(-1.0f, 1.0f); - } glEnd(); } - } glPopMatrix(); glDisable(GL_TEXTURE_2D); @@ -167,6 +159,7 @@ void BillboardOverlay::setProperties(const QScriptValue &properties) { } void BillboardOverlay::setBillboardURL(const QUrl url) { + _isLoaded = false; QNetworkReply* reply = NetworkAccessManager::getInstance().get(QNetworkRequest(url)); connect(reply, &QNetworkReply::finished, this, &BillboardOverlay::replyFinished); } @@ -175,4 +168,5 @@ void BillboardOverlay::replyFinished() { // replace our byte array with the downloaded data QNetworkReply* reply = static_cast(sender()); _billboard = reply->readAll(); + _isLoaded = true; } diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index aeea781eb6..7104b3aced 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -24,6 +24,7 @@ ImageOverlay::ImageOverlay() : _textureBound(false), _wantClipFromImage(false) { + _isLoaded = false; } ImageOverlay::~ImageOverlay() { @@ -35,6 +36,7 @@ ImageOverlay::~ImageOverlay() { // TODO: handle setting image multiple times, how do we manage releasing the bound texture? void ImageOverlay::setImageURL(const QUrl& url) { + _isLoaded = false; NetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); QNetworkReply* reply = networkAccessManager.get(QNetworkRequest(url)); connect(reply, &QNetworkReply::finished, this, &ImageOverlay::replyFinished); @@ -47,10 +49,11 @@ void ImageOverlay::replyFinished() { QByteArray rawData = reply->readAll(); _textureImage.loadFromData(rawData); _renderImage = true; + _isLoaded = true; } void ImageOverlay::render() { - if (!_visible) { + if (!_visible || !_isLoaded) { return; // do nothing if we're not visible } if (_renderImage && !_textureBound) { diff --git a/interface/src/ui/overlays/ModelOverlay.cpp b/interface/src/ui/overlays/ModelOverlay.cpp index 57f098aee3..b1d55de12a 100644 --- a/interface/src/ui/overlays/ModelOverlay.cpp +++ b/interface/src/ui/overlays/ModelOverlay.cpp @@ -15,8 +15,10 @@ ModelOverlay::ModelOverlay() : _model(), _scale(1.0f), - _updateModel(false) { + _updateModel(false) +{ _model.init(); + _isLoaded = false; } void ModelOverlay::update(float deltatime) { @@ -32,6 +34,7 @@ void ModelOverlay::update(float deltatime) { } else { _model.simulate(deltatime); } + _isLoaded = _model.isActive(); } void ModelOverlay::render() { @@ -90,6 +93,7 @@ void ModelOverlay::setProperties(const QScriptValue &properties) { if (urlValue.isValid()) { _url = urlValue.toVariant().toString(); _updateModel = true; + _isLoaded = false; } QScriptValue scaleValue = properties.property("scale"); diff --git a/interface/src/ui/overlays/Overlay.cpp b/interface/src/ui/overlays/Overlay.cpp index bc7096c471..9d492c6e50 100644 --- a/interface/src/ui/overlays/Overlay.cpp +++ b/interface/src/ui/overlays/Overlay.cpp @@ -21,6 +21,7 @@ Overlay::Overlay() : _parent(NULL), + _isLoaded(true), _alpha(DEFAULT_ALPHA), _color(DEFAULT_OVERLAY_COLOR), _visible(true), diff --git a/interface/src/ui/overlays/Overlay.h b/interface/src/ui/overlays/Overlay.h index f8d6400bf6..c5329688ff 100644 --- a/interface/src/ui/overlays/Overlay.h +++ b/interface/src/ui/overlays/Overlay.h @@ -40,6 +40,7 @@ public: virtual void render() = 0; // getters + bool isLoaded() { return _isLoaded; } bool getVisible() const { return _visible; } const xColor& getColor() const { return _color; } float getAlpha() const { return _alpha; } @@ -55,6 +56,7 @@ public: protected: QGLWidget* _parent; + bool _isLoaded; float _alpha; xColor _color; bool _visible; // should the overlay be drawn at all diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 581947c074..5d16bd78e5 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -227,11 +227,23 @@ unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) { i.previous(); unsigned int thisID = i.key(); Overlay2D* thisOverlay = static_cast(i.value()); - if (thisOverlay->getVisible() && thisOverlay->getBounds().contains(point.x, point.y, false)) { + if (thisOverlay->getVisible() && thisOverlay->isLoaded() && thisOverlay->getBounds().contains(point.x, point.y, false)) { return thisID; } } return 0; // not found } +bool Overlays::isLoaded(unsigned int id) { + QReadLocker lock(&_lock); + Overlay* overlay = _overlays2D.value(id); + if (!overlay) { + _overlays3D.value(id); + } + if (!overlay) { + return false; // not found + } + + return overlay->isLoaded(); +} diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index 2fbdb993f4..8bd8224f82 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -38,6 +38,9 @@ public slots: /// returns the top most overlay at the screen point, or 0 if not overlay at that point unsigned int getOverlayAtPoint(const glm::vec2& point); + + /// returns whether the overlay's assets are loaded or not + bool isLoaded(unsigned int id); private: QMap _overlays2D;