import { ColorUtils , ExtensionProperty , IProperty , Nullable , PropertyType , Texture , TextureChannel , TextureInfo , vec3 , vec4 , } from '@gltf-transform/core' ; import { KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS } from '../constants' ; interface IPBRSpecularGlossiness extends IProperty { diffuseFactor : vec4 ; diffuseTexture : Texture ; diffuseTextureInfo : TextureInfo ; specularFactor : vec3 ; glossinessFactor : number ; specularGlossinessTexture : Texture ; specularGlossinessTextureInfo : TextureInfo ; } const { R , G , B , A } = TextureChannel ; /**
 * # PBRSpecularGlossiness
 *
 * Converts a  Material to a spec/gloss workflow. See  MaterialsPBRSpecularGlossiness .
  export class PBRSpecularGlossiness extends ExtensionProperty < IPBRSpecularGlossiness > { public static EXTENSION_NAME = KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS ; public declare extensionName : typeof KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS ; public declare propertyType : 'PBRSpecularGlossiness' ; public declare parentTypes : [ PropertyType . MATERIAL ] ; protected init ( ) { this . extensionName = KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS ; this . propertyType = 'PBRSpecularGlossiness' ; this . parentTypes = [ PropertyType . MATERIAL ] ; } protected getDefaults ( ) { return Object . assign ( super . getDefaults ( ) as IProperty , { diffuseFactor : [ 1.0 , 1.0 , 1.0 , 1.0 ] as vec4 , diffuseTexture : null , diffuseTextureInfo : new TextureInfo ( this . graph , 'diffuseTextureInfo' ) , specularFactor : [ 1.0 , 1.0 , 1.0 ] as vec3 , glossinessFactor : 1.0 , specularGlossinessTexture : null , specularGlossinessTextureInfo : new TextureInfo ( this . graph , 'specularGlossinessTextureInfo' ) , } ) ; } /**********************************************************************************************
     * Diffuse.
     */ /** Diffuse; linear multiplier. See  getDiffuseTexture .  public getDiffuseFactor ( ) { return this . get ( 'diffuseFactor' ) ; } /** Diffuse; linear multiplier. See  getDiffuseTexture .  public setDiffuseFactor ( factor ) { return this . set ( 'diffuseFactor' , factor ) ; } /** Diffuse; hex color in sRGB colorspace. */ public getDiffuseHex ( ) { return ColorUtils . factorToHex ( this . getDiffuseFactor ( ) ) ; } /** Diffuse; hex color in sRGB colorspace. */ public setDiffuseHex ( hex ) { const factor = this . getDiffuseFactor ( ) . slice ( ) as vec4 ; return this . setDiffuseFactor ( ColorUtils . hexToFactor ( hex , factor ) ) ; } /**
     * Diffuse texture; linear multiplier. Alternative to baseColorTexture used within the
     * spec/gloss PBR workflow.
     */ public getDiffuseTexture ( ) { return this . getRef ( 'diffuseTexture' ) ; } /**
     * Settings affecting the material's use of its diffuse texture. If no texture is attached,
     *  TextureInfo is `null`.
      public getDiffuseTextureInfo ( ) { return this . getRef ( 'diffuseTexture' ) ? this . getRef ( 'diffuseTextureInfo' ) : null ; } /** Sets diffuse texture. See  getDiffuseTexture .  public setDiffuseTexture ( texture ) { return this . setRef ( 'diffuseTexture' , texture , { channels : R | G | B | A } ) ; } /**********************************************************************************************
     * Specular.
     */ /** Specular; linear multiplier. */ public getSpecularFactor ( ) { return this . get ( 'specularFactor' ) ; } /** Specular; linear multiplier. */ public setSpecularFactor ( factor ) { return this . set ( 'specularFactor' , factor ) ; } /**********************************************************************************************
     * Glossiness.
     */ /** Glossiness; linear multiplier. */ public getGlossinessFactor ( ) { return this . get ( 'glossinessFactor' ) ; } /** Glossiness; linear multiplier. */ public setGlossinessFactor ( factor ) { return this . set ( 'glossinessFactor' , factor ) ; } /**********************************************************************************************
     * Specular/Glossiness.
     */ /** Spec/gloss texture; linear multiplier. */ public getSpecularGlossinessTexture ( ) { return this . getRef ( 'specularGlossinessTexture' ) ; } /**
     * Settings affecting the material's use of its spec/gloss texture. If no texture is attached,
     *  TextureInfo is `null`.
      public getSpecularGlossinessTextureInfo ( ) { return this . getRef ( 'specularGlossinessTexture' ) ? this . getRef ( 'specularGlossinessTextureInfo' ) : null ; } /** Spec/gloss texture; linear multiplier. */ public setSpecularGlossinessTexture ( texture ) { return this . setRef ( 'specularGlossinessTexture' , texture , { channels : R | G | B | A } ) ; } }