import { ExtensionProperty , IProperty , Nullable , PropertyType , vec3 } from '@gltf-transform/core' ; import { ColorUtils } from '@gltf-transform/core' ; import { KHR_LIGHTS_PUNCTUAL } from '../constants' ; interface ILight extends IProperty { color : vec3 ; intensity : number ; type : PunctualLightType ; range : number | null ; innerConeAngle : number ; outerConeAngle : number ; } type PunctualLightType = 'point' | 'spot' | 'directional' ; /**
 * # Light
 *
 * Defines a light attached to a  Node . See  LightsPunctual .
  export class Light extends ExtensionProperty < ILight > { public static EXTENSION_NAME = KHR_LIGHTS_PUNCTUAL ; public declare extensionName : typeof KHR_LIGHTS_PUNCTUAL ; public declare propertyType : 'Light' ; public declare parentTypes : [ PropertyType . NODE ] ; /**********************************************************************************************
     * CONSTANTS.
     */ public static Type : Record < string , PunctualLightType > = { POINT : 'point' , SPOT : 'spot' , DIRECTIONAL : 'directional' , } ; /**********************************************************************************************
     * INSTANCE.
     */ protected init ( ) { this . extensionName = KHR_LIGHTS_PUNCTUAL ; this . propertyType = 'Light' ; this . parentTypes = [ PropertyType . NODE ] ; } protected getDefaults ( ) { return Object . assign ( super . getDefaults ( ) as IProperty , { color : [ 1 , 1 , 1 ] as vec3 , intensity : 1 , type : Light . Type . POINT , range : null , innerConeAngle : 0 , outerConeAngle : Math . PI / 4 , } ) ; } /**********************************************************************************************
     * COLOR.
     */ /** Components (R, G, B) of light's color in linear space. */ public getColor ( ) { return this . get ( 'color' ) ; } /** Components (R, G, B) of light's color in linear space. */ public setColor ( color ) { return this . set ( 'color' , color ) ; } /** Hex light color in sRGB colorspace. */ public getColorHex ( ) { return ColorUtils . factorToHex ( this . getColor ( ) ) ; } /** Hex light color in sRGB colorspace. */ public setColorHex ( hex ) { const color = this . getColor ( ) . slice ( ) as vec3 ; ColorUtils . hexToFactor ( hex , color ) ; return this . setColor ( color ) ; } /**********************************************************************************************
     * INTENSITY.
     */ /**
     * Brightness of light. Units depend on the type of light: point and spot lights use luminous
     * intensity in candela (lm/sr) while directional lights use illuminance in lux (lm/m2).
     */ public getIntensity ( ) { return this . get ( 'intensity' ) ; } /**
     * Brightness of light. Units depend on the type of light: point and spot lights use luminous
     * intensity in candela (lm/sr) while directional lights use illuminance in lux (lm/m2).
     */ public setIntensity ( intensity ) { return this . set ( 'intensity' , intensity ) ; } /**********************************************************************************************
     * TYPE.
     */ /** Type. */ public getType ( ) { return this . get ( 'type' ) ; } /** Type. */ public setType ( type ) { return this . set ( 'type' , type ) ; } /**********************************************************************************************
     * RANGE.
     */ /**
     * Hint defining a distance cutoff at which the light's intensity may be considered to have
     * reached zero. Supported only for point and spot lights. Must be > 0. When undefined, range
     * is assumed to be infinite.
     */ public getRange ( ) { return this . get ( 'range' ) ; } /**
     * Hint defining a distance cutoff at which the light's intensity may be considered to have
     * reached zero. Supported only for point and spot lights. Must be > 0. When undefined, range
     * is assumed to be infinite.
     */ public setRange ( range ) { return this . set ( 'range' , range ) ; } /**********************************************************************************************
     * SPOT LIGHT PROPERTIES
     */ /**
     * Angle, in radians, from centre of spotlight where falloff begins. Must be ≥ 0 and
     * < outerConeAngle.
     */ public getInnerConeAngle ( ) { return this . get ( 'innerConeAngle' ) ; } /**
     * Angle, in radians, from centre of spotlight where falloff begins. Must be ≥ 0 and
     * < outerConeAngle.
     */ public setInnerConeAngle ( angle ) { return this . set ( 'innerConeAngle' , angle ) ; } /**
     * Angle, in radians, from centre of spotlight where falloff ends. Must be > innerConeAngle and
     * ≤ PI / 2.0.
     */ public getOuterConeAngle ( ) { return this . get ( 'outerConeAngle' ) ; } /**
     * Angle, in radians, from centre of spotlight where falloff ends. Must be > innerConeAngle and
     * ≤ PI / 2.0.
     */ public setOuterConeAngle ( angle ) { return this . set ( 'outerConeAngle' , angle ) ; } }