diff --git a/src/components/light/_light.ts b/src/components/light/_light.ts index 4c265d5c..8fd81269 100644 --- a/src/components/light/_light.ts +++ b/src/components/light/_light.ts @@ -1,9 +1,15 @@ import { Component, ComponentSchema, Types } from 'ecsy'; +import { Color3 } from '@babylonjs/core/Maths/math.color'; +import { BabylonTypes } from '../../-private/ecsy-types'; export default abstract class Light extends Component { intensity!: number; + diffuse!: Color3; + specular!: Color3; } export const schema: ComponentSchema = { intensity: { type: Types.Number, default: 1 }, + diffuse: { type: BabylonTypes.Color3, default: Color3.White() }, + specular: { type: BabylonTypes.Color3, default: Color3.White() }, }; diff --git a/src/components/light/hemispheric.ts b/src/components/light/hemispheric.ts index b9d4d805..f59dfc52 100644 --- a/src/components/light/hemispheric.ts +++ b/src/components/light/hemispheric.ts @@ -3,12 +3,15 @@ import { schema as baseSchema } from './_shadow'; import { ComponentSchema } from 'ecsy'; import { BabylonTypes } from '../../-private/ecsy-types'; import Light from './_light'; +import { Color3 } from '@babylonjs/core/Maths/math.color'; export default class HemisphericLight extends Light { direction!: Vector3; + groundColor!: Color3; static schema: ComponentSchema = { ...baseSchema, direction: { type: BabylonTypes.Vector3, default: new Vector3(0, -1, 0) }, + groundColor: { type: BabylonTypes.Color3, default: Color3.Black() }, }; } diff --git a/test/light.test.ts b/test/light.test.ts index d935240f..6df38c15 100644 --- a/test/light.test.ts +++ b/test/light.test.ts @@ -5,6 +5,7 @@ import { SpotLight as BabylonSpotLight } from '@babylonjs/core/Lights/spotLight' import { HemisphericLight as BabylonHemisphericLight } from '@babylonjs/core/Lights/hemisphericLight'; import { Vector3 } from '@babylonjs/core/Maths/math.vector'; import setupWorld from './helpers/setup-world'; +import { Color3 } from '@babylonjs/core/Maths/math.color'; describe('light system', function () { describe('point-light', function () { @@ -27,7 +28,9 @@ describe('light system', function () { const { world, scene } = setupWorld(); const lightEntity = world.createEntity(); - lightEntity.addComponent(Parent).addComponent(PointLight, { intensity: 2 }); + lightEntity + .addComponent(Parent) + .addComponent(PointLight, { intensity: 2, diffuse: new Color3(1, 0, 0), specular: new Color3(0, 1, 0) }); world.execute(0, 0); @@ -36,6 +39,8 @@ describe('light system', function () { const light = scene.lights[0]; expect(light).toBeInstanceOf(BabylonPointLight); expect(light.intensity).toBe(2); + expect(light.diffuse.equalsFloats(1, 0, 0)).toBeTrue(); + expect(light.specular.equalsFloats(0, 1, 0)).toBeTrue(); }); it('can update point-light', function () { @@ -241,9 +246,11 @@ describe('light system', function () { const { world, scene } = setupWorld(); const lightEntity = world.createEntity(); - lightEntity - .addComponent(Parent) - .addComponent(HemisphericLight, { intensity: 2, direction: new Vector3(1, 0, 0) }); + lightEntity.addComponent(Parent).addComponent(HemisphericLight, { + intensity: 2, + direction: new Vector3(1, 0, 0), + groundColor: new Color3(1, 0, 0), + }); world.execute(0, 0); @@ -253,6 +260,7 @@ describe('light system', function () { expect(light).toBeInstanceOf(BabylonHemisphericLight); expect(light.intensity).toBe(2); expect(light.direction.equalsToFloats(1, 0, 0)).toBeTrue(); + expect(light.groundColor.equalsFloats(1, 0, 0)).toBeTrue(); }); it('can update hemispheric-light', function () {