UNPKG

@playcanvas/react

Version:

A React renderer for PlayCanvas – build interactive 3D applications using React's declarative paradigm.

30 lines 1.44 kB
import { useComponent } from "../hooks/index.js"; import { Entity } from "playcanvas"; import { validatePropsWithDefaults, createComponentDefinition, getStaticNullApplication } from "../utils/validation.js"; /** * The Light component adds a light source to the entity. A light can be a directional, omni, or spot light. * Lights can be moved and orientated with the `position` and `rotation` props of its entity. * * @param {LightProps} props - The props to pass to the light component. * @see https://api.playcanvas.com/engine/classes/LightComponent.html * * @example * <Entity rotation={[0, 10, 0]}> * <Light type="directional" /> * </Entity> */ export const Light = (props) => { const safeProps = validatePropsWithDefaults(props, componentDefinition); useComponent("light", safeProps, componentDefinition.schema); return null; }; const componentDefinition = createComponentDefinition("Light", () => new Entity('mock-light', getStaticNullApplication()).addComponent('light'), (component) => component.system.destroy(), "LightComponent"); componentDefinition.schema = { ...componentDefinition.schema, type: { validate: (value) => typeof value === 'string' && ['directional', 'omni', 'spot'].includes(value), errorMsg: (value) => `Invalid value for prop "type": ${value}. Expected one of: "directional", "omni", "spot".`, default: "directional" } }; //# sourceMappingURL=Light.js.map