Explorar el Código

Improve scene fading performance by using canvas instead of Image.

pull/880/head
Nico Höllerich hace 4 años
padre
commit
fdf02d9803
Se han modificado 2 ficheros con 19 adiciones y 6 borrados
  1. +5
    -1
      src/js/libpannellum.js
  2. +14
    -5
      src/js/pannellum.js

+ 5
- 1
src/js/libpannellum.js Ver fichero

@@ -899,7 +899,11 @@ function Renderer(container) {
}

if (params.returnImage !== undefined) {
return canvas.toDataURL('image/png');
var canv = document.createElement('canvas');
canv.width = canvas.width;
canv.height = canvas.height;
canv.getContext('2d').drawImage(canvas, 0, 0);
return canv;
}
};


+ 14
- 5
src/js/pannellum.js Ver fichero

@@ -2424,15 +2424,24 @@ function loadScene(sceneId, targetPitch, targetYaw, targetHfov, fadeDone) {
if (config.sceneFadeDuration && !fadeDone) {
var data = renderer.render(config.pitch * Math.PI / 180, config.yaw * Math.PI / 180, config.hfov * Math.PI / 180, {returnImage: true});
if (data !== undefined) {
fadeImg = new Image();
if (data instanceof HTMLCanvasElement)
fadeImg = data;
else
fadeImg = new Image();

fadeImg.className = 'pnlm-fade-img';
fadeImg.style.transition = 'opacity ' + (config.sceneFadeDuration / 1000) + 's';
fadeImg.style.width = '100%';
fadeImg.style.height = '100%';
fadeImg.onload = function() {
setTimeout(() => loadScene(sceneId, targetPitch, targetYaw, targetHfov, true), 100); // prevents black flickering before fading
};
fadeImg.src = data;

if (data instanceof HTMLCanvasElement)
setTimeout(() => loadScene(sceneId, targetPitch, targetYaw, targetHfov, true), 100);
else {
fadeImg.onload = function () {
setTimeout(() => loadScene(sceneId, targetPitch, targetYaw, targetHfov, true), 100); // prevents black flickering before fading
};
fadeImg.src = data;
}
renderContainer.appendChild(fadeImg);
renderer.fadeImg = fadeImg;
return;


Cargando…
Cancelar
Guardar