Socket
Socket
Sign inDemoInstall

@lumiscaphe/viewer

Package Overview
Dependencies
Maintainers
1
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lumiscaphe/viewer - npm Package Compare versions

Comparing version 1.0.9 to 2.0.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## [Version 2.0.0]
### Breaking changes
- Add `accessory` and `decor` property on scene products to identify accessory and decor databases for WebRender API v1
## [Version 1.0.0]

@@ -2,0 +8,0 @@

2

dist/index.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("lodash.clonedeep"),require("debounce-promise"),require("twgl.js"),require("axios")):"function"==typeof define&&define.amd?define(["lodash.clonedeep","debounce-promise","twgl.js","axios"],e):(t=t||self).LumiscapheViewer=e(t.cloneDeep,t.debounce,t.twgl,t.axios)}(this,function(t,e,i,n){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e;var o="default"in i?i.default:i;n=n&&n.hasOwnProperty("default")?n.default:n;var r=function(){};r.fit=function(t,e,i,n){var o=t.width/t.height,r=e/i,s=0,a=0;switch(n){case"contain":s=r<o?e:i*o,a=r<o?e/o:i;break;case"cover":default:s=r<o?i*o:e,a=r<o?i:e/o;break;case"fill":s=e,a=i}return{width:Math.round(s),height:Math.round(a),top:Math.round((i-a)/2),left:Math.round((e-s)/2)}},r.getStandardAspectRatio=function(t,e){if(0===t||0===e)return 0;var i=t/e;return t<e?Math.abs(.75-i)<Math.abs(9/16-i)?.75:9/16:Math.abs(4/3-i)<Math.abs(16/9-i)?4/3:16/9},r.getStandardQuality=function(t){return t<=240?240:t<=360?360:t<=480?480:t<=720?720:1080},r.getStandardResolution=function(t,e){if(0===t||0===e)return{width:0,height:0};var i=r.getStandardAspectRatio(t,e);if(t<e){var n=r.getStandardQuality(e*i);return{width:Math.round(n),height:Math.round(n/i)}}var o=r.getStandardQuality(t/i);return{width:Math.round(o*i),height:Math.round(o)}};var s=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.backCanvas=document.createElement("canvas"),this.backContext=this.backCanvas.getContext("2d"),this.requestAnimationId=null};s.prototype.show=function(t){t?this.element.style.display="block":this.element.style.opacity=1},s.prototype.hide=function(t){t?this.element.style.display="none":this.element.style.opacity=0},s.prototype.resize=function(t,e,i){var n=r.fit(i,t,e,"cover");this.element.style.width=n.width+"px",this.element.style.height=n.height+"px",this.element.style.top=n.top+"px",this.element.style.left=n.left+"px",i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height,this.backCanvas.width=i.width,this.backCanvas.height=i.height)},s.prototype.load=function(t){var e=this,i=new Image;i.onload=function(){e.draw(i,!1)},i.src=t},s.prototype.draw=function(t,e,i){t&&(this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=null),e?(this.backContext.drawImage(this.element,0,0,this.element.width,this.element.height),this.context.globalAlpha=0,this.fadeLoop(t,i)):(this.context.globalAlpha=1,this.context.drawImage(t,0,0,this.element.width,this.element.height)))},s.prototype.fadeLoop=function(t,e){var i=this;if(this.context.globalAlpha>=1)return cancelAnimationFrame(this.requestAnimationId),void(this.requestAnimationId=null);var n=Math.min(this.context.globalAlpha+e,1);this.context.clearRect(0,0,this.element.width,this.element.height),this.context.globalAlpha=1,this.context.drawImage(this.backCanvas,0,0,this.element.width,this.element.height),this.context.globalAlpha=n,this.context.drawImage(t,0,0,this.element.width,this.element.height),this.requestAnimationId=requestAnimationFrame(function(){i.fadeLoop(t,e)})};var a=function(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity=0,this.context=o.getContext(this.element),o.setDefaultTextureColor([1,1,1,1]),this.requestAnimationId=null};a.prototype.show=function(){this.element.style.opacity=1},a.prototype.hide=function(){this.element.style.opacity=0},a.prototype.resize=function(){this.element.style.width="100%",this.element.style.height="100%",this.element.style.top=0,this.element.style.left=0};var h=function(){};h.accelerate=function(t,e){var i=e||1.5;return Math.pow(Math.abs(t),i)*(t>0?1:-1)},h.degreesToRadians=function(t){return t*(Math.PI/180)},h.radiansToDegrees=function(t){return t*(180/Math.PI)},h.mod=function(t,e){return t-e*Math.floor(t/e)};var c=/directUrl="([^"]*)"/g,d=function(t){this.server=t};d.buildQuery=function(t){return Object.keys(t).filter(function(e){return void 0!==t[e]}).map(function(e){return e+"="+t[e]}).join("&")},d.sceneParameters=function(t){var e=t.scene,i={},n=e.length>1?e.find(function(t){return t.master})||e[0]:null;if(n){var o=e.find(function(t){return t!==n});i.databaseId=o.database,i.configuration=o.configuration,i.decorDatabaseId=n.database,i.decorDeltaAltitude=n.translation.y}else{var r=e[0];i.databaseId=r.database,i.configuration=r.configuration,i.animations=r.animations&&r.animations.length?r.animations.join("/"):void 0}return i},d.renderParameters=function(t){var e=t.parameters;return{width:e.width,height:e.height,softwareAntialiasing:e.antialiasing,superSampling:e.superSampling}},d.encoderParameters=function(t){var e=t.encoder;return{imageFormat:e.format,imageQuality:e.quality}},d.fetch=function(t){return n.get(t).then(function(t){var e=t.data.replace(/&amp;/g,"&").match(c);return e?e.map(function(t){return t.replace(c,"$1")}):Promise.reject()})},d.prototype.animation=function(t){var e={};Object.assign(e,d.sceneParameters(t)),Object.assign(e,{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(e,d.renderParameters(t)),Object.assign(e,d.encoderParameters(t));var i=d.buildQuery(e);return d.fetch(this.server+"/ImagesFromAnimation?"+i)},d.prototype.image=function(t){var e={};Object.assign(e,d.sceneParameters(t)),Object.assign(e,{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],background:t.view.background}),Object.assign(e,d.renderParameters(t)),Object.assign(e,d.encoderParameters(t));var i=d.buildQuery(e);return Promise.resolve(this.server+"/ImageFromBookmark?"+i)},d.prototype.video=function(t){var e={};Object.assign(e,d.sceneParameters(t)),Object.assign(e,{animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],duration:t.view.duration,frames:t.view.frames,loop:!!t.view.loop,reverse:!!t.view.reverse,background:t.view.background}),Object.assign(e,d.renderParameters(t)),Object.assign(e,d.encoderParameters(t));var i=d.buildQuery(e);return Promise.resolve(this.server+"/ImagesFromAnimation?"+i)},d.prototype.vrCube=function(t){var e={};Object.assign(e,d.sceneParameters(t)),Object.assign(e,{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],background:t.view.background}),Object.assign(e,d.renderParameters(t)),Object.assign(e,d.encoderParameters(t)),e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);var i=d.buildQuery(e);return d.fetch(this.server+"/CubeFromBookmark?"+i)},d.prototype.vrObject=function(t){var e={};Object.assign(e,d.sceneParameters(t)),Object.assign(e,{bookmarkSet:t.view.camera,background:t.view.background}),Object.assign(e,d.renderParameters(t)),Object.assign(e,d.encoderParameters(t));var i=d.buildQuery(e);return d.fetch(this.server+"/ImagesFromBookmarkSet?"+i)};var u=function(t,e){this.webrender=new d(t),this.loadingId=0,this.loaded=0,this.total=0,this.onLoadStart=e&&e.onLoadStart?e.onLoadStart:function(){},this.onLoadProgress=e&&e.onLoadProgress?e.onLoadProgress:function(){},this.onLoadEnd=e&&e.onLoadEnd?e.onLoadEnd:function(){}},l={progress:{configurable:!0}};l.progress.get=function(){return this.total?this.loaded/this.total:0},u.prototype.loadImage=function(t,e){var i=this,n=new Image;n.crossOrigin="anonymous";var o=new Promise(function(t,o){n.addEventListener("load",function(){e===i.loadingId&&(i.loaded+=1,i.onLoadProgress(i.progress),t(n))},{once:!0}),n.addEventListener("error",function(t){e===i.loadingId&&o(t)},{once:!0})});return n.src=t,o},u.prototype.loadImageFrames=function(t,e,i,n){var o=this;this.total=t.length;for(var r=new Array(t.length),s=i||0,a=0,c=t.length;a<c;a+=1){var d=Math.ceil(a/2)*(a%2==0?1:-1),u=e?h.mod(s+d,c):a;r[u]=this.loadImage(t[u],n)}return Promise.all(r).then(function(){return o.onLoadEnd(o.progress)}),r},u.prototype.loadVideo=function(t,e,i,n){var o=this;t.loop=i;var r=new Promise(function(e,i){t.addEventListener("canplaythrough",function(){n===o.loadingId&&(o.loaded+=1,o.onLoadProgress(o.progress),e())},{once:!0}),t.addEventListener("error",function(t){n===o.loadingId&&i(t)},{once:!0})});return t.src=e,t.load(),r},u.prototype.loadVideoFrame=function(t,e,i,n,o){var r=this,s=0;return new Promise(function(a,h){var c=function(){if(o===r.loadingId)if(s===n){t.removeEventListener("seeked",c);var h=document.createElement("canvas");h.width=t.videoWidth,h.height=t.videoHeight,h.getContext("2d").drawImage(t,0,0),a(h),r.loaded+=1,r.onLoadProgress(r.progress),n!==i-1&&(t.currentTime+=1/e)}else s+=1};t.addEventListener("seeked",c),t.addEventListener("error",function(t){o===r.loadingId&&h(t)},{once:!0})})},u.prototype.loadVideoFrames=function(t,e,i,n){var o=this;this.total=e;for(var r=new Array(e),s=document.createElement("video"),a=0,h=e;a<h;a+=1)r[a]=this.loadVideoFrame(s,i,e,a,n);return s.addEventListener("canplaythrough",function(){n===o.loadingId&&(s.currentTime=1/i/2)},{once:!0}),s.src=t,s.load(),Promise.all(r).then(function(){return o.onLoadEnd(o.progress)}),r},u.prototype.loadImageSnapshot=function(t){var e=this;this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);var i=this.loadingId;return this.webrender.image(t).then(function(t){return e.loadImage(t,i)}).then(function(t){return e.onLoadEnd(e.progress),t})},u.prototype.loadVideoSnapshot=function(t,e){var i=this;this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);var n=this.loadingId;return this.webrender.video(e).then(function(o){return i.loadVideo(t,o,e.view.loop,n)}).then(function(){return i.onLoadEnd(i.progress),t})},u.prototype.loadVRCubeSnapshot=function(t){var e=this;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);var i=this.loadingId;return this.webrender.vrCube(t).then(function(t){e.total=t.length;var n=t.map(function(t){return e.loadImage(t,i)});return Promise.all(n)}).then(function(t){return e.onLoadEnd(e.progress),t})},u.prototype.loadVRObjectSnapshot=function(t,e){var i=this;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);var n,o=this.loadingId;return n=t.view.animation?"mp4"===t.encoder.format?"video":"animation":"vrObject",this.webrender[n](t).then(function(n){return Array.isArray(n)?i.loadImageFrames(n,t.view.loop,e,o):i.loadVideoFrames(n,t.view.frames,30,o)})},Object.defineProperties(u.prototype,l);var p=function(){this.element=document.createElement("video"),this.element.classList.add("ls-viewer-video"),this.element.style.opacity=0,this.element.setAttribute("muted",""),this.element.setAttribute("playsinline",""),this.element.setAttribute("preload","auto")};p.prototype.show=function(){this.element.style.opacity=1},p.prototype.hide=function(){this.element.style.opacity=0},p.prototype.resize=function(t,e,i){var n=r.fit(i,t,e,"cover");this.element.style.width=n.width+"px",this.element.style.height=n.height+"px",this.element.style.top=n.top+"px",this.element.style.left=n.left+"px",i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height)};var m=function(t,e,i,n){this.container=t,this.canvas=e,this.loader=i,this.options=Object.assign({},n),this.image=null,this.goto=function(){},this.onStart=function(){},this.onEnter=function(){},this.onMove=function(){},this.onEnd=function(){},this.onDeviceOrientation=function(){}};m.prototype.show=function(){this.canvas.show(),this.container.classList.add("ls-viewer-container-image")},m.prototype.hide=function(){this.canvas.hide(),this.container.classList.remove("ls-viewer-container-image")},m.prototype.load=function(t,e,i){var n=this,o=JSON.stringify(t);return o===this.hash?(this.canvas.draw(this.image,i,.05),Promise.resolve()):(this.hash=o,this.loader.loadImageSnapshot(t).then(function(t){n.image=t,n.canvas.draw(n.image,i,.05)}))};var v=function(t,e,i,n){this.container=t,this.loader=i,this.options=Object.assign({},n),this.video=e,this.onStart=function(){},this.onEnter=function(){},this.onMove=function(){},this.onEnd=function(){},this.onDeviceOrientation=function(){}};v.prototype.show=function(){this.video.show(),this.container.classList.add("ls-viewer-container-video")},v.prototype.hide=function(){this.video.hide(),this.container.classList.remove("ls-viewer-container-video")},v.prototype.load=function(t){var e=JSON.stringify(t);return e===this.hash?(this.video.load(),Promise.resolve()):(this.hash=e,this.loader.loadVideoSnapshot(this.video.element,t))},v.prototype.play=function(){var t=this;return new Promise(function(e,i){t.video.element.addEventListener("ended",function(){e()},{once:!0});var n=t.video.element.play();n&&n.catch(function(){i()}),t.show()})};var g=function(){};g.point=function(t){if("touchmove"===t.type||"touchstart"===t.type||"touchend"===t.type){var e=t.targetTouches[0]||t.changedTouches[0];return{x:e.screenX,y:e.screenY}}return{x:t.screenX,y:t.screenY}};var f=function(){for(var t,e=[],n=arguments.length;n--;)e[n]=arguments[n];3===e.length?(t=e,this.u=t[0],this.v=t[1],this.o=t[2],this.w=i.v3.cross(this.u,this.v)):(this.u=[1,0,0],this.v=[0,1,0],this.w=[0,0,1],this.o=[0,0,0])},y={localToGlobalMatrix:{configurable:!0},globalToLocalMatrix:{configurable:!0}};y.localToGlobalMatrix.get=function(){var t=[this.u[0],this.u[1],this.u[2],0],e=[this.v[0],this.v[1],this.v[2],0],i=[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,e,i,n])},y.globalToLocalMatrix.get=function(){return i.m4.inverse(this.localToGlobalMatrix)},Object.defineProperties(f.prototype,y);var w=function(t){this.animationFrameId=null,this.points=[],this.onMotion=t,this.loop=this.loop.bind(this)};w.prototype.track=function(t){var e=Date.now();this.points=this.points.filter(function(t){return e-t.time<=100}),this.points.push({x:t.x,y:t.y,time:e}),this.lastPoint=t},w.prototype.start=function(){if(0!==this.points.length){var t=this.points[0],e=this.points[this.points.length-1],i=e.x-t.x,n=e.y-t.y,o=e.time-t.time;this.velocity={x:0===o?0:i/(o/15),y:0===o?0:n/(o/15)},this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.animationFrameId=requestAnimationFrame(this.loop)}},w.prototype.stop=function(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.points=[]},w.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 b=function(t,e,n){this.isStarted=!1,this.inertia=new w(this.motion.bind(this)),this.pov=t,this.fov=h.degreesToRadians(e),this.orientationMatrix=i.m4.identity(),this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=h.degreesToRadians(window.orientation)||0,this.onMotion=n},E={orientedPov:{configurable:!0}};E.orientedPov.get=function(){var t=i.v3.normalize(i.v3.cross(this.pov.up,this.pov.target)),e=new f(t,[0,1,0],this.pov.eye),n=i.m4.identity();return i.m4.multiply(n,e.localToGlobalMatrix,n),i.m4.multiply(n,this.orientationMatrix,n),i.m4.multiply(n,e.globalToLocalMatrix,n),{eye:Array.from(this.pov.eye),target:Array.from(i.m4.transformDirection(n,this.pov.target)),up:Array.from(i.m4.transformDirection(n,this.pov.up))}},b.prototype.reset=function(){this.pov={eye:Array.from(this.initPov.eye),target:Array.from(this.initPov.target),up:Array.from(this.initPov.up)},this.fov=this.initFov},b.prototype.start=function(t,e){this.isStarted=!0,this.startPov=this.pov,this.startPoint=t,this.startSize=e,this.previousPoint=t,this.inertia.stop()},b.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=h.accelerate(e.x,1.3)/this.startSize.width*.2*Math.PI*1.5,o=h.accelerate(e.y,1.3)/this.startSize.height*.2*Math.PI,r=i.m4.multiply(i.m4.rotationY(-n),i.m4.rotationX(-o)),s=i.v3.normalize(i.v3.cross(this.pov.up,this.pov.target)),a=new f(s,[0,1,0],this.pov.eye),c=i.m4.identity();i.m4.multiply(c,a.localToGlobalMatrix,c),i.m4.multiply(c,r,c),i.m4.multiply(c,a.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=Array.from(d),this.pov.up=Array.from(u)),this.previousPoint={x:t.x,y:t.y},this.onMotion()},b.prototype.end=function(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())},b.prototype.orientation=function(t){if(null!==t.alpha&&null!==t.beta&&null!==t.gamma){var e=h.degreesToRadians(window.orientation)||0,n=h.degreesToRadians(t.alpha),o=h.degreesToRadians(-t.beta),r=h.degreesToRadians(-t.gamma),s=i.m4.rotationX(h.degreesToRadians(90));i.m4.rotateZ(s,this.initOrientation,s),i.m4.rotateZ(s,n,s),i.m4.rotateX(s,o,s),i.m4.rotateY(s,r,s),i.m4.rotateZ(s,-e,s),this.orientationMatrix=s,this.onMotion()}},Object.defineProperties(b.prototype,E);var P=function(t,e,i,n,r){var s=this;this.container=t,this.canvas=e,this.loader=i,this.options=Object.assign({},n);var a={eye:[0,0,0],target:[0,0,1],up:[0,1,0]},c=o.m4.rotationX(h.degreesToRadians(15));o.m4.transformDirection(c,a.target,a.target),o.m4.transformDirection(c,a.up,a.up),this.interaction=new b(a,60,function(){requestAnimationFrame(s.render),s.onInteraction({pov:{eye:[].concat(s.interaction.pov.eye),target:[].concat(s.interaction.pov.target),up:[].concat(s.interaction.pov.up)},fov:s.interaction.fov})}),this.onInteraction=r,this.gl=this.canvas.context,this.programInfo=o.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=o.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_matrix:o.m4.identity(),u_mix:0,u_texture_back:o.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:o.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1})},this.render=this.render.bind(this),this.goto=function(){}},L={pov:{configurable:!0},fov:{configurable:!0}};P.prototype.show=function(){this.canvas.show(),this.container.classList.add("ls-viewer-container-vrcube")},P.prototype.hide=function(){this.canvas.hide(),this.container.classList.remove("ls-viewer-container-vrcube")},L.pov.get=function(){return this.interaction.pov},L.pov.set=function(t){this.interaction.pov.eye.every(function(e,i){return e===t.eye[i]})&&this.interaction.pov.target.every(function(e,i){return e===t.target[i]})&&this.interaction.pov.up.every(function(e,i){return e===t.up[i]})||(this.interaction.pov={eye:[].concat(t.eye),target:[].concat(t.target),up:[].concat(t.up)},requestAnimationFrame(this.render))},L.fov.get=function(){return h.radiansToDegrees(this.interaction.fov)},L.fov.set=function(t){this.interaction.fov!==t&&(this.interaction.fov=h.degreesToRadians(t),requestAnimationFrame(this.render))},P.prototype.load=function(t,e,i){var n=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){o.createTexture(n.gl,{target:n.gl.TEXTURE_CUBE_MAP,minMag:n.gl.LINEAR,auto:!1,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:t},function(t,o){t||(e&&n.interaction.reset(),n.uniforms.u_mix=i?0:1,n.uniforms.u_texture_back=n.uniforms.u_texture,n.uniforms.u_texture=o,requestAnimationFrame(n.render))})}))},P.prototype.render=function(){o.resizeCanvasToDisplaySize(this.gl.canvas,window.devicePixelRatio),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);var t=this.gl.canvas.clientWidth,e=this.gl.canvas.clientHeight,i=r.getStandardAspectRatio(t,e),n=t/e,s=this.interaction.fov*(i/n),a=o.m4.inverse(o.m4.perspective(s,n,.5,100)),h=this.interaction.orientedPov,c=o.m4.lookAt(h.eye,h.target,h.up);this.uniforms.u_matrix=o.m4.multiply(c,a),this.gl.useProgram(this.programInfo.program),o.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),o.setUniforms(this.programInfo,this.uniforms),o.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))},P.prototype.onStart=function(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(g.point(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})},P.prototype.onEnter=function(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(g.point(t),!1))},P.prototype.onMove=function(t){this.interaction.isStarted&&(this.interaction.motion(g.point(t)),t.preventDefault())},P.prototype.onEnd=function(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(g.point(t),!0))},P.prototype.onDeviceOrientation=function(t){this.interaction.orientation({alpha:t.alpha,beta:t.beta,gamma:t.gamma})},Object.defineProperties(P.prototype,L);var x=function(t,e,i,n){this.isStarted=!1,this.inertia=new w(this.motion.bind(this)),this.position=t,this.count=e,this.loop=i,this.onMotion=n,this.initPosition=this.position};x.prototype.reset=function(){this.position=this.initPosition},x.prototype.start=function(t,e){this.isStarted=!0,this.startPosition=this.position,this.startPoint=t,this.startSize=e,this.inertia.stop()},x.prototype.motion=function(t){this.isStarted&&this.inertia.track(t);var e={x:t.x-this.startPoint.x,y:t.y-this.startPoint.y},i=h.accelerate(e.x,1.3)/this.startSize.width*(this.count/4),n=this.startPosition-Math.round(i);(n=this.loop?h.mod(n,this.count):Math.max(0,Math.min(n,this.count-1)))!==this.position&&(this.position=n,this.onMotion())},x.prototype.end=function(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())};var I=function(t,e,i,n,o){var r=this;this.container=t,this.canvas=e,this.loader=i,this.options=Object.assign({},{loop:!0},n),this.images=[],this.interaction=new x(0,1,!1,function(){r.canvas.draw(r.image,!0,.5),r.onInteraction({position:r.interaction.position})}),this.onDeviceOrientation=function(){},this.onInteraction=o},A={position:{configurable:!0},image:{configurable:!0}};I.prototype.show=function(){this.canvas.show(),this.container.classList.add("ls-viewer-container-vrobject")},I.prototype.hide=function(){this.canvas.hide(),this.container.classList.remove("ls-viewer-container-vrobject")},A.position.get=function(){return this.interaction.position},A.position.set=function(t){this.interaction.position!==t&&(this.interaction.loop?this.interaction.position=h.mod(t,this.interaction.count):this.interaction.position=Math.max(0,Math.min(t,this.interaction.count-1)),this.canvas.draw(this.image,!0,.5))},I.prototype.goto=function(t){var e=this;return new Promise(function(i){var n=e.interaction.position,o=function(){if(e.interaction.position===t)i();else{var r=n>t?-1:1;e.interaction.loop&&e.interaction.count-n+t<Math.abs(t-n)&&(r*=-1),n+=.5*r,e.position=Math.floor(n),requestAnimationFrame(o)}};requestAnimationFrame(o)})},A.image.get=function(){return this.images[this.interaction.position]},I.prototype.load=function(t,e,i){var n=this,o=JSON.stringify(t);if(o===this.hash)return this.canvas.draw(this.image,i,.05),Promise.resolve();this.hash=o,this.images=[],e&&this.interaction.reset();var r=this.interaction.position;return this.loader.loadVRObjectSnapshot(t,r).then(function(e){var o=e.length;return n.images=new Array(o),n.interaction.count=o,n.interaction.loop=!!t.view.loop,e.forEach(function(t,e){t.then(function(t){n.images[e]=t,t===n.image&&n.canvas.draw(n.image,i,.05)})}),e[n.interaction.position]})},I.prototype.onStart=function(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(g.point(t),{width:this.canvas.element.width,height:this.canvas.element.height})},I.prototype.onEnter=function(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(g.point(t),!1))},I.prototype.onMove=function(t){this.interaction.isStarted&&(this.interaction.motion(g.point(t)),t.preventDefault())},I.prototype.onEnd=function(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(g.point(t),!0))},Object.defineProperties(I.prototype,A);!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===i&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=t:o.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,.ls-viewer-container-video{cursor:default;pointer-events:none}.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;opacity:0;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");var S=function(t,i){this.checkResize=this.checkResize.bind(this),this.onDeviceOrientation=this.onDeviceOrientation.bind(this),this.onResize=this.onResize.bind(this),this.onStart=this.onStart.bind(this),this.onEnter=this.onEnter.bind(this),this.onMove=this.onMove.bind(this),this.onEnd=this.onEnd.bind(this),this.onLoadStart=this.onLoadStart.bind(this),this.onLoadProgress=this.onLoadProgress.bind(this),this.onLoadEnd=this.onLoadEnd.bind(this),this.onLoadError=this.onLoadError.bind(this),this.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options=Object.assign({},{server:"localhost",image:{},video:{},vrcube:{},vrobject:{}},i),this.options.events=Object.assign({},{onLoadStart:function(){},onLoadProgress:function(){},onLoadEnd:function(){},onLoadError:function(){},onInteraction:function(){},onVrcubeInteraction:function(){},onVrobjectInteraction:function(){}},i.events),this.options.events.onLoadError=e(this.options.events.onLoadError,10),this.container=t,this.container.classList.add("ls-viewer-container"),this.canvas2D=new s,this.container.appendChild(this.canvas2D.element),this.canvas3D=new a,this.container.appendChild(this.canvas3D.element),this.video=new p,this.container.appendChild(this.video.element),this.loader=new u(i.server,this),this.resolution={width:0,height:0},this.scene=null,this.view=null,this.parameters={antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.widgets={image:new m(t,this.canvas2D,this.loader,this.options.image),video:new v(t,this.video,this.loader,this.options.video),vrcube:new P(t,this.canvas3D,this.loader,this.options.vrcube,this.onVrcubeInteraction),vrobject:new I(t,this.canvas2D,this.loader,this.options.vrobject,this.onVrobjectInteraction)},this.widget=this.widgets.image,this.container.addEventListener("mousedown",this.onStart),this.container.addEventListener("mouseenter",this.onEnter),this.container.addEventListener("touchstart",this.onStart),document.addEventListener("mousemove",this.onMove),document.addEventListener("mouseup",this.onEnd),document.addEventListener("touchmove",this.onMove),document.addEventListener("touchend",this.onEnd),window.addEventListener("deviceorientation",this.onDeviceOrientation),this.checkResize(),this.loadWidget=e(this.loadWidget,10),this.onResize=e(this.onResize,250)};return S.prototype.destroy=function(){this.container.removeEventListener("mousedown",this.onStart),this.container.removeEventListener("mouseenter",this.onEnter),this.container.removeEventListener("touchstart",this.onStart),document.removeEventListener("mousemove",this.onMove),document.removeEventListener("mouseup",this.onEnd),document.removeEventListener("touchmove",this.onMove),document.removeEventListener("touchend",this.onEnd),window.removeEventListener("deviceorientation",this.onDeviceOrientation),this.isDestroyed=!0},S.prototype.load=function(e,i){var n=this,o=Promise.resolve();i&&void 0!==i.animation&&(o=o.then(function(){return n.loadAnimation(i.animation)})),this.view&&i&&void 0!==i.position&&(o=o.then(function(){return n.widgets[n.view.mode].goto(i.position)})),i&&void 0!==i.animation&&(o=o.then(function(){return n.widgets.video.play()})),(o=o.then(function(){return n.scene=Array.isArray(e)?t(e):[t(e)],n.loadWidget(!1,!(i&&i.animation))})).catch(function(t){n.onLoadError(t)})},S.prototype.setEncoder=function(e){var i=this;this.encoder=t(e);var n=Promise.resolve();(n=n.then(function(){return i.loadWidget(!1,!0)})).catch(function(t){i.onLoadError(t)})},S.prototype.setParameters=function(e){var i=this;this.parameters=t(e),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height;var n=Promise.resolve();(n=n.then(function(){return i.loadWidget(!1,!0)})).catch(function(t){i.onLoadError(t)})},S.prototype.setView=function(e,i){var n=this,o=Promise.resolve();i&&void 0!==i.animation&&(o=o.then(function(){return n.loadAnimation(i.animation)})),this.view&&i&&void 0!==i.fromPosition&&(o=o.then(function(){return n.widgets[n.view.mode].goto(i.fromPosition)})),i&&void 0!==i.animation&&(o=o.then(function(){return n.widgets.video.play()})),(o=o.then(function(){var o=!0;return n.view=t(e),n.view&&i&&void 0!==i.toPosition&&(o=!1,n.widgets[n.view.mode].position=i.toPosition),n.loadWidget(o,!(i&&i.animation))})).catch(function(t){n.onLoadError(t)})},S.prototype.setVrcube=function(t){Object.assign(this.widgets.vrcube,t)},S.prototype.setVrobject=function(t){Object.assign(this.widgets.vrobject,t)},S.prototype.loadAnimation=function(t){var e=this,i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return i.view.background||(i.view.background="product"),this.widgets.video.load(i).catch(function(t){e.onLoadError(t)})},S.prototype.playAnimation=function(t){var e=this;return this.loadAnimation(t).then(function(){return e.widgets.video.play()})},S.prototype.stopAnimation=function(){this.widgets.video.hide()},S.prototype.loadWidget=function(t,e){var i=this;if(!this.scene||!this.view)return Promise.resolve();if(!this.parameters.width||!this.parameters.height)return Promise.resolve();var n=this.widgets[this.view.mode];if(!n)return Promise.reject(new Error("Unknown view mode"));var o={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return o.view.background||(o.view.background="product"),n.load(o,t,e).then(function(){i.widget.hide(),i.widget=n,i.widget.show(),i.widgets.video.hide()})},S.prototype.checkResize=function(){if(!this.isDestroyed){var t=this.container.offsetWidth,e=this.container.offsetHeight;t===this.containerWidth&&e===this.containerHeight||(this.containerWidth=t,this.containerHeight=e,this.onResize()),this.isDestroyed||requestAnimationFrame(this.checkResize)}},S.prototype.onStart=function(t){this.widget.onStart(t)},S.prototype.onEnter=function(t){this.widget.onEnter(t)},S.prototype.onMove=function(t){this.widget.onMove(t)},S.prototype.onEnd=function(t){this.widget.onEnd(t)},S.prototype.onDeviceOrientation=function(t){this.widget.onDeviceOrientation(t)},S.prototype.onResize=function(){var t=this,e=window.devicePixelRatio,i=this.container.offsetWidth*e,n=this.container.offsetHeight*e;this.resolution=r.getStandardResolution(i,n),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height,this.canvas2D.resize(i/e,n/e,this.resolution),this.canvas3D.resize(i/e,n/e,this.resolution),this.video.resize(i/e,n/e,this.resolution),this.loadWidget(!1,!1).catch(function(e){t.onLoadError(e)})},S.prototype.onVrcubeInteraction=function(){for(var t,e,i=[],n=arguments.length;n--;)i[n]=arguments[n];(t=this.options.events).onInteraction.apply(t,i),(e=this.options.events).onVrcubeInteraction.apply(e,i)},S.prototype.onVrobjectInteraction=function(){for(var t,e,i=[],n=arguments.length;n--;)i[n]=arguments[n];(t=this.options.events).onInteraction.apply(t,i),(e=this.options.events).onVrobjectInteraction.apply(e,i)},S.prototype.onLoadStart=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];this.container.classList.add("ls-viewer-container-loading"),(t=this.options.events).onLoadStart.apply(t,e)},S.prototype.onLoadProgress=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];(t=this.options.events).onLoadProgress.apply(t,e)},S.prototype.onLoadEnd=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];this.container.classList.remove("ls-viewer-container-loading"),(t=this.options.events).onLoadEnd.apply(t,e)},S.prototype.onLoadError=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];this.container.classList.remove("ls-viewer-container-loading"),(t=this.options.events).onLoadError.apply(t,e)},S});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("lodash.clonedeep"),require("debounce-promise"),require("twgl.js"),require("axios")):"function"==typeof define&&define.amd?define(["lodash.clonedeep","debounce-promise","twgl.js","axios"],e):(t=t||self).LumiscapheViewer=e(t.cloneDeep,t.debounce,t.twgl,t.axios)}(this,(function(t,e,i,n){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e;var o="default"in i?i.default:i;n=n&&n.hasOwnProperty("default")?n.default:n;var r=function(){};r.fit=function(t,e,i,n){var o=t.width/t.height,r=e/i,s=0,a=0;switch(n){case"contain":s=r<o?e:i*o,a=r<o?e/o:i;break;case"cover":default:s=r<o?i*o:e,a=r<o?i:e/o;break;case"fill":s=e,a=i}return{width:Math.round(s),height:Math.round(a),top:Math.round((i-a)/2),left:Math.round((e-s)/2)}},r.getStandardAspectRatio=function(t,e){if(0===t||0===e)return 0;var i=t/e;return t<e?Math.abs(.75-i)<Math.abs(9/16-i)?.75:9/16:Math.abs(4/3-i)<Math.abs(16/9-i)?4/3:16/9},r.getStandardQuality=function(t){return t<=240?240:t<=360?360:t<=480?480:t<=720?720:1080},r.getStandardResolution=function(t,e){if(0===t||0===e)return{width:0,height:0};var i=r.getStandardAspectRatio(t,e);if(t<e){var n=r.getStandardQuality(e*i);return{width:Math.round(n),height:Math.round(n/i)}}var o=r.getStandardQuality(t/i);return{width:Math.round(o*i),height:Math.round(o)}};var s=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.backCanvas=document.createElement("canvas"),this.backContext=this.backCanvas.getContext("2d"),this.requestAnimationId=null};s.prototype.show=function(t){t?this.element.style.display="block":this.element.style.opacity=1},s.prototype.hide=function(t){t?this.element.style.display="none":this.element.style.opacity=0},s.prototype.resize=function(t,e,i){var n=r.fit(i,t,e,"cover");this.element.style.width=n.width+"px",this.element.style.height=n.height+"px",this.element.style.top=n.top+"px",this.element.style.left=n.left+"px",i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height,this.backCanvas.width=i.width,this.backCanvas.height=i.height)},s.prototype.load=function(t){var e=this,i=new Image;i.onload=function(){e.draw(i,!1)},i.src=t},s.prototype.draw=function(t,e,i){t&&(this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=null),e?(this.backContext.drawImage(this.element,0,0,this.element.width,this.element.height),this.context.globalAlpha=0,this.fadeLoop(t,i)):(this.context.globalAlpha=1,this.context.drawImage(t,0,0,this.element.width,this.element.height)))},s.prototype.fadeLoop=function(t,e){var i=this;if(this.context.globalAlpha>=1)return cancelAnimationFrame(this.requestAnimationId),void(this.requestAnimationId=null);var n=Math.min(this.context.globalAlpha+e,1);this.context.clearRect(0,0,this.element.width,this.element.height),this.context.globalAlpha=1,this.context.drawImage(this.backCanvas,0,0,this.element.width,this.element.height),this.context.globalAlpha=n,this.context.drawImage(t,0,0,this.element.width,this.element.height),this.requestAnimationId=requestAnimationFrame((function(){i.fadeLoop(t,e)}))};var a=function(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity=0,this.context=o.getContext(this.element),o.setDefaultTextureColor([1,1,1,1]),this.requestAnimationId=null};a.prototype.show=function(){this.element.style.opacity=1},a.prototype.hide=function(){this.element.style.opacity=0},a.prototype.resize=function(){this.element.style.width="100%",this.element.style.height="100%",this.element.style.top=0,this.element.style.left=0};var h=function(){};h.accelerate=function(t,e){var i=e||1.5;return Math.pow(Math.abs(t),i)*(t>0?1:-1)},h.degreesToRadians=function(t){return t*(Math.PI/180)},h.radiansToDegrees=function(t){return t*(180/Math.PI)},h.mod=function(t,e){return t-e*Math.floor(t/e)};var c=/directUrl="([^"]*)"/g,d=function(t){this.server=t};d.buildQuery=function(t){return Object.keys(t).filter((function(e){return void 0!==t[e]})).map((function(e){return e+"="+t[e]})).join("&")},d.sceneParameters=function(t){var e=t.scene,i=e.length>1?e.find((function(t){return t.accessory})):null,n=e.length>1?e.find((function(t){return t.decor})):null,o=e.find((function(t){return t!==i&&t!==n})),r={databaseId:o.database};return o.configuration&&(r.configuration=o.configuration),o.animations&&o.animations.length&&(r.animations=o.animations.join("/")),i&&(r.accessoryDatabaseId=i.database),n&&(r.decorDatabaseId=n.database,r.decorDeltaAltitude=n.translation.y),r},d.renderParameters=function(t){var e=t.parameters;return{width:e.width,height:e.height,softwareAntialiasing:e.antialiasing,superSampling:e.superSampling}},d.encoderParameters=function(t){var e=t.encoder;return{imageFormat:e.format,imageQuality:e.quality}},d.fetch=function(t){return n.get(t).then((function(t){var e=t.data.replace(/&amp;/g,"&").match(c);return e?e.map((function(t){return t.replace(c,"$1")})):Promise.reject()}))},d.prototype.animation=function(t){var e={};Object.assign(e,d.sceneParameters(t)),Object.assign(e,{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(e,d.renderParameters(t)),Object.assign(e,d.encoderParameters(t));var i=d.buildQuery(e);return d.fetch(this.server+"/ImagesFromAnimation?"+i)},d.prototype.image=function(t){var e={};Object.assign(e,d.sceneParameters(t)),Object.assign(e,{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],background:t.view.background}),Object.assign(e,d.renderParameters(t)),Object.assign(e,d.encoderParameters(t));var i=d.buildQuery(e);return Promise.resolve(this.server+"/ImageFromBookmark?"+i)},d.prototype.video=function(t){var e={};Object.assign(e,d.sceneParameters(t)),Object.assign(e,{animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],duration:t.view.duration,frames:t.view.frames,loop:!!t.view.loop,reverse:!!t.view.reverse,background:t.view.background}),Object.assign(e,d.renderParameters(t)),Object.assign(e,d.encoderParameters(t));var i=d.buildQuery(e);return Promise.resolve(this.server+"/ImagesFromAnimation?"+i)},d.prototype.vrCube=function(t){var e={};Object.assign(e,d.sceneParameters(t)),Object.assign(e,{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],background:t.view.background}),Object.assign(e,d.renderParameters(t)),Object.assign(e,d.encoderParameters(t)),e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);var i=d.buildQuery(e);return d.fetch(this.server+"/CubeFromBookmark?"+i)},d.prototype.vrObject=function(t){var e={};Object.assign(e,d.sceneParameters(t)),Object.assign(e,{bookmarkSet:t.view.camera,background:t.view.background}),Object.assign(e,d.renderParameters(t)),Object.assign(e,d.encoderParameters(t));var i=d.buildQuery(e);return d.fetch(this.server+"/ImagesFromBookmarkSet?"+i)};var u=function(t,e){this.webrender=new d(t),this.loadingId=0,this.loaded=0,this.total=0,this.onLoadStart=e&&e.onLoadStart?e.onLoadStart:function(){},this.onLoadProgress=e&&e.onLoadProgress?e.onLoadProgress:function(){},this.onLoadEnd=e&&e.onLoadEnd?e.onLoadEnd:function(){}},l={progress:{configurable:!0}};l.progress.get=function(){return this.total?this.loaded/this.total:0},u.prototype.loadImage=function(t,e){var i=this,n=new Image;n.crossOrigin="anonymous";var o=new Promise((function(t,o){n.addEventListener("load",(function(){e===i.loadingId&&(i.loaded+=1,i.onLoadProgress(i.progress),t(n))}),{once:!0}),n.addEventListener("error",(function(t){e===i.loadingId&&o(t)}),{once:!0})}));return n.src=t,o},u.prototype.loadImageFrames=function(t,e,i,n){var o=this;this.total=t.length;for(var r=new Array(t.length),s=i||0,a=0,c=t.length;a<c;a+=1){var d=Math.ceil(a/2)*(a%2==0?1:-1),u=e?h.mod(s+d,c):a;r[u]=this.loadImage(t[u],n)}return Promise.all(r).then((function(){return o.onLoadEnd(o.progress)})),r},u.prototype.loadVideo=function(t,e,i,n){var o=this;t.loop=i;var r=new Promise((function(e,i){t.addEventListener("canplaythrough",(function(){n===o.loadingId&&(o.loaded+=1,o.onLoadProgress(o.progress),e())}),{once:!0}),t.addEventListener("error",(function(t){n===o.loadingId&&i(t)}),{once:!0})}));return t.src=e,t.load(),r},u.prototype.loadVideoFrame=function(t,e,i,n,o){var r=this,s=0;return new Promise((function(a,h){var c=function(){if(o===r.loadingId)if(s===n){t.removeEventListener("seeked",c);var h=document.createElement("canvas");h.width=t.videoWidth,h.height=t.videoHeight,h.getContext("2d").drawImage(t,0,0),a(h),r.loaded+=1,r.onLoadProgress(r.progress),n!==i-1&&(t.currentTime+=1/e)}else s+=1};t.addEventListener("seeked",c),t.addEventListener("error",(function(t){o===r.loadingId&&h(t)}),{once:!0})}))},u.prototype.loadVideoFrames=function(t,e,i,n){var o=this;this.total=e;for(var r=new Array(e),s=document.createElement("video"),a=0,h=e;a<h;a+=1)r[a]=this.loadVideoFrame(s,i,e,a,n);return s.addEventListener("canplaythrough",(function(){n===o.loadingId&&(s.currentTime=1/i/2)}),{once:!0}),s.src=t,s.load(),Promise.all(r).then((function(){return o.onLoadEnd(o.progress)})),r},u.prototype.loadImageSnapshot=function(t){var e=this;this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);var i=this.loadingId;return this.webrender.image(t).then((function(t){return e.loadImage(t,i)})).then((function(t){return e.onLoadEnd(e.progress),t}))},u.prototype.loadVideoSnapshot=function(t,e){var i=this;this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);var n=this.loadingId;return this.webrender.video(e).then((function(o){return i.loadVideo(t,o,e.view.loop,n)})).then((function(){return i.onLoadEnd(i.progress),t}))},u.prototype.loadVRCubeSnapshot=function(t){var e=this;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);var i=this.loadingId;return this.webrender.vrCube(t).then((function(t){e.total=t.length;var n=t.map((function(t){return e.loadImage(t,i)}));return Promise.all(n)})).then((function(t){return e.onLoadEnd(e.progress),t}))},u.prototype.loadVRObjectSnapshot=function(t,e){var i=this;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);var n,o=this.loadingId;return n=t.view.animation?"mp4"===t.encoder.format?"video":"animation":"vrObject",this.webrender[n](t).then((function(n){return Array.isArray(n)?i.loadImageFrames(n,t.view.loop,e,o):i.loadVideoFrames(n,t.view.frames,30,o)}))},Object.defineProperties(u.prototype,l);var p=function(){this.element=document.createElement("video"),this.element.classList.add("ls-viewer-video"),this.element.style.opacity=0,this.element.setAttribute("muted",""),this.element.setAttribute("playsinline",""),this.element.setAttribute("preload","auto")};p.prototype.show=function(){this.element.style.opacity=1},p.prototype.hide=function(){this.element.style.opacity=0},p.prototype.resize=function(t,e,i){var n=r.fit(i,t,e,"cover");this.element.style.width=n.width+"px",this.element.style.height=n.height+"px",this.element.style.top=n.top+"px",this.element.style.left=n.left+"px",i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height)};var m=function(t,e,i,n){this.container=t,this.canvas=e,this.loader=i,this.options=Object.assign({},n),this.image=null,this.goto=function(){},this.onStart=function(){},this.onEnter=function(){},this.onMove=function(){},this.onEnd=function(){},this.onDeviceOrientation=function(){}};m.prototype.show=function(){this.canvas.show(),this.container.classList.add("ls-viewer-container-image")},m.prototype.hide=function(){this.canvas.hide(),this.container.classList.remove("ls-viewer-container-image")},m.prototype.load=function(t,e,i){var n=this,o=JSON.stringify(t);return o===this.hash?(this.canvas.draw(this.image,i,.05),Promise.resolve()):(this.hash=o,this.loader.loadImageSnapshot(t).then((function(t){n.image=t,n.canvas.draw(n.image,i,.05)})))};var v=function(t,e,i,n){this.container=t,this.loader=i,this.options=Object.assign({},n),this.video=e,this.onStart=function(){},this.onEnter=function(){},this.onMove=function(){},this.onEnd=function(){},this.onDeviceOrientation=function(){}};v.prototype.show=function(){this.video.show(),this.container.classList.add("ls-viewer-container-video")},v.prototype.hide=function(){this.video.hide(),this.container.classList.remove("ls-viewer-container-video")},v.prototype.load=function(t){var e=JSON.stringify(t);return e===this.hash?(this.video.load(),Promise.resolve()):(this.hash=e,this.loader.loadVideoSnapshot(this.video.element,t))},v.prototype.play=function(){var t=this;return new Promise((function(e,i){t.video.element.addEventListener("ended",(function(){e()}),{once:!0});var n=t.video.element.play();n&&n.catch((function(){i()})),t.show()}))};var g=function(){};g.point=function(t){if("touchmove"===t.type||"touchstart"===t.type||"touchend"===t.type){var e=t.targetTouches[0]||t.changedTouches[0];return{x:e.screenX,y:e.screenY}}return{x:t.screenX,y:t.screenY}};var f=function(){for(var t,e=[],n=arguments.length;n--;)e[n]=arguments[n];3===e.length?(t=e,this.u=t[0],this.v=t[1],this.o=t[2],this.w=i.v3.cross(this.u,this.v)):(this.u=[1,0,0],this.v=[0,1,0],this.w=[0,0,1],this.o=[0,0,0])},y={localToGlobalMatrix:{configurable:!0},globalToLocalMatrix:{configurable:!0}};y.localToGlobalMatrix.get=function(){var t=[this.u[0],this.u[1],this.u[2],0],e=[this.v[0],this.v[1],this.v[2],0],i=[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,e,i,n])},y.globalToLocalMatrix.get=function(){return i.m4.inverse(this.localToGlobalMatrix)},Object.defineProperties(f.prototype,y);var w=function(t){this.animationFrameId=null,this.points=[],this.onMotion=t,this.loop=this.loop.bind(this)};w.prototype.track=function(t){var e=Date.now();this.points=this.points.filter((function(t){return e-t.time<=100})),this.points.push({x:t.x,y:t.y,time:e}),this.lastPoint=t},w.prototype.start=function(){if(0!==this.points.length){var t=this.points[0],e=this.points[this.points.length-1],i=e.x-t.x,n=e.y-t.y,o=e.time-t.time;this.velocity={x:0===o?0:i/(o/15),y:0===o?0:n/(o/15)},this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.animationFrameId=requestAnimationFrame(this.loop)}},w.prototype.stop=function(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.points=[]},w.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 b=function(t,e,n){this.isStarted=!1,this.inertia=new w(this.motion.bind(this)),this.pov=t,this.fov=h.degreesToRadians(e),this.orientationMatrix=i.m4.identity(),this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=h.degreesToRadians(window.orientation)||0,this.onMotion=n},E={orientedPov:{configurable:!0}};E.orientedPov.get=function(){var t=i.v3.normalize(i.v3.cross(this.pov.up,this.pov.target)),e=new f(t,[0,1,0],this.pov.eye),n=i.m4.identity();return i.m4.multiply(n,e.localToGlobalMatrix,n),i.m4.multiply(n,this.orientationMatrix,n),i.m4.multiply(n,e.globalToLocalMatrix,n),{eye:Array.from(this.pov.eye),target:Array.from(i.m4.transformDirection(n,this.pov.target)),up:Array.from(i.m4.transformDirection(n,this.pov.up))}},b.prototype.reset=function(){this.pov={eye:Array.from(this.initPov.eye),target:Array.from(this.initPov.target),up:Array.from(this.initPov.up)},this.fov=this.initFov},b.prototype.start=function(t,e){this.isStarted=!0,this.startPov=this.pov,this.startPoint=t,this.startSize=e,this.previousPoint=t,this.inertia.stop()},b.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=h.accelerate(e.x,1.3)/this.startSize.width*.2*Math.PI*1.5,o=h.accelerate(e.y,1.3)/this.startSize.height*.2*Math.PI,r=i.m4.multiply(i.m4.rotationY(-n),i.m4.rotationX(-o)),s=i.v3.normalize(i.v3.cross(this.pov.up,this.pov.target)),a=new f(s,[0,1,0],this.pov.eye),c=i.m4.identity();i.m4.multiply(c,a.localToGlobalMatrix,c),i.m4.multiply(c,r,c),i.m4.multiply(c,a.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=Array.from(d),this.pov.up=Array.from(u)),this.previousPoint={x:t.x,y:t.y},this.onMotion()},b.prototype.end=function(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())},b.prototype.orientation=function(t){if(null!==t.alpha&&null!==t.beta&&null!==t.gamma){var e=h.degreesToRadians(window.orientation)||0,n=h.degreesToRadians(t.alpha),o=h.degreesToRadians(-t.beta),r=h.degreesToRadians(-t.gamma),s=i.m4.rotationX(h.degreesToRadians(90));i.m4.rotateZ(s,this.initOrientation,s),i.m4.rotateZ(s,n,s),i.m4.rotateX(s,o,s),i.m4.rotateY(s,r,s),i.m4.rotateZ(s,-e,s),this.orientationMatrix=s,this.onMotion()}},Object.defineProperties(b.prototype,E);var P=function(t,e,i,n,r){var s=this;this.container=t,this.canvas=e,this.loader=i,this.options=Object.assign({},n);var a={eye:[0,0,0],target:[0,0,1],up:[0,1,0]},c=o.m4.rotationX(h.degreesToRadians(15));o.m4.transformDirection(c,a.target,a.target),o.m4.transformDirection(c,a.up,a.up),this.interaction=new b(a,60,(function(){requestAnimationFrame(s.render),s.onInteraction({pov:{eye:[].concat(s.interaction.pov.eye),target:[].concat(s.interaction.pov.target),up:[].concat(s.interaction.pov.up)},fov:s.interaction.fov})})),this.onInteraction=r,this.gl=this.canvas.context,this.programInfo=o.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=o.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_matrix:o.m4.identity(),u_mix:0,u_texture_back:o.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:o.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1})},this.render=this.render.bind(this),this.goto=function(){}},L={pov:{configurable:!0},fov:{configurable:!0}};P.prototype.show=function(){this.canvas.show(),this.container.classList.add("ls-viewer-container-vrcube")},P.prototype.hide=function(){this.canvas.hide(),this.container.classList.remove("ls-viewer-container-vrcube")},L.pov.get=function(){return this.interaction.pov},L.pov.set=function(t){this.interaction.pov.eye.every((function(e,i){return e===t.eye[i]}))&&this.interaction.pov.target.every((function(e,i){return e===t.target[i]}))&&this.interaction.pov.up.every((function(e,i){return e===t.up[i]}))||(this.interaction.pov={eye:[].concat(t.eye),target:[].concat(t.target),up:[].concat(t.up)},requestAnimationFrame(this.render))},L.fov.get=function(){return h.radiansToDegrees(this.interaction.fov)},L.fov.set=function(t){this.interaction.fov!==t&&(this.interaction.fov=h.degreesToRadians(t),requestAnimationFrame(this.render))},P.prototype.load=function(t,e,i){var n=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){o.createTexture(n.gl,{target:n.gl.TEXTURE_CUBE_MAP,minMag:n.gl.LINEAR,auto:!1,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:t},(function(t,o){t||(e&&n.interaction.reset(),n.uniforms.u_mix=i?0:1,n.uniforms.u_texture_back=n.uniforms.u_texture,n.uniforms.u_texture=o,requestAnimationFrame(n.render))}))})))},P.prototype.render=function(){o.resizeCanvasToDisplaySize(this.gl.canvas,window.devicePixelRatio),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);var t=this.gl.canvas.clientWidth,e=this.gl.canvas.clientHeight,i=r.getStandardAspectRatio(t,e),n=t/e,s=this.interaction.fov*(i/n),a=o.m4.inverse(o.m4.perspective(s,n,.5,100)),h=this.interaction.orientedPov,c=o.m4.lookAt(h.eye,h.target,h.up);this.uniforms.u_matrix=o.m4.multiply(c,a),this.gl.useProgram(this.programInfo.program),o.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),o.setUniforms(this.programInfo,this.uniforms),o.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))},P.prototype.onStart=function(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(g.point(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})},P.prototype.onEnter=function(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(g.point(t),!1))},P.prototype.onMove=function(t){this.interaction.isStarted&&(this.interaction.motion(g.point(t)),t.preventDefault())},P.prototype.onEnd=function(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(g.point(t),!0))},P.prototype.onDeviceOrientation=function(t){this.interaction.orientation({alpha:t.alpha,beta:t.beta,gamma:t.gamma})},Object.defineProperties(P.prototype,L);var x=function(t,e,i,n){this.isStarted=!1,this.inertia=new w(this.motion.bind(this)),this.position=t,this.count=e,this.loop=i,this.onMotion=n,this.initPosition=this.position};x.prototype.reset=function(){this.position=this.initPosition},x.prototype.start=function(t,e){this.isStarted=!0,this.startPosition=this.position,this.startPoint=t,this.startSize=e,this.inertia.stop()},x.prototype.motion=function(t){this.isStarted&&this.inertia.track(t);var e={x:t.x-this.startPoint.x,y:t.y-this.startPoint.y},i=h.accelerate(e.x,1.3)/this.startSize.width*(this.count/4),n=this.startPosition-Math.round(i);(n=this.loop?h.mod(n,this.count):Math.max(0,Math.min(n,this.count-1)))!==this.position&&(this.position=n,this.onMotion())},x.prototype.end=function(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())};var I=function(t,e,i,n,o){var r=this;this.container=t,this.canvas=e,this.loader=i,this.options=Object.assign({},{loop:!0},n),this.images=[],this.interaction=new x(0,1,!1,(function(){r.canvas.draw(r.image,!0,.5),r.onInteraction({position:r.interaction.position})})),this.onDeviceOrientation=function(){},this.onInteraction=o},A={position:{configurable:!0},image:{configurable:!0}};I.prototype.show=function(){this.canvas.show(),this.container.classList.add("ls-viewer-container-vrobject")},I.prototype.hide=function(){this.canvas.hide(),this.container.classList.remove("ls-viewer-container-vrobject")},A.position.get=function(){return this.interaction.position},A.position.set=function(t){this.interaction.position!==t&&(this.interaction.loop?this.interaction.position=h.mod(t,this.interaction.count):this.interaction.position=Math.max(0,Math.min(t,this.interaction.count-1)),this.canvas.draw(this.image,!0,.5))},I.prototype.goto=function(t){var e=this;return new Promise((function(i){var n=e.interaction.position,o=function(){if(e.interaction.position===t)i();else{var r=n>t?-1:1;e.interaction.loop&&e.interaction.count-n+t<Math.abs(t-n)&&(r*=-1),n+=.5*r,e.position=Math.floor(n),requestAnimationFrame(o)}};requestAnimationFrame(o)}))},A.image.get=function(){return this.images[this.interaction.position]},I.prototype.load=function(t,e,i){var n=this,o=JSON.stringify(t);if(o===this.hash)return this.canvas.draw(this.image,i,.05),Promise.resolve();this.hash=o,this.images=[],e&&this.interaction.reset();var r=this.interaction.position;return this.loader.loadVRObjectSnapshot(t,r).then((function(e){var o=e.length;return n.images=new Array(o),n.interaction.count=o,n.interaction.loop=!!t.view.loop,e.forEach((function(t,e){t.then((function(t){n.images[e]=t,t===n.image&&n.canvas.draw(n.image,i,.05)}))})),e[n.interaction.position]}))},I.prototype.onStart=function(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(g.point(t),{width:this.canvas.element.width,height:this.canvas.element.height})},I.prototype.onEnter=function(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(g.point(t),!1))},I.prototype.onMove=function(t){this.interaction.isStarted&&(this.interaction.motion(g.point(t)),t.preventDefault())},I.prototype.onEnd=function(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(g.point(t),!0))},Object.defineProperties(I.prototype,A);!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===i&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=t:o.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,.ls-viewer-container-video{cursor:default;pointer-events:none}.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;opacity:0;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");var S=function(t,i){this.checkResize=this.checkResize.bind(this),this.onDeviceOrientation=this.onDeviceOrientation.bind(this),this.onResize=this.onResize.bind(this),this.onStart=this.onStart.bind(this),this.onEnter=this.onEnter.bind(this),this.onMove=this.onMove.bind(this),this.onEnd=this.onEnd.bind(this),this.onLoadStart=this.onLoadStart.bind(this),this.onLoadProgress=this.onLoadProgress.bind(this),this.onLoadEnd=this.onLoadEnd.bind(this),this.onLoadError=this.onLoadError.bind(this),this.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options=Object.assign({},{server:"localhost",image:{},video:{},vrcube:{},vrobject:{}},i),this.options.events=Object.assign({},{onLoadStart:function(){},onLoadProgress:function(){},onLoadEnd:function(){},onLoadError:function(){},onInteraction:function(){},onVrcubeInteraction:function(){},onVrobjectInteraction:function(){}},i.events),this.options.events.onLoadError=e(this.options.events.onLoadError,10),this.container=t,this.container.classList.add("ls-viewer-container"),this.canvas2D=new s,this.container.appendChild(this.canvas2D.element),this.canvas3D=new a,this.container.appendChild(this.canvas3D.element),this.video=new p,this.container.appendChild(this.video.element),this.loader=new u(i.server,this),this.resolution={width:0,height:0},this.scene=null,this.view=null,this.parameters={antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.widgets={image:new m(t,this.canvas2D,this.loader,this.options.image),video:new v(t,this.video,this.loader,this.options.video),vrcube:new P(t,this.canvas3D,this.loader,this.options.vrcube,this.onVrcubeInteraction),vrobject:new I(t,this.canvas2D,this.loader,this.options.vrobject,this.onVrobjectInteraction)},this.widget=this.widgets.image,this.container.addEventListener("mousedown",this.onStart),this.container.addEventListener("mouseenter",this.onEnter),this.container.addEventListener("touchstart",this.onStart),document.addEventListener("mousemove",this.onMove),document.addEventListener("mouseup",this.onEnd),document.addEventListener("touchmove",this.onMove),document.addEventListener("touchend",this.onEnd),window.addEventListener("deviceorientation",this.onDeviceOrientation),this.checkResize(),this.loadWidget=e(this.loadWidget,10),this.onResize=e(this.onResize,250)};return S.prototype.destroy=function(){this.container.removeEventListener("mousedown",this.onStart),this.container.removeEventListener("mouseenter",this.onEnter),this.container.removeEventListener("touchstart",this.onStart),document.removeEventListener("mousemove",this.onMove),document.removeEventListener("mouseup",this.onEnd),document.removeEventListener("touchmove",this.onMove),document.removeEventListener("touchend",this.onEnd),window.removeEventListener("deviceorientation",this.onDeviceOrientation),this.isDestroyed=!0},S.prototype.load=function(e,i){var n=this,o=Promise.resolve();i&&void 0!==i.animation&&(o=o.then((function(){return n.loadAnimation(i.animation)}))),this.view&&i&&void 0!==i.position&&(o=o.then((function(){return n.widgets[n.view.mode].goto(i.position)}))),i&&void 0!==i.animation&&(o=o.then((function(){return n.widgets.video.play()}))),(o=o.then((function(){return n.scene=Array.isArray(e)?t(e):[t(e)],n.loadWidget(!1,!(i&&i.animation))}))).catch((function(t){n.onLoadError(t)}))},S.prototype.setEncoder=function(e){var i=this;this.encoder=t(e);var n=Promise.resolve();(n=n.then((function(){return i.loadWidget(!1,!0)}))).catch((function(t){i.onLoadError(t)}))},S.prototype.setParameters=function(e){var i=this;this.parameters=t(e),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height;var n=Promise.resolve();(n=n.then((function(){return i.loadWidget(!1,!0)}))).catch((function(t){i.onLoadError(t)}))},S.prototype.setView=function(e,i){var n=this,o=Promise.resolve();i&&void 0!==i.animation&&(o=o.then((function(){return n.loadAnimation(i.animation)}))),this.view&&i&&void 0!==i.fromPosition&&(o=o.then((function(){return n.widgets[n.view.mode].goto(i.fromPosition)}))),i&&void 0!==i.animation&&(o=o.then((function(){return n.widgets.video.play()}))),(o=o.then((function(){var o=!0;return n.view=t(e),n.view&&i&&void 0!==i.toPosition&&(o=!1,n.widgets[n.view.mode].position=i.toPosition),n.loadWidget(o,!(i&&i.animation))}))).catch((function(t){n.onLoadError(t)}))},S.prototype.setVrcube=function(t){Object.assign(this.widgets.vrcube,t)},S.prototype.setVrobject=function(t){Object.assign(this.widgets.vrobject,t)},S.prototype.loadAnimation=function(t){var e=this,i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return i.view.background||(i.view.background="product"),this.widgets.video.load(i).catch((function(t){e.onLoadError(t)}))},S.prototype.playAnimation=function(t){var e=this;return this.loadAnimation(t).then((function(){return e.widgets.video.play()}))},S.prototype.stopAnimation=function(){this.widgets.video.hide()},S.prototype.loadWidget=function(t,e){var i=this;if(!this.scene||!this.view)return Promise.resolve();if(!this.parameters.width||!this.parameters.height)return Promise.resolve();var n=this.widgets[this.view.mode];if(!n)return Promise.reject(new Error("Unknown view mode"));var o={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return o.view.background||(o.view.background="product"),n.load(o,t,e).then((function(){i.widget.hide(),i.widget=n,i.widget.show(),i.widgets.video.hide()}))},S.prototype.checkResize=function(){if(!this.isDestroyed){var t=this.container.offsetWidth,e=this.container.offsetHeight;t===this.containerWidth&&e===this.containerHeight||(this.containerWidth=t,this.containerHeight=e,this.onResize()),this.isDestroyed||requestAnimationFrame(this.checkResize)}},S.prototype.onStart=function(t){this.widget.onStart(t)},S.prototype.onEnter=function(t){this.widget.onEnter(t)},S.prototype.onMove=function(t){this.widget.onMove(t)},S.prototype.onEnd=function(t){this.widget.onEnd(t)},S.prototype.onDeviceOrientation=function(t){this.widget.onDeviceOrientation(t)},S.prototype.onResize=function(){var t=this,e=window.devicePixelRatio,i=this.container.offsetWidth*e,n=this.container.offsetHeight*e;this.resolution=r.getStandardResolution(i,n),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height,this.canvas2D.resize(i/e,n/e,this.resolution),this.canvas3D.resize(i/e,n/e,this.resolution),this.video.resize(i/e,n/e,this.resolution),this.loadWidget(!1,!1).catch((function(e){t.onLoadError(e)}))},S.prototype.onVrcubeInteraction=function(){for(var t,e,i=[],n=arguments.length;n--;)i[n]=arguments[n];(t=this.options.events).onInteraction.apply(t,i),(e=this.options.events).onVrcubeInteraction.apply(e,i)},S.prototype.onVrobjectInteraction=function(){for(var t,e,i=[],n=arguments.length;n--;)i[n]=arguments[n];(t=this.options.events).onInteraction.apply(t,i),(e=this.options.events).onVrobjectInteraction.apply(e,i)},S.prototype.onLoadStart=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];this.container.classList.add("ls-viewer-container-loading"),(t=this.options.events).onLoadStart.apply(t,e)},S.prototype.onLoadProgress=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];(t=this.options.events).onLoadProgress.apply(t,e)},S.prototype.onLoadEnd=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];this.container.classList.remove("ls-viewer-container-loading"),(t=this.options.events).onLoadEnd.apply(t,e)},S.prototype.onLoadError=function(){for(var t,e=[],i=arguments.length;i--;)e[i]=arguments[i];this.container.classList.remove("ls-viewer-container-loading"),(t=this.options.events).onLoadError.apply(t,e)},S}));
{
"name": "@lumiscaphe/viewer",
"version": "1.0.9",
"version": "2.0.0",
"description": "Lumiscaphe 3D Viewer",

@@ -18,4 +18,4 @@ "main": "dist/index.js",

"devDependencies": {
"cross-env": "~5.2.0",
"eslint": "~6.3.0",
"cross-env": "~6.0.0",
"eslint": "~6.5.0",
"eslint-config-airbnb-base": "~14.0.0",

@@ -26,3 +26,3 @@ "eslint-plugin-import": "~2.18.0",

"postcss-reporter": "~6.0.0",
"rollup": "~1.20.0",
"rollup": "~1.25.0",
"rollup-plugin-buble": "~0.19.0",

@@ -36,5 +36,5 @@ "rollup-plugin-commonjs": "~10.1.0",

"rollup-plugin-terser": "~5.1.0",
"stylelint": "~10.1.0",
"stylelint-config-standard": "~18.3.0"
"stylelint": "~11.1.0",
"stylelint-config-standard": "~19.0.0"
}
}

@@ -85,27 +85,70 @@ # viewer

When a 3D model does not contain integrated decors, it can be added with an external 3D model. For example:
When a 3D model does not contain integrated decors, it can be added with an external 3D model (product configuration will be applies on both products). For example:
```javascript
const product = {
database: 'ee294840-5689-49b0-9edb-527598602df0',
configuration: 'Bin.Blue/Cabin.Yellow/Style.Design1/Wheels.Red',
animations: ['LeftDoor'],
};
const decorProduct = {
database: '82c1f7e8-9ae4-4f00-b45c-c857e21a954f',
translation: { x: 0, y: -0.12, z: 0 },
decor: true,
};
const scene = [product, decorProduct];
viewer.load(scene);
```
Decor product is defined with:
* `database` : decor product 3D model guid string
* `translation` : decor product 3D position (e.g. decorDeltaAltitude)
* `decor` : boolean to indicate that this product is a decor database
## Accessories
Two ways to drive scene accessories.
**Integrated**
When a 3D model contains integrated accessories, it can be change through product configuration. For example: add `AXS$8201468182` to product configuration string.
```javascript
const scene = [{
database: 'ee294840-5689-49b0-9edb-527598602df0',
configuration: 'Bin.Blue/Cabin.Yellow/Style.Design1/Wheels.Red/AXS$8201468182',
animations: ['LeftDoor'],
}];
viewer.load(scene);
```
**External**
When a 3D model does not contain integrated accessories, it can be added with an external 3D model (product configuration will be applies on both products). For example:
```javascript
const product = {
database: 'ee294840-5689-49b0-9edb-527598602df0',
configuration: 'Bin.Blue/Cabin.Yellow/Style.Design1/Wheels.Red',
configuration: 'Bin.Blue/Cabin.Yellow/Style.Design1/Wheels.Red/AXS$8201468182',
animations: ['LeftDoor'],
};
const scene = [decorProduct, product];
const accessoryProduct = {
database: '82c1f7e8-9ae4-4f00-b45c-c857e21a954f',
accessory: true,
};
const scene = [product, accessoryProduct];
viewer.load(scene);
```
Decor product is defined with:
* `database` : decor product 3D model guid string
* `translation` : decor product 3D position (e.g. decorDeltaAltitude)
Accessory product is defined with:
* `database` : accessory product 3D model guid string
* `accessory` : boolean to indicate that this product is a accessory database
Note: decor product should always be the first product in the scene.
## View

@@ -112,0 +155,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc