@lumiscaphe/viewer
Advanced tools
Comparing version 0.2.8 to 0.2.9
@@ -1,1 +0,1 @@ | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i(require("lodash.debounce"),require("twgl.js")):"function"==typeof define&&define.amd?define(["lodash.debounce","twgl.js"],i):t.LumiscapheViewer=i(t.debounce,t.twgl)}(this,function(t,i){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var e="default"in i?i.default:i,n=function(){};n.fit=function(t,i,e,n){var o=t.width/t.height,r=i/e,s=0,a=0;switch(n){case"contain":s=r<o?i:e*o,a=r<o?i/o:e;break;case"cover":default:s=r<o?e*o:i,a=r<o?e:i/o;break;case"fill":s=i,a=e}return{width:Math.round(s),height:Math.round(a),top:Math.round((e-a)/2),left:Math.round((i-s)/2)}},n.getStandardQuality=function(t){return t<=240?240:t<=360?360:t<=480?480:t<=720?720:1080},n.getStandardResolution=function(t,i){if(0===t||0===i)return{width:0,height:0};if(t<i){var e=t/i<.75?9/16:.75,o=n.getStandardQuality(i*e);return{width:Math.round(o),height:Math.round(o/e)}}var r=t/i>4/3?16/9:4/3,s=n.getStandardQuality(t/r);return{width:Math.round(s*r),height:Math.round(s)}};var o=function(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity=0,this.context=this.element.getContext("2d"),this.requestAnimationId=null};o.prototype.show=function(){this.element.style.opacity=1},o.prototype.hide=function(){this.element.style.opacity=0},o.prototype.resize=function(t,i,e){var o=n.fit(e,t,i,"cover");this.element.style.width=o.width+"px",this.element.style.height=o.height+"px",this.element.style.top=o.top+"px",this.element.style.left=o.left+"px",e.width===this.element.width&&e.height===this.element.height||(this.element.width=e.width,this.element.height=e.height)},o.prototype.draw=function(t,i,e){t&&(this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=null),i?(this.context.globalAlpha=0,this.fadeInLoop(t,e)):(this.context.globalAlpha=1,this.context.drawImage(t,0,0,this.element.width,this.element.height)))},o.prototype.fadeInLoop=function(t,i){var e=this;if(this.context.globalAlpha>1)return cancelAnimationFrame(this.requestAnimationId),void(this.requestAnimationId=null);this.context.globalAlpha+=i,this.context.drawImage(t,0,0,this.element.width,this.element.height),this.requestAnimationId=requestAnimationFrame(function(){e.fadeInLoop(t,i)})};var r=function(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity=0,this.context=e.getContext(this.element),e.setDefaultTextureColor([1,1,1,1]),this.requestAnimationId=null};r.prototype.show=function(){this.element.style.opacity=1},r.prototype.hide=function(){this.element.style.opacity=0},r.prototype.resize=function(){this.element.style.width="100%",this.element.style.height="100%",this.element.style.top=0,this.element.style.left=0};var s=function(){};s.accelerate=function(t,i){var e=i||1.5;return Math.pow(Math.abs(t),e)*(t>0?1:-1)},s.degreesToRadians=function(t){return t*(Math.PI/180)},s.mod=function(t,i){return t-i*Math.floor(t/i)};var a=function(t){this.server=t};a.buildQuery=function(t){return Object.keys(t).map(function(i){return i+"="+t[i]}).join("&")},a.sceneParameters=function(t){var i=t.scene,e={},n=i.length>1?i.find(function(t){return t.master})||i[0]:null;if(n){var o=i.find(function(t){return t!==n});e.databaseId=o.database,e.configuration=o.configuration,e.decorDatabaseId=n.database,e.decorDeltaAltitude=n.translation.y}else{var r=i[0];e.databaseId=r.database,e.configuration=r.configuration}return e},a.renderParameters=function(t){var i=t.parameters;return{width:i.width,height:i.height,softwareAntialiasing:i.antialiasing,superSampling:i.superSampling}},a.encoderParameters=function(t){var i=t.encoder;return{imageFormat:i.format,imageQuality:i.quality}},a.fetch=function(t){return fetch(t).then(function(t){return t.text()}).then(function(t){var i=t.replace(/&/g,"&").match(/directUrl="([^"]*)"/g);return i?i.map(function(t){return t.replace(/directUrl="([^"]*)"/g,"$1")}):Promise.reject()})},a.prototype.image=function(t){var i={};Object.assign(i,a.sceneParameters(t)),Object.assign(i,{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],background:t.view.background}),Object.assign(i,a.renderParameters(t)),Object.assign(i,a.encoderParameters(t));var e=a.buildQuery(i);return Promise.resolve(this.server+"/ImageFromBookmark?"+e)},a.prototype.vrCube=function(t){var i={};Object.assign(i,a.sceneParameters(t)),Object.assign(i,{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],background:t.view.background}),Object.assign(i,a.renderParameters(t)),Object.assign(i,a.encoderParameters(t)),i.width=Math.max(i.width,i.height),i.height=Math.max(i.width,i.height);var e=a.buildQuery(i);return a.fetch(this.server+"/CubeFromBookmark?"+e)},a.prototype.vrObject=function(t){var i={};Object.assign(i,a.sceneParameters(t)),Object.assign(i,{bookmarkSet:t.view.camera,background:t.view.background}),Object.assign(i,a.renderParameters(t)),Object.assign(i,a.encoderParameters(t));var e=a.buildQuery(i);return a.fetch(this.server+"/ImagesFromBookmarkSet?"+e)},a.prototype.animation=function(t){var i={};Object.assign(i,a.sceneParameters(t)),Object.assign(i,{animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],frames:t.view.frames,loop:t.view.loop,background:t.view.background}),Object.assign(i,a.renderParameters(t)),Object.assign(i,a.encoderParameters(t));var e=a.buildQuery(i);return a.fetch(this.server+"/ImagesFromAnimation?"+e)};var h=function(t,i){this.webrender=new a(t),this.loadingId=0,this.loaded=0,this.total=0,this.onLoadStart=i.onLoadStart||function(){},this.onLoadProgress=i.onLoadProgress||function(){},this.onLoadEnd=i.onLoadEnd||function(){}},c={progress:{configurable:!0}};c.progress.get=function(){return this.total?this.loaded/this.total:0},h.prototype.loadImage=function(t,i){var e=this,n=new Image;n.crossOrigin="anonymous";var o=new Promise(function(t,o){n.addEventListener("load",function(){i===e.loadingId&&(e.loaded+=1,e.onLoadProgress(e.progress),t(n))}),n.addEventListener("error",function(t){i===e.loadingId&&o(t)})});return n.src=t,o},h.prototype.loadVideoFrames=function(t,i,e,n){var o=this,r=1/e/2,s=[],a=document.createElement("video");a.autoplay=!0,a.muted=!0,a.playsinline=!0,a.preload="auto";var h=new Promise(function(t,h){a.addEventListener("loadeddata",function(){n===o.loadingId&&(a.currentTime=r)}),a.addEventListener("seeked",function(){if(n===o.loadingId){var h=document.createElement("canvas");h.width=a.videoWidth,h.height=a.videoHeight,h.getContext("2d").drawImage(a,0,0),s.push(h),o.loaded+=1,o.onLoadProgress(o.progress),(r+=1/e)<=i/e?a.currentTime=r:t(s)}}),a.addEventListener("error",function(t){n===o.loadingId&&h(t)})});return a.src=t,h},h.prototype.loadImageSnapshot=function(t){var i=this;this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);var e=this.loadingId;return this.webrender.image(t).then(function(t){return i.loadImage(t,e)}).then(function(t){return i.onLoadEnd(i.progress),t})},h.prototype.loadVRCubeSnapshot=function(t){var i=this;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);var e=this.loadingId;return this.webrender.vrCube(t).then(function(t){i.total=t.length;var n=t.map(function(t){return i.loadImage(t,e)});return Promise.all(n)}).then(function(t){return i.onLoadEnd(i.progress),t})},h.prototype.loadVRObjectSnapshot=function(t,i){var e=this;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);var n=this.loadingId,o=t.view.animation?"animation":"vrObject";return this.webrender[o](t).then(function(o){e.total=o.length;for(var r=new Array(o.length),a=i||0,h=0,c=o.length;h<c;h+=1){var d=Math.ceil(h/2)*(h%2==0?1:-1),l=t.view.loop?s.mod(a+d,c):h;r[l]=e.loadImage(o[l],n)}return Promise.all(r).then(function(){return e.onLoadEnd(e.progress)}),r})},Object.defineProperties(h.prototype,c);var d=function(t,i,e){this.container=t,this.canvas=i,this.loader=e,this.image=null,this.onStart=function(){},this.onEnter=function(){},this.onMove=function(){},this.onEnd=function(){},this.onDeviceOrientation=function(){}};d.prototype.load=function(t,i,e){var n=this,o=JSON.stringify(t);return o===this.hash?(this.canvas.draw(this.image,e,.01),Promise.resolve()):(this.hash=o,this.loader.loadImageSnapshot(t).then(function(t){n.image=t,n.canvas.draw(n.image,e,.01)}))};var l=function(){};l.point=function(t){if("touchmove"===t.type||"touchstart"===t.type||"touchend"===t.type){var i=t.targetTouches[0]||t.changedTouches[0];return{x:i.screenX,y:i.screenY}}return{x:t.screenX,y:t.screenY}};var u=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(3===t.length){var n;n=t,this.u=n[0],this.v=n[1],this.o=n[2],this.w=i.v3.cross(this.u,this.v)}else this.u=[1,0,0],this.v=[0,1,0],this.w=[0,0,1],this.o=[0,0,0]},p={localToGlobalMatrix:{configurable:!0},globalToLocalMatrix:{configurable:!0}};p.localToGlobalMatrix.get=function(){var t=[this.u[0],this.u[1],this.u[2],0],i=[this.v[0],this.v[1],this.v[2],0],e=[this.w[0],this.w[1],this.w[2],0],n=[this.o[0],this.o[1],this.o[2],1];return[].concat.apply([],[t,i,e,n])},p.globalToLocalMatrix.get=function(){return i.m4.inverse(this.localToGlobalMatrix)},Object.defineProperties(u.prototype,p);var m=function(t){this.animationFrameId=null,this.points=[],this.onMotion=t,this.loop=this.loop.bind(this)};m.prototype.track=function(t){var i=Date.now();this.points=this.points.filter(function(t){return i-t.time<=100}),this.points.push({x:t.x,y:t.y,time:i}),this.lastPoint=t},m.prototype.start=function(){if(0!==this.points.length){var t=this.points[0],i=this.points[this.points.length-1],e=i.x-t.x,n=i.y-t.y,o=i.time-t.time;this.velocity={x:0===o?0:e/(o/15),y:0===o?0:n/(o/15)},this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.animationFrameId=requestAnimationFrame(this.loop)}},m.prototype.stop=function(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.points=[]},m.prototype.loop=function(){if(Math.abs(this.velocity.x)<1&&Math.abs(this.velocity.y)<1)return this.animationFrameId=null,void(this.points=[]);this.lastPoint.x+=this.velocity.x,this.lastPoint.y+=this.velocity.y,this.velocity.x*=.9,this.velocity.y*=.9,this.onMotion(this.lastPoint),this.animationFrameId=requestAnimationFrame(this.loop)};var v=function(t,i,e){this.changed=!1,this.isStarted=!1,this.inertia=new m(this.motion.bind(this)),this.fov=s.degreesToRadians(t),this.pov=i,this.initFov=this.fov,this.initPov=this.pov,this.onMotion=e};v.prototype.reset=function(){this.fov=this.initFov,this.pov={eye:Array.from(this.initPov.eye),target:Array.from(this.initPov.target),up:Array.from(this.initPov.up)}},v.prototype.start=function(t,i){this.changed=!1,this.isStarted=!0,this.startPov=this.pov,this.startPoint=t,this.startSize=i,this.previousPoint=t,this.inertia.stop()},v.prototype.motion=function(t){this.isStarted&&this.inertia.track(t);var e={x:t.x-this.previousPoint.x,y:t.y-this.previousPoint.y},n=s.accelerate(e.x,1.2)/this.startSize.width*.2*Math.PI*1.5,o=s.accelerate(e.y,1.2)/this.startSize.height*.2*Math.PI,r=i.m4.multiply(i.m4.rotationY(-n),i.m4.rotationX(-o)),a=i.v3.normalize(i.v3.cross(this.pov.up,this.pov.target)),h=new u(a,[0,1,0],this.pov.eye),c=i.m4.identity();i.m4.multiply(c,h.localToGlobalMatrix,c),i.m4.multiply(c,r,c),i.m4.multiply(c,h.globalToLocalMatrix,c);var d=i.m4.transformPoint(c,this.pov.target),l=i.m4.transformDirection(c,this.pov.up);i.v3.cross(l,[0,0,1])[0]>=0&&(this.pov.target=d,this.pov.up=l),this.previousPoint={x:t.x,y:t.y},this.onMotion(),this.changed=!0},v.prototype.end=function(t){this.isStarted=!1,t&&this.inertia.start()},v.prototype.orientation=function(t){var e=s.degreesToRadians(90-t.beta),n=s.degreesToRadians(-t.alpha),o=i.m4.identity();i.m4.multiply(o,i.m4.rotationZ(0),o),i.m4.multiply(o,i.m4.rotationY(n),o),i.m4.multiply(o,i.m4.rotationX(e),o),this.reset();var r=i.v3.normalize(i.v3.cross(this.pov.up,this.pov.target)),a=new u(r,[0,1,0],this.pov.eye),h=i.m4.identity();i.m4.multiply(h,a.localToGlobalMatrix,h),i.m4.multiply(h,o,h),i.m4.multiply(h,a.globalToLocalMatrix,h);var c=i.m4.transformPoint(h,this.pov.target),d=i.m4.transformDirection(h,this.pov.up);i.v3.cross(d,[0,0,1])[0]>=0&&(this.pov.target=c,this.pov.up=d),this.onMotion()};var g=function(t,i,n,o){var r=this;this.container=t,this.canvas=i,this.loader=n,this.onInteraction=o;var a={eye:[0,0,0],target:[0,0,1],up:[0,1,0]},h=e.m4.rotationX(s.degreesToRadians(15));e.m4.transformDirection(h,a.target,a.target),this.interaction=new v(60,a,function(){requestAnimationFrame(r.render)}),this.gl=this.canvas.context,this.programInfo=e.createProgramInfo(this.gl,["attribute vec4 position;uniform mat4 u_matrix;varying vec3 direction;void main(){direction=(u_matrix*position).xyz;gl_Position=position*vec4(-1,1,1,1);}\n","precision mediump float;uniform samplerCube u_texture;varying vec3 direction;void main(){gl_FragColor=textureCube(u_texture,direction);}\n"]),this.quad=e.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_texture:e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_matrix:e.m4.identity()},this.render=this.render.bind(this)};g.prototype.load=function(t,i){var n=this,o=JSON.stringify(t);return o===this.hash?(requestAnimationFrame(this.render),Promise.resolve()):(this.hash=o,this.images=[],requestAnimationFrame(this.render),this.loader.loadVRCubeSnapshot(t).then(function(t){var o=t.map(function(t){return t.src});n.uniforms.u_texture=e.createTexture(n.gl,{target:n.gl.TEXTURE_CUBE_MAP,minMag:n.gl.LINEAR,cubeFaceOrder:[n.gl.TEXTURE_CUBE_MAP_POSITIVE_Z,n.gl.TEXTURE_CUBE_MAP_POSITIVE_X,n.gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,n.gl.TEXTURE_CUBE_MAP_NEGATIVE_X,n.gl.TEXTURE_CUBE_MAP_POSITIVE_Y,n.gl.TEXTURE_CUBE_MAP_NEGATIVE_Y],src:o,crossOrigin:"anonymous"},function(){i&&n.interaction.reset(),requestAnimationFrame(n.render)})}))},g.prototype.render=function(){e.resizeCanvasToDisplaySize(this.gl.canvas,window.devicePixelRatio),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);var t=this.interaction.fov,i=this.gl.canvas.clientWidth/this.gl.canvas.clientHeight,n=e.m4.inverse(e.m4.perspective(t,i,.5,100)),o=this.interaction.pov,r=e.m4.lookAt(o.eye,o.target,o.up);this.uniforms.u_matrix=e.m4.multiply(r,n),this.gl.useProgram(this.programInfo.program),e.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),e.setUniforms(this.programInfo,this.uniforms),e.drawBufferInfo(this.gl,this.quad)},g.prototype.onStart=function(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(l.point(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})},g.prototype.onEnter=function(t){this.interaction.isStarted||0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(!1))},g.prototype.onMove=function(t){this.interaction.isStarted&&(this.interaction.motion(l.point(t)),t.preventDefault())},g.prototype.onEnd=function(){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(!0),this.interaction.changed&&this.onInteraction())},g.prototype.onDeviceOrientation=function(t){!1!==this.interaction.isStarted&&this.interaction.orientation({alpha:t.alpha,beta:t.beta,gamma:t.gamma})};var f=function(t,i,e,n){this.changed=!1,this.isStarted=!1,this.inertia=new m(this.motion.bind(this)),this.position=t,this.count=i,this.loop=e,this.onMotion=n,this.initPosition=this.position};f.prototype.set=function(t){var i=this.position;this.loop?this.position=s.mod(t,this.count):this.position=Math.max(0,Math.min(t,this.count-1)),this.position!==i&&(this.onMotion(),this.changed=!0)},f.prototype.reset=function(){this.position=this.initPosition},f.prototype.start=function(t,i){this.changed=!1,this.isStarted=!0,this.startPosition=this.position,this.startPoint=t,this.startSize=i,this.inertia.stop()},f.prototype.motion=function(t){this.isStarted&&this.inertia.track(t);var i={x:t.x-this.startPoint.x,y:t.y-this.startPoint.y},e=s.accelerate(i.x,1.2)/this.startSize.width*(this.count/4),n=this.startPosition-Math.round(e);this.set(n)},f.prototype.end=function(t){this.isStarted=!1,t&&this.inertia.start()};var b=function(t,i,e,n){var o=this;this.container=t,this.canvas=i,this.loader=e,this.onInteraction=n,this.images=[],this.interaction=new f(0,1,!1,function(){o.canvas.draw(o.image,!0,.25)}),this.options={loop:!0},this.onDeviceOrientation=function(){}},y={image:{configurable:!0}};y.image.get=function(){return this.images[this.interaction.position]},b.prototype.load=function(t,i,e){var n=this,o=JSON.stringify(t);if(o===this.hash)return this.canvas.draw(this.image,e,.01),Promise.resolve();this.hash=o,this.images=[],i&&this.interaction.reset();var r=this.interaction.position;return this.loader.loadVRObjectSnapshot(t,r).then(function(i){var o=i.length;return n.images=new Array(o),n.interaction.count=o,n.interaction.loop=t.view.loop,i.forEach(function(t,i){t.then(function(t){n.images[i]=t,n.canvas.draw(n.image,e,.01)})}),i[n.interaction.position]})},b.prototype.onStart=function(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(l.point(t),{width:this.canvas.element.width,height:this.canvas.element.height})},b.prototype.onEnter=function(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(!1))},b.prototype.onMove=function(t){this.interaction.isStarted&&(this.interaction.motion(l.point(t)),t.preventDefault())},b.prototype.onEnd=function(){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(!0),this.interaction.changed&&this.onInteraction())},Object.defineProperties(b.prototype,y),function(t,i){if("undefined"==typeof document)return i;t=t||"";var e=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",e.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}(".ls-viewer-container{display:block;position:relative;overflow:hidden;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:100%;height:100%}.ls-viewer-container-image{cursor:default}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}",void 0);var w=function(i,e){this.container=i,this.container.classList.add("ls-viewer-container"),this.canvas2D=new o,this.container.appendChild(this.canvas2D.element),this.canvas3D=new r,this.container.appendChild(this.canvas3D.element),this.container.addEventListener("mousedown",this.onStart.bind(this)),this.container.addEventListener("mouseenter",this.onEnter.bind(this)),this.container.addEventListener("mousemove",this.onMove.bind(this)),this.container.addEventListener("mouseup",this.onEnd.bind(this)),this.container.addEventListener("touchstart",this.onStart.bind(this)),this.container.addEventListener("touchmove",this.onMove.bind(this)),this.container.addEventListener("touchend",this.onEnd.bind(this)),this.options=Object.assign({},{server:"localhost",events:{onInteraction:function(){},onLoadStart:function(){},onLoadProgress:function(){},onLoadEnd:function(){},onError:function(){}}},e),this.loader=new h(e.server,{onLoadStart:this.onLoadStart.bind(this),onLoadProgress:this.onLoadProgress.bind(this),onLoadEnd:this.onLoadEnd.bind(this),onError:this.onError.bind(this)}),this.params=null,this.resolution={};var n=this.onInteraction.bind(this);this.widgetImage=new d(i,this.canvas2D,this.loader,n),this.widgetVRCube=new g(i,this.canvas3D,this.loader,n),this.widgetVRObject=new b(i,this.canvas2D,this.loader,n),this.widget=this.widgetImage,window.addEventListener("resize",t(this.onResize.bind(this),250)),this.onResize()};return w.prototype.load=function(t,i,e){var n=this;if(t&&(this.snapshot=t,this.resolution.width&&this.resolution.height)){this.snapshot.parameters=Object.assign({},{antialiasing:!1,superSampling:2},this.snapshot.parameters,{width:this.resolution.width,height:this.resolution.height}),this.snapshot.encoder=Object.assign({},{format:"jpeg",quality:90},this.snapshot.encoder),this.snapshot.view.background||(this.snapshot.view.background="product");var o=null;switch(t.view.mode){case"image":o=this.widgetImage,this.container.classList.remove("ls-viewer-container-vrcube"),this.container.classList.remove("ls-viewer-container-vrobject"),this.container.classList.add("ls-viewer-container-image");break;case"vrcube":o=this.widgetVRCube,this.container.classList.remove("ls-viewer-container-image"),this.container.classList.remove("ls-viewer-container-vrobject"),this.container.classList.add("ls-viewer-container-vrcube");break;case"vrobject":o=this.widgetVRObject,this.container.classList.remove("ls-viewer-container-image"),this.container.classList.remove("ls-viewer-container-vrcube"),this.container.classList.add("ls-viewer-container-vrobject")}o&&o.load(t,i,e).then(function(){o.canvas!==n.widget.canvas&&n.widget.canvas.hide(),o.canvas.show(),n.widget=o},function(t){n.options.events.onError(t)})}},w.prototype.onDeviceOrientation=function(t){this.widget.onDeviceOrientation(t)},w.prototype.onStart=function(t){this.widget.onStart(t)},w.prototype.onEnter=function(t){this.widget.onEnter(t)},w.prototype.onMove=function(t){this.widget.onMove(t)},w.prototype.onEnd=function(t){this.widget.onEnd(t)},w.prototype.onResize=function(){var t=window.devicePixelRatio,i=this.container.offsetWidth*t,e=this.container.offsetHeight*t;this.resolution=n.getStandardResolution(i,e),this.canvas2D.resize(i/t,e/t,this.resolution),this.canvas3D.resize(i/t,e/t,this.resolution),this.load(this.snapshot,!1,!1)},w.prototype.onInteraction=function(){for(var t=[],i=arguments.length;i--;)t[i]=arguments[i];this.options.events.onInteraction(t)},w.prototype.onLoadStart=function(){for(var t=[],i=arguments.length;i--;)t[i]=arguments[i];this.container.classList.add("ls-viewer-container-loading"),this.options.events.onLoadStart(t)},w.prototype.onLoadProgress=function(){for(var t=[],i=arguments.length;i--;)t[i]=arguments[i];this.options.events.onLoadProgress(t)},w.prototype.onLoadEnd=function(){for(var t=[],i=arguments.length;i--;)t[i]=arguments[i];this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadEnd(t)},w.prototype.onError=function(){for(var t=[],i=arguments.length;i--;)t[i]=arguments[i];this.options.events.onError(t)},w}); | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i(require("lodash.debounce"),require("twgl.js")):"function"==typeof define&&define.amd?define(["lodash.debounce","twgl.js"],i):t.LumiscapheViewer=i(t.debounce,t.twgl)}(this,function(t,i){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var e="default"in i?i.default:i,n=function(){};n.fit=function(t,i,e,n){var o=t.width/t.height,r=i/e,s=0,a=0;switch(n){case"contain":s=r<o?i:e*o,a=r<o?i/o:e;break;case"cover":default:s=r<o?e*o:i,a=r<o?e:i/o;break;case"fill":s=i,a=e}return{width:Math.round(s),height:Math.round(a),top:Math.round((e-a)/2),left:Math.round((i-s)/2)}},n.getStandardQuality=function(t){return t<=240?240:t<=360?360:t<=480?480:t<=720?720:1080},n.getStandardResolution=function(t,i){if(0===t||0===i)return{width:0,height:0};if(t<i){var e=t/i<.75?9/16:.75,o=n.getStandardQuality(i*e);return{width:Math.round(o),height:Math.round(o/e)}}var r=t/i>4/3?16/9:4/3,s=n.getStandardQuality(t/r);return{width:Math.round(s*r),height:Math.round(s)}};var o=function(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity=0,this.context=this.element.getContext("2d"),this.requestAnimationId=null};o.prototype.show=function(){this.element.style.opacity=1},o.prototype.hide=function(){this.element.style.opacity=0},o.prototype.resize=function(t,i,e){var o=n.fit(e,t,i,"cover");this.element.style.width=o.width+"px",this.element.style.height=o.height+"px",this.element.style.top=o.top+"px",this.element.style.left=o.left+"px",e.width===this.element.width&&e.height===this.element.height||(this.element.width=e.width,this.element.height=e.height)},o.prototype.draw=function(t,i,e){t&&(this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=null),i?(this.context.globalAlpha=0,this.fadeLoop(t,e)):(this.context.globalAlpha=1,this.context.drawImage(t,0,0,this.element.width,this.element.height)))},o.prototype.fadeLoop=function(t,i){var e=this;if(this.context.globalAlpha>1)return cancelAnimationFrame(this.requestAnimationId),void(this.requestAnimationId=null);this.context.globalAlpha+=i,this.context.drawImage(t,0,0,this.element.width,this.element.height),this.requestAnimationId=requestAnimationFrame(function(){e.fadeLoop(t,i)})};var r=function(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity=0,this.context=e.getContext(this.element),e.setDefaultTextureColor([1,1,1,1]),this.requestAnimationId=null};r.prototype.show=function(){this.element.style.opacity=1},r.prototype.hide=function(){this.element.style.opacity=0},r.prototype.resize=function(){this.element.style.width="100%",this.element.style.height="100%",this.element.style.top=0,this.element.style.left=0};var s=function(){};s.accelerate=function(t,i){var e=i||1.5;return Math.pow(Math.abs(t),e)*(t>0?1:-1)},s.degreesToRadians=function(t){return t*(Math.PI/180)},s.mod=function(t,i){return t-i*Math.floor(t/i)};var a=function(t){this.server=t};a.buildQuery=function(t){return Object.keys(t).map(function(i){return i+"="+t[i]}).join("&")},a.sceneParameters=function(t){var i=t.scene,e={},n=i.length>1?i.find(function(t){return t.master})||i[0]:null;if(n){var o=i.find(function(t){return t!==n});e.databaseId=o.database,e.configuration=o.configuration,e.decorDatabaseId=n.database,e.decorDeltaAltitude=n.translation.y}else{var r=i[0];e.databaseId=r.database,e.configuration=r.configuration}return e},a.renderParameters=function(t){var i=t.parameters;return{width:i.width,height:i.height,softwareAntialiasing:i.antialiasing,superSampling:i.superSampling}},a.encoderParameters=function(t){var i=t.encoder;return{imageFormat:i.format,imageQuality:i.quality}},a.fetch=function(t){return fetch(t).then(function(t){return t.text()}).then(function(t){var i=t.replace(/&/g,"&").match(/directUrl="([^"]*)"/g);return i?i.map(function(t){return t.replace(/directUrl="([^"]*)"/g,"$1")}):Promise.reject()})},a.prototype.image=function(t){var i={};Object.assign(i,a.sceneParameters(t)),Object.assign(i,{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],background:t.view.background}),Object.assign(i,a.renderParameters(t)),Object.assign(i,a.encoderParameters(t));var e=a.buildQuery(i);return Promise.resolve(this.server+"/ImageFromBookmark?"+e)},a.prototype.vrCube=function(t){var i={};Object.assign(i,a.sceneParameters(t)),Object.assign(i,{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],background:t.view.background}),Object.assign(i,a.renderParameters(t)),Object.assign(i,a.encoderParameters(t)),i.width=Math.max(i.width,i.height),i.height=Math.max(i.width,i.height);var e=a.buildQuery(i);return a.fetch(this.server+"/CubeFromBookmark?"+e)},a.prototype.vrObject=function(t){var i={};Object.assign(i,a.sceneParameters(t)),Object.assign(i,{bookmarkSet:t.view.camera,background:t.view.background}),Object.assign(i,a.renderParameters(t)),Object.assign(i,a.encoderParameters(t));var e=a.buildQuery(i);return a.fetch(this.server+"/ImagesFromBookmarkSet?"+e)},a.prototype.animation=function(t){var i={};Object.assign(i,a.sceneParameters(t)),Object.assign(i,{animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],frames:t.view.frames,loop:t.view.loop,background:t.view.background}),Object.assign(i,a.renderParameters(t)),Object.assign(i,a.encoderParameters(t));var e=a.buildQuery(i);return a.fetch(this.server+"/ImagesFromAnimation?"+e)};var h=function(t,i){this.webrender=new a(t),this.loadingId=0,this.loaded=0,this.total=0,this.onLoadStart=i.onLoadStart||function(){},this.onLoadProgress=i.onLoadProgress||function(){},this.onLoadEnd=i.onLoadEnd||function(){}},c={progress:{configurable:!0}};c.progress.get=function(){return this.total?this.loaded/this.total:0},h.prototype.loadImage=function(t,i){var e=this,n=new Image;n.crossOrigin="anonymous";var o=new Promise(function(t,o){n.addEventListener("load",function(){i===e.loadingId&&(e.loaded+=1,e.onLoadProgress(e.progress),t(n))}),n.addEventListener("error",function(t){i===e.loadingId&&o(t)})});return n.src=t,o},h.prototype.loadVideoFrames=function(t,i,e,n){var o=this,r=1/e/2,s=[],a=document.createElement("video");a.autoplay=!0,a.muted=!0,a.playsinline=!0,a.preload="auto";var h=new Promise(function(t,h){a.addEventListener("loadeddata",function(){n===o.loadingId&&(a.currentTime=r)}),a.addEventListener("seeked",function(){if(n===o.loadingId){var h=document.createElement("canvas");h.width=a.videoWidth,h.height=a.videoHeight,h.getContext("2d").drawImage(a,0,0),s.push(h),o.loaded+=1,o.onLoadProgress(o.progress),(r+=1/e)<=i/e?a.currentTime=r:t(s)}}),a.addEventListener("error",function(t){n===o.loadingId&&h(t)})});return a.src=t,h},h.prototype.loadImageSnapshot=function(t){var i=this;this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);var e=this.loadingId;return this.webrender.image(t).then(function(t){return i.loadImage(t,e)}).then(function(t){return i.onLoadEnd(i.progress),t})},h.prototype.loadVRCubeSnapshot=function(t){var i=this;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);var e=this.loadingId;return this.webrender.vrCube(t).then(function(t){i.total=t.length;var n=t.map(function(t){return i.loadImage(t,e)});return Promise.all(n)}).then(function(t){return i.onLoadEnd(i.progress),t})},h.prototype.loadVRObjectSnapshot=function(t,i){var e=this;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);var n=this.loadingId,o=t.view.animation?"animation":"vrObject";return this.webrender[o](t).then(function(o){e.total=o.length;for(var r=new Array(o.length),a=i||0,h=0,c=o.length;h<c;h+=1){var d=Math.ceil(h/2)*(h%2==0?1:-1),u=t.view.loop?s.mod(a+d,c):h;r[u]=e.loadImage(o[u],n)}return Promise.all(r).then(function(){return e.onLoadEnd(e.progress)}),r})},Object.defineProperties(h.prototype,c);var d=function(t,i,e){this.container=t,this.canvas=i,this.loader=e,this.image=null,this.onStart=function(){},this.onEnter=function(){},this.onMove=function(){},this.onEnd=function(){},this.onDeviceOrientation=function(){}};d.prototype.load=function(t,i,e){var n=this,o=JSON.stringify(t);return o===this.hash?(this.canvas.draw(this.image,e,.01),Promise.resolve()):(this.hash=o,this.loader.loadImageSnapshot(t).then(function(t){n.image=t,n.canvas.draw(n.image,e,.01)}))};var u=function(){};u.point=function(t){if("touchmove"===t.type||"touchstart"===t.type||"touchend"===t.type){var i=t.targetTouches[0]||t.changedTouches[0];return{x:i.screenX,y:i.screenY}}return{x:t.screenX,y:t.screenY}};var l=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(3===t.length){var n;n=t,this.u=n[0],this.v=n[1],this.o=n[2],this.w=i.v3.cross(this.u,this.v)}else this.u=[1,0,0],this.v=[0,1,0],this.w=[0,0,1],this.o=[0,0,0]},m={localToGlobalMatrix:{configurable:!0},globalToLocalMatrix:{configurable:!0}};m.localToGlobalMatrix.get=function(){var t=[this.u[0],this.u[1],this.u[2],0],i=[this.v[0],this.v[1],this.v[2],0],e=[this.w[0],this.w[1],this.w[2],0],n=[this.o[0],this.o[1],this.o[2],1];return[].concat.apply([],[t,i,e,n])},m.globalToLocalMatrix.get=function(){return i.m4.inverse(this.localToGlobalMatrix)},Object.defineProperties(l.prototype,m);var p=function(t){this.animationFrameId=null,this.points=[],this.onMotion=t,this.loop=this.loop.bind(this)};p.prototype.track=function(t){var i=Date.now();this.points=this.points.filter(function(t){return i-t.time<=100}),this.points.push({x:t.x,y:t.y,time:i}),this.lastPoint=t},p.prototype.start=function(){if(0!==this.points.length){var t=this.points[0],i=this.points[this.points.length-1],e=i.x-t.x,n=i.y-t.y,o=i.time-t.time;this.velocity={x:0===o?0:e/(o/15),y:0===o?0:n/(o/15)},this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.animationFrameId=requestAnimationFrame(this.loop)}},p.prototype.stop=function(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.points=[]},p.prototype.loop=function(){if(Math.abs(this.velocity.x)<1&&Math.abs(this.velocity.y)<1)return this.animationFrameId=null,void(this.points=[]);this.lastPoint.x+=this.velocity.x,this.lastPoint.y+=this.velocity.y,this.velocity.x*=.9,this.velocity.y*=.9,this.onMotion(this.lastPoint),this.animationFrameId=requestAnimationFrame(this.loop)};var v=function(t,i,e){this.changed=!1,this.isStarted=!1,this.inertia=new p(this.motion.bind(this)),this.fov=s.degreesToRadians(t),this.pov=i,this.initFov=this.fov,this.initPov=this.pov,this.onMotion=e};v.prototype.reset=function(){this.fov=this.initFov,this.pov={eye:Array.from(this.initPov.eye),target:Array.from(this.initPov.target),up:Array.from(this.initPov.up)}},v.prototype.start=function(t,i){this.changed=!1,this.isStarted=!0,this.startPov=this.pov,this.startPoint=t,this.startSize=i,this.previousPoint=t,this.inertia.stop()},v.prototype.motion=function(t){this.isStarted&&this.inertia.track(t);var e={x:t.x-this.previousPoint.x,y:t.y-this.previousPoint.y},n=s.accelerate(e.x,1.2)/this.startSize.width*.2*Math.PI*1.5,o=s.accelerate(e.y,1.2)/this.startSize.height*.2*Math.PI,r=i.m4.multiply(i.m4.rotationY(-n),i.m4.rotationX(-o)),a=i.v3.normalize(i.v3.cross(this.pov.up,this.pov.target)),h=new l(a,[0,1,0],this.pov.eye),c=i.m4.identity();i.m4.multiply(c,h.localToGlobalMatrix,c),i.m4.multiply(c,r,c),i.m4.multiply(c,h.globalToLocalMatrix,c);var d=i.m4.transformPoint(c,this.pov.target),u=i.m4.transformDirection(c,this.pov.up);i.v3.cross(u,[0,0,1])[0]>=0&&(this.pov.target=d,this.pov.up=u),this.previousPoint={x:t.x,y:t.y},this.onMotion(),this.changed=!0},v.prototype.end=function(t){this.isStarted=!1,t&&this.inertia.start()},v.prototype.orientation=function(t){var e=s.degreesToRadians(90-t.beta),n=s.degreesToRadians(-t.alpha),o=i.m4.identity();i.m4.multiply(o,i.m4.rotationZ(0),o),i.m4.multiply(o,i.m4.rotationY(n),o),i.m4.multiply(o,i.m4.rotationX(e),o),this.reset();var r=i.v3.normalize(i.v3.cross(this.pov.up,this.pov.target)),a=new l(r,[0,1,0],this.pov.eye),h=i.m4.identity();i.m4.multiply(h,a.localToGlobalMatrix,h),i.m4.multiply(h,o,h),i.m4.multiply(h,a.globalToLocalMatrix,h);var c=i.m4.transformPoint(h,this.pov.target),d=i.m4.transformDirection(h,this.pov.up);i.v3.cross(d,[0,0,1])[0]>=0&&(this.pov.target=c,this.pov.up=d),this.onMotion()};var g=function(t,i,n,o){var r=this;this.container=t,this.canvas=i,this.loader=n,this.onInteraction=o;var a={eye:[0,0,0],target:[0,0,1],up:[0,1,0]},h=e.m4.rotationX(s.degreesToRadians(15));e.m4.transformDirection(h,a.target,a.target),this.interaction=new v(60,a,function(){requestAnimationFrame(r.render)}),this.gl=this.canvas.context,this.programInfo=e.createProgramInfo(this.gl,["attribute vec4 position;uniform mat4 u_matrix;varying vec3 direction;void main(){direction=(u_matrix*position).xyz;gl_Position=position*vec4(-1,1,1,1);}\n","precision mediump float;uniform float u_mix;uniform samplerCube u_texture;uniform samplerCube u_texture_back;varying vec3 direction;void main(){vec4 backColor=textureCube(u_texture_back,direction);vec4 color=textureCube(u_texture,direction);gl_FragColor=mix(backColor,color,u_mix);}\n"]),this.quad=e.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_matrix:e.m4.identity(),u_mix:0,u_texture_back:e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1})},this.render=this.render.bind(this)};g.prototype.load=function(t,i,n){var o=this,r=JSON.stringify(t);return r===this.hash?(requestAnimationFrame(this.render),Promise.resolve()):(this.hash=r,this.images=[],requestAnimationFrame(this.render),this.loader.loadVRCubeSnapshot(t).then(function(t){e.createTexture(o.gl,{target:o.gl.TEXTURE_CUBE_MAP,minMag:o.gl.LINEAR,cubeFaceOrder:[o.gl.TEXTURE_CUBE_MAP_POSITIVE_Z,o.gl.TEXTURE_CUBE_MAP_POSITIVE_X,o.gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,o.gl.TEXTURE_CUBE_MAP_NEGATIVE_X,o.gl.TEXTURE_CUBE_MAP_POSITIVE_Y,o.gl.TEXTURE_CUBE_MAP_NEGATIVE_Y],src:t,crossOrigin:"anonymous"},function(t,e){t||(i&&o.interaction.reset(),o.uniforms.u_mix=n?0:1,o.uniforms.u_texture_back=o.uniforms.u_texture,o.uniforms.u_texture=e,requestAnimationFrame(o.render))})}))},g.prototype.render=function(){e.resizeCanvasToDisplaySize(this.gl.canvas,window.devicePixelRatio),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);var t=this.interaction.fov,i=this.gl.canvas.clientWidth/this.gl.canvas.clientHeight,n=e.m4.inverse(e.m4.perspective(t,i,.5,100)),o=this.interaction.pov,r=e.m4.lookAt(o.eye,o.target,o.up);this.uniforms.u_matrix=e.m4.multiply(r,n),this.gl.useProgram(this.programInfo.program),e.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),e.setUniforms(this.programInfo,this.uniforms),e.drawBufferInfo(this.gl,this.quad),this.uniforms.u_mix<1&&(this.uniforms.u_mix=Math.min(this.uniforms.u_mix+.05,1),requestAnimationFrame(this.render))},g.prototype.onStart=function(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(u.point(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})},g.prototype.onEnter=function(t){this.interaction.isStarted||0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(!1))},g.prototype.onMove=function(t){this.interaction.isStarted&&(this.interaction.motion(u.point(t)),t.preventDefault())},g.prototype.onEnd=function(){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(!0),this.interaction.changed&&this.onInteraction())},g.prototype.onDeviceOrientation=function(t){!1!==this.interaction.isStarted&&this.interaction.orientation({alpha:t.alpha,beta:t.beta,gamma:t.gamma})};var f=function(t,i,e,n){this.changed=!1,this.isStarted=!1,this.inertia=new p(this.motion.bind(this)),this.position=t,this.count=i,this.loop=e,this.onMotion=n,this.initPosition=this.position};f.prototype.set=function(t){var i=this.position;this.loop?this.position=s.mod(t,this.count):this.position=Math.max(0,Math.min(t,this.count-1)),this.position!==i&&(this.onMotion(),this.changed=!0)},f.prototype.reset=function(){this.position=this.initPosition},f.prototype.start=function(t,i){this.changed=!1,this.isStarted=!0,this.startPosition=this.position,this.startPoint=t,this.startSize=i,this.inertia.stop()},f.prototype.motion=function(t){this.isStarted&&this.inertia.track(t);var i={x:t.x-this.startPoint.x,y:t.y-this.startPoint.y},e=s.accelerate(i.x,1.3)/this.startSize.width*(this.count/4),n=this.startPosition-Math.round(e);this.set(n)},f.prototype.end=function(t){this.isStarted=!1,t&&this.inertia.start()};var b=function(t,i,e,n){var o=this;this.container=t,this.canvas=i,this.loader=e,this.onInteraction=n,this.images=[],this.interaction=new f(0,1,!1,function(){o.canvas.draw(o.image,!0,.25)}),this.options={loop:!0},this.onDeviceOrientation=function(){}},y={image:{configurable:!0}};y.image.get=function(){return this.images[this.interaction.position]},b.prototype.load=function(t,i,e){var n=this,o=JSON.stringify(t);if(o===this.hash)return this.canvas.draw(this.image,e,.01),Promise.resolve();this.hash=o,this.images=[],i&&this.interaction.reset();var r=this.interaction.position;return this.loader.loadVRObjectSnapshot(t,r).then(function(i){var o=i.length;return n.images=new Array(o),n.interaction.count=o,n.interaction.loop=t.view.loop,i.forEach(function(t,i){t.then(function(t){n.images[i]=t,n.canvas.draw(n.image,e,.01)})}),i[n.interaction.position]})},b.prototype.onStart=function(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(u.point(t),{width:this.canvas.element.width,height:this.canvas.element.height})},b.prototype.onEnter=function(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(!1))},b.prototype.onMove=function(t){this.interaction.isStarted&&(this.interaction.motion(u.point(t)),t.preventDefault())},b.prototype.onEnd=function(){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(!0),this.interaction.changed&&this.onInteraction())},Object.defineProperties(b.prototype,y),function(t,i){if("undefined"==typeof document)return i;t=t||"";var e=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",e.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}(".ls-viewer-container{display:block;position:relative;overflow:hidden;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:100%;height:100%}.ls-viewer-container-image{cursor:default}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}",void 0);var w=function(i,e){this.container=i,this.container.classList.add("ls-viewer-container"),this.canvas2D=new o,this.container.appendChild(this.canvas2D.element),this.canvas3D=new r,this.container.appendChild(this.canvas3D.element),this.container.addEventListener("mousedown",this.onStart.bind(this)),this.container.addEventListener("mouseenter",this.onEnter.bind(this)),this.container.addEventListener("mousemove",this.onMove.bind(this)),this.container.addEventListener("mouseup",this.onEnd.bind(this)),this.container.addEventListener("touchstart",this.onStart.bind(this)),this.container.addEventListener("touchmove",this.onMove.bind(this)),this.container.addEventListener("touchend",this.onEnd.bind(this)),this.options=Object.assign({},{server:"localhost",events:{onInteraction:function(){},onLoadStart:function(){},onLoadProgress:function(){},onLoadEnd:function(){},onError:function(){}}},e),this.loader=new h(e.server,{onLoadStart:this.onLoadStart.bind(this),onLoadProgress:this.onLoadProgress.bind(this),onLoadEnd:this.onLoadEnd.bind(this),onError:this.onError.bind(this)}),this.params=null,this.resolution={};var n=this.onInteraction.bind(this);this.widgetImage=new d(i,this.canvas2D,this.loader,n),this.widgetVRCube=new g(i,this.canvas3D,this.loader,n),this.widgetVRObject=new b(i,this.canvas2D,this.loader,n),this.widget=this.widgetImage,window.addEventListener("resize",t(this.onResize.bind(this),250)),this.onResize()};return w.prototype.load=function(t,i,e){var n=this;if(t&&(this.snapshot=t,this.resolution.width&&this.resolution.height)){this.snapshot.parameters=Object.assign({},{antialiasing:!1,superSampling:2},this.snapshot.parameters,{width:this.resolution.width,height:this.resolution.height}),this.snapshot.encoder=Object.assign({},{format:"jpeg",quality:90},this.snapshot.encoder),this.snapshot.view.background||(this.snapshot.view.background="product");var o=null;switch(t.view.mode){case"image":o=this.widgetImage,this.container.classList.remove("ls-viewer-container-vrcube"),this.container.classList.remove("ls-viewer-container-vrobject"),this.container.classList.add("ls-viewer-container-image");break;case"vrcube":o=this.widgetVRCube,this.container.classList.remove("ls-viewer-container-image"),this.container.classList.remove("ls-viewer-container-vrobject"),this.container.classList.add("ls-viewer-container-vrcube");break;case"vrobject":o=this.widgetVRObject,this.container.classList.remove("ls-viewer-container-image"),this.container.classList.remove("ls-viewer-container-vrcube"),this.container.classList.add("ls-viewer-container-vrobject")}o&&o.load(t,i,e).then(function(){o.canvas!==n.widget.canvas&&n.widget.canvas.hide(),o.canvas.show(),n.widget=o},function(t){n.options.events.onError(t)})}},w.prototype.onDeviceOrientation=function(t){this.widget.onDeviceOrientation(t)},w.prototype.onStart=function(t){this.widget.onStart(t)},w.prototype.onEnter=function(t){this.widget.onEnter(t)},w.prototype.onMove=function(t){this.widget.onMove(t)},w.prototype.onEnd=function(t){this.widget.onEnd(t)},w.prototype.onResize=function(){var t=window.devicePixelRatio,i=this.container.offsetWidth*t,e=this.container.offsetHeight*t;this.resolution=n.getStandardResolution(i,e),this.canvas2D.resize(i/t,e/t,this.resolution),this.canvas3D.resize(i/t,e/t,this.resolution),this.load(this.snapshot,!1,!1)},w.prototype.onInteraction=function(){for(var t=[],i=arguments.length;i--;)t[i]=arguments[i];this.options.events.onInteraction(t)},w.prototype.onLoadStart=function(){for(var t=[],i=arguments.length;i--;)t[i]=arguments[i];this.container.classList.add("ls-viewer-container-loading"),this.options.events.onLoadStart(t)},w.prototype.onLoadProgress=function(){for(var t=[],i=arguments.length;i--;)t[i]=arguments[i];this.options.events.onLoadProgress(t)},w.prototype.onLoadEnd=function(){for(var t=[],i=arguments.length;i--;)t[i]=arguments[i];this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadEnd(t)},w.prototype.onError=function(){for(var t=[],i=arguments.length;i--;)t[i]=arguments[i];this.options.events.onError(t)},w}); |
{ | ||
"name": "@lumiscaphe/viewer", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"description": "Lumiscaphe 3D Viewer", | ||
@@ -14,3 +14,3 @@ "main": "dist/index.js", | ||
"lodash.debounce": "^4.0.8", | ||
"twgl.js": "^4.2.0" | ||
"twgl.js": "^4.4.0" | ||
}, | ||
@@ -17,0 +17,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24546
91
Updatedtwgl.js@^4.4.0