Преглед изворни кода

external loader for tiles

multiRes.loader: function(node, image) => Promise<Image|ImageData>
pull/880/head
NiHoel пре 6 година
родитељ
комит
53dccc5408
2 измењених фајлова са 23 додато и 6 уклоњено
  1. +22
    -6
      src/js/libpannellum.js
  2. +1
    -0
      src/js/pannellum.js

+ 22
- 6
src/js/libpannellum.js Прегледај датотеку

@@ -845,7 +845,12 @@ function Renderer(container) {
this.level = level;
this.x = x;
this.y = y;
this.path = path.replace('%s',side).replace('%l',level).replace('%x',x).replace('%y',y);
if (!path) {
this.path = side + '_' + level + '_' + x + '_' + y;
} else {
this.path = path.replace('%s', side).replace('%l', level).replace('%x', x).replace('%y', y);
}
this.uri = encodeURI(this.path + '.' + image.extension);
}

/**
@@ -1146,10 +1151,21 @@ function Renderer(container) {
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) {
TextureImageLoader.prototype.loadTexture = function(node, src, texture, callback) {
this.texture = texture;
this.callback = callback;
this.image.src = src;
if (src instanceof Function) {
src(node, this.image, this.texture).then(img => {
if (!image)
this.callback(this.texture, false);
else if (img != this.image) {
processLoadedTexture(img, this.texture);
this.callback(img, true);
}
})
} else {
this.image.src = src;
}
};

function PendingTextureRequest(node, src, texture, callback) {
@@ -1162,7 +1178,7 @@ function Renderer(container) {
function releaseTextureImageLoader(til) {
if (pendingTextureRequests.length) {
var req = pendingTextureRequests.shift();
til.loadTexture(req.src, req.texture, req.callback);
til.loadTexture(req.node, req.src, req.texture, req.callback);
} else
textureImageCache[cacheTop++] = til;
}
@@ -1174,7 +1190,7 @@ function Renderer(container) {
crossOrigin = _crossOrigin;
var texture = gl.createTexture();
if (cacheTop)
textureImageCache[--cacheTop].loadTexture(src, texture, callback);
textureImageCache[--cacheTop].loadTexture(node, src, texture, callback);
else
pendingTextureRequests.push(new PendingTextureRequest(node, src, texture, callback));
return texture;
@@ -1187,7 +1203,7 @@ function Renderer(container) {
* @param {MultiresNode} node - Input node.
*/
function processNextTile(node) {
loadTexture(node, encodeURI(node.path + '.' + image.extension), function(texture, loaded) {
loadTexture(node, image.loader || node.uri, function (texture, loaded) {
node.texture = texture;
node.textureLoaded = loaded ? 2 : 1;
}, globalParams.crossOrigin);


+ 1
- 0
src/js/pannellum.js Прегледај датотеку

@@ -322,6 +322,7 @@ function init() {
infoDisplay.load.lbar.style.display = 'none';
} else if (config.type == 'multires') {
var c = JSON.parse(JSON.stringify(config.multiRes)); // Deep copy
c.loader = config.multiRes.loader;
// Avoid "undefined" in path, check (optional) multiRes.basePath, too
// Use only multiRes.basePath if it's an absolute URL
if (config.basePath && config.multiRes.basePath &&


Loading…
Откажи
Сачувај