1 line
21 KiB
JavaScript
1 line
21 KiB
JavaScript
|
"use strict";window.libpannellum=function(e,t,r){function a(a){var l,d,c,f,g,_,m,v,E,x,p,T,R,w,M,A,b=t.createElement("canvas");function I(e,t){return 1==e.level&&1!=t.level?-1:1==t.level&&1!=e.level?1:t.timestamp-e.timestamp}function C(e,t){return e.level!=t.level?e.level-t.level:e.diff-t.diff}function U(e,t,r,a,i,o){this.vertices=e,this.side=t,this.level=r,this.x=a,this.y=i,this.path=o.replace("%s",t).replace("%l",r).replace("%x",a).replace("%y",i)}function P(e,t,r,a,i){if(function(e,t){var r=S(e,t.slice(0,3)),a=S(e,t.slice(3,6)),i=S(e,t.slice(6,9)),o=S(e,t.slice(9,12)),n=r[0]+a[0]+i[0]+o[0];if(-4==n||4==n)return!1;var h=r[1]+a[1]+i[1]+o[1];return-4!=h&&4!=h&&r[2]+a[2]+i[2]+o[2]!=4}(e,t.vertices)){var o=t.vertices,n=o[0]+o[3]+o[6]+o[9],h=o[1]+o[4]+o[7]+o[10],s=o[2]+o[5]+o[8]+o[11],u=Math.sqrt(n*n+h*h+s*s),d=Math.asin(s/u),c=Math.atan2(h,n)-a;c+=c>Math.PI?-2*Math.PI:c<-Math.PI?2*Math.PI:0,c=Math.abs(c),t.diff=Math.acos(Math.sin(r)*Math.sin(d)+Math.cos(r)*Math.cos(d)*Math.cos(c));for(var f=!1,g=0;g<l.nodeCache.length;g++)if(l.nodeCache[g].path==t.path){f=!0,l.nodeCache[g].timestamp=l.nodeCacheTimestamp++,l.nodeCache[g].diff=t.diff,l.currentNodes.push(l.nodeCache[g]);break}if(f||(t.timestamp=l.nodeCacheTimestamp++,l.currentNodes.push(t),l.nodeCache.push(t)),t.level<l.level){var _=E.cubeResolution*Math.pow(2,t.level-E.maxLevel),m=Math.ceil(_*E.invTileResolution)-1,v=_%E.tileResolution*2,x=2*_%E.tileResolution;0===x&&(x=E.tileResolution),0===v&&(v=2*E.tileResolution);var p=.5;t.x!=m&&t.y!=m||(p=1-E.tileResolution/(E.tileResolution+x));var T,R=1-p,w=[],M=p,A=p,b=p,I=R,C=R,B=R;x<E.tileResolution&&(t.x==m&&t.y!=m?(A=.5,C=.5,"d"!=t.side&&"u"!=t.side||(b=.5,B=.5)):t.x!=m&&t.y==m&&(M=.5,I=.5,"l"!=t.side&&"r"!=t.side||(b=.5,B=.5))),v<=E.tileResolution&&(t.x==m&&(M=0,I=1,"l"!=t.side&&"r"!=t.side||(b=0,B=1)),t.y==m&&(A=0,C=1,"d"!=t.side&&"u"!=t.side||(b=0,B=1))),T=new U([o[0],o[1],o[2],o[0]*M+o[3]*I,o[1]*p+o[4]*R,o[2]*b+o[5]*B,o[0]*M+o[6]*I,o[1]*A+o[7]*C,o[2]*b+o[8]*B,o[0]*p+o[9]*R,o[1]*A+o[10]*C,o[2]*b+o[11]*B],t.side,t.level+1,2*t.x,2*t.y,E.fullpath),w.push(T),t.x==m&&v<=E.tileResolution||(T=new U([o[0]*M+o[3]*I,o[1]*p+o[4]*R,o[2]*b+o[5]*B,o[3],o[4],o[5],o[3]*p+o[6]*R,o[4]*A+o[7]*C,o[5]*b+o[8]*B,o[0]*M+o[6]*I,o[1]*A+o[7]*C,o[2]*b+o[8]*B],t.side,t.level+1,2*t.x+1,2*t.y,E.fullpath),w.push(T)),t.x==m&&v<=E.tileResolution||t.y==m&&v<=E.tileResolution||(T=new U([o[0]*M+o[6]*I,o[1]*A+o[7]*C,o[2]*b+o[8]*B,o[3]*p+o[6]*R,o[4]*A+o[7]*C,o[5]*b+o[8]*B,o[6],o[7],o[8],o[9]*M+o[6]*I,o[10]*p+o[7]*R,o[11]*b+o[8]*B],t.side,t.level+1,2*t.x+1,2*t.y+1,E.fullpath),w.push(T)),t.y==m&&v<=E.tileResolution||(T=new U([o[0]*p+o[9]*R,o[1]*A+o[10]*C,o[2]*b+o[11]*B,o[0]*M+o[6]*I,o[1]*A+o[7]*C,o[2]*b+o[8]*B,o[9]*M+o[6]*I,o[10]*p+o[7]*R,o[11]*b+o[8]*B,o[9],o[10],o[11]],t.side,t.level+1,2*t.x,2*t.y+1,E.fullpath),w.push(T));for(var L=0;L<w.length;L++)P(e,w[L],r,a,i)}}}function B(e,t,r){var a=Math.sin(t),i=Math.cos(t);return"x"==r?[e[0],i*e[1]+a*e[2],i*e[2]-a*e[1],e[3],i*e[4]+a*e[5],i*e[5]-a*e[4],e[6],i*e[7]+a*e[8],i*e[8]-a*e[7]]:"y"==r?[i*e[0]-a*e[2],e[1],i*e[2]+a*e[0],i*e[3]-a*e[5],e[4],i*e[5]+a*e[3],i*e[6]-a*e[8],e[7],i*e[8]+a*e[6]]:"z"==r?[i*e[0]+a*e[1],i*e[1]-a*e[0],e[2],i*e[3]+a*e[4],i*e[4]-a*e[3],e[5],i*e[6]+a*e[7],i*e[7]-a*e[6],e[8]]:void 0}function L(e){return[e[0],e[4],e[8],e[12],e[1],e[5],e[9],e[13],e[2],e[6],e[10],e[14],e[3],e[7],e[11],e[15]]}b.style.width=b.style.height="100%",a.appendChild(b),this.init=function(e,I,C,U,P,B,L,D){if(I===r&&(I="equirectangular"),"equirectangular"!=I&&"cubemap"!=I&&"multires"!=I)throw console.log("Error: invalid image type specified!"),{type:"config error"};if(x=I,E=e,p=C,A=D||{},l){if(c&&(d.detachShader(l,c),d.deleteShader(c)),f&&(d.detachShader(l,f),d.deleteShader(f)),d.bindBuffer(d.ARRAY_BUFFER,null),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,null),l.texture&&d.deleteTexture(l.texture),l.nodeCache)for(var N=0;N<l.nodeCache.length;N++)d.deleteTexture(l.nodeCache[N].texture);d.deleteProgram(l),l=r}var y;v=r;var S,F=!1;if("cubemap"==x)for(y=0;y<6;y++)E[y].width>0?(S===r&&(S=E[y].width),S!=E[y].width&&console.log("Cube faces have
|