Skip to content

Instantly share code, notes, and snippets.

@mokargas
Last active September 5, 2017 02:25
Show Gist options
  • Save mokargas/184ec0a6989e49c96c20be775472f0ad to your computer and use it in GitHub Desktop.
Save mokargas/184ec0a6989e49c96c20be775472f0ad to your computer and use it in GitHub Desktop.
A-Frame + Three.JS RectAreaLight
//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)
}
},
});
@mokargas
Copy link
Author

mokargas commented Sep 5, 2017

Now available as a component, here https://github.com/mokargas/aframe-area-light-component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment