/**
 * 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 { CubismMath } from '../math/cubismmath' ; import { CubismModel } from '../model/cubismmodel' ; import { csmString } from '../type/csmstring' ; import { csmVector } from '../type/csmvector' ; import { CSM_ASSERT } from '../utils/cubismdebug' ; import { CubismMotionQueueEntry } from './cubismmotionqueueentry' ; /** モーション再生終了コールバック関数定義 */ export type FinishedMotionCallback = ( self : ACubismMotion ) => void ; /**
 * モーションの抽象基底クラス
 *
 * モーションの抽象基底クラス。MotionQueueManagerによってモーションの再生を管理する。
 */ export abstract class ACubismMotion { /**
     * インスタンスの破棄
     */ public static delete ( motion ) { motion . release ( ) ; motion = null ; } /**
     * コンストラクタ
     */ public constructor ( ) { this . _fadeInSeconds = - 1.0 ; this . _fadeOutSeconds = - 1.0 ; this . _weight = 1.0 ; this . _offsetSeconds = 0.0 ; this . _firedEventValues = new csmVector < csmString > ( ) ; } /**
     * デストラクタ相当の処理
     */ public release ( ) { this . _weight = 0.0 ; } param model param motionQueueEntry param userTimeSeconds public updateParameters ( model , motionQueueEntry , userTimeSeconds ) { if ( ! motionQueueEntry . isAvailable ( ) || motionQueueEntry . isFinished ( ) ) { return ; } if ( ! motionQueueEntry . isStarted ( ) ) { motionQueueEntry . setIsStarted ( true ) ; motionQueueEntry . setStartTime ( userTimeSeconds - this . _offsetSeconds ) ; motionQueueEntry . setFadeInStartTime ( userTimeSeconds ) ; const duration = this . getDuration ( ) ; if ( motionQueueEntry . getEndTime ( ) < 0 ) { motionQueueEntry . setEndTime ( duration <= 0 ? - 1 : motionQueueEntry . getStartTime ( ) + duration ) ; } } let fadeWeight = this . _weight ; const fadeIn = this . _fadeInSeconds == 0.0 ? 1.0 : CubismMath . getEasingSine ( ( userTimeSeconds - motionQueueEntry . getFadeInStartTime ( ) ) / this . _fadeInSeconds ) ; const fadeOut = this . _fadeOutSeconds == 0.0 || motionQueueEntry . getEndTime ( ) < 0.0 ? 1.0 : CubismMath . getEasingSine ( ( motionQueueEntry . getEndTime ( ) - userTimeSeconds ) / this . _fadeOutSeconds ) ; fadeWeight = fadeWeight * fadeIn * fadeOut ; motionQueueEntry . setState ( userTimeSeconds , fadeWeight ) ; CSM_ASSERT ( 0.0 <= fadeWeight && fadeWeight <= 1.0 ) ; this . doUpdateParameters ( model , userTimeSeconds , fadeWeight , motionQueueEntry ) ; if ( motionQueueEntry . getEndTime ( ) > 0 && motionQueueEntry . getEndTime ( ) < userTimeSeconds ) { motionQueueEntry . setIsFinished ( true ) ; } } param fadeInSeconds public setFadeInTime ( fadeInSeconds ) { this . _fadeInSeconds = fadeInSeconds ; } param fadeOutSeconds public setFadeOutTime ( fadeOutSeconds ) { this . _fadeOutSeconds = fadeOutSeconds ; } return public getFadeOutTime ( ) { return this . _fadeOutSeconds ; } return public getFadeInTime ( ) { return this . _fadeInSeconds ; } param weight public setWeight ( weight ) { this . _weight = weight ; } return public getWeight ( ) { return this . _weight ; } return note public getDuration ( ) { return - 1.0 ; } return note public getLoopDuration ( ) { return - 1.0 ; } param offsetSeconds public setOffsetTime ( offsetSeconds ) { this . _offsetSeconds = offsetSeconds ; } param beforeCheckTimeSeconds param motionTimeSeconds public getFiredEvent ( beforeCheckTimeSeconds , motionTimeSeconds ) { return this . _firedEventValues ; } param model param userTimeSeconds param weight param motionQueueEntry return return public abstract doUpdateParameters ( model , userTimeSeconds , weight , motionQueueEntry ) ; param onFinishedMotionHandler public setFinishedMotionHandler = ( onFinishedMotionHandler ) => ( this . _onFinishedMotion = onFinishedMotionHandler ) ; return public getFinishedMotionHandler = ( ) => this . _onFinishedMotion ; public _fadeInSeconds : number ; public _fadeOutSeconds : number ; public _weight : number ; public _offsetSeconds : number ; public _firedEventValues : csmVector < csmString > ; public _onFinishedMotion ? : FinishedMotionCallback ; } import * as $ from './acubismmotion' ; export namespace Live2DCubismFramework { export const ACubismMotion = $ . ACubismMotion ; export type ACubismMotion = $ . ACubismMotion ; export type FinishedMotionCallback = $ . FinishedMotionCallback ; }