/**
 * 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 { ICubismModelSetting } from '../icubismmodelsetting' ; import { CubismIdHandle } from '../id/cubismid' ; import { CubismModel } from '../model/cubismmodel' ; import { csmVector } from '../type/csmvector' ; /**
 * 自動まばたき機能
 *
 * 自動まばたき機能を提供する。
 */ export class CubismEyeBlink { param modelSetting return note public static create ( modelSetting = null ) { return new CubismEyeBlink ( modelSetting ) ; } param eyeBlink public static delete ( eyeBlink ) { if ( eyeBlink != null ) { eyeBlink = null ; } } param blinkingInterval public setBlinkingInterval ( blinkingInterval ) { this . _blinkingIntervalSeconds = blinkingInterval ; } param closing param closed param opening public setBlinkingSetting ( closing , closed , opening ) { this . _closingSeconds = closing ; this . _closedSeconds = closed ; this . _openingSeconds = opening ; } param parameterIds public setParameterIds ( parameterIds ) { this . _parameterIds = parameterIds ; } return public getParameterIds ( ) { return this . _parameterIds ; } param model param deltaTimeSeconds public updateParameters ( model , deltaTimeSeconds ) { this . _userTimeSeconds += deltaTimeSeconds ; let parameterValue ; let t = 0.0 ; switch ( this . _blinkingState ) { case EyeState . EyeState_Closing : t = ( this . _userTimeSeconds - this . _stateStartTimeSeconds ) / this . _closingSeconds ; if ( t >= 1.0 ) { t = 1.0 ; this . _blinkingState = EyeState . EyeState_Closed ; this . _stateStartTimeSeconds = this . _userTimeSeconds ; } parameterValue = 1.0 - t ; break ; case EyeState . EyeState_Closed : t = ( this . _userTimeSeconds - this . _stateStartTimeSeconds ) / this . _closedSeconds ; if ( t >= 1.0 ) { this . _blinkingState = EyeState . EyeState_Opening ; this . _stateStartTimeSeconds = this . _userTimeSeconds ; } parameterValue = 0.0 ; break ; case EyeState . EyeState_Opening : t = ( this . _userTimeSeconds - this . _stateStartTimeSeconds ) / this . _openingSeconds ; if ( t >= 1.0 ) { t = 1.0 ; this . _blinkingState = EyeState . EyeState_Interval ; this . _nextBlinkingTime = this . determinNextBlinkingTiming ( ) ; } parameterValue = t ; break ; case EyeState . EyeState_Interval : if ( this . _nextBlinkingTime < this . _userTimeSeconds ) { this . _blinkingState = EyeState . EyeState_Closing ; this . _stateStartTimeSeconds = this . _userTimeSeconds ; } parameterValue = 1.0 ; break ; case EyeState . EyeState_First : default : this . _blinkingState = EyeState . EyeState_Interval ; this . _nextBlinkingTime = this . determinNextBlinkingTiming ( ) ; parameterValue = 1.0 ; break ; } if ( ! CubismEyeBlink . CloseIfZero ) { parameterValue = - parameterValue ; } for ( let i = 0 ; i < this . _parameterIds . getSize ( ) ; ++ i ) { model . setParameterValueById ( this . _parameterIds . at ( i ) , parameterValue ) ; } } param modelSetting public constructor ( modelSetting ) { this . _blinkingState = EyeState . EyeState_First ; this . _nextBlinkingTime = 0.0 ; this . _stateStartTimeSeconds = 0.0 ; this . _blinkingIntervalSeconds = 4.0 ; this . _closingSeconds = 0.1 ; this . _closedSeconds = 0.05 ; this . _openingSeconds = 0.15 ; this . _userTimeSeconds = 0.0 ; this . _parameterIds = new csmVector < CubismIdHandle > ( ) ; if ( modelSetting == null ) { return ; } for ( let i = 0 ; i < modelSetting . getEyeBlinkParameterCount ( ) ; ++ i ) { this . _parameterIds . pushBack ( modelSetting . getEyeBlinkParameterId ( i ) ) ; } } return public determinNextBlinkingTiming ( ) { const r = Math . random ( ) ; return ( this . _userTimeSeconds + r * ( 2.0 * this . _blinkingIntervalSeconds - 1.0 ) ) ; } _blinkingState : number ; _parameterIds : csmVector < CubismIdHandle > ; _nextBlinkingTime : number ; _stateStartTimeSeconds : number ; _blinkingIntervalSeconds : number ; _closingSeconds : number ; _closedSeconds : number ; _openingSeconds : number ; _userTimeSeconds : number ; /**
     * IDで指定された目のパラメータが、0のときに閉じるなら true 、1の時に閉じるなら false 。
     */ static readonly CloseIfZero : boolean = true ; } /**
 * まばたきの状態
 *
 * まばたきの状態を表す列挙型
 */ export enum EyeState { EyeState_First = 0 , EyeState_Interval , EyeState_Closing , EyeState_Closed , EyeState_Opening } import * as $ from './cubismeyeblink' ; export namespace Live2DCubismFramework { export const CubismEyeBlink = $ . CubismEyeBlink ; export type CubismEyeBlink = $ . CubismEyeBlink ; export const EyeState = $ . EyeState ; export type EyeState = $ . EyeState ; }