From 7f318c774e451d99e6cadaa9e7fe7e97b859572a Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Wed, 10 Oct 2018 14:04:09 -0700 Subject: [PATCH] apply logo light only to logo --- src/components/logo-light.js | 42 ++++++++++++++++++++++++++++++++++++ src/templates/stage.html | 17 +++++++-------- 2 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/components/logo-light.js diff --git a/src/components/logo-light.js b/src/components/logo-light.js new file mode 100644 index 0000000..b883cdf --- /dev/null +++ b/src/components/logo-light.js @@ -0,0 +1,42 @@ +var ONCE = {once: true}; + +/** + * Delay logo light so it only applies to the logo. + */ +AFRAME.registerComponent('logo-light', { + init: function () { + this.logoBack = document.getElementById('logoBack'); + this.logoFront = document.getElementById('logoFront'); + this.logoFrontU = document.getElementById('logoFrontU'); + }, + + play: function () { + setTimeout(() => { + this.el.setAttribute('light', { + type: 'spot', + penumbra: 1, + intensity: 5, + angle: 20 + }); + this.waitAndUpdate(this.logoBack); + this.waitAndUpdate(this.logoFront); + this.waitAndUpdate(this.logoFrontU); + }, 1000); + }, + + waitAndUpdate: function (el) { + if (el.getObject3D('mesh')) { + el.object3D.traverse(this.updateMaterials); + } else { + el.addEventListener('model-loaded', () => { + el.object3D.traverse(this.updateMaterials); + }, ONCE); + } + }, + + updateMaterials: function (node) { + if (node.material) { + node.material.needsUpdate = true; + } + } +}); diff --git a/src/templates/stage.html b/src/templates/stage.html index 02cdb11..f35fdf1 100644 --- a/src/templates/stage.html +++ b/src/templates/stage.html @@ -77,19 +77,18 @@ - + rotation="0 50 0" + logo-light + animation__rotate="property: object3D.rotation.y; from: 50; to: -50; dur: 300; easing: linear; startEvents: audioanalyser-beat">