diff --git a/src/lights/RectAreaLight.js b/src/lights/RectAreaLight.js new file mode 100644 index 0000000..de91d2b --- /dev/null +++ b/src/lights/RectAreaLight.js @@ -0,0 +1,27 @@ +import { RectAreaLight } from 'three'; +import { RectAreaLightUniformsLib } from 'three/examples/jsm/lights/RectAreaLightUniformsLib.js'; +import { RectAreaLightHelper } from 'three/examples/jsm/helpers/RectAreaLightHelper.js'; +import { watch } from 'vue'; +import Light from './Light.js'; + +export default { + extends: Light, + props: { + width: { type: Number, default: 10 }, + height: { type: Number, default: 10 }, + }, + created() { + RectAreaLightUniformsLib.init(); + this.light = new RectAreaLight(this.color, this.intensity, this.width, this.height); + + ['width', 'height'].forEach(p => { + watch(() => this[p], () => { + this.light[p] = this[p]; + }); + }); + + this.$parent.add(new RectAreaLightHelper(this.light)); + this.initLight(); + }, + __hmrId: 'RectAreaLight', +}; diff --git a/src/lights/index.js b/src/lights/index.js index 5bc680d..d54391c 100644 --- a/src/lights/index.js +++ b/src/lights/index.js @@ -1,4 +1,5 @@ export { default as AmbientLight } from './AmbientLight.js'; export { default as DirectionalLight } from './DirectionalLight.js'; export { default as PointLight } from './PointLight.js'; +export { default as RectAreaLight } from './RectAreaLight.js'; export { default as SpotLight } from './SpotLight.js'; diff --git a/src/plugin.js b/src/plugin.js index 470e5ab..cedd359 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -30,6 +30,7 @@ export const TroisJSVuePlugin = { 'AmbientLight', 'DirectionalLight', 'PointLight', + 'RectAreaLight', 'SpotLight', 'BasicMaterial',