-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathaframe-stereo-component.min.js
1 lines (1 loc) · 2.83 KB
/
aframe-stereo-component.min.js
1
!function(e){function t(a){if(i[a])return i[a].exports;var r=i[a]={exports:{},id:a,loaded:!1};return e[a].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t,i){!function(){if(!AFRAME)return void console.error("Component attempted to register before AFRAME was available.");var e={stereo:i(1).stereo_component,stereocam:i(1).stereocam_component};Object.keys(e).forEach(function(t){AFRAME.aframeCore?AFRAME.aframeCore.registerComponent(t,e[t]):AFRAME.registerComponent(t,e[t])})}()},function(e,t){e.exports={stereo_component:{schema:{eye:{type:"string",default:"left"},mode:{type:"string",default:"full"},split:{type:"string",default:"horizontal"},playOnClick:{type:"boolean",default:!0}},init:function(){if(this.video_click_event_added=!1,this.material_is_a_video=!1,null!==this.el.getAttribute("material")&&"src"in this.el.getAttribute("material")&&""!==this.el.getAttribute("material").src){var e=this.el.getAttribute("material").src;"object"==typeof e&&"tagName"in e&&"VIDEO"===e.tagName&&(this.material_is_a_video=!0)}var t=this.el.object3D.children[0],i=[THREE.SphereGeometry,THREE.BufferGeometry],a=i.some(function(e){return t.geometry instanceof e});if(a&&this.material_is_a_video){if("half"===this.data.mode)var r=this.el.getAttribute("geometry"),o=new THREE.SphereGeometry(r.radius||100,r.segmentsWidth||64,r.segmentsHeight||64,Math.PI/2,Math.PI,0,Math.PI);else var r=this.el.getAttribute("geometry"),o=new THREE.SphereGeometry(r.radius||100,r.segmentsWidth||64,r.segmentsHeight||64);t.rotation.y=Math.PI/2;for(var n="horizontal"===this.data.split?"y":"x",s="left"===this.data.eye?"y"===n?{x:0,y:0}:{x:0,y:.5}:"y"===n?{x:.5,y:0}:{x:0,y:0},l="y"===n?{x:.5,y:1}:{x:1,y:.5},c=o.attributes.uv,h=0;h<c.count;h++){var d=c.getX(h)*l.x+s.x,y=c.getY(h)*l.y+s.y;c.setXY(h,d,y)}c.needsUpdate=!0,this.originalGeometry=t.geometry,t.geometry=o}else this.video_click_event_added=!0},remove:function(){var e=this.el.object3D.children[0];e.geometry.dispose(),this.originalGeometry&&(e.geometry=this.originalGeometry)},update:function(e){var t=this.el.object3D.children[0],i=this.data;"both"===i.eye?t.layers.set(0):t.layers.set("left"===i.eye?1:2)},tick:function(e){if(!this.video_click_event_added&&this.data.playOnClick&&"undefined"!=typeof this.el.sceneEl.canvas){this.videoEl=this.el.object3D.children[0].material.map.image;var t=this;this.el.sceneEl.canvas.onclick=function(){t.videoEl.play()},this.video_click_event_added=!0}}},stereocam_component:{schema:{eye:{type:"string",default:"left"}},init:function(){this.layer_changed=!1},tick:function(e){var t=this.data;if(!this.layer_changed){var i=[];this.el.object3D.children.forEach(function(e,t,a){i[t]=e.type});var a=i.indexOf("PerspectiveCamera"),r=this.el.object3D.children[a];"both"===t.eye?(r.layers.enable(1),r.layers.enable(2)):r.layers.enable("left"===t.eye?1:2),this.layer_changed=!0}}}}}]);