UNPKG

photo-sphere-viewer-lensflare-plugin

Version:

Plugin to add lens flares on a 360° pano built with photo-sphere-viewer

260 lines (259 loc) 7.21 kB
import { AbstractPlugin, Viewer, ExtendedPosition, Position, Size, TypedEvent } from '@photo-sphere-viewer/core'; import { Object3D, PointLight } from "three"; type HSL = { h: number; s: number; l: number; }; /** * Configuration of a lensflare */ type LensflareConfig = { /** * Unique identifier of the lensflare */ id: string; /** * Type of the lensflare * currently-supported: 0 * * @default 0 * @see LensflareType */ type?: number; /** * Position of the lensflare (required but for `polygon` and `polyline`) */ position?: ExtendedPosition; /** * The "hsl" color of the lensflare * @default [0.08, 0.2, 0.5] * @see https://en.wikipedia.org/wiki/HSL_and_HSV * @see https://www.w3schools.com/colors/colors_hsl.asp */ color?: HSL; /** * Size of the lensflare (required for `image` and `imageLayer`, recommended for `html`, ignored for others) */ size?: Size; /** * Applies a perspective on the image to make it look like placed on the floor or on a wall (only for `imageLayer`) */ orientation?: "front" | "horizontal" | "vertical-left" | "vertical-right"; /** * Configures the scale of the lensflare depending on the zoom level and/or the horizontal offset (ignored for `polygon`, `polyline` and `imageLayer`) */ scale?: [ number, number ] | { zoom?: [ number, number ]; yaw?: [ number, number ]; } | ((zoomLevel: number, position: Position) => number); /** * Opacity of the lensflare * @default 1 */ opacity?: number; /** * Defines where the lensflare is placed toward its defined position * @default 'center center' */ anchor?: string; /** * Initial visibility of the lensflare * @default true */ visible?: boolean; }; type LensflarePluginConfig = { /** * initial lensflares */ lensflares?: LensflareConfig[]; }; declare class LensflareObject { private readonly viewer; private config; private loader; private textureFlare; private readonly element; visible: boolean; get id(): string; get domElement(): HTMLElement | SVGElement; get threeElement(): Object3D; constructor(viewer: Viewer, config: LensflareConfig); private refreshAfterLoad; destroy(): void; addLight(h: number, s: number, l: number, x: number, y: number, z: number): PointLight; /** * Updates a 3D lensflare */ private __update3d; private __createMesh; } /** * Base class for events dispatched by {@link LensflaresPlugin} */ declare abstract class LensflaresPluginEvent extends TypedEvent<LensflarePlugin> { } /** * @event Triggered when the visibility of a lensflare changes */ declare class LensflareVisibilityEvent extends LensflaresPluginEvent { readonly lensflare: LensflareObject; readonly visible: boolean; static readonly type = "lensflare-visibility"; constructor(lensflare: LensflareObject, visible: boolean); } /** * @event Triggered when the lensflares change */ declare class SetLensflaresEvent extends LensflaresPluginEvent { readonly lensflares: LensflareObject[]; static readonly type = "set-lensflares"; constructor(lensflares: LensflareObject[]); } type LensflaresPluginEvents = LensflareVisibilityEvent | SetLensflaresEvent; declare class LensflarePlugin extends AbstractPlugin<LensflaresPluginEvents> { static readonly id = "lensflare"; readonly config: LensflarePluginConfig; private readonly lensflares; private readonly state; constructor(viewer: Viewer, config: LensflarePluginConfig); init(): void; destroy(): void; /** * Toggles all lensflares */ /** * Toggles all lensflares */ toggleAllLensflares(): void; /** * Shows all lensflares */ /** * Shows all lensflares */ showAllLensflares(): void; /** * Hides all lensflares */ /** * Hides all lensflares */ hideAllLensflares(): void; /** * Returns the total number of lensflares */ /** * Returns the total number of lensflares */ getNbLensflares(): number; /** * Returns all the lensflares */ /** * Returns all the lensflares */ getLensflares(): LensflareObject[]; /** * Adds a new Lensflare to viewer * @throws {@link PSVError} when the lensflare's id is missing or already exists */ /** * Adds a new Lensflare to viewer * @throws {@link PSVError} when the lensflare's id is missing or already exists */ addLensflare(config: LensflareConfig, render?: boolean): void; /** * Returns the internal lensflare object for a lensflare id * @throws {@link PSVError} when the lensflare cannot be found */ /** * Returns the internal lensflare object for a lensflare id * @throws {@link PSVError} when the lensflare cannot be found */ getLensflare(lensflareId: string | LensflareConfig): LensflareObject; /** * Returns the last lensflare selected by the user */ /** * Returns the last lensflare selected by the user */ getCurrentLensflare(): LensflareObject; /** * Updates the existing lensflare with the same id * @description Every property can be changed but you can't change its type (Eg: `image` to `html`) */ /** * Updates the existing lensflare with the same id * @description Every property can be changed but you can't change its type (Eg: `image` to `html`) */ updateLensflare(config: LensflareConfig, render?: boolean): void; /** * Removes a lensflare from the viewer */ /** * Removes a lensflare from the viewer */ removeLensflare(lensflareId: string | LensflareConfig, render?: boolean): void; /** * Removes multiple lensflares */ /** * Removes multiple lensflares */ removeLensflares(lensflareIds: string[], render?: boolean): void; /** * Replaces all lensflares */ /** * Replaces all lensflares */ setLensflares(lensflares: LensflareConfig[], render?: boolean): void; /** * Removes all lensflares */ /** * Removes all lensflares */ clearLensflares(render?: boolean): void; /** * Hides a lensflare */ /** * Hides a lensflare */ hideLensflare(lensflareId: string | LensflareConfig): void; /** * Shows a lensflare */ /** * Shows a lensflare */ showLensflare(lensflareId: string | LensflareConfig): void; /** * Toggles a lensflare visibility */ /** * Toggles a lensflare visibility */ toggleLensflare(lensflareId: string | LensflareConfig, visible?: boolean): void; /** * Updates the visibility and the position of all lensflares */ /** * Updates the visibility and the position of all lensflares */ renderLensflares(): void; private __afterChangerLensflares; } export { LensflarePlugin };