-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaframe-slideshow-component.min.js
More file actions
1 lines (1 loc) · 6.88 KB
/
aframe-slideshow-component.min.js
File metadata and controls
1 lines (1 loc) · 6.88 KB
1
!function(t){function e(n){if(i[n])return i[n].exports;var s=i[n]={exports:{},id:n,loaded:!1};return t[n].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e){if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");AFRAME.registerComponent("aframe-slideshow",{schema:{transitionHeight:{type:"number",default:"2"},stepTransition:{type:"number",default:"0.01"},folder:{type:"string",default:"public/assets/slides/"},namingConv:{type:"string",default:"Slide_%num%"},imageExtension:{type:"string",default:"jpg"},videoExtension:{type:"string",default:"mp4"},nbslides:{type:"number",default:"0"},startpos:{type:"vec3",default:void 0},distBetweenSlides:{type:"number",default:"5"},nbColumns:{type:"number",default:"5"},slideYPos:{type:"number",default:"1.6"}},multiple:!1,init:function(){if(this.hasBeenUpdated=!1,this.initVariables(),!document.querySelector("a-assets")){var t=document.createElement("a-assets");document.querySelector("a-scene").appendChild(t)}this.addListeners(),this.initSlides()},initVariables:function(){this.registeredChildren=0,this.nbChildren=parseInt(this.data.nbslides,10),this.currentIndex=0,this.data.startpos?this.startpos=this.data.startpos:(this.startpos=new THREE.Vector3,this.startpos.x=-((this.data.nbColumns-1)/2)*this.data.distBetweenSlides,this.startpos.y=this.data.slideYPos,this.startpos.z=(this.nbChildren/this.data.nbColumns-1)/2*this.data.distBetweenSlides),this.oldCamParentPos=new THREE.Vector3,this.cameraPath=void 0,this.transitionHeight=this.data.transitionHeight,this.deltaTransition=1,this.stepTransition=this.data.stepTransition},update:function(){if(!this.hasBeenUpdated)return void(this.hasBeenUpdated=!0)},addListeners:function(){function t(t){document.querySelector("a-scene").is("vr-mode")||(1===t.detail.id?e.nextSlide():2===t.detail.id&&e.prevSlide())}var e=this;document.addEventListener("keydown",function(t){var i=!1;39===t.keyCode?(e.nextSlide(),i=!0):37===t.keyCode&&(e.prevSlide(),i=!0),i&&(t.stopPropagation(),t.preventDefault())}),document.querySelector("#right-hand")&&document.querySelector("#right-hand").addEventListener("buttondown",t),document.querySelector("#left-hand")&&document.querySelector("#left-hand").addEventListener("buttondown",t),window.addEventListener("resize",function(){this.goToSlide(this.currentIndex,!0)}),document.querySelector("a-scene").addEventListener("exit-vr",function(){document.querySelector("#camParent").object3D.position.copy(e.oldCamParentPos)}),document.querySelector("a-scene").addEventListener("enter-vr",function(){e.oldCamParentPos.copy(document.querySelector("#camParent").object3D.position),document.querySelector("#camParent").object3D.position.set(0,0,0)})},initSlides:function(){for(var t=this.data.vidSlidesIndex.split(",").map(function(t){return parseInt(t,10)}),e=this.data.animSlidesIndex.split(",").map(function(t){return parseInt(t,10)}),i=1,n=this.data.nbslides;i<=n;++i){var s=document.createElement("a-entity");s.id="slide"+i;var a="";e.indexOf(i)!==-1&&(a="animTransition: true;"),t.indexOf(i)!==-1?s.setAttribute("aframe-slideshow-slide","src: "+this.data.folder+this.data.namingConv.replace("%num%",i)+"."+this.data.videoExtension+"; type: video;"+a):s.setAttribute("aframe-slideshow-slide","src: "+this.data.folder+this.data.namingConv.replace("%num%",i)+"."+this.data.imageExtension+"; type: image;"+a),this.el.appendChild(s)}},addChild:function(t){var e=Array.from(this.el.children).indexOf(t),i=new THREE.Vector3;i.x=e%this.data.nbColumns,i.z=-Math.floor(e/this.data.nbColumns),i.multiplyScalar(this.data.distBetweenSlides).add(this.startpos),i.y=this.data.slideYPos,t.setAttribute("position",i),++this.registeredChildren>=this.nbChildren&&this.onSlideshowReady()},onSlideshowReady:function(){document.getElementById("loaderDiv").classList.remove("make-container--visible");try{var t=document.createElement("a");if(t.href=location.href,""!==t.hash&&t.hash.indexOf("#p")!==-1){var e=parseInt(t.hash.replace("#p",""),10);this.currentIndex=isNaN(e)?this.currentIndex:e}}catch(t){console.log("[AFRAME-SLIDESHOW Component] Error parsing url",t)}finally{this.goToSlide(this.currentIndex,!0)}},nextSlide:function(){var t=(this.currentIndex+1)%this.registeredChildren;this.goToSlide(t),this.currentIndex=t},prevSlide:function(){var t=Math.max(this.currentIndex-1,0);this.goToSlide(t),this.currentIndex=t},goToSlide:function(t,e){var i=this.el.children[t];if(i){var n=document.querySelector("a-scene").camera,s=document.querySelector("#camParent").object3D,a=document.querySelector("a-scene").renderer,o=document.querySelector("#"+i.id).components["aframe-slideshow-slide"].geomWidth,r=n.fov,d=a.getSize().width/a.getSize().height,h=o/2/Math.tan(r*Math.PI/180/2)/d,l=new THREE.Vector3(i.object3D.position.x,0,i.object3D.position.z+h);if(i.components["aframe-slideshow-slide"].data.animTransition&&!e){var c=[];c.push(s.position.clone()),c.push(l.clone().sub(s.position).divideScalar(2).add(s.position).add(new THREE.Vector3(0,this.transitionHeight,0))),c.push(l.clone()),this.cameraPath=new THREE.CatmullRomCurve3(c),this.deltaTransition=0}else s.position.copy(l),document.querySelector("#acamera").object3D.rotation.set(0,0,0),document.querySelector("#acamera").components["look-controls"].el.setAttribute("rotation","0, 0, 0")}},tick:function(t,e){if(this.deltaTransition<1){var i=document.querySelector("#camParent").object3D;i.position.copy(this.cameraPath.getPointAt(this.deltaTransition)),this.deltaTransition+=this.stepTransition,this.deltaTransition>1&&i.position.copy(this.cameraPath.getPointAt(1))}},pause:function(){},play:function(){},remove:function(){}}),AFRAME.registerComponent("aframe-slideshow-slide",{schema:{src:{type:"string",default:""},type:{type:"string",default:"image"}},multiple:!1,init:function(){this.assetId=this.data.type+"_"+this.el.id;var t;"image"===this.data.type?(t=document.createElement("img"),t.setAttribute("id",this.assetId),t.addEventListener("load",this.createBox.bind(this)),t.setAttribute("src",this.data.src),t.setAttribute("crossorigin","anonymous"),document.querySelector("a-assets").appendChild(t)):"video"===this.data.type&&(t=document.createElement("video"),t.setAttribute("id",this.assetId),t.setAttribute("src",this.data.src),t.setAttribute("crossorigin","anonymous"),t.setAttribute("autoplay","autoplay"),t.setAttribute("loop",!0),t.setAttribute("muted","true"),t.muted=!0,document.querySelector("a-assets").appendChild(t),this.createBox())},createBox:function(){this.width=1024,this.height=512,this.geomHeight=2,this.geomWidth=this.geomHeight*(this.width/this.height);var t=document.createElement("a-box");t.setAttribute("material","shader: flat; src: #"+this.assetId),t.setAttribute("depth",.05),t.setAttribute("height",this.geomHeight),t.setAttribute("width",this.geomWidth),this.el.appendChild(t),this.el.parentEl.components["aframe-slideshow"].addChild(this.el)},update:function(){},tick:function(t,e){},pause:function(){},play:function(){},remove:function(){}})}]);