mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 12:24:29 +02:00
commit
fdead9802e
8 changed files with 52 additions and 19 deletions
|
@ -255,13 +255,24 @@ function update(deltaTime){
|
||||||
}
|
}
|
||||||
frame++;
|
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 &&
|
if (MyAvatar.position.x != avatarOldPosition.x ||
|
||||||
MyAvatar.position.y != avatarOldPosition.y &&
|
MyAvatar.position.y != avatarOldPosition.y ||
|
||||||
MyAvatar.position.z != avatarOldPosition.z) {
|
MyAvatar.position.z != avatarOldPosition.z ||
|
||||||
|
locationChanged) {
|
||||||
avatarOldPosition = MyAvatar.position;
|
avatarOldPosition = MyAvatar.position;
|
||||||
|
|
||||||
var SEARCH_RADIUS = 10;
|
var SEARCH_RADIUS = 50;
|
||||||
var foundModels = Models.findModels(MyAvatar.position, SEARCH_RADIUS);
|
var foundModels = Models.findModels(MyAvatar.position, SEARCH_RADIUS);
|
||||||
// Let's remove indicator that got out of radius
|
// Let's remove indicator that got out of radius
|
||||||
for (model in models) {
|
for (model in models) {
|
||||||
|
@ -274,7 +285,10 @@ function update(deltaTime){
|
||||||
for (var i = 0; i < foundModels.length; ++i) {
|
for (var i = 0; i < foundModels.length; ++i) {
|
||||||
var model = foundModels[i];
|
var model = foundModels[i];
|
||||||
if (typeof(models[model.id]) == "undefined") {
|
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) {
|
function addIndicators(modelID) {
|
||||||
modelID.properties = Models.getModelProperties(modelID);
|
|
||||||
if (modelID.properties.sittingPoints.length > 0) {
|
if (modelID.properties.sittingPoints.length > 0) {
|
||||||
for (var i = 0; i < modelID.properties.sittingPoints.length; ++i) {
|
for (var i = 0; i < modelID.properties.sittingPoints.length; ++i) {
|
||||||
modelID.properties.sittingPoints[i].indicator = new SeatIndicator(modelID.properties, i);
|
modelID.properties.sittingPoints[i].indicator = new SeatIndicator(modelID.properties, i);
|
||||||
|
|
|
@ -17,10 +17,11 @@ BillboardOverlay::BillboardOverlay()
|
||||||
: _fromImage(-1,-1,-1,-1),
|
: _fromImage(-1,-1,-1,-1),
|
||||||
_scale(1.0f),
|
_scale(1.0f),
|
||||||
_isFacingAvatar(true) {
|
_isFacingAvatar(true) {
|
||||||
|
_isLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BillboardOverlay::render() {
|
void BillboardOverlay::render() {
|
||||||
if (!_visible) {
|
if (!_visible || !_isLoaded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,16 +86,7 @@ void BillboardOverlay::render() {
|
||||||
((float)_fromImage.y() + (float)_fromImage.height()) / (float)_size.height());
|
((float)_fromImage.y() + (float)_fromImage.height()) / (float)_size.height());
|
||||||
glVertex2f(-x, y);
|
glVertex2f(-x, y);
|
||||||
} glEnd();
|
} 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();
|
} glPopMatrix();
|
||||||
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
@ -167,6 +159,7 @@ void BillboardOverlay::setProperties(const QScriptValue &properties) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BillboardOverlay::setBillboardURL(const QUrl url) {
|
void BillboardOverlay::setBillboardURL(const QUrl url) {
|
||||||
|
_isLoaded = false;
|
||||||
QNetworkReply* reply = NetworkAccessManager::getInstance().get(QNetworkRequest(url));
|
QNetworkReply* reply = NetworkAccessManager::getInstance().get(QNetworkRequest(url));
|
||||||
connect(reply, &QNetworkReply::finished, this, &BillboardOverlay::replyFinished);
|
connect(reply, &QNetworkReply::finished, this, &BillboardOverlay::replyFinished);
|
||||||
}
|
}
|
||||||
|
@ -175,4 +168,5 @@ void BillboardOverlay::replyFinished() {
|
||||||
// replace our byte array with the downloaded data
|
// replace our byte array with the downloaded data
|
||||||
QNetworkReply* reply = static_cast<QNetworkReply*>(sender());
|
QNetworkReply* reply = static_cast<QNetworkReply*>(sender());
|
||||||
_billboard = reply->readAll();
|
_billboard = reply->readAll();
|
||||||
|
_isLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ ImageOverlay::ImageOverlay() :
|
||||||
_textureBound(false),
|
_textureBound(false),
|
||||||
_wantClipFromImage(false)
|
_wantClipFromImage(false)
|
||||||
{
|
{
|
||||||
|
_isLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageOverlay::~ImageOverlay() {
|
ImageOverlay::~ImageOverlay() {
|
||||||
|
@ -35,6 +36,7 @@ ImageOverlay::~ImageOverlay() {
|
||||||
|
|
||||||
// TODO: handle setting image multiple times, how do we manage releasing the bound texture?
|
// TODO: handle setting image multiple times, how do we manage releasing the bound texture?
|
||||||
void ImageOverlay::setImageURL(const QUrl& url) {
|
void ImageOverlay::setImageURL(const QUrl& url) {
|
||||||
|
_isLoaded = false;
|
||||||
NetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
NetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||||
QNetworkReply* reply = networkAccessManager.get(QNetworkRequest(url));
|
QNetworkReply* reply = networkAccessManager.get(QNetworkRequest(url));
|
||||||
connect(reply, &QNetworkReply::finished, this, &ImageOverlay::replyFinished);
|
connect(reply, &QNetworkReply::finished, this, &ImageOverlay::replyFinished);
|
||||||
|
@ -47,10 +49,11 @@ void ImageOverlay::replyFinished() {
|
||||||
QByteArray rawData = reply->readAll();
|
QByteArray rawData = reply->readAll();
|
||||||
_textureImage.loadFromData(rawData);
|
_textureImage.loadFromData(rawData);
|
||||||
_renderImage = true;
|
_renderImage = true;
|
||||||
|
_isLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageOverlay::render() {
|
void ImageOverlay::render() {
|
||||||
if (!_visible) {
|
if (!_visible || !_isLoaded) {
|
||||||
return; // do nothing if we're not visible
|
return; // do nothing if we're not visible
|
||||||
}
|
}
|
||||||
if (_renderImage && !_textureBound) {
|
if (_renderImage && !_textureBound) {
|
||||||
|
|
|
@ -15,8 +15,10 @@
|
||||||
ModelOverlay::ModelOverlay()
|
ModelOverlay::ModelOverlay()
|
||||||
: _model(),
|
: _model(),
|
||||||
_scale(1.0f),
|
_scale(1.0f),
|
||||||
_updateModel(false) {
|
_updateModel(false)
|
||||||
|
{
|
||||||
_model.init();
|
_model.init();
|
||||||
|
_isLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelOverlay::update(float deltatime) {
|
void ModelOverlay::update(float deltatime) {
|
||||||
|
@ -32,6 +34,7 @@ void ModelOverlay::update(float deltatime) {
|
||||||
} else {
|
} else {
|
||||||
_model.simulate(deltatime);
|
_model.simulate(deltatime);
|
||||||
}
|
}
|
||||||
|
_isLoaded = _model.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelOverlay::render() {
|
void ModelOverlay::render() {
|
||||||
|
@ -90,6 +93,7 @@ void ModelOverlay::setProperties(const QScriptValue &properties) {
|
||||||
if (urlValue.isValid()) {
|
if (urlValue.isValid()) {
|
||||||
_url = urlValue.toVariant().toString();
|
_url = urlValue.toVariant().toString();
|
||||||
_updateModel = true;
|
_updateModel = true;
|
||||||
|
_isLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue scaleValue = properties.property("scale");
|
QScriptValue scaleValue = properties.property("scale");
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
Overlay::Overlay() :
|
Overlay::Overlay() :
|
||||||
_parent(NULL),
|
_parent(NULL),
|
||||||
|
_isLoaded(true),
|
||||||
_alpha(DEFAULT_ALPHA),
|
_alpha(DEFAULT_ALPHA),
|
||||||
_color(DEFAULT_OVERLAY_COLOR),
|
_color(DEFAULT_OVERLAY_COLOR),
|
||||||
_visible(true),
|
_visible(true),
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
virtual void render() = 0;
|
virtual void render() = 0;
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
|
bool isLoaded() { return _isLoaded; }
|
||||||
bool getVisible() const { return _visible; }
|
bool getVisible() const { return _visible; }
|
||||||
const xColor& getColor() const { return _color; }
|
const xColor& getColor() const { return _color; }
|
||||||
float getAlpha() const { return _alpha; }
|
float getAlpha() const { return _alpha; }
|
||||||
|
@ -55,6 +56,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QGLWidget* _parent;
|
QGLWidget* _parent;
|
||||||
|
bool _isLoaded;
|
||||||
float _alpha;
|
float _alpha;
|
||||||
xColor _color;
|
xColor _color;
|
||||||
bool _visible; // should the overlay be drawn at all
|
bool _visible; // should the overlay be drawn at all
|
||||||
|
|
|
@ -227,11 +227,23 @@ unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) {
|
||||||
i.previous();
|
i.previous();
|
||||||
unsigned int thisID = i.key();
|
unsigned int thisID = i.key();
|
||||||
Overlay2D* thisOverlay = static_cast<Overlay2D*>(i.value());
|
Overlay2D* thisOverlay = static_cast<Overlay2D*>(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 thisID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0; // not found
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,9 @@ public slots:
|
||||||
|
|
||||||
/// returns the top most overlay at the screen point, or 0 if not overlay at that point
|
/// returns the top most overlay at the screen point, or 0 if not overlay at that point
|
||||||
unsigned int getOverlayAtPoint(const glm::vec2& point);
|
unsigned int getOverlayAtPoint(const glm::vec2& point);
|
||||||
|
|
||||||
|
/// returns whether the overlay's assets are loaded or not
|
||||||
|
bool isLoaded(unsigned int id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<unsigned int, Overlay*> _overlays2D;
|
QMap<unsigned int, Overlay*> _overlays2D;
|
||||||
|
|
Loading…
Reference in a new issue