Last active
September 5, 2017 02:25
-
-
Save mokargas/184ec0a6989e49c96c20be775472f0ad to your computer and use it in GitHub Desktop.
A-Frame + Three.JS RectAreaLight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This is now outdated. Please see: https://github.com/mokargas/aframe-area-light-component | |
/** | |
* A-Frame Wrapper for THREE.JS RectAreaLight | |
* @author Mo Kargas (DEVLAD) mo@devlad.com | |
*/ | |
/* global AFRAME */ | |
/* global THREE */ | |
if (typeof AFRAME === 'undefined') { | |
throw new Error('Component attempted to register before AFRAME was available.') | |
} | |
if (typeof THREE === 'undefined') { | |
throw new Error('Component attempted to register before THREE was available.') | |
} | |
AFRAME.registerComponent('area-light', { | |
schema: { | |
intensity:{ | |
type: 'number', | |
default: 1.0 | |
}, | |
color: { | |
type: 'color', | |
default: '#FFFFFF' | |
}, | |
width:{ | |
type:'number', | |
default: 2 | |
}, | |
height:{ | |
type: 'number', | |
default: 2 | |
}, | |
showHelper:{ | |
type: 'boolean', | |
default: true | |
} | |
}, | |
init: function(){ | |
const rectLight = new THREE.RectAreaLight( this.data.color, this.data.intensity, this.data.width, this.data.height ) | |
rectLight.position.set(this.data.width/2, 0, 0) | |
this.el.object3D.add(rectLight) | |
if(this.data.showHelper){ | |
const rectLightHelper = new THREE.RectAreaLightHelper( rectLight ) | |
rectLightHelper.position.set(this.data.width/2, 0, 0) | |
this.el.object3D.add(rectLightHelper) | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now available as a component, here https://github.com/mokargas/aframe-area-light-component