Skip to content

Commit

Permalink
Merge pull request #5918 from mozilla/BitECSAmbientLight
Browse files Browse the repository at this point in the history
Add AmbientLights to bitecs
  • Loading branch information
takahirox authored Feb 3, 2023
2 parents f446dda + 9e54209 commit 67d199a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bit-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const AEntity = defineComponent();
export const Object3DTag = defineComponent();
export const GLTFModel = defineComponent();
export const LightTag = defineComponent();
export const AmbientLightTag = defineComponent();
export const DirectionalLight = defineComponent();
export const CursorRaycastable = defineComponent();
export const RemoteHoverTarget = defineComponent();
Expand Down
26 changes: 26 additions & 0 deletions src/inflators/ambient-light.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { addComponent } from "bitecs";
import { addObject3DComponent } from "../utils/jsx-entity";
import { AmbientLightTag, LightTag } from "../bit-components";
import { AmbientLight } from "three";
import { HubsWorld } from "../app";

export type AmbientLightParams = {
color: string;
intensity: number;
};

const DEFAULTS = {
intensity: 1.0
};

export function inflateAmbientLight(world: HubsWorld, eid: number, params: AmbientLightParams) {
params = Object.assign({}, DEFAULTS, params);
const light = new AmbientLight();
light.color.set(params.color).convertSRGBToLinear();
light.intensity = params.intensity;

addObject3DComponent(world, eid, light);
addComponent(world, LightTag, eid);
addComponent(world, AmbientLightTag, eid);
return eid;
}
3 changes: 3 additions & 0 deletions src/utils/jsx-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { AlphaMode } from "./create-image-mesh";
import { MediaLoaderParams } from "../inflators/media-loader";
import { preload } from "./preload";
import { DirectionalLightParams, inflateDirectionalLight } from "../inflators/directional-light";
import { AmbientLightParams, inflateAmbientLight } from "../inflators/ambient-light";
import { ProjectionMode } from "./projection-mode";
import { inflateSkybox, SkyboxParams } from "../inflators/skybox";
import { inflateSpawner, SpawnerParams } from "../inflators/spawner";
Expand Down Expand Up @@ -221,6 +222,7 @@ interface InflatorFn {

// @TODO these properties should import types from their inflators
export interface ComponentData {
ambientLight?: AmbientLightParams;
directionalLight?: DirectionalLightParams;
grabbable?: GrabbableParams;
billboard?: { onlyY: boolean };
Expand Down Expand Up @@ -365,6 +367,7 @@ export const commonInflators: Required<{ [K in keyof ComponentData]: InflatorFn
billboard: createDefaultInflator(Billboard),

// inflators that create Object3Ds
ambientLight: inflateAmbientLight,
directionalLight: inflateDirectionalLight,
simpleWater: inflateSimpleWater
};
Expand Down

0 comments on commit 67d199a

Please sign in to comment.