1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

improve lights

This commit is contained in:
Kevin Levron 2021-03-13 19:18:16 +01:00
parent d8cc705b99
commit c3d48d467d
2 changed files with 6 additions and 4 deletions

View File

@ -1,15 +1,15 @@
import { HemisphereLight } from 'three'; import { HemisphereLight } from 'three';
import { watch } from 'vue';
import Light from './Light.js'; import Light from './Light.js';
import { bindProp } from '../tools.js';
export default { export default {
extends: Light, extends: Light,
props: { props: {
groundColor: { type: String, default: '#ffffff' }, groundColor: { type: String, default: '#444444' },
}, },
created() { created() {
this.light = new HemisphereLight(this.color, this.groundColor, this.intensity); this.light = new HemisphereLight(this.color, this.groundColor, this.intensity);
bindProp(this, 'groundColor', this.light); watch(() => this.groundColor, (value) => { this.light.groundColor.set(value); });
this.initLight(); this.initLight();
}, },
__hmrId: 'HemisphereLight', __hmrId: 'HemisphereLight',

View File

@ -11,6 +11,7 @@ export default {
intensity: { type: Number, default: 1 }, intensity: { type: Number, default: 1 },
castShadow: { type: Boolean, default: false }, castShadow: { type: Boolean, default: false },
shadowMapSize: { type: Object, default: { x: 512, y: 512 } }, shadowMapSize: { type: Object, default: { x: 512, y: 512 } },
shadowCamera: { type: Object, default: {} },
}, },
// can't use setup because it will not be used in sub components // can't use setup because it will not be used in sub components
// setup() {}, // setup() {},
@ -26,12 +27,13 @@ export default {
if (this.light.shadow) { if (this.light.shadow) {
this.light.castShadow = this.castShadow; this.light.castShadow = this.castShadow;
setFromProp(this.light.shadow.mapSize, this.shadowMapSize); setFromProp(this.light.shadow.mapSize, this.shadowMapSize);
setFromProp(this.light.shadow.camera, this.shadowCamera);
} }
['color', 'intensity', 'castShadow'].forEach(p => { ['color', 'intensity', 'castShadow'].forEach(p => {
watch(() => this[p], () => { watch(() => this[p], () => {
if (p === 'color') { if (p === 'color') {
this.light.color = new Color(this.color); this.light.color.set(this.color);
} else { } else {
this.light[p] = this[p]; this.light[p] = this[p];
} }