Skip to content

Commit

Permalink
avoid loading invisible files for partial panos of any image type (#562)
Browse files Browse the repository at this point in the history
Avoid loading invisible files for partial panos of any image type.
  • Loading branch information
DDvO authored and mpetroff committed Mar 4, 2018
1 parent 9ba4c93 commit 034d27a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/js/libpannellum.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ function Renderer(container) {
// Draw image width duplicated edge pixels on canvas
faceContext.putImageData(imgData, 0, 0);

incLoaded();
};
var incLoaded = function() {
if (this.width != 0) // support partial fallback/cubemap image
fallbackImgSize = this.width;
if (loaded == 5 && this.width == 0) // support partial fallback/cubemap image
this.width = fallbackImgSize;
loaded++;
if (loaded == 6) {
fallbackImgSize = this.width;
Expand All @@ -218,6 +225,7 @@ function Renderer(container) {
faceImg.crossOrigin = globalParams.crossOrigin ? globalParams.crossOrigin : 'anonymous';
faceImg.side = s;
faceImg.onload = onLoad;
faceImg.onerror = incLoaded; // ignore missing face file to support partial fallback/cubemap image
if (imageType == 'multires') {
faceImg.src = encodeURI(path.replace('%s', sides[s]) + '.' + image.extension);
} else {
Expand Down Expand Up @@ -542,9 +550,11 @@ function Renderer(container) {
// Apply face transforms
var faces = Object.keys(transforms);
for (i = 0; i < 6; i++) {
var face = world.querySelector('.pnlm-' + faces[i] + 'face').style;
face.webkitTransform = transform + transforms[faces[i]];
face.transform = transform + transforms[faces[i]];
var face = world.querySelector('.pnlm-' + faces[i] + 'face');
if (!face)
continue; // ignore missing face to support partial fallback/cubemap image
face.style.webkitTransform = transform + transforms[faces[i]];
face.style.transform = transform + transforms[faces[i]];
}
return;
}
Expand Down Expand Up @@ -1024,11 +1034,14 @@ function Renderer(container) {
this.texture = this.callback = null;
this.image = new Image();
this.image.crossOrigin = crossOrigin ? crossOrigin : 'anonymous';
this.image.addEventListener('load', function() {
processLoadedTexture(self.image, self.texture);
var loadFn = (function() {
if (self.image.width > 0 && self.image.height > 0) // ignore missing tile to supporting partial image
processLoadedTexture(self.image, self.texture);
self.callback(self.texture);
releaseTextureImageLoader(self);
});
this.image.addEventListener('load', loadFn);
this.image.addEventListener('error', loadFn); // ignore missing tile file to support partial image, otherwise retry loop causes high CPU load
};

TextureImageLoader.prototype.loadTexture = function(src, texture, callback) {
Expand Down

0 comments on commit 034d27a

Please sign in to comment.