Skip to content
Merged
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
61 changes: 31 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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)
// 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: {
Expand Down Expand Up @@ -169,50 +169,51 @@ module.exports = {
'stereocam_component':{

schema: {
eye: { type: 'string', default: "left"}
eye: { type: 'string', default: "left"}
},

// Cam is not attached on init, so use a flag to do this once at 'tick'
// Cam is not attached on init, so use a flag to do this once at 'tick'

// Use update every tick if flagged as 'not changed yet'
// Use update every tick if flagged as 'not changed yet'

init: function(){
// Flag to register if cam layer has already changed
this.layer_changed = false;
},
init: function(){
// Flag to register if cam layer has already changed
this.layer_changed = false;
},

tick: function(time){
tick: function(time){

var originalData = this.data;
var originalData = this.data;

// If layer never changed
// If layer never changed

if(!this.layer_changed){
if(!this.layer_changed){

// because stereocam component should be attached to an a-camera element
// need to get down to the root PerspectiveCamera before addressing layers
// because stereocam component should be attached to 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
// Gather the children of this a-camera and identify types

var childrenTypes = [];
var childrenTypes = [];

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

// Retrieve the PerspectiveCamera
var rootIndex = childrenTypes.indexOf("PerspectiveCamera");
var rootCam = this.el.object3D.children[rootIndex];
// Retrieve the PerspectiveCamera
var rootIndex = childrenTypes.indexOf("PerspectiveCamera");
var rootCam = this.el.object3D.children[rootIndex];

if(originalData.eye === "both"){
rootCam.layers.enable( 1 );
rootCam.layers.enable( 2 );
if(originalData.eye === "both"){
rootCam.layers.enable( 1 );
rootCam.layers.enable( 2 );
}
else{
rootCam.layers.enable(originalData.eye === 'left' ? 1:2);
rootCam.layers.enable(originalData.eye === 'left' ? 1:2);
}
}
}

this.layer_changed = true;
}
}
}
};