From 42386a572df0e1dcce344e20ea4f3807a6655095 Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Sun, 7 Mar 2021 00:48:06 +0100 Subject: [PATCH] add RectAreaLight --- src/lights/RectAreaLight.js | 27 +++++++++++++++++++++++++++ src/lights/index.js | 1 + src/plugin.js | 1 + 3 files changed, 29 insertions(+) create mode 100644 src/lights/RectAreaLight.js 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',