Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/two_boxes/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!-- in VR mode, the first box is displayed only in the left eye, the second one in the right eye -->

<a-entity geometry="primitive: box" material="color: #C03546" stereo="eye:left"></a-entity>
<a-entity geometry="primitive: box" material="color: #3546C0" position="0 5 0" stereo="eye: right"></a-entity> -->
<a-entity geometry="primitive: box" material="color: #3546C0" position="0 5 0" stereo="eye: right"></a-entity>

</a-scene>

Expand Down
35 changes: 23 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
// Put an object into left, right or both eyes.
// If it's a video sphere, take care of correct stereo mapping for both eyes (if full dome)
// or half the sphere (if half dome)

'stereo_component' : {
schema: {
eye: { type: 'string', default: "left"},
Expand All @@ -16,7 +16,7 @@ module.exports = {
// Check if it's a sphere w/ video material, and if so

if(object3D.geometry instanceof THREE.SphereGeometry
&& 'map' in object3D.material
&& 'map' in object3D.material
&& object3D.material.map instanceof THREE.VideoTexture) {


Expand Down Expand Up @@ -67,28 +67,41 @@ module.exports = {
for (var i = 0; i < uvs.length; i++) {
for (var j = 0; j < 3; j++) {
uvs[ i ][ j ].x *= 0.5;
uvs[ i ][ j ].x += 0.5;
uvs[ i ][ j ].x += 0.5;
}
}

}
}


}

},
// On element update, put in the right layer, 0:both, 1:left, 2:right (spheres or not)
},
// On element update, put in the correct layer, 0:both, 1:left, 2:right (spheres or not)

update: function(oldData){

var object3D = this.el.object3D;
var data = this.data;

var childrenTypes = [];

this.el.object3D.children.forEach( function (item, index, array) {
childrenTypes[index] = item.type;
});

// Retrieve the Mesh object
var rootIndex = childrenTypes.indexOf("Mesh");
var rootMesh = this.el.object3D.children[rootIndex];
console.log(rootMesh);

if(data.eye === "both"){
object3D.layers.set(0);
rootMesh.layers.set(0);
this.layer_changed = true;
}
else{
object3D.layers.set(data.eye === 'left' ? 1:2);
rootMesh.layers.set(data.eye === 'left' ? 1:2);
this.layer_changed = true;
}

}
Expand All @@ -106,21 +119,19 @@ module.exports = {
// Use update every tick if flagged as 'not changed yet'

init: function(){
// Register update on tick
this.el.sceneEl.addBehavior(this);
this.layer_changed = false;
},

update: function(oldData){


var originalData = this.data;

// If layer never changed

if(!this.layer_changed){

// because stereocam component should be attached to an a-camera element
// because stereocam component is a child of an a-camera element,
// need to get down to the root PerspectiveCamera before addressing layers

// Gather the children of this a-camera and identify types
Expand Down