import { ColorUtils , ExtensionProperty , IProperty , Nullable , PropertyType , Texture , TextureChannel , TextureInfo , vec3 , } from '@gltf-transform/core' ; import { KHR_MATERIALS_SPECULAR } from '../constants' ; interface ISpecular extends IProperty { specularFactor : number ; specularTexture : Texture ; specularTextureInfo : TextureInfo ; specularColorFactor : vec3 ; specularColorTexture : Texture ; specularColorTextureInfo : TextureInfo ; } const { R , G , B , A } = TextureChannel ; /**
 * # Specular
 *
 * Defines specular reflectivity on a PBR  Material . See  MaterialsSpecular .
  export class Specular extends ExtensionProperty < ISpecular > { public static EXTENSION_NAME = KHR_MATERIALS_SPECULAR ; public declare extensionName : typeof KHR_MATERIALS_SPECULAR ; public declare propertyType : 'Specular' ; public declare parentTypes : [ PropertyType . MATERIAL ] ; protected init ( ) { this . extensionName = KHR_MATERIALS_SPECULAR ; this . propertyType = 'Specular' ; this . parentTypes = [ PropertyType . MATERIAL ] ; } protected getDefaults ( ) { return Object . assign ( super . getDefaults ( ) as IProperty , { specularFactor : 1.0 , specularTexture : null , specularTextureInfo : new TextureInfo ( this . graph , 'specularTextureInfo' ) , specularColorFactor : [ 1.0 , 1.0 , 1.0 ] as vec3 , specularColorTexture : null , specularColorTextureInfo : new TextureInfo ( this . graph , 'specularColorTextureInfo' ) , } ) ; } /**********************************************************************************************
     * Specular.
     */ /** Specular; linear multiplier. See  getSpecularTexture .  public getSpecularFactor ( ) { return this . get ( 'specularFactor' ) ; } /** Specular; linear multiplier. See  getSpecularTexture .  public setSpecularFactor ( factor ) { return this . set ( 'specularFactor' , factor ) ; } /** Specular color; components in linear space. See  getSpecularTexture .  public getSpecularColorFactor ( ) { return this . get ( 'specularColorFactor' ) ; } /** Specular color; components in linear space. See  getSpecularTexture .  public setSpecularColorFactor ( factor ) { return this . set ( 'specularColorFactor' , factor ) ; } /** Specular color; hexadecimal in sRGB colorspace. See  getSpecularTexture public getSpecularColorHex ( ) { return ColorUtils . factorToHex ( this . getSpecularColorFactor ( ) ) ; } /** Specular color; hexadecimal in sRGB colorspace. See  getSpecularTexture public setSpecularColorHex ( hex ) { const factor = this . getSpecularColorFactor ( ) . slice ( ) as vec3 ; return this . set ( 'specularColorFactor' , ColorUtils . hexToFactor ( hex , factor ) ) ; } /**
     * Specular texture; linear multiplier. Configures the strength of the specular reflection in
     * the dielectric BRDF. A value of zero disables the specular reflection, resulting in a pure
     * diffuse material.
     *
     * Only the alpha (A) channel is used for specular strength, but this texture may optionally
     * be packed with specular color (RGB) into a single texture.
     */ public getSpecularTexture ( ) { return this . getRef ( 'specularTexture' ) ; } /**
     * Settings affecting the material's use of its specular texture. If no texture is attached,
     *  TextureInfo is `null`.
      public getSpecularTextureInfo ( ) { return this . getRef ( 'specularTexture' ) ? this . getRef ( 'specularTextureInfo' ) : null ; } /** Sets specular texture. See  getSpecularTexture .  public setSpecularTexture ( texture ) { return this . setRef ( 'specularTexture' , texture , { channels : A } ) ; } /**
     * Specular color texture; linear multiplier. Defines the F0 color of the specular reflection
     * (RGB channels, encoded in sRGB) in the the dielectric BRDF.
     *
     * Only RGB channels are used here, but this texture may optionally be packed with a specular
     * factor (A) into a single texture.
     */ public getSpecularColorTexture ( ) { return this . getRef ( 'specularColorTexture' ) ; } /**
     * Settings affecting the material's use of its specular color texture. If no texture is
     * attached,  TextureInfo is `null`.
      public getSpecularColorTextureInfo ( ) { return this . getRef ( 'specularColorTexture' ) ? this . getRef ( 'specularColorTextureInfo' ) : null ; } /** Sets specular color texture. See  getSpecularColorTexture .  public setSpecularColorTexture ( texture ) { return this . setRef ( 'specularColorTexture' , texture , { channels : R | G | B } ) ; } }