From b1bbc8622420a040bc94038100fa7fd78391ad30 Mon Sep 17 00:00:00 2001 From: Janne Cederberg Date: Wed, 15 Jun 2016 09:05:46 +0300 Subject: [PATCH 1/2] Prevent empty values in URL config from stopping panorama rendering Should the user use URL configuration for their panorama and then specify an option/key but leave the value empty, previously this would stop the panorama from being displayed due to the generated JSON config from src/standalone/standalone.js being invalid. This commit omits creating an on-the-fly JSON string and instead uses a JavaScript object (which the generated JSON string was converted to anyway). The background of wanting to enable URL options with possibly empty values relates to using Pannellum with static site generators. Depending on the static site generator, specifying default values for undefined template variables can result in lots of template notation whereas outputting a value for a variable that isn't defined usuallly simply outputs an empty string. It would hence be desirable to treat the empty-string value of an option/key in URL config as if that option/key were not user-supplied at all and hence the Pannellum default value for that option/key be used. --- src/standalone/standalone.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/standalone/standalone.js b/src/standalone/standalone.js index a04b66b..f12f0af 100644 --- a/src/standalone/standalone.js +++ b/src/standalone/standalone.js @@ -14,35 +14,31 @@ function parseURLParameters() { return; } URL = URL[0].split('&'); - var json = '{'; + var configFromURL = {}; for (var i = 0; i < URL.length; i++) { var option = URL[i].split('=')[0]; var value = URL[i].split('=')[1]; - json += '"' + option + '":'; + if (value == '') + continue; // Skip options with empty values in URL config switch(option) { case 'hfov': case 'pitch': case 'yaw': case 'haov': case 'vaov': - case 'minHfov': case 'maxHfov': case 'minPitch': case 'maxPitch': case 'minYaw': case 'maxYaw': - case 'vOffset': case 'autoRotate': - json += value; + case 'minHfov': case 'maxHfov': case 'minPitch': case 'maxPitch': + case 'minYaw': case 'maxYaw': case 'vOffset': case 'autoRotate': + configFromURL[option] = Number(value); break; case 'autoLoad': case 'ignoreGPanoXMP': - json += JSON.parse(value); + configFromURL[option] = JSON.parse(value); break; case 'tour': console.log('The `tour` parameter is deprecated and will be removed. Use the `config` parameter instead.') case 'author': case 'title': case 'firstScene': case 'fallback': case 'preview': case 'panorama': case 'config': - json += '"' + decodeURIComponent(value) + '"'; + configFromURL[option] = decodeURIComponent(value); break; default: anError('An invalid configuration parameter was specified: ' + option); } - if (i < URL.length - 1) { - json += ','; - } } - json += '}'; - var configFromURL = JSON.parse(json); var request; From 8daf61dda93793da0133f8f9d5b48ff5475fe504 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 17 Jun 2016 19:05:27 -0400 Subject: [PATCH 2/2] Fix rounding bug that caused rendering artifacts. --- src/js/libpannellum.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/js/libpannellum.js b/src/js/libpannellum.js index 293ab16..2669a20 100644 --- a/src/js/libpannellum.js +++ b/src/js/libpannellum.js @@ -464,7 +464,7 @@ function Renderer(container, image, imageType, dynamic) { z = Math.cos(horizonRoll) * Math.cos(horizonPitch) * Math.sin(pitch) + Math.cos(pitch) * (-Math.cos(yaw) * Math.sin(horizonPitch) + Math.cos(horizonPitch) * Math.sin(horizonRoll) * Math.sin(yaw)); - pitch = Math.asin(z); + pitch = Math.asin(Math.max(Math.min(z, 1), -1)); yaw = Math.atan2(y, x); // Calculate roll @@ -474,9 +474,9 @@ function Renderer(container, image, imageType, dynamic) { Math.cos(orig_pitch) * (Math.cos(horizonPitch) * Math.sin(horizonRoll) * Math.cos(orig_yaw) + Math.sin(orig_yaw) * Math.sin(horizonPitch))], w = [-Math.cos(pitch) * Math.sin(yaw), Math.cos(pitch) * Math.cos(yaw)]; - var roll_adj = Math.acos((v[0]*w[0] + v[1]*w[1]) / + var roll_adj = Math.acos(Math.max(Math.min((v[0]*w[0] + v[1]*w[1]) / (Math.sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]) * - Math.sqrt(w[0]*w[0]+w[1]*w[1]))); + Math.sqrt(w[0]*w[0]+w[1]*w[1])), 1), -1)); if (v[2] < 0) roll_adj = 2 * Math.PI - roll_adj; roll += roll_adj;