/**
 * Copyright(c) Live2D Inc. All rights reserved.
 *
 * Use of this source code is governed by the Live2D Open Software license
 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
 */ import { CubismIdHandle } from '../id/cubismid' ; import { CubismFramework } from '../live2dcubismframework' ; import { CubismModel } from '../model/cubismmodel' ; import { csmVector } from '../type/csmvector' ; import { CubismJson , Value } from '../utils/cubismjson' ; import { ACubismMotion } from './acubismmotion' ; import { CubismMotionQueueEntry } from './cubismmotionqueueentry' ; const ExpressionKeyFadeIn = 'FadeInTime' ; const ExpressionKeyFadeOut = 'FadeOutTime' ; const ExpressionKeyParameters = 'Parameters' ; const ExpressionKeyId = 'Id' ; const ExpressionKeyValue = 'Value' ; const ExpressionKeyBlend = 'Blend' ; const BlendValueAdd = 'Add' ; const BlendValueMultiply = 'Multiply' ; const BlendValueOverwrite = 'Overwrite' ; const DefaultFadeTime = 1.0 ; /**
 * 表情のモーション
 *
 * 表情のモーションクラス。
 */ export class CubismExpressionMotion extends ACubismMotion { param buffer param size return public static create ( buffer , size ) { const expression = new CubismExpressionMotion ( ) ; const json = CubismJson . create ( buffer , size ) ; const root = json . getRoot ( ) ; expression . setFadeInTime ( root . getValueByString ( ExpressionKeyFadeIn ) . toFloat ( DefaultFadeTime ) ) ; expression . setFadeOutTime ( root . getValueByString ( ExpressionKeyFadeOut ) . toFloat ( DefaultFadeTime ) ) ; const parameterCount = root . getValueByString ( ExpressionKeyParameters ) . getSize ( ) ; expression . _parameters . prepareCapacity ( parameterCount ) ; for ( let i = 0 ; i < parameterCount ; ++ i ) { const param = root . getValueByString ( ExpressionKeyParameters ) . getValueByIndex ( i ) ; const parameterId = CubismFramework . getIdManager ( ) . getId ( param . getValueByString ( ExpressionKeyId ) . getRawString ( ) ) ; const value = param . getValueByString ( ExpressionKeyValue ) . toFloat ( ) ; let blendType ; if ( param . getValueByString ( ExpressionKeyBlend ) . isNull ( ) || param . getValueByString ( ExpressionKeyBlend ) . getString ( ) == BlendValueAdd ) { blendType = ExpressionBlendType . ExpressionBlendType_Add ; } else if ( param . getValueByString ( ExpressionKeyBlend ) . getString ( ) == BlendValueMultiply ) { blendType = ExpressionBlendType . ExpressionBlendType_Multiply ; } else if ( param . getValueByString ( ExpressionKeyBlend ) . getString ( ) == BlendValueOverwrite ) { blendType = ExpressionBlendType . ExpressionBlendType_Overwrite ; } else { blendType = ExpressionBlendType . ExpressionBlendType_Add ; } const item = new ExpressionParameter ( ) ; item . parameterId = parameterId ; item . blendType = blendType ; item . value = value ; expression . _parameters . pushBack ( item ) ; } CubismJson . delete ( json ) ; return expression ; } param model param userTimeSeconds param weight param motionQueueEntry public doUpdateParameters ( model , userTimeSeconds , weight , motionQueueEntry ) { for ( let i = 0 ; i < this . _parameters . getSize ( ) ; ++ i ) { const parameter = this . _parameters . at ( i ) ; switch ( parameter . blendType ) { case ExpressionBlendType . ExpressionBlendType_Add : { model . addParameterValueById ( parameter . parameterId , parameter . value , weight ) ; break ; } case ExpressionBlendType . ExpressionBlendType_Multiply : { model . multiplyParameterValueById ( parameter . parameterId , parameter . value , weight ) ; break ; } case ExpressionBlendType . ExpressionBlendType_Overwrite : { model . setParameterValueById ( parameter . parameterId , parameter . value , weight ) ; break ; } default : break ; } } } /**
     * コンストラクタ
     */ constructor ( ) { super ( ) ; this . _parameters = new csmVector < ExpressionParameter > ( ) ; } _parameters : csmVector < ExpressionParameter > ; } /**
 * 表情パラメータ値の計算方式
 */ export enum ExpressionBlendType { ExpressionBlendType_Add = 0 , ExpressionBlendType_Multiply = 1 , ExpressionBlendType_Overwrite = 2 } /**
 * 表情のパラメータ情報
 */ export class ExpressionParameter { parameterId : CubismIdHandle ; blendType : ExpressionBlendType ; value : number ; } import * as $ from './cubismexpressionmotion' ; export namespace Live2DCubismFramework { export const CubismExpressionMotion = $ . CubismExpressionMotion ; export type CubismExpressionMotion = $ . CubismExpressionMotion ; export const ExpressionBlendType = $ . ExpressionBlendType ; export type ExpressionBlendType = $ . ExpressionBlendType ; export const ExpressionParameter = $ . ExpressionParameter ; export type ExpressionParameter = $ . ExpressionParameter ; }