UNPKG

@quanticpotatoes/aframe-stereo-component

Version:
1 lines 3.51 kB
!function(e){var t={};function i(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,i),n.l=!0,n.exports}i.m=e,i.c=t,i.d=function(e,t,r){i.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},i.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=1)}([function(e,t,i){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};e.exports={stereo_component:{schema:{eye:{type:"string",default:"left"},mode:{type:"string",default:"full"},split:{type:"string",default:""},playOnClick:{type:"boolean",default:!0}},init:function(){this.video_click_event_added=!1,this.material_is_a_video=!1,this.material_is_a_image=!1;var e=this.el.object3D.children[0];n(e,this.el,this.data),this.material_is_a_video||(this.video_click_event_added=!0)},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),i.split!==e.split&&n(t,this.el,this.data)},tick:function(e){if(!this.video_click_event_added&&this.data.playOnClick&&void 0!==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,r){i[t]=e.type});var r=i.indexOf("PerspectiveCamera"),n=this.el.object3D.children[r];"both"===t.eye?(n.layers.enable(1),n.layers.enable(2)):n.layers.enable("left"===t.eye?1:2)}}}};var n=function(e,t,i){var n=!1,o=!1;if(null!==t.getAttribute("material")&&"src"in t.getAttribute("material")&&""!==t.getAttribute("material").src){var a=t.getAttribute("material").src;"object"===(void 0===a?"undefined":r(a))&&"tagName"in a&&"VIDEO"===a.tagName?n=!0:"object"===(void 0===a?"undefined":r(a))&&"tagName"in a&&"IMG"===a.tagName&&(o=!0)}if([THREE.SphereGeometry,THREE.SphereBufferGeometry,THREE.BufferGeometry].some(function(t){return e.geometry instanceof t})&&(n||o&&i.split)){var s=t.getAttribute("geometry"),l=null;if(l="half"===i.mode?new THREE.SphereGeometry(s.radius||100,s.segmentsWidth||64,s.segmentsHeight||64,Math.PI/2,Math.PI,0,Math.PI):new THREE.SphereGeometry(s.radius||100,s.segmentsWidth||64,s.segmentsHeight||64),e.rotation.y=Math.PI/2,"left"===i.eye)for(var c=l.faceVertexUvs[0],f="vertical"===i.split?"y":"x",u=0;u<c.length;u++)for(var d=0;d<3;d++)"x"==f?c[u][d][f]*=.5:(c[u][d][f]*=.5,c[u][d][f]+=.5);if("right"===i.eye)for(c=l.faceVertexUvs[0],f="vertical"===i.split?"y":"x",u=0;u<c.length;u++)for(d=0;d<3;d++)"x"==f?(c[u][d][f]*=.5,c[u][d][f]+=.5):c[u][d][f]*=.5;e.geometry=(new THREE.BufferGeometry).fromGeometry(l)}}},function(e,t,i){"use strict";!function(){if(AFRAME){var e={stereo:i(0).stereo_component,stereocam:i(0).stereocam_component};Object.keys(e).forEach(function(t){AFRAME.aframeCore?AFRAME.aframeCore.registerComponent(t,e[t]):AFRAME.registerComponent(t,e[t])})}else console.error("Component attempted to register before AFRAME was available.")}()}]);