import type { RayHandler } from "../RayHandler"; import { LightMesh } from "../LightMesh"; import { LightColor, RGBA } from "../utils"; import { XY, Vector2 } from "../math"; export type DebugDrawPolygon = (vertices: XY[], vertexCount: number, color: RGBA) => void; export interface LightContactFilter { categoryBits: number; maskBits: number; groupIndex: number; } /** * Light is data container for all the light parameters. When created lights * are automatically added to rayHandler and could be removed by calling * {@link #remove()} and added manually by calling {@link #add(RayHandler)}. * *
Implements {@link Disposable} * * @author kalle_h */ export declare abstract class Light { static readonly DefaultColor: LightColor; static readonly DebugColor: LightColor; static readonly MIN_RAYS = 3; protected readonly color: LightColor; protected readonly tmpPosition: Vector2; protected rayHandler: RayHandler; protected active: boolean; protected soft: boolean; protected xray: boolean; protected staticLight: boolean; protected culled: boolean; protected dirty: boolean; protected ignoreBody: boolean; protected rayNum: number; protected vertexNum: number; protected distance: number; protected direction: number; protected colorF: number; protected softShadowLength: number; protected readonly lightMesh: LightMesh; protected softShadowMesh: LightMesh | null; protected mx: number[]; protected my: number[]; protected f: number[]; protected m_index: number; protected gl: WebGLRenderingContext; /** This light specific filter */ private contactFilter; /** Global lights filter */ private static globalContactFilter; readonly rayCast: (point1: XY, point2: XY) => void; /** * Creates new active light and automatically adds it to the specified * {@link RayHandler} instance. * * @param rayHandler * not null instance of RayHandler * @param rays * number of rays - more rays make light to look more realistic * but will decrease performance, can't be less than MIN_RAYS * @param color * light color * @param distance * light distance (if applicable), soft shadow length is set to distance * 0.1 * @param directionDegree * direction in degrees (if applicable) */ constructor(rayHandler: RayHandler, rays: number, color: RGBA, distance: number, directionDegree: number); protected setupSoftShadowMesh(): void; getSoftShadowVertexCount(): number; abstract debugRender(drawPolygon: DebugDrawPolygon): void; /** * Updates this light */ abstract update(): void; /** * Render this light */ abstract render(): void; /** * Sets light distance * *
NOTE: MIN value should be capped to 0.1 meter */ abstract setDistance(dist: number): void; /** * Sets light direction */ abstract setDirection(directionDegree: number): void; /** * Attaches light to specified body * * @param body * that will be automatically followed, note that the body * rotation angle is taken into account for the light offset * and direction calculations */ abstract attachToBody(body: any): void; /** * @returns Attached body or {@code null} * * @see #attachToBody(any) */ abstract getBody(): any | null; /** * Sets light starting position * * @see #setPosition(XY) */ abstract setPosition(x: number, y: number): void; /** * Sets light starting position * * @see #setPosition(float, float) */ abstract setPositionV(position: XY): void; /** * @returns Horizontal starting position of light in world coordinates */ abstract getX(): number; /** * @returns Vertical starting position of light in world coordinates */ abstract getY(): number; /** * @returns Starting position of light in world coordinates *
NOTE: changing this vector does nothing */ getPosition(): Vector2; /** * Sets light color * *
NOTE: you can also use colorless light with shadows, e.g. (0,0,0,1) * * @param newColor * RGB set the color and Alpha set intensity * * @see #setColor(float, float, float, float) */ setColorC(newColor: RGBA): void; /** * Sets light color * *
NOTE: you can also use colorless light with shadows, e.g. (0,0,0,1) * * @param r * lights color red component * @param g * lights color green component * @param b * lights color blue component * @param a * lights shadow intensity * * @see #setColor(LightContactFilter) */ setColor(r: number, g: number, b: number, a: number): void; /** * Adds light to specified RayHandler */ add(rayHandler: RayHandler): void; /** * Removes light from specified RayHandler and disposes it if requested */ remove(doDispose?: boolean): void; /** * Disposes all light resources. * Don't forget to remove the light from the RayHandler first! * FIXME: this is too confusing */ dispose(): void; /** * @returns If this light is active */ isActive(): boolean; /** * Enables/disables this light update and rendering */ setActive(active: boolean): void; /** * @returns If this light beams go through obstacles */ isXray(): boolean; /** * Enables/disables x-ray beams for this light * *
Enabling this will allow beams go through obstacles that reduce CPU * burden of light about 70%. * *
Use the combination of x-ray and non x-ray lights wisely */ setXray(xray: boolean): void; /** * @returns If this light is static *
Static light do not get any automatic updates but setting * any parameters will update it. Static lights are useful for * lights that you want to collide with static geometry but ignore * all the dynamic objects. */ isStaticLight(): boolean; /** * Enables/disables this light static behavior * *
Static light do not get any automatic updates but setting any * parameters will update it. Static lights are useful for lights that you * want to collide with static geometry but ignore all the dynamic objects * *
Reduce CPU burden of light about 90% */ setStaticLight(staticLight: boolean): void; /** * @returns If tips of this light beams are soft */ isSoft(): boolean; /** * Enables/disables softness on tips of this light beams */ setSoft(soft: boolean): void; /** * @returns Softness value for beams tips *
Default: {@code 2.5 } */ getSoftShadowLength(): number; /** * Sets softness value for beams tips * *
Default: {@code 2.5 } */ setSoftnessLength(softShadowLength: number): void; /** * @returns Current color of this light */ getColor(): LightColor; /** * @returns Rays distance of this light (without gamma correction) */ getDistance(): number; /** * @returns Direction in degrees (0 if not applicable) */ getDirection(): number; /** * Checks if given point is inside of this light area * * @param x - horizontal position of point in world coordinates * @param y - vertical position of point in world coordinates */ contains(_x: number, _y: number): boolean; /** * Sets if the attached body fixtures should be ignored during raycasting * * @param flag - if {@code true} all the fixtures of attached body * will be ignored and will not create any shadows for this * light. By default is set to {@code false}. */ setIgnoreAttachedBody(flag: boolean): void; /** * @returns If the attached body fixtures will be ignored during raycasting */ getIgnoreAttachedBody(): boolean; /** * Internal method for mesh update depending on ray number */ protected setRayNum(rays: number, updateMesh?: boolean): void; /** * @returns Number of rays set for this light */ getRayNum(): number; /** * Sets given contact filter for this light */ setContactFilter(filter: LightContactFilter | null): void; getContactFilter(): LightContactFilter | null; /** * Creates new contact filter for this light with given parameters * * @param categoryBits - see {@link LightContactFilter#categoryBits} * @param groupIndex - see {@link LightContactFilter#groupIndex} * @param maskBits - see {@link LightContactFilter#maskBits} */ setContactFilterBits(categoryBits: number, groupIndex: number, maskBits: number): void; /** * Sets given contact filter for ALL LIGHTS */ static setGlobalContactFilter(filter: LightContactFilter | null): void; /** * Creates new contact filter for ALL LIGHTS with give parameters * * @param categoryBits - see {@link LightContactFilter#categoryBits} * @param groupIndex - see {@link LightContactFilter#groupIndex} * @param maskBits - see {@link LightContactFilter#maskBits} */ static setGlobalContactFilterBits(categoryBits: number, groupIndex: number, maskBits: number): void; static getGlobalContactFilter(): LightContactFilter | null; reportFixture(filterB: LightContactFilter, bodyB: any, point: XY, fraction: number): number; private runContactFilter; } //# sourceMappingURL=Light.d.ts.map