diff --git a/dist/aframe-stereo-component.js b/dist/aframe-stereo-component.js index 164af6b..6b08c57 100644 --- a/dist/aframe-stereo-component.js +++ b/dist/aframe-stereo-component.js @@ -144,7 +144,13 @@ var axis = this.data.split === "vertical" ? "y" : "x"; for (var i = 0; i < uvs.length; i++) { for (var j = 0; j < 3; j++) { - uvs[ i ][ j ][ axis ] *= 0.5; + if (axis == "x") { + uvs[ i ][ j ][ axis ] *= 0.5; + } + else { + uvs[ i ][ j ][ axis ] *= 0.5; + uvs[ i ][ j ][ axis ] += 0.5; + } } } } @@ -157,9 +163,13 @@ var axis = this.data.split === "vertical" ? "y" : "x"; for (var i = 0; i < uvs.length; i++) { for (var j = 0; j < 3; j++) { - uvs[ i ][ j ][ axis ] *= 0.5; - uvs[ i ][ j ][ axis ] += 0.5; - + if (axis == "x") { + uvs[ i ][ j ][ axis ] *= 0.5; + uvs[ i ][ j ][ axis ] += 0.5; + } + else { + uvs[ i ][ j ][ axis ] *= 0.5; + } } } } diff --git a/dist/aframe-stereo-component.min.js b/dist/aframe-stereo-component.min.js index 610f138..035291f 100644 --- a/dist/aframe-stereo-component.min.js +++ b/dist/aframe-stereo-component.min.js @@ -1 +1 @@ -!function(e){function t(r){if(i[r])return i[r].exports;var a=i[r]={exports:{},id:r,loaded:!1};return e[r].call(a.exports,a,a.exports,t),a.loaded=!0,a.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"}},init:function(){this.video_click_event_added=!1,this.material_is_a_video=!1,null!==this.el.getAttribute("material")&&"src"in this.el.getAttribute("material")&&null!==document.querySelector(this.el.getAttribute("material").src)&&"VIDEO"===document.querySelector(this.el.getAttribute("material").src).tagName&&(this.material_is_a_video=!0);var e=this.el.object3D.children[0],t=[THREE.SphereGeometry,THREE.SphereBufferGeometry,THREE.BufferGeometry],i=t.some(function(t){return e.geometry instanceof t});if(i&&this.material_is_a_video){if("half"===this.data.mode)var r=this.el.getAttribute("geometry"),a=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"),a=new THREE.SphereGeometry(r.radius||100,r.segmentsWidth||64,r.segmentsHeight||64);if(e.rotation.y=Math.PI/2,"left"===this.data.eye)for(var o=a.faceVertexUvs[0],n="vertical"===this.data.split?"y":"x",s=0;sl;l++)o[s][l][n]*=.5;if("right"===this.data.eye)for(var o=a.faceVertexUvs[0],n="vertical"===this.data.split?"y":"x",s=0;sl;l++)o[s][l][n]*=.5,o[s][l][n]+=.5;e.geometry=(new THREE.BufferGeometry).fromGeometry(a)}else 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)},tick:function(e){if(!this.video_click_event_added&&"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,r){i[t]=e.type});var r=i.indexOf("PerspectiveCamera"),a=this.el.object3D.children[r];"both"===t.eye?(a.layers.enable(1),a.layers.enable(2)):a.layers.enable("left"===t.eye?1:2)}}}}}]); \ No newline at end of file +!function(e){function t(r){if(i[r])return i[r].exports;var a=i[r]={exports:{},id:r,loaded:!1};return e[r].call(a.exports,a,a.exports,t),a.loaded=!0,a.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"}},init:function(){this.video_click_event_added=!1,this.material_is_a_video=!1,null!==this.el.getAttribute("material")&&"src"in this.el.getAttribute("material")&&null!==document.querySelector(this.el.getAttribute("material").src)&&"VIDEO"===document.querySelector(this.el.getAttribute("material").src).tagName&&(this.material_is_a_video=!0);var e=this.el.object3D.children[0],t=[THREE.SphereGeometry,THREE.SphereBufferGeometry,THREE.BufferGeometry],i=t.some(function(t){return e.geometry instanceof t});if(i&&this.material_is_a_video){if("half"===this.data.mode)var r=this.el.getAttribute("geometry"),a=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"),a=new THREE.SphereGeometry(r.radius||100,r.segmentsWidth||64,r.segmentsHeight||64);if(e.rotation.y=Math.PI/2,"left"===this.data.eye)for(var o=a.faceVertexUvs[0],n="vertical"===this.data.split?"y":"x",s=0;sl;l++)"x"==n?o[s][l][n]*=.5:(o[s][l][n]*=.5,o[s][l][n]+=.5);if("right"===this.data.eye)for(var o=a.faceVertexUvs[0],n="vertical"===this.data.split?"y":"x",s=0;sl;l++)"x"==n?(o[s][l][n]*=.5,o[s][l][n]+=.5):o[s][l][n]*=.5;e.geometry=(new THREE.BufferGeometry).fromGeometry(a)}else 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)},tick:function(e){if(!this.video_click_event_added&&"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,r){i[t]=e.type});var r=i.indexOf("PerspectiveCamera"),a=this.el.object3D.children[r];"both"===t.eye?(a.layers.enable(1),a.layers.enable(2)):a.layers.enable("left"===t.eye?1:2)}}}}}]); \ No newline at end of file diff --git a/examples/build.js b/examples/build.js index c1b3ade..96bb881 100644 --- a/examples/build.js +++ b/examples/build.js @@ -81,7 +81,13 @@ module.exports = { var axis = this.data.split === "vertical" ? "y" : "x"; for (var i = 0; i < uvs.length; i++) { for (var j = 0; j < 3; j++) { - uvs[ i ][ j ][ axis ] *= 0.5; + if (axis == "x") { + uvs[ i ][ j ][ axis ] *= 0.5; + } + else { + uvs[ i ][ j ][ axis ] *= 0.5; + uvs[ i ][ j ][ axis ] += 0.5; + } } } } @@ -94,9 +100,13 @@ module.exports = { var axis = this.data.split === "vertical" ? "y" : "x"; for (var i = 0; i < uvs.length; i++) { for (var j = 0; j < 3; j++) { - uvs[ i ][ j ][ axis ] *= 0.5; - uvs[ i ][ j ][ axis ] += 0.5; - + if (axis == "x") { + uvs[ i ][ j ][ axis ] *= 0.5; + uvs[ i ][ j ][ axis ] += 0.5; + } + else { + uvs[ i ][ j ][ axis ] *= 0.5; + } } } } diff --git a/index.js b/index.js index 8bd2562..2c1af5d 100644 --- a/index.js +++ b/index.js @@ -70,7 +70,13 @@ module.exports = { var axis = this.data.split === "vertical" ? "y" : "x"; for (var i = 0; i < uvs.length; i++) { for (var j = 0; j < 3; j++) { - uvs[ i ][ j ][ axis ] *= 0.5; + if (axis == "x") { + uvs[ i ][ j ][ axis ] *= 0.5; + } + else { + uvs[ i ][ j ][ axis ] *= 0.5; + uvs[ i ][ j ][ axis ] += 0.5; + } } } } @@ -83,9 +89,13 @@ module.exports = { var axis = this.data.split === "vertical" ? "y" : "x"; for (var i = 0; i < uvs.length; i++) { for (var j = 0; j < 3; j++) { - uvs[ i ][ j ][ axis ] *= 0.5; - uvs[ i ][ j ][ axis ] += 0.5; - + if (axis == "x") { + uvs[ i ][ j ][ axis ] *= 0.5; + uvs[ i ][ j ][ axis ] += 0.5; + } + else { + uvs[ i ][ j ][ axis ] *= 0.5; + } } } } diff --git a/package.json b/package.json index 66a3a7b..813bf1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aframe-stereo-component", - "version": "0.3.0", + "version": "0.3.1", "description": "Stereoscopic component for A-Frame VR.", "main": "index.js", "scripts": {