mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
improve lights
This commit is contained in:
parent
d8cc705b99
commit
c3d48d467d
@ -1,15 +1,15 @@
|
||||
import { HemisphereLight } from 'three';
|
||||
import { watch } from 'vue';
|
||||
import Light from './Light.js';
|
||||
import { bindProp } from '../tools.js';
|
||||
|
||||
export default {
|
||||
extends: Light,
|
||||
props: {
|
||||
groundColor: { type: String, default: '#ffffff' },
|
||||
groundColor: { type: String, default: '#444444' },
|
||||
},
|
||||
created() {
|
||||
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();
|
||||
},
|
||||
__hmrId: 'HemisphereLight',
|
||||
|
@ -11,6 +11,7 @@ export default {
|
||||
intensity: { type: Number, default: 1 },
|
||||
castShadow: { type: Boolean, default: false },
|
||||
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
|
||||
// setup() {},
|
||||
@ -26,12 +27,13 @@ export default {
|
||||
if (this.light.shadow) {
|
||||
this.light.castShadow = this.castShadow;
|
||||
setFromProp(this.light.shadow.mapSize, this.shadowMapSize);
|
||||
setFromProp(this.light.shadow.camera, this.shadowCamera);
|
||||
}
|
||||
|
||||
['color', 'intensity', 'castShadow'].forEach(p => {
|
||||
watch(() => this[p], () => {
|
||||
if (p === 'color') {
|
||||
this.light.color = new Color(this.color);
|
||||
this.light.color.set(this.color);
|
||||
} else {
|
||||
this.light[p] = this[p];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user