From 1c712f55210fdeed5e204d9a88ea7b1e2fa0bd3a Mon Sep 17 00:00:00 2001 From: Fei YU Date: Fri, 18 Aug 2017 11:16:37 -0700 Subject: [PATCH 1/2] Set Layout_change flag after setting layer. layout_change flag was not set after it is used. This would lead to setting camera for every tick(). I also format the code a little bit. --- index.js | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index 29b5ca2..b0facad 100755 --- a/index.js +++ b/index.js @@ -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: { @@ -172,14 +172,14 @@ module.exports = { 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){ @@ -189,28 +189,30 @@ module.exports = { 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 ); - } - else{ - rootCam.layers.enable(originalData.eye === 'left' ? 1:2); - } + if(originalData.eye === "both"){ + rootCam.layers.enable( 1 ); + rootCam.layers.enable( 2 ); + } + else{ + rootCam.layers.enable(originalData.eye === 'left' ? 1:2); + } + + this.layer_changed = true; } } From 552488163d1c7d12f76446e74d379430b3b4928b Mon Sep 17 00:00:00 2001 From: Fei YU Date: Fri, 18 Aug 2017 11:26:15 -0700 Subject: [PATCH 2/2] Refomating code ( cont ) --- index.js | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index b0facad..81b0eb8 100755 --- a/index.js +++ b/index.js @@ -169,7 +169,7 @@ 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' @@ -181,40 +181,39 @@ module.exports = { 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 ); - } - else{ - rootCam.layers.enable(originalData.eye === 'left' ? 1:2); - } - - this.layer_changed = true; - } - } + if(originalData.eye === "both"){ + rootCam.layers.enable( 1 ); + rootCam.layers.enable( 2 ); + } + else{ + rootCam.layers.enable(originalData.eye === 'left' ? 1:2); + } + this.layer_changed = true; + } + } } };