import { VRMSchema } from '../types' ; import { saturate } from '../utils/math' ; import { VRMBlendShapeGroup } from './VRMBlendShapeGroup' ; export class VRMBlendShapeProxy { /**
     * List of registered blend shape.
     */ private readonly _blendShapeGroups : { [ name ] : VRMBlendShapeGroup ; } = { } ; /**
     * A map from [[VRMSchema.BlendShapePresetName]] to its actual blend shape name.
     */ private readonly _blendShapePresetMap : { [ presetName in VRMSchema . BlendShapePresetName ] ? : string ; } = { } ; /**
     * A list of name of unknown blend shapes.
     */ private readonly _unknownGroupNames : string [ ] = [ ] ; /**
     * Create a new VRMBlendShape.
     */ public constructor ( ) { } /**
     * List of name of registered blend shape group.
     */ public get expressions ( ) : string [ ] { return Object . keys ( this . _blendShapeGroups ) ; } /**
     * A map from [[VRMSchema.BlendShapePresetName]] to its actual blend shape name.
     */ public get blendShapePresetMap ( ) : { [ presetName in VRMSchema . BlendShapePresetName ] ? : string ; } { return this . _blendShapePresetMap ; } /**
     * A list of name of unknown blend shapes.
     */ public get unknownGroupNames ( ) : string [ ] { return this . _unknownGroupNames ; } param name public getBlendShapeGroup ( name ) { const presetName = this . _blendShapePresetMap [ name as VRMSchema . BlendShapePresetName ] ; const controller = presetName ? this . _blendShapeGroups [ presetName ] : this . _blendShapeGroups [ name ] ; if ( ! controller ) { console . warn ( `no blend shape found by ${ name }` ) ; return undefined ; } return controller ; } param name param controller public registerBlendShapeGroup ( name , presetName , controller ) { this . _blendShapeGroups [ name ] = controller ; if ( presetName ) { this . _blendShapePresetMap [ presetName ] = name ; } else { this . _unknownGroupNames . push ( name ) ; } } param name public getValue ( name ) { const controller = this . getBlendShapeGroup ( name ) ; return controller ?. weight ?? null ; } param name param weight public setValue ( name , weight ) { const controller = this . getBlendShapeGroup ( name ) ; if ( controller ) { controller . weight = saturate ( weight ) ; } } example param name public getBlendShapeTrackName ( name ) { const controller = this . getBlendShapeGroup ( name ) ; return controller ? `${ controller . name }.weight` : null ; } /**
     * Update every blend shape groups.
     */ public update ( ) { Object . keys ( this . _blendShapeGroups ) . forEach ( ( name ) => { const controller = this . _blendShapeGroups [ name ] ; controller . clearAppliedWeight ( ) ; } ) ; Object . keys ( this . _blendShapeGroups ) . forEach ( ( name ) => { const controller = this . _blendShapeGroups [ name ] ; controller . applyWeight ( ) ; } ) ; } }