Change to compatible syntax without namaspace
This commit is contained in:
@ -5,274 +5,276 @@
|
||||
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
|
||||
*/
|
||||
|
||||
import { Live2DCubismFramework as cubismmath } from '../math/cubismmath';
|
||||
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel';
|
||||
import { Live2DCubismFramework as cubismmotionqueueentry } from './cubismmotionqueueentry';
|
||||
import { Live2DCubismFramework as csmstring } from '../type/csmstring';
|
||||
import { Live2DCubismFramework as csmvector } from '../type/csmvector';
|
||||
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 csmVector = csmvector.csmVector;
|
||||
import csmString = csmstring.csmString;
|
||||
import CubismMotionQueueEntry = cubismmotionqueueentry.CubismMotionQueueEntry;
|
||||
import CubismModel = cubismmodel.CubismModel;
|
||||
import CubismMath = cubismmath.CubismMath;
|
||||
import { CubismMotionQueueEntry } from './cubismmotionqueueentry';
|
||||
|
||||
export namespace Live2DCubismFramework {
|
||||
/** モーション再生終了コールバック関数定義 */
|
||||
export type FinishedMotionCallback = (self: ACubismMotion) => void;
|
||||
/** モーション再生終了コールバック関数定義 */
|
||||
export type FinishedMotionCallback = (self: ACubismMotion) => void;
|
||||
|
||||
/**
|
||||
* モーションの抽象基底クラス
|
||||
*
|
||||
* モーションの抽象基底クラス。MotionQueueManagerによってモーションの再生を管理する。
|
||||
*/
|
||||
export abstract class ACubismMotion {
|
||||
/**
|
||||
* インスタンスの破棄
|
||||
*/
|
||||
public static delete(motion: ACubismMotion): void {
|
||||
motion.release();
|
||||
motion = void 0;
|
||||
motion = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの抽象基底クラス
|
||||
*
|
||||
* モーションの抽象基底クラス。MotionQueueManagerによってモーションの再生を管理する。
|
||||
* コンストラクタ
|
||||
*/
|
||||
export abstract class ACubismMotion {
|
||||
/**
|
||||
* インスタンスの破棄
|
||||
*/
|
||||
public static delete(motion: ACubismMotion): void {
|
||||
motion.release();
|
||||
motion = void 0;
|
||||
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(): void {
|
||||
this._weight = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* モデルのパラメータ
|
||||
* @param model 対象のモデル
|
||||
* @param motionQueueEntry CubismMotionQueueManagerで管理されているモーション
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
*/
|
||||
public updateParameters(
|
||||
model: CubismModel,
|
||||
motionQueueEntry: CubismMotionQueueEntry,
|
||||
userTimeSeconds: number
|
||||
): void {
|
||||
if (!motionQueueEntry.isAvailable() || motionQueueEntry.isFinished()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!motionQueueEntry.isStarted()) {
|
||||
motionQueueEntry.setIsStarted(true);
|
||||
motionQueueEntry.setStartTime(userTimeSeconds - this._offsetSeconds); // モーションの開始時刻を記録
|
||||
motionQueueEntry.setFadeInStartTime(userTimeSeconds); // フェードインの開始時刻
|
||||
|
||||
const duration: number = this.getDuration();
|
||||
|
||||
if (motionQueueEntry.getEndTime() < 0) {
|
||||
// 開始していないうちに終了設定している場合がある。
|
||||
motionQueueEntry.setEndTime(
|
||||
duration <= 0 ? -1 : motionQueueEntry.getStartTime() + duration
|
||||
);
|
||||
// duration == -1 の場合はループする
|
||||
}
|
||||
}
|
||||
|
||||
let fadeWeight: number = this._weight; // 現在の値と掛け合わせる割合
|
||||
|
||||
//---- フェードイン・アウトの処理 ----
|
||||
// 単純なサイン関数でイージングする
|
||||
const fadeIn: number =
|
||||
this._fadeInSeconds == 0.0
|
||||
? 1.0
|
||||
: CubismMath.getEasingSine(
|
||||
(userTimeSeconds - motionQueueEntry.getFadeInStartTime()) /
|
||||
this._fadeInSeconds
|
||||
);
|
||||
|
||||
const fadeOut: number =
|
||||
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);
|
||||
|
||||
//---- 全てのパラメータIDをループする ----
|
||||
this.doUpdateParameters(
|
||||
model,
|
||||
userTimeSeconds,
|
||||
fadeWeight,
|
||||
motionQueueEntry
|
||||
);
|
||||
|
||||
// 後処理
|
||||
// 終了時刻を過ぎたら終了フラグを立てる(CubismMotionQueueManager)
|
||||
if (
|
||||
motionQueueEntry.getEndTime() > 0 &&
|
||||
motionQueueEntry.getEndTime() < userTimeSeconds
|
||||
) {
|
||||
motionQueueEntry.setIsFinished(true); // 終了
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインの時間を設定する
|
||||
* @param fadeInSeconds フェードインにかかる時間[秒]
|
||||
*/
|
||||
public setFadeInTime(fadeInSeconds: number): void {
|
||||
this._fadeInSeconds = fadeInSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウトの時間を設定する
|
||||
* @param fadeOutSeconds フェードアウトにかかる時間[秒]
|
||||
*/
|
||||
public setFadeOutTime(fadeOutSeconds: number): void {
|
||||
this._fadeOutSeconds = fadeOutSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウトにかかる時間の取得
|
||||
* @return フェードアウトにかかる時間[秒]
|
||||
*/
|
||||
public getFadeOutTime(): number {
|
||||
return this._fadeOutSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインにかかる時間の取得
|
||||
* @return フェードインにかかる時間[秒]
|
||||
*/
|
||||
public getFadeInTime(): number {
|
||||
return this._fadeInSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーション適用の重みの設定
|
||||
* @param weight 重み(0.0 - 1.0)
|
||||
*/
|
||||
public setWeight(weight: number): void {
|
||||
this._weight = weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーション適用の重みの取得
|
||||
* @return 重み(0.0 - 1.0)
|
||||
*/
|
||||
public getWeight(): number {
|
||||
return this._weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの長さの取得
|
||||
* @return モーションの長さ[秒]
|
||||
*
|
||||
* @note ループの時は「-1」。
|
||||
* ループでない場合は、オーバーライドする。
|
||||
* 正の値の時は取得される時間で終了する。
|
||||
* 「-1」の時は外部から停止命令がない限り終わらない処理となる。
|
||||
*/
|
||||
public getDuration(): number {
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのループ1回分の長さの取得
|
||||
* @return モーションのループ一回分の長さ[秒]
|
||||
*
|
||||
* @note ループしない場合は、getDuration()と同じ値を返す
|
||||
* ループ一回分の長さが定義できない場合(プログラム的に動き続けるサブクラスなど)の場合は「-1」を返す
|
||||
*/
|
||||
public getLoopDuration(): number {
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーション再生の開始時刻の設定
|
||||
* @param offsetSeconds モーション再生の開始時刻[秒]
|
||||
*/
|
||||
public setOffsetTime(offsetSeconds: number): void {
|
||||
this._offsetSeconds = offsetSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* モデルのパラメータ更新
|
||||
*
|
||||
* イベント発火のチェック。
|
||||
* 入力する時間は呼ばれるモーションタイミングを0とした秒数で行う。
|
||||
*
|
||||
* @param beforeCheckTimeSeconds 前回のイベントチェック時間[秒]
|
||||
* @param motionTimeSeconds 今回の再生時間[秒]
|
||||
*/
|
||||
public getFiredEvent(
|
||||
beforeCheckTimeSeconds: number,
|
||||
motionTimeSeconds: number
|
||||
): csmVector<csmString> {
|
||||
return this._firedEventValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションを更新して、モデルにパラメータ値を反映する
|
||||
* @param model 対象のモデル
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
* @param weight モーションの重み
|
||||
* @param motionQueueEntry CubismMotionQueueManagerで管理されているモーション
|
||||
* @return true モデルへパラメータ値の反映あり
|
||||
* @return false モデルへのパラメータ値の反映なし(モーションの変化なし)
|
||||
*/
|
||||
public abstract doUpdateParameters(
|
||||
model: CubismModel,
|
||||
userTimeSeconds: number,
|
||||
weight: number,
|
||||
motionQueueEntry: CubismMotionQueueEntry
|
||||
): void;
|
||||
|
||||
/**
|
||||
* モーション再生終了コールバックの登録
|
||||
*
|
||||
* モーション再生終了コールバックを登録する。
|
||||
* isFinishedフラグを設定するタイミングで呼び出される。
|
||||
* 以下の状態の際には呼び出されない:
|
||||
* 1. 再生中のモーションが「ループ」として設定されているとき
|
||||
* 2. コールバックが登録されていない時
|
||||
*
|
||||
* @param onFinishedMotionHandler モーション再生終了コールバック関数
|
||||
*/
|
||||
public setFinishedMotionHandler = (
|
||||
onFinishedMotionHandler: FinishedMotionCallback
|
||||
) => (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;
|
||||
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(): void {
|
||||
this._weight = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* モデルのパラメータ
|
||||
* @param model 対象のモデル
|
||||
* @param motionQueueEntry CubismMotionQueueManagerで管理されているモーション
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
*/
|
||||
public updateParameters(
|
||||
model: CubismModel,
|
||||
motionQueueEntry: CubismMotionQueueEntry,
|
||||
userTimeSeconds: number
|
||||
): void {
|
||||
if (!motionQueueEntry.isAvailable() || motionQueueEntry.isFinished()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!motionQueueEntry.isStarted()) {
|
||||
motionQueueEntry.setIsStarted(true);
|
||||
motionQueueEntry.setStartTime(userTimeSeconds - this._offsetSeconds); // モーションの開始時刻を記録
|
||||
motionQueueEntry.setFadeInStartTime(userTimeSeconds); // フェードインの開始時刻
|
||||
|
||||
const duration: number = this.getDuration();
|
||||
|
||||
if (motionQueueEntry.getEndTime() < 0) {
|
||||
// 開始していないうちに終了設定している場合がある。
|
||||
motionQueueEntry.setEndTime(
|
||||
duration <= 0 ? -1 : motionQueueEntry.getStartTime() + duration
|
||||
);
|
||||
// duration == -1 の場合はループする
|
||||
}
|
||||
}
|
||||
|
||||
let fadeWeight: number = this._weight; // 現在の値と掛け合わせる割合
|
||||
|
||||
//---- フェードイン・アウトの処理 ----
|
||||
// 単純なサイン関数でイージングする
|
||||
const fadeIn: number =
|
||||
this._fadeInSeconds == 0.0
|
||||
? 1.0
|
||||
: CubismMath.getEasingSine(
|
||||
(userTimeSeconds - motionQueueEntry.getFadeInStartTime()) /
|
||||
this._fadeInSeconds
|
||||
);
|
||||
|
||||
const fadeOut: number =
|
||||
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);
|
||||
|
||||
//---- 全てのパラメータIDをループする ----
|
||||
this.doUpdateParameters(
|
||||
model,
|
||||
userTimeSeconds,
|
||||
fadeWeight,
|
||||
motionQueueEntry
|
||||
);
|
||||
|
||||
// 後処理
|
||||
// 終了時刻を過ぎたら終了フラグを立てる(CubismMotionQueueManager)
|
||||
if (
|
||||
motionQueueEntry.getEndTime() > 0 &&
|
||||
motionQueueEntry.getEndTime() < userTimeSeconds
|
||||
) {
|
||||
motionQueueEntry.setIsFinished(true); // 終了
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインの時間を設定する
|
||||
* @param fadeInSeconds フェードインにかかる時間[秒]
|
||||
*/
|
||||
public setFadeInTime(fadeInSeconds: number): void {
|
||||
this._fadeInSeconds = fadeInSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウトの時間を設定する
|
||||
* @param fadeOutSeconds フェードアウトにかかる時間[秒]
|
||||
*/
|
||||
public setFadeOutTime(fadeOutSeconds: number): void {
|
||||
this._fadeOutSeconds = fadeOutSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウトにかかる時間の取得
|
||||
* @return フェードアウトにかかる時間[秒]
|
||||
*/
|
||||
public getFadeOutTime(): number {
|
||||
return this._fadeOutSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインにかかる時間の取得
|
||||
* @return フェードインにかかる時間[秒]
|
||||
*/
|
||||
public getFadeInTime(): number {
|
||||
return this._fadeInSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーション適用の重みの設定
|
||||
* @param weight 重み(0.0 - 1.0)
|
||||
*/
|
||||
public setWeight(weight: number): void {
|
||||
this._weight = weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーション適用の重みの取得
|
||||
* @return 重み(0.0 - 1.0)
|
||||
*/
|
||||
public getWeight(): number {
|
||||
return this._weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの長さの取得
|
||||
* @return モーションの長さ[秒]
|
||||
*
|
||||
* @note ループの時は「-1」。
|
||||
* ループでない場合は、オーバーライドする。
|
||||
* 正の値の時は取得される時間で終了する。
|
||||
* 「-1」の時は外部から停止命令がない限り終わらない処理となる。
|
||||
*/
|
||||
public getDuration(): number {
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのループ1回分の長さの取得
|
||||
* @return モーションのループ一回分の長さ[秒]
|
||||
*
|
||||
* @note ループしない場合は、getDuration()と同じ値を返す
|
||||
* ループ一回分の長さが定義できない場合(プログラム的に動き続けるサブクラスなど)の場合は「-1」を返す
|
||||
*/
|
||||
public getLoopDuration(): number {
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーション再生の開始時刻の設定
|
||||
* @param offsetSeconds モーション再生の開始時刻[秒]
|
||||
*/
|
||||
public setOffsetTime(offsetSeconds: number): void {
|
||||
this._offsetSeconds = offsetSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* モデルのパラメータ更新
|
||||
*
|
||||
* イベント発火のチェック。
|
||||
* 入力する時間は呼ばれるモーションタイミングを0とした秒数で行う。
|
||||
*
|
||||
* @param beforeCheckTimeSeconds 前回のイベントチェック時間[秒]
|
||||
* @param motionTimeSeconds 今回の再生時間[秒]
|
||||
*/
|
||||
public getFiredEvent(
|
||||
beforeCheckTimeSeconds: number,
|
||||
motionTimeSeconds: number
|
||||
): csmVector<csmString> {
|
||||
return this._firedEventValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションを更新して、モデルにパラメータ値を反映する
|
||||
* @param model 対象のモデル
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
* @param weight モーションの重み
|
||||
* @param motionQueueEntry CubismMotionQueueManagerで管理されているモーション
|
||||
* @return true モデルへパラメータ値の反映あり
|
||||
* @return false モデルへのパラメータ値の反映なし(モーションの変化なし)
|
||||
*/
|
||||
public abstract doUpdateParameters(
|
||||
model: CubismModel,
|
||||
userTimeSeconds: number,
|
||||
weight: number,
|
||||
motionQueueEntry: CubismMotionQueueEntry
|
||||
): void;
|
||||
|
||||
/**
|
||||
* モーション再生終了コールバックの登録
|
||||
*
|
||||
* モーション再生終了コールバックを登録する。
|
||||
* isFinishedフラグを設定するタイミングで呼び出される。
|
||||
* 以下の状態の際には呼び出されない:
|
||||
* 1. 再生中のモーションが「ループ」として設定されているとき
|
||||
* 2. コールバックが登録されていない時
|
||||
*
|
||||
* @param onFinishedMotionHandler モーション再生終了コールバック関数
|
||||
*/
|
||||
public setFinishedMotionHandler = (
|
||||
onFinishedMotionHandler: FinishedMotionCallback
|
||||
) => (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;
|
||||
}
|
||||
|
||||
// Namespace definition for compatibility.
|
||||
import * as $ from './acubismmotion';
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
export namespace Live2DCubismFramework {
|
||||
export const ACubismMotion = $.ACubismMotion;
|
||||
export type ACubismMotion = $.ACubismMotion;
|
||||
export type FinishedMotionCallback = $.FinishedMotionCallback;
|
||||
}
|
||||
|
@ -5,195 +5,195 @@
|
||||
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
|
||||
*/
|
||||
|
||||
import { Live2DCubismFramework as acubismmotion } from './acubismmotion';
|
||||
import { Live2DCubismFramework as cubismjson } from '../utils/cubismjson';
|
||||
import { Live2DCubismFramework as cubismid } from '../id/cubismid';
|
||||
import { Live2DCubismFramework as cubismframework } from '../live2dcubismframework';
|
||||
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel';
|
||||
import { Live2DCubismFramework as cubismmotionqueueentry } from './cubismmotionqueueentry';
|
||||
import { Live2DCubismFramework as csmvector } from '../type/csmvector';
|
||||
import JsonFloat = cubismjson.JsonFloat;
|
||||
import csmVector = csmvector.csmVector;
|
||||
import CubismMotionQueueEntry = cubismmotionqueueentry.CubismMotionQueueEntry;
|
||||
import CubismModel = cubismmodel.CubismModel;
|
||||
import CubismFramework = cubismframework.CubismFramework;
|
||||
import CubismIdHandle = cubismid.CubismIdHandle;
|
||||
import CubismJson = cubismjson.CubismJson;
|
||||
import Value = cubismjson.Value;
|
||||
import ACubismMotion = acubismmotion.ACubismMotion;
|
||||
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';
|
||||
|
||||
export namespace Live2DCubismFramework {
|
||||
// exp3.jsonのキーとデフォルト
|
||||
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;
|
||||
// exp3.jsonのキーとデフォルト
|
||||
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 expファイルが読み込まれているバッファ
|
||||
* @param size バッファのサイズ
|
||||
* @return 作成されたインスタンス
|
||||
*/
|
||||
export class CubismExpressionMotion extends ACubismMotion {
|
||||
/**
|
||||
* インスタンスを作成する。
|
||||
* @param buffer expファイルが読み込まれているバッファ
|
||||
* @param size バッファのサイズ
|
||||
* @return 作成されたインスタンス
|
||||
*/
|
||||
public static create(
|
||||
buffer: ArrayBuffer,
|
||||
size: number
|
||||
): CubismExpressionMotion {
|
||||
const expression: CubismExpressionMotion = new CubismExpressionMotion();
|
||||
public static create(
|
||||
buffer: ArrayBuffer,
|
||||
size: number
|
||||
): CubismExpressionMotion {
|
||||
const expression: CubismExpressionMotion = new CubismExpressionMotion();
|
||||
|
||||
const json: CubismJson = CubismJson.create(buffer, size);
|
||||
const root: Value = json.getRoot();
|
||||
const json: CubismJson = CubismJson.create(buffer, size);
|
||||
const root: Value = json.getRoot();
|
||||
|
||||
expression.setFadeInTime(
|
||||
root.getValueByString(ExpressionKeyFadeIn).toFloat(DefaultFadeTime)
|
||||
); // フェードイン
|
||||
expression.setFadeOutTime(
|
||||
root.getValueByString(ExpressionKeyFadeOut).toFloat(DefaultFadeTime)
|
||||
); // フェードアウト
|
||||
expression.setFadeInTime(
|
||||
root.getValueByString(ExpressionKeyFadeIn).toFloat(DefaultFadeTime)
|
||||
); // フェードイン
|
||||
expression.setFadeOutTime(
|
||||
root.getValueByString(ExpressionKeyFadeOut).toFloat(DefaultFadeTime)
|
||||
); // フェードアウト
|
||||
|
||||
// 各パラメータについて
|
||||
const parameterCount = root
|
||||
// 各パラメータについて
|
||||
const parameterCount = root
|
||||
.getValueByString(ExpressionKeyParameters)
|
||||
.getSize();
|
||||
expression._parameters.prepareCapacity(parameterCount);
|
||||
|
||||
for (let i = 0; i < parameterCount; ++i) {
|
||||
const param: Value = root
|
||||
.getValueByString(ExpressionKeyParameters)
|
||||
.getSize();
|
||||
expression._parameters.prepareCapacity(parameterCount);
|
||||
.getValueByIndex(i);
|
||||
const parameterId: CubismIdHandle = CubismFramework.getIdManager().getId(
|
||||
param.getValueByString(ExpressionKeyId).getRawString()
|
||||
); // パラメータID
|
||||
|
||||
for (let i = 0; i < parameterCount; ++i) {
|
||||
const param: Value = root
|
||||
.getValueByString(ExpressionKeyParameters)
|
||||
.getValueByIndex(i);
|
||||
const parameterId: CubismIdHandle = CubismFramework.getIdManager().getId(
|
||||
param.getValueByString(ExpressionKeyId).getRawString()
|
||||
); // パラメータID
|
||||
const value: number = param
|
||||
.getValueByString(ExpressionKeyValue)
|
||||
.toFloat(); // 値
|
||||
|
||||
const value: number = param
|
||||
.getValueByString(ExpressionKeyValue)
|
||||
.toFloat(); // 値
|
||||
// 計算方法の設定
|
||||
let blendType: ExpressionBlendType;
|
||||
|
||||
// 計算方法の設定
|
||||
let blendType: ExpressionBlendType;
|
||||
|
||||
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: ExpressionParameter = new ExpressionParameter();
|
||||
|
||||
item.parameterId = parameterId;
|
||||
item.blendType = blendType;
|
||||
item.value = value;
|
||||
|
||||
expression._parameters.pushBack(item);
|
||||
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;
|
||||
}
|
||||
|
||||
CubismJson.delete(json); // JSONデータは不要になったら削除する
|
||||
return expression;
|
||||
// 設定オブジェクトを作成してリストに追加する
|
||||
const item: ExpressionParameter = new ExpressionParameter();
|
||||
|
||||
item.parameterId = parameterId;
|
||||
item.blendType = blendType;
|
||||
item.value = value;
|
||||
|
||||
expression._parameters.pushBack(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* モデルのパラメータの更新の実行
|
||||
* @param model 対象のモデル
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
* @param weight モーションの重み
|
||||
* @param motionQueueEntry CubismMotionQueueManagerで管理されているモーション
|
||||
*/
|
||||
public doUpdateParameters(
|
||||
model: CubismModel,
|
||||
userTimeSeconds: number,
|
||||
weight: number,
|
||||
motionQueueEntry: CubismMotionQueueEntry
|
||||
): void {
|
||||
for (let i = 0; i < this._parameters.getSize(); ++i) {
|
||||
const parameter: ExpressionParameter = 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>; // 表情のパラメータ情報リスト
|
||||
CubismJson.delete(json); // JSONデータは不要になったら削除する
|
||||
return expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* 表情パラメータ値の計算方式
|
||||
* モデルのパラメータの更新の実行
|
||||
* @param model 対象のモデル
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
* @param weight モーションの重み
|
||||
* @param motionQueueEntry CubismMotionQueueManagerで管理されているモーション
|
||||
*/
|
||||
export enum ExpressionBlendType {
|
||||
ExpressionBlendType_Add = 0, // 加算
|
||||
ExpressionBlendType_Multiply = 1, // 乗算
|
||||
ExpressionBlendType_Overwrite = 2 // 上書き
|
||||
public doUpdateParameters(
|
||||
model: CubismModel,
|
||||
userTimeSeconds: number,
|
||||
weight: number,
|
||||
motionQueueEntry: CubismMotionQueueEntry
|
||||
): void {
|
||||
for (let i = 0; i < this._parameters.getSize(); ++i) {
|
||||
const parameter: ExpressionParameter = 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 表情のパラメータ情報
|
||||
* コンストラクタ
|
||||
*/
|
||||
export class ExpressionParameter {
|
||||
parameterId: CubismIdHandle; // パラメータID
|
||||
blendType: ExpressionBlendType; // パラメータの演算種類
|
||||
value: number; // 値
|
||||
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; // パラメータID
|
||||
blendType: ExpressionBlendType; // パラメータの演算種類
|
||||
value: number; // 値
|
||||
}
|
||||
|
||||
// Namespace definition for compatibility.
|
||||
import * as $ from './cubismexpressionmotion';
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
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;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,136 +5,152 @@
|
||||
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
|
||||
*/
|
||||
|
||||
import { Live2DCubismFramework as cubismid } from '../id/cubismid';
|
||||
import { Live2DCubismFramework as csmstring } from '../type/csmstring';
|
||||
import { Live2DCubismFramework as csmvector } from '../type/csmvector';
|
||||
import csmVector = csmvector.csmVector;
|
||||
import csmString = csmstring.csmString;
|
||||
import CubismIdHandle = cubismid.CubismIdHandle;
|
||||
import { CubismIdHandle } from '../id/cubismid';
|
||||
import { csmString } from '../type/csmstring';
|
||||
import { csmVector } from '../type/csmvector';
|
||||
|
||||
export namespace Live2DCubismFramework {
|
||||
/**
|
||||
* @brief モーションカーブの種類
|
||||
*
|
||||
* モーションカーブの種類。
|
||||
*/
|
||||
export enum CubismMotionCurveTarget {
|
||||
CubismMotionCurveTarget_Model, // モデルに対して
|
||||
CubismMotionCurveTarget_Parameter, // パラメータに対して
|
||||
CubismMotionCurveTarget_PartOpacity // パーツの不透明度に対して
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief モーションカーブのセグメントの種類
|
||||
*
|
||||
* モーションカーブのセグメントの種類。
|
||||
*/
|
||||
export enum CubismMotionSegmentType {
|
||||
CubismMotionSegmentType_Linear = 0, // リニア
|
||||
CubismMotionSegmentType_Bezier = 1, // ベジェ曲線
|
||||
CubismMotionSegmentType_Stepped = 2, // ステップ
|
||||
CubismMotionSegmentType_InverseStepped = 3 // インバースステップ
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief モーションカーブの制御点
|
||||
*
|
||||
* モーションカーブの制御点。
|
||||
*/
|
||||
export class CubismMotionPoint {
|
||||
time = 0.0; // 時間[秒]
|
||||
value = 0.0; // 値
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションカーブのセグメントの評価関数
|
||||
*
|
||||
* @param points モーションカーブの制御点リスト
|
||||
* @param time 評価する時間[秒]
|
||||
*/
|
||||
export interface csmMotionSegmentEvaluationFunction {
|
||||
(points: CubismMotionPoint[], time: number): number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief モーションカーブのセグメント
|
||||
*
|
||||
* モーションカーブのセグメント。
|
||||
*/
|
||||
export class CubismMotionSegment {
|
||||
/**
|
||||
* @brief コンストラクタ
|
||||
*
|
||||
* コンストラクタ。
|
||||
*/
|
||||
public constructor() {
|
||||
this.evaluate = null;
|
||||
this.basePointIndex = 0;
|
||||
this.segmentType = 0;
|
||||
}
|
||||
|
||||
evaluate: csmMotionSegmentEvaluationFunction; // 使用する評価関数
|
||||
basePointIndex: number; // 最初のセグメントへのインデックス
|
||||
segmentType: number; // セグメントの種類
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief モーションカーブ
|
||||
*
|
||||
* モーションカーブ。
|
||||
*/
|
||||
export class CubismMotionCurve {
|
||||
public constructor() {
|
||||
this.type = CubismMotionCurveTarget.CubismMotionCurveTarget_Model;
|
||||
this.segmentCount = 0;
|
||||
this.baseSegmentIndex = 0;
|
||||
this.fadeInTime = 0.0;
|
||||
this.fadeOutTime = 0.0;
|
||||
}
|
||||
|
||||
type: CubismMotionCurveTarget; // カーブの種類
|
||||
id: CubismIdHandle; // カーブのID
|
||||
segmentCount: number; // セグメントの個数
|
||||
baseSegmentIndex: number; // 最初のセグメントのインデックス
|
||||
fadeInTime: number; // フェードインにかかる時間[秒]
|
||||
fadeOutTime: number; // フェードアウトにかかる時間[秒]
|
||||
}
|
||||
|
||||
/**
|
||||
* イベント。
|
||||
*/
|
||||
export class CubismMotionEvent {
|
||||
fireTime = 0.0;
|
||||
value: csmString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief モーションデータ
|
||||
*
|
||||
* モーションデータ。
|
||||
*/
|
||||
export class CubismMotionData {
|
||||
public constructor() {
|
||||
this.duration = 0.0;
|
||||
this.loop = false;
|
||||
this.curveCount = 0;
|
||||
this.eventCount = 0;
|
||||
this.fps = 0.0;
|
||||
|
||||
this.curves = new csmVector<CubismMotionCurve>();
|
||||
this.segments = new csmVector<CubismMotionSegment>();
|
||||
this.points = new csmVector<CubismMotionPoint>();
|
||||
this.events = new csmVector<CubismMotionEvent>();
|
||||
}
|
||||
|
||||
duration: number; // モーションの長さ[秒]
|
||||
loop: boolean; // ループするかどうか
|
||||
curveCount: number; // カーブの個数
|
||||
eventCount: number; // UserDataの個数
|
||||
fps: number; // フレームレート
|
||||
curves: csmVector<CubismMotionCurve>; // カーブのリスト
|
||||
segments: csmVector<CubismMotionSegment>; // セグメントのリスト
|
||||
points: csmVector<CubismMotionPoint>; // ポイントのリスト
|
||||
events: csmVector<CubismMotionEvent>; // イベントのリスト
|
||||
}
|
||||
/**
|
||||
* @brief モーションカーブの種類
|
||||
*
|
||||
* モーションカーブの種類。
|
||||
*/
|
||||
export enum CubismMotionCurveTarget {
|
||||
CubismMotionCurveTarget_Model, // モデルに対して
|
||||
CubismMotionCurveTarget_Parameter, // パラメータに対して
|
||||
CubismMotionCurveTarget_PartOpacity // パーツの不透明度に対して
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief モーションカーブのセグメントの種類
|
||||
*
|
||||
* モーションカーブのセグメントの種類。
|
||||
*/
|
||||
export enum CubismMotionSegmentType {
|
||||
CubismMotionSegmentType_Linear = 0, // リニア
|
||||
CubismMotionSegmentType_Bezier = 1, // ベジェ曲線
|
||||
CubismMotionSegmentType_Stepped = 2, // ステップ
|
||||
CubismMotionSegmentType_InverseStepped = 3 // インバースステップ
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief モーションカーブの制御点
|
||||
*
|
||||
* モーションカーブの制御点。
|
||||
*/
|
||||
export class CubismMotionPoint {
|
||||
time = 0.0; // 時間[秒]
|
||||
value = 0.0; // 値
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションカーブのセグメントの評価関数
|
||||
*
|
||||
* @param points モーションカーブの制御点リスト
|
||||
* @param time 評価する時間[秒]
|
||||
*/
|
||||
export interface csmMotionSegmentEvaluationFunction {
|
||||
(points: CubismMotionPoint[], time: number): number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief モーションカーブのセグメント
|
||||
*
|
||||
* モーションカーブのセグメント。
|
||||
*/
|
||||
export class CubismMotionSegment {
|
||||
/**
|
||||
* @brief コンストラクタ
|
||||
*
|
||||
* コンストラクタ。
|
||||
*/
|
||||
public constructor() {
|
||||
this.evaluate = null;
|
||||
this.basePointIndex = 0;
|
||||
this.segmentType = 0;
|
||||
}
|
||||
|
||||
evaluate: csmMotionSegmentEvaluationFunction; // 使用する評価関数
|
||||
basePointIndex: number; // 最初のセグメントへのインデックス
|
||||
segmentType: number; // セグメントの種類
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief モーションカーブ
|
||||
*
|
||||
* モーションカーブ。
|
||||
*/
|
||||
export class CubismMotionCurve {
|
||||
public constructor() {
|
||||
this.type = CubismMotionCurveTarget.CubismMotionCurveTarget_Model;
|
||||
this.segmentCount = 0;
|
||||
this.baseSegmentIndex = 0;
|
||||
this.fadeInTime = 0.0;
|
||||
this.fadeOutTime = 0.0;
|
||||
}
|
||||
|
||||
type: CubismMotionCurveTarget; // カーブの種類
|
||||
id: CubismIdHandle; // カーブのID
|
||||
segmentCount: number; // セグメントの個数
|
||||
baseSegmentIndex: number; // 最初のセグメントのインデックス
|
||||
fadeInTime: number; // フェードインにかかる時間[秒]
|
||||
fadeOutTime: number; // フェードアウトにかかる時間[秒]
|
||||
}
|
||||
|
||||
/**
|
||||
* イベント。
|
||||
*/
|
||||
export class CubismMotionEvent {
|
||||
fireTime = 0.0;
|
||||
value: csmString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief モーションデータ
|
||||
*
|
||||
* モーションデータ。
|
||||
*/
|
||||
export class CubismMotionData {
|
||||
public constructor() {
|
||||
this.duration = 0.0;
|
||||
this.loop = false;
|
||||
this.curveCount = 0;
|
||||
this.eventCount = 0;
|
||||
this.fps = 0.0;
|
||||
|
||||
this.curves = new csmVector<CubismMotionCurve>();
|
||||
this.segments = new csmVector<CubismMotionSegment>();
|
||||
this.points = new csmVector<CubismMotionPoint>();
|
||||
this.events = new csmVector<CubismMotionEvent>();
|
||||
}
|
||||
|
||||
duration: number; // モーションの長さ[秒]
|
||||
loop: boolean; // ループするかどうか
|
||||
curveCount: number; // カーブの個数
|
||||
eventCount: number; // UserDataの個数
|
||||
fps: number; // フレームレート
|
||||
curves: csmVector<CubismMotionCurve>; // カーブのリスト
|
||||
segments: csmVector<CubismMotionSegment>; // セグメントのリスト
|
||||
points: csmVector<CubismMotionPoint>; // ポイントのリスト
|
||||
events: csmVector<CubismMotionEvent>; // イベントのリスト
|
||||
}
|
||||
|
||||
// Namespace definition for compatibility.
|
||||
import * as $ from './cubismmotioninternal';
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
export namespace Live2DCubismFramework {
|
||||
export const CubismMotionCurve = $.CubismMotionCurve;
|
||||
export type CubismMotionCurve = $.CubismMotionCurve;
|
||||
export const CubismMotionCurveTarget = $.CubismMotionCurveTarget;
|
||||
export type CubismMotionCurveTarget = $.CubismMotionCurveTarget;
|
||||
export const CubismMotionData = $.CubismMotionData;
|
||||
export type CubismMotionData = $.CubismMotionData;
|
||||
export const CubismMotionEvent = $.CubismMotionEvent;
|
||||
export type CubismMotionEvent = $.CubismMotionEvent;
|
||||
export const CubismMotionPoint = $.CubismMotionPoint;
|
||||
export type CubismMotionPoint = $.CubismMotionPoint;
|
||||
export const CubismMotionSegment = $.CubismMotionSegment;
|
||||
export type CubismMotionSegment = $.CubismMotionSegment;
|
||||
export const CubismMotionSegmentType = $.CubismMotionSegmentType;
|
||||
export type CubismMotionSegmentType = $.CubismMotionSegmentType;
|
||||
export type csmMotionSegmentEvaluationFunction = $.csmMotionSegmentEvaluationFunction;
|
||||
}
|
||||
|
@ -5,355 +5,357 @@
|
||||
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
|
||||
*/
|
||||
|
||||
import { Live2DCubismFramework as cubismjson } from '../utils/cubismjson';
|
||||
import { Live2DCubismFramework as cubismid } from '../id/cubismid';
|
||||
import { Live2DCubismFramework as cubismframework } from '../live2dcubismframework';
|
||||
import { Live2DCubismFramework as csmstring } from '../type/csmstring';
|
||||
import csmString = csmstring.csmString;
|
||||
import CubismFramework = cubismframework.CubismFramework;
|
||||
import CubismIdHandle = cubismid.CubismIdHandle;
|
||||
import CubismJson = cubismjson.CubismJson;
|
||||
import { CubismIdHandle } from '../id/cubismid';
|
||||
import { CubismFramework } from '../live2dcubismframework';
|
||||
import { csmString } from '../type/csmstring';
|
||||
import { CubismJson } from '../utils/cubismjson';
|
||||
|
||||
export namespace Live2DCubismFramework {
|
||||
// JSON keys
|
||||
const Meta = 'Meta';
|
||||
const Duration = 'Duration';
|
||||
const Loop = 'Loop';
|
||||
const CurveCount = 'CurveCount';
|
||||
const Fps = 'Fps';
|
||||
const TotalSegmentCount = 'TotalSegmentCount';
|
||||
const TotalPointCount = 'TotalPointCount';
|
||||
const Curves = 'Curves';
|
||||
const Target = 'Target';
|
||||
const Id = 'Id';
|
||||
const FadeInTime = 'FadeInTime';
|
||||
const FadeOutTime = 'FadeOutTime';
|
||||
const Segments = 'Segments';
|
||||
const UserData = 'UserData';
|
||||
const UserDataCount = 'UserDataCount';
|
||||
const TotalUserDataSize = 'TotalUserDataSize';
|
||||
const Time = 'Time';
|
||||
const Value = 'Value';
|
||||
// JSON keys
|
||||
const Meta = 'Meta';
|
||||
const Duration = 'Duration';
|
||||
const Loop = 'Loop';
|
||||
const CurveCount = 'CurveCount';
|
||||
const Fps = 'Fps';
|
||||
const TotalSegmentCount = 'TotalSegmentCount';
|
||||
const TotalPointCount = 'TotalPointCount';
|
||||
const Curves = 'Curves';
|
||||
const Target = 'Target';
|
||||
const Id = 'Id';
|
||||
const FadeInTime = 'FadeInTime';
|
||||
const FadeOutTime = 'FadeOutTime';
|
||||
const Segments = 'Segments';
|
||||
const UserData = 'UserData';
|
||||
const UserDataCount = 'UserDataCount';
|
||||
const TotalUserDataSize = 'TotalUserDataSize';
|
||||
const Time = 'Time';
|
||||
const Value = 'Value';
|
||||
|
||||
/**
|
||||
* motion3.jsonのコンテナ。
|
||||
*/
|
||||
export class CubismMotionJson {
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param buffer motion3.jsonが読み込まれているバッファ
|
||||
* @param size バッファのサイズ
|
||||
*/
|
||||
public constructor(buffer: ArrayBuffer, size: number) {
|
||||
this._json = CubismJson.create(buffer, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* motion3.jsonのコンテナ。
|
||||
* デストラクタ相当の処理
|
||||
*/
|
||||
export class CubismMotionJson {
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param buffer motion3.jsonが読み込まれているバッファ
|
||||
* @param size バッファのサイズ
|
||||
*/
|
||||
public constructor(buffer: ArrayBuffer, size: number) {
|
||||
this._json = CubismJson.create(buffer, size);
|
||||
}
|
||||
public release(): void {
|
||||
CubismJson.delete(this._json);
|
||||
}
|
||||
|
||||
/**
|
||||
* デストラクタ相当の処理
|
||||
*/
|
||||
public release(): void {
|
||||
CubismJson.delete(this._json);
|
||||
}
|
||||
/**
|
||||
* モーションの長さを取得する
|
||||
* @return モーションの長さ[秒]
|
||||
*/
|
||||
public getMotionDuration(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(Duration)
|
||||
.toFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの長さを取得する
|
||||
* @return モーションの長さ[秒]
|
||||
*/
|
||||
public getMotionDuration(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(Duration)
|
||||
.toFloat();
|
||||
}
|
||||
/**
|
||||
* モーションのループ情報の取得
|
||||
* @return true ループする
|
||||
* @return false ループしない
|
||||
*/
|
||||
public isMotionLoop(): boolean {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(Loop)
|
||||
.toBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのループ情報の取得
|
||||
* @return true ループする
|
||||
* @return false ループしない
|
||||
*/
|
||||
public isMotionLoop(): boolean {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(Loop)
|
||||
.toBoolean();
|
||||
}
|
||||
/**
|
||||
* モーションカーブの個数の取得
|
||||
* @return モーションカーブの個数
|
||||
*/
|
||||
public getMotionCurveCount(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(CurveCount)
|
||||
.toInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションカーブの個数の取得
|
||||
* @return モーションカーブの個数
|
||||
*/
|
||||
public getMotionCurveCount(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(CurveCount)
|
||||
.toInt();
|
||||
}
|
||||
/**
|
||||
* モーションのフレームレートの取得
|
||||
* @return フレームレート[FPS]
|
||||
*/
|
||||
public getMotionFps(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(Fps)
|
||||
.toFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのフレームレートの取得
|
||||
* @return フレームレート[FPS]
|
||||
*/
|
||||
public getMotionFps(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(Fps)
|
||||
.toFloat();
|
||||
}
|
||||
/**
|
||||
* モーションのセグメントの総合計の取得
|
||||
* @return モーションのセグメントの取得
|
||||
*/
|
||||
public getMotionTotalSegmentCount(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(TotalSegmentCount)
|
||||
.toInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのセグメントの総合計の取得
|
||||
* @return モーションのセグメントの取得
|
||||
*/
|
||||
public getMotionTotalSegmentCount(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(TotalSegmentCount)
|
||||
.toInt();
|
||||
}
|
||||
/**
|
||||
* モーションのカーブの制御店の総合計の取得
|
||||
* @return モーションのカーブの制御点の総合計
|
||||
*/
|
||||
public getMotionTotalPointCount(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(TotalPointCount)
|
||||
.toInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのカーブの制御店の総合計の取得
|
||||
* @return モーションのカーブの制御点の総合計
|
||||
*/
|
||||
public getMotionTotalPointCount(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(TotalPointCount)
|
||||
.toInt();
|
||||
}
|
||||
/**
|
||||
* モーションのフェードイン時間の存在
|
||||
* @return true 存在する
|
||||
* @return false 存在しない
|
||||
*/
|
||||
public isExistMotionFadeInTime(): boolean {
|
||||
return !this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(FadeInTime)
|
||||
.isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのフェードイン時間の存在
|
||||
* @return true 存在する
|
||||
* @return false 存在しない
|
||||
*/
|
||||
public isExistMotionFadeInTime(): boolean {
|
||||
return !this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(FadeInTime)
|
||||
.isNull();
|
||||
}
|
||||
/**
|
||||
* モーションのフェードアウト時間の存在
|
||||
* @return true 存在する
|
||||
* @return false 存在しない
|
||||
*/
|
||||
public isExistMotionFadeOutTime(): boolean {
|
||||
return !this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(FadeOutTime)
|
||||
.isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのフェードアウト時間の存在
|
||||
* @return true 存在する
|
||||
* @return false 存在しない
|
||||
*/
|
||||
public isExistMotionFadeOutTime(): boolean {
|
||||
return !this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(FadeOutTime)
|
||||
.isNull();
|
||||
}
|
||||
/**
|
||||
* モーションのフェードイン時間の取得
|
||||
* @return フェードイン時間[秒]
|
||||
*/
|
||||
public getMotionFadeInTime(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(FadeInTime)
|
||||
.toFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのフェードイン時間の取得
|
||||
* @return フェードイン時間[秒]
|
||||
*/
|
||||
public getMotionFadeInTime(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(FadeInTime)
|
||||
.toFloat();
|
||||
}
|
||||
/**
|
||||
* モーションのフェードアウト時間の取得
|
||||
* @return フェードアウト時間[秒]
|
||||
*/
|
||||
public getMotionFadeOutTime(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(FadeOutTime)
|
||||
.toFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのフェードアウト時間の取得
|
||||
* @return フェードアウト時間[秒]
|
||||
*/
|
||||
public getMotionFadeOutTime(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(FadeOutTime)
|
||||
.toFloat();
|
||||
}
|
||||
/**
|
||||
* モーションのカーブの種類の取得
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return カーブの種類
|
||||
*/
|
||||
public getMotionCurveTarget(curveIndex: number): string {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(Target)
|
||||
.getRawString();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのカーブの種類の取得
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return カーブの種類
|
||||
*/
|
||||
public getMotionCurveTarget(curveIndex: number): string {
|
||||
return this._json
|
||||
/**
|
||||
* モーションのカーブのIDの取得
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return カーブのID
|
||||
*/
|
||||
public getMotionCurveId(curveIndex: number): CubismIdHandle {
|
||||
return CubismFramework.getIdManager().getId(
|
||||
this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(Target)
|
||||
.getRawString();
|
||||
}
|
||||
.getValueByString(Id)
|
||||
.getRawString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのカーブのIDの取得
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return カーブのID
|
||||
*/
|
||||
public getMotionCurveId(curveIndex: number): CubismIdHandle {
|
||||
return CubismFramework.getIdManager().getId(
|
||||
this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(Id)
|
||||
.getRawString()
|
||||
);
|
||||
}
|
||||
/**
|
||||
* モーションのカーブのフェードイン時間の存在
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return true 存在する
|
||||
* @return false 存在しない
|
||||
*/
|
||||
public isExistMotionCurveFadeInTime(curveIndex: number): boolean {
|
||||
return !this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(FadeInTime)
|
||||
.isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのカーブのフェードイン時間の存在
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return true 存在する
|
||||
* @return false 存在しない
|
||||
*/
|
||||
public isExistMotionCurveFadeInTime(curveIndex: number): boolean {
|
||||
return !this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(FadeInTime)
|
||||
.isNull();
|
||||
}
|
||||
/**
|
||||
* モーションのカーブのフェードアウト時間の存在
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return true 存在する
|
||||
* @return false 存在しない
|
||||
*/
|
||||
public isExistMotionCurveFadeOutTime(curveIndex: number): boolean {
|
||||
return !this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(FadeOutTime)
|
||||
.isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのカーブのフェードアウト時間の存在
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return true 存在する
|
||||
* @return false 存在しない
|
||||
*/
|
||||
public isExistMotionCurveFadeOutTime(curveIndex: number): boolean {
|
||||
return !this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(FadeOutTime)
|
||||
.isNull();
|
||||
}
|
||||
/**
|
||||
* モーションのカーブのフェードイン時間の取得
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return フェードイン時間[秒]
|
||||
*/
|
||||
public getMotionCurveFadeInTime(curveIndex: number): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(FadeInTime)
|
||||
.toFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのカーブのフェードイン時間の取得
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return フェードイン時間[秒]
|
||||
*/
|
||||
public getMotionCurveFadeInTime(curveIndex: number): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(FadeInTime)
|
||||
.toFloat();
|
||||
}
|
||||
/**
|
||||
* モーションのカーブのフェードアウト時間の取得
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return フェードアウト時間[秒]
|
||||
*/
|
||||
public getMotionCurveFadeOutTime(curveIndex: number): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(FadeOutTime)
|
||||
.toFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのカーブのフェードアウト時間の取得
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return フェードアウト時間[秒]
|
||||
*/
|
||||
public getMotionCurveFadeOutTime(curveIndex: number): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(FadeOutTime)
|
||||
.toFloat();
|
||||
}
|
||||
/**
|
||||
* モーションのカーブのセグメントの個数を取得する
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return モーションのカーブのセグメントの個数
|
||||
*/
|
||||
public getMotionCurveSegmentCount(curveIndex: number): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(Segments)
|
||||
.getVector()
|
||||
.getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのカーブのセグメントの個数を取得する
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @return モーションのカーブのセグメントの個数
|
||||
*/
|
||||
public getMotionCurveSegmentCount(curveIndex: number): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(Segments)
|
||||
.getVector()
|
||||
.getSize();
|
||||
}
|
||||
/**
|
||||
* モーションのカーブのセグメントの値の取得
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @param segmentIndex セグメントのインデックス
|
||||
* @return セグメントの値
|
||||
*/
|
||||
public getMotionCurveSegment(
|
||||
curveIndex: number,
|
||||
segmentIndex: number
|
||||
): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(Segments)
|
||||
.getValueByIndex(segmentIndex)
|
||||
.toFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションのカーブのセグメントの値の取得
|
||||
* @param curveIndex カーブのインデックス
|
||||
* @param segmentIndex セグメントのインデックス
|
||||
* @return セグメントの値
|
||||
*/
|
||||
public getMotionCurveSegment(
|
||||
curveIndex: number,
|
||||
segmentIndex: number
|
||||
): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Curves)
|
||||
.getValueByIndex(curveIndex)
|
||||
.getValueByString(Segments)
|
||||
.getValueByIndex(segmentIndex)
|
||||
.toFloat();
|
||||
}
|
||||
/**
|
||||
* イベントの個数の取得
|
||||
* @return イベントの個数
|
||||
*/
|
||||
public getEventCount(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(UserDataCount)
|
||||
.toInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* イベントの個数の取得
|
||||
* @return イベントの個数
|
||||
*/
|
||||
public getEventCount(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(UserDataCount)
|
||||
.toInt();
|
||||
}
|
||||
/**
|
||||
* イベントの総文字数の取得
|
||||
* @return イベントの総文字数
|
||||
*/
|
||||
public getTotalEventValueSize(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(TotalUserDataSize)
|
||||
.toInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* イベントの総文字数の取得
|
||||
* @return イベントの総文字数
|
||||
*/
|
||||
public getTotalEventValueSize(): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(Meta)
|
||||
.getValueByString(TotalUserDataSize)
|
||||
.toInt();
|
||||
}
|
||||
/**
|
||||
* イベントの時間の取得
|
||||
* @param userDataIndex イベントのインデックス
|
||||
* @return イベントの時間[秒]
|
||||
*/
|
||||
public getEventTime(userDataIndex: number): number {
|
||||
return this._json
|
||||
.getRoot()
|
||||
.getValueByString(UserData)
|
||||
.getValueByIndex(userDataIndex)
|
||||
.getValueByString(Time)
|
||||
.toInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* イベントの時間の取得
|
||||
* @param userDataIndex イベントのインデックス
|
||||
* @return イベントの時間[秒]
|
||||
*/
|
||||
public getEventTime(userDataIndex: number): number {
|
||||
return this._json
|
||||
/**
|
||||
* イベントの取得
|
||||
* @param userDataIndex イベントのインデックス
|
||||
* @return イベントの文字列
|
||||
*/
|
||||
public getEventValue(userDataIndex: number): csmString {
|
||||
return new csmString(
|
||||
this._json
|
||||
.getRoot()
|
||||
.getValueByString(UserData)
|
||||
.getValueByIndex(userDataIndex)
|
||||
.getValueByString(Time)
|
||||
.toInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* イベントの取得
|
||||
* @param userDataIndex イベントのインデックス
|
||||
* @return イベントの文字列
|
||||
*/
|
||||
public getEventValue(userDataIndex: number): csmString {
|
||||
return new csmString(
|
||||
this._json
|
||||
.getRoot()
|
||||
.getValueByString(UserData)
|
||||
.getValueByIndex(userDataIndex)
|
||||
.getValueByString(Value)
|
||||
.getRawString()
|
||||
);
|
||||
}
|
||||
|
||||
_json: CubismJson; // motion3.jsonのデータ
|
||||
.getValueByString(Value)
|
||||
.getRawString()
|
||||
);
|
||||
}
|
||||
|
||||
_json: CubismJson; // motion3.jsonのデータ
|
||||
}
|
||||
|
||||
// Namespace definition for compatibility.
|
||||
import * as $ from './cubismmotionjson';
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
export namespace Live2DCubismFramework {
|
||||
export const CubismMotionJson = $.CubismMotionJson;
|
||||
export type CubismMotionJson = $.CubismMotionJson;
|
||||
}
|
||||
|
@ -5,120 +5,122 @@
|
||||
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
|
||||
*/
|
||||
|
||||
import { Live2DCubismFramework as cubismmotionqueuemanager } from './cubismmotionqueuemanager';
|
||||
import { Live2DCubismFramework as acubismmotion } from './acubismmotion';
|
||||
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel';
|
||||
import CubismMotionQueueEntryHandle = cubismmotionqueuemanager.CubismMotionQueueEntryHandle;
|
||||
import CubismModel = cubismmodel.CubismModel;
|
||||
import ACubismMotion = acubismmotion.ACubismMotion;
|
||||
import CubismMotionQueueManager = cubismmotionqueuemanager.CubismMotionQueueManager;
|
||||
import { CubismModel } from '../model/cubismmodel';
|
||||
import { ACubismMotion } from './acubismmotion';
|
||||
import {
|
||||
CubismMotionQueueEntryHandle,
|
||||
CubismMotionQueueManager
|
||||
} from './cubismmotionqueuemanager';
|
||||
|
||||
export namespace Live2DCubismFramework {
|
||||
/**
|
||||
* モーションの管理
|
||||
*
|
||||
* モーションの管理を行うクラス
|
||||
*/
|
||||
export class CubismMotionManager extends CubismMotionQueueManager {
|
||||
/**
|
||||
* モーションの管理
|
||||
*
|
||||
* モーションの管理を行うクラス
|
||||
* コンストラクタ
|
||||
*/
|
||||
export class CubismMotionManager extends CubismMotionQueueManager {
|
||||
/**
|
||||
* コンストラクタ
|
||||
*/
|
||||
public constructor() {
|
||||
super();
|
||||
this._currentPriority = 0;
|
||||
this._reservePriority = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 再生中のモーションの優先度の取得
|
||||
* @return モーションの優先度
|
||||
*/
|
||||
public getCurrentPriority(): number {
|
||||
return this._currentPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* 予約中のモーションの優先度を取得する。
|
||||
* @return モーションの優先度
|
||||
*/
|
||||
public getReservePriority(): number {
|
||||
return this._reservePriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* 予約中のモーションの優先度を設定する。
|
||||
* @param val 優先度
|
||||
*/
|
||||
public setReservePriority(val: number): void {
|
||||
this._reservePriority = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* 優先度を設定してモーションを開始する。
|
||||
*
|
||||
* @param motion モーション
|
||||
* @param autoDelete 再生が狩猟したモーションのインスタンスを削除するならtrue
|
||||
* @param priority 優先度
|
||||
* @return 開始したモーションの識別番号を返す。個別のモーションが終了したか否かを判定するIsFinished()の引数で使用する。開始できない時は「-1」
|
||||
*/
|
||||
public startMotionPriority(
|
||||
motion: ACubismMotion,
|
||||
autoDelete: boolean,
|
||||
priority: number
|
||||
): CubismMotionQueueEntryHandle {
|
||||
if (priority == this._reservePriority) {
|
||||
this._reservePriority = 0; // 予約を解除
|
||||
}
|
||||
|
||||
this._currentPriority = priority; // 再生中モーションの優先度を設定
|
||||
|
||||
return super.startMotion(motion, autoDelete, this._userTimeSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションを更新して、モデルにパラメータ値を反映する。
|
||||
*
|
||||
* @param model 対象のモデル
|
||||
* @param deltaTimeSeconds デルタ時間[秒]
|
||||
* @return true 更新されている
|
||||
* @return false 更新されていない
|
||||
*/
|
||||
public updateMotion(model: CubismModel, deltaTimeSeconds: number): boolean {
|
||||
this._userTimeSeconds += deltaTimeSeconds;
|
||||
|
||||
const updated: boolean = super.doUpdateMotion(
|
||||
model,
|
||||
this._userTimeSeconds
|
||||
);
|
||||
|
||||
if (this.isFinished()) {
|
||||
this._currentPriority = 0; // 再生中のモーションの優先度を解除
|
||||
}
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションを予約する。
|
||||
*
|
||||
* @param priority 優先度
|
||||
* @return true 予約できた
|
||||
* @return false 予約できなかった
|
||||
*/
|
||||
public reserveMotion(priority: number): boolean {
|
||||
if (
|
||||
priority <= this._reservePriority ||
|
||||
priority <= this._currentPriority
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._reservePriority = priority;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_currentPriority: number; // 現在再生中のモーションの優先度
|
||||
_reservePriority: number; // 再生予定のモーションの優先度。再生中は0になる。モーションファイルを別スレッドで読み込むときの機能。
|
||||
public constructor() {
|
||||
super();
|
||||
this._currentPriority = 0;
|
||||
this._reservePriority = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 再生中のモーションの優先度の取得
|
||||
* @return モーションの優先度
|
||||
*/
|
||||
public getCurrentPriority(): number {
|
||||
return this._currentPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* 予約中のモーションの優先度を取得する。
|
||||
* @return モーションの優先度
|
||||
*/
|
||||
public getReservePriority(): number {
|
||||
return this._reservePriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* 予約中のモーションの優先度を設定する。
|
||||
* @param val 優先度
|
||||
*/
|
||||
public setReservePriority(val: number): void {
|
||||
this._reservePriority = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* 優先度を設定してモーションを開始する。
|
||||
*
|
||||
* @param motion モーション
|
||||
* @param autoDelete 再生が狩猟したモーションのインスタンスを削除するならtrue
|
||||
* @param priority 優先度
|
||||
* @return 開始したモーションの識別番号を返す。個別のモーションが終了したか否かを判定するIsFinished()の引数で使用する。開始できない時は「-1」
|
||||
*/
|
||||
public startMotionPriority(
|
||||
motion: ACubismMotion,
|
||||
autoDelete: boolean,
|
||||
priority: number
|
||||
): CubismMotionQueueEntryHandle {
|
||||
if (priority == this._reservePriority) {
|
||||
this._reservePriority = 0; // 予約を解除
|
||||
}
|
||||
|
||||
this._currentPriority = priority; // 再生中モーションの優先度を設定
|
||||
|
||||
return super.startMotion(motion, autoDelete, this._userTimeSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションを更新して、モデルにパラメータ値を反映する。
|
||||
*
|
||||
* @param model 対象のモデル
|
||||
* @param deltaTimeSeconds デルタ時間[秒]
|
||||
* @return true 更新されている
|
||||
* @return false 更新されていない
|
||||
*/
|
||||
public updateMotion(model: CubismModel, deltaTimeSeconds: number): boolean {
|
||||
this._userTimeSeconds += deltaTimeSeconds;
|
||||
|
||||
const updated: boolean = super.doUpdateMotion(model, this._userTimeSeconds);
|
||||
|
||||
if (this.isFinished()) {
|
||||
this._currentPriority = 0; // 再生中のモーションの優先度を解除
|
||||
}
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションを予約する。
|
||||
*
|
||||
* @param priority 優先度
|
||||
* @return true 予約できた
|
||||
* @return false 予約できなかった
|
||||
*/
|
||||
public reserveMotion(priority: number): boolean {
|
||||
if (
|
||||
priority <= this._reservePriority ||
|
||||
priority <= this._currentPriority
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._reservePriority = priority;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_currentPriority: number; // 現在再生中のモーションの優先度
|
||||
_reservePriority: number; // 再生予定のモーションの優先度。再生中は0になる。モーションファイルを別スレッドで読み込むときの機能。
|
||||
}
|
||||
|
||||
// Namespace definition for compatibility.
|
||||
import * as $ from './cubismmotionmanager';
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
export namespace Live2DCubismFramework {
|
||||
export const CubismMotionManager = $.CubismMotionManager;
|
||||
export type CubismMotionManager = $.CubismMotionManager;
|
||||
}
|
||||
|
@ -5,245 +5,249 @@
|
||||
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
|
||||
*/
|
||||
|
||||
import { Live2DCubismFramework as acubismmotion } from './acubismmotion';
|
||||
import { Live2DCubismFramework as cubismmotionqueuemanager } from './cubismmotionqueuemanager';
|
||||
import CubismMotionQueueEntryHandle = cubismmotionqueuemanager.CubismMotionQueueEntryHandle;
|
||||
import ACubismMotion = acubismmotion.ACubismMotion;
|
||||
import { ACubismMotion } from './acubismmotion';
|
||||
import { CubismMotionQueueEntryHandle } from './cubismmotionqueuemanager';
|
||||
|
||||
export namespace Live2DCubismFramework {
|
||||
/**
|
||||
* CubismMotionQueueManagerで再生している各モーションの管理クラス。
|
||||
*/
|
||||
export class CubismMotionQueueEntry {
|
||||
/**
|
||||
* CubismMotionQueueManagerで再生している各モーションの管理クラス。
|
||||
* コンストラクタ
|
||||
*/
|
||||
export class CubismMotionQueueEntry {
|
||||
/**
|
||||
* コンストラクタ
|
||||
*/
|
||||
public constructor() {
|
||||
this._autoDelete = false;
|
||||
this._motion = null;
|
||||
this._available = true;
|
||||
this._finished = false;
|
||||
this._started = false;
|
||||
this._startTimeSeconds = -1.0;
|
||||
this._fadeInStartTimeSeconds = 0.0;
|
||||
this._endTimeSeconds = -1.0;
|
||||
this._stateTimeSeconds = 0.0;
|
||||
this._stateWeight = 0.0;
|
||||
this._lastEventCheckSeconds = 0.0;
|
||||
this._motionQueueEntryHandle = this;
|
||||
this._fadeOutSeconds = 0.0;
|
||||
this._isTriggeredFadeOut = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* デストラクタ相当の処理
|
||||
*/
|
||||
public release(): void {
|
||||
if (this._autoDelete && this._motion) {
|
||||
ACubismMotion.delete(this._motion); //
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウト時間と開始判定の設定
|
||||
* @param fadeOutSeconds フェードアウトにかかる時間[秒]
|
||||
*/
|
||||
public setFadeOut(fadeOutSeconds: number): void {
|
||||
this._fadeOutSeconds = fadeOutSeconds;
|
||||
this._isTriggeredFadeOut = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウトの開始
|
||||
* @param fadeOutSeconds フェードアウトにかかる時間[秒]
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
*/
|
||||
public startFadeOut(fadeOutSeconds: number, userTimeSeconds: number): void {
|
||||
const newEndTimeSeconds: number = userTimeSeconds + fadeOutSeconds;
|
||||
this._isTriggeredFadeOut = true;
|
||||
|
||||
if (
|
||||
this._endTimeSeconds < 0.0 ||
|
||||
newEndTimeSeconds < this._endTimeSeconds
|
||||
) {
|
||||
this._endTimeSeconds = newEndTimeSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの終了の確認
|
||||
*
|
||||
* @return true モーションが終了した
|
||||
* @return false 終了していない
|
||||
*/
|
||||
public isFinished(): boolean {
|
||||
return this._finished;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの開始の確認
|
||||
* @return true モーションが開始した
|
||||
* @return false 開始していない
|
||||
*/
|
||||
public isStarted(): boolean {
|
||||
return this._started;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの開始時刻の取得
|
||||
* @return モーションの開始時刻[秒]
|
||||
*/
|
||||
public getStartTime(): number {
|
||||
return this._startTimeSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインの開始時刻の取得
|
||||
* @return フェードインの開始時刻[秒]
|
||||
*/
|
||||
public getFadeInStartTime(): number {
|
||||
return this._fadeInStartTimeSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインの終了時刻の取得
|
||||
* @return フェードインの終了時刻の取得
|
||||
*/
|
||||
public getEndTime(): number {
|
||||
return this._endTimeSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの開始時刻の設定
|
||||
* @param startTime モーションの開始時刻
|
||||
*/
|
||||
public setStartTime(startTime: number): void {
|
||||
this._startTimeSeconds = startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインの開始時刻の設定
|
||||
* @param startTime フェードインの開始時刻[秒]
|
||||
*/
|
||||
public setFadeInStartTime(startTime: number): void {
|
||||
this._fadeInStartTimeSeconds = startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインの終了時刻の設定
|
||||
* @param endTime フェードインの終了時刻[秒]
|
||||
*/
|
||||
public setEndTime(endTime: number): void {
|
||||
this._endTimeSeconds = endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの終了の設定
|
||||
* @param f trueならモーションの終了
|
||||
*/
|
||||
public setIsFinished(f: boolean): void {
|
||||
this._finished = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーション開始の設定
|
||||
* @param f trueならモーションの開始
|
||||
*/
|
||||
public setIsStarted(f: boolean): void {
|
||||
this._started = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの有効性の確認
|
||||
* @return true モーションは有効
|
||||
* @return false モーションは無効
|
||||
*/
|
||||
public isAvailable(): boolean {
|
||||
return this._available;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの有効性の設定
|
||||
* @param v trueならモーションは有効
|
||||
*/
|
||||
public setIsAvailable(v: boolean): void {
|
||||
this._available = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの状態の設定
|
||||
* @param timeSeconds 現在時刻[秒]
|
||||
* @param weight モーション尾重み
|
||||
*/
|
||||
public setState(timeSeconds: number, weight: number): void {
|
||||
this._stateTimeSeconds = timeSeconds;
|
||||
this._stateWeight = weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの現在時刻の取得
|
||||
* @return モーションの現在時刻[秒]
|
||||
*/
|
||||
public getStateTime(): number {
|
||||
return this._stateTimeSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの重みの取得
|
||||
* @return モーションの重み
|
||||
*/
|
||||
public getStateWeight(): number {
|
||||
return this._stateWeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最後にイベントの発火をチェックした時間を取得
|
||||
*
|
||||
* @return 最後にイベントの発火をチェックした時間[秒]
|
||||
*/
|
||||
public getLastCheckEventSeconds(): number {
|
||||
return this._lastEventCheckSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最後にイベントをチェックした時間を設定
|
||||
* @param checkSeconds 最後にイベントをチェックした時間[秒]
|
||||
*/
|
||||
public setLastCheckEventSeconds(checkSeconds: number): void {
|
||||
this._lastEventCheckSeconds = checkSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウト開始判定の取得
|
||||
* @return フェードアウト開始するかどうか
|
||||
*/
|
||||
public isTriggeredFadeOut(): boolean {
|
||||
return this._isTriggeredFadeOut && this._endTimeSeconds < 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウト時間の取得
|
||||
* @return フェードアウト時間[秒]
|
||||
*/
|
||||
public getFadeOutSeconds(): number {
|
||||
return this._fadeOutSeconds;
|
||||
}
|
||||
|
||||
_autoDelete: boolean; // 自動削除
|
||||
_motion: ACubismMotion; // モーション
|
||||
|
||||
_available: boolean; // 有効化フラグ
|
||||
_finished: boolean; // 終了フラグ
|
||||
_started: boolean; // 開始フラグ
|
||||
_startTimeSeconds: number; // モーション再生開始時刻[秒]
|
||||
_fadeInStartTimeSeconds: number; // フェードイン開始時刻(ループの時は初回のみ)[秒]
|
||||
_endTimeSeconds: number; // 終了予定時刻[秒]
|
||||
_stateTimeSeconds: number; // 時刻の状態[秒]
|
||||
_stateWeight: number; // 重みの状態
|
||||
_lastEventCheckSeconds: number; // 最終のMotion側のチェックした時間
|
||||
private _fadeOutSeconds: number; // フェードアウト時間[秒]
|
||||
private _isTriggeredFadeOut: boolean; // フェードアウト開始フラグ
|
||||
|
||||
_motionQueueEntryHandle: CubismMotionQueueEntryHandle; // インスタンスごとに一意の値を持つ識別番号
|
||||
public constructor() {
|
||||
this._autoDelete = false;
|
||||
this._motion = null;
|
||||
this._available = true;
|
||||
this._finished = false;
|
||||
this._started = false;
|
||||
this._startTimeSeconds = -1.0;
|
||||
this._fadeInStartTimeSeconds = 0.0;
|
||||
this._endTimeSeconds = -1.0;
|
||||
this._stateTimeSeconds = 0.0;
|
||||
this._stateWeight = 0.0;
|
||||
this._lastEventCheckSeconds = 0.0;
|
||||
this._motionQueueEntryHandle = this;
|
||||
this._fadeOutSeconds = 0.0;
|
||||
this._isTriggeredFadeOut = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* デストラクタ相当の処理
|
||||
*/
|
||||
public release(): void {
|
||||
if (this._autoDelete && this._motion) {
|
||||
ACubismMotion.delete(this._motion); //
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウト時間と開始判定の設定
|
||||
* @param fadeOutSeconds フェードアウトにかかる時間[秒]
|
||||
*/
|
||||
public setFadeOut(fadeOutSeconds: number): void {
|
||||
this._fadeOutSeconds = fadeOutSeconds;
|
||||
this._isTriggeredFadeOut = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウトの開始
|
||||
* @param fadeOutSeconds フェードアウトにかかる時間[秒]
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
*/
|
||||
public startFadeOut(fadeOutSeconds: number, userTimeSeconds: number): void {
|
||||
const newEndTimeSeconds: number = userTimeSeconds + fadeOutSeconds;
|
||||
this._isTriggeredFadeOut = true;
|
||||
|
||||
if (
|
||||
this._endTimeSeconds < 0.0 ||
|
||||
newEndTimeSeconds < this._endTimeSeconds
|
||||
) {
|
||||
this._endTimeSeconds = newEndTimeSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの終了の確認
|
||||
*
|
||||
* @return true モーションが終了した
|
||||
* @return false 終了していない
|
||||
*/
|
||||
public isFinished(): boolean {
|
||||
return this._finished;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの開始の確認
|
||||
* @return true モーションが開始した
|
||||
* @return false 開始していない
|
||||
*/
|
||||
public isStarted(): boolean {
|
||||
return this._started;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの開始時刻の取得
|
||||
* @return モーションの開始時刻[秒]
|
||||
*/
|
||||
public getStartTime(): number {
|
||||
return this._startTimeSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインの開始時刻の取得
|
||||
* @return フェードインの開始時刻[秒]
|
||||
*/
|
||||
public getFadeInStartTime(): number {
|
||||
return this._fadeInStartTimeSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインの終了時刻の取得
|
||||
* @return フェードインの終了時刻の取得
|
||||
*/
|
||||
public getEndTime(): number {
|
||||
return this._endTimeSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの開始時刻の設定
|
||||
* @param startTime モーションの開始時刻
|
||||
*/
|
||||
public setStartTime(startTime: number): void {
|
||||
this._startTimeSeconds = startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインの開始時刻の設定
|
||||
* @param startTime フェードインの開始時刻[秒]
|
||||
*/
|
||||
public setFadeInStartTime(startTime: number): void {
|
||||
this._fadeInStartTimeSeconds = startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードインの終了時刻の設定
|
||||
* @param endTime フェードインの終了時刻[秒]
|
||||
*/
|
||||
public setEndTime(endTime: number): void {
|
||||
this._endTimeSeconds = endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの終了の設定
|
||||
* @param f trueならモーションの終了
|
||||
*/
|
||||
public setIsFinished(f: boolean): void {
|
||||
this._finished = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーション開始の設定
|
||||
* @param f trueならモーションの開始
|
||||
*/
|
||||
public setIsStarted(f: boolean): void {
|
||||
this._started = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの有効性の確認
|
||||
* @return true モーションは有効
|
||||
* @return false モーションは無効
|
||||
*/
|
||||
public isAvailable(): boolean {
|
||||
return this._available;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの有効性の設定
|
||||
* @param v trueならモーションは有効
|
||||
*/
|
||||
public setIsAvailable(v: boolean): void {
|
||||
this._available = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの状態の設定
|
||||
* @param timeSeconds 現在時刻[秒]
|
||||
* @param weight モーション尾重み
|
||||
*/
|
||||
public setState(timeSeconds: number, weight: number): void {
|
||||
this._stateTimeSeconds = timeSeconds;
|
||||
this._stateWeight = weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの現在時刻の取得
|
||||
* @return モーションの現在時刻[秒]
|
||||
*/
|
||||
public getStateTime(): number {
|
||||
return this._stateTimeSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの重みの取得
|
||||
* @return モーションの重み
|
||||
*/
|
||||
public getStateWeight(): number {
|
||||
return this._stateWeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最後にイベントの発火をチェックした時間を取得
|
||||
*
|
||||
* @return 最後にイベントの発火をチェックした時間[秒]
|
||||
*/
|
||||
public getLastCheckEventSeconds(): number {
|
||||
return this._lastEventCheckSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最後にイベントをチェックした時間を設定
|
||||
* @param checkSeconds 最後にイベントをチェックした時間[秒]
|
||||
*/
|
||||
public setLastCheckEventSeconds(checkSeconds: number): void {
|
||||
this._lastEventCheckSeconds = checkSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウト開始判定の取得
|
||||
* @return フェードアウト開始するかどうか
|
||||
*/
|
||||
public isTriggeredFadeOut(): boolean {
|
||||
return this._isTriggeredFadeOut && this._endTimeSeconds < 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* フェードアウト時間の取得
|
||||
* @return フェードアウト時間[秒]
|
||||
*/
|
||||
public getFadeOutSeconds(): number {
|
||||
return this._fadeOutSeconds;
|
||||
}
|
||||
|
||||
_autoDelete: boolean; // 自動削除
|
||||
_motion: ACubismMotion; // モーション
|
||||
|
||||
_available: boolean; // 有効化フラグ
|
||||
_finished: boolean; // 終了フラグ
|
||||
_started: boolean; // 開始フラグ
|
||||
_startTimeSeconds: number; // モーション再生開始時刻[秒]
|
||||
_fadeInStartTimeSeconds: number; // フェードイン開始時刻(ループの時は初回のみ)[秒]
|
||||
_endTimeSeconds: number; // 終了予定時刻[秒]
|
||||
_stateTimeSeconds: number; // 時刻の状態[秒]
|
||||
_stateWeight: number; // 重みの状態
|
||||
_lastEventCheckSeconds: number; // 最終のMotion側のチェックした時間
|
||||
private _fadeOutSeconds: number; // フェードアウト時間[秒]
|
||||
private _isTriggeredFadeOut: boolean; // フェードアウト開始フラグ
|
||||
|
||||
_motionQueueEntryHandle: CubismMotionQueueEntryHandle; // インスタンスごとに一意の値を持つ識別番号
|
||||
}
|
||||
|
||||
// Namespace definition for compatibility.
|
||||
import * as $ from './cubismmotionqueueentry';
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
export namespace Live2DCubismFramework {
|
||||
export const CubismMotionQueueEntry = $.CubismMotionQueueEntry;
|
||||
export type CubismMotionQueueEntry = $.CubismMotionQueueEntry;
|
||||
}
|
||||
|
@ -5,346 +5,345 @@
|
||||
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
|
||||
*/
|
||||
|
||||
import { Live2DCubismFramework as acubismmotion } from './acubismmotion';
|
||||
import { Live2DCubismFramework as cubismmotionqueueentry } from './cubismmotionqueueentry';
|
||||
import { Live2DCubismFramework as csmvector } from '../type/csmvector';
|
||||
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel';
|
||||
import { Live2DCubismFramework as csmstring } from '../type/csmstring';
|
||||
import csmString = csmstring.csmString;
|
||||
import CubismModel = cubismmodel.CubismModel;
|
||||
import csmVector = csmvector.csmVector;
|
||||
import iterator = csmvector.iterator;
|
||||
import CubismMotionQueueEntry = cubismmotionqueueentry.CubismMotionQueueEntry;
|
||||
import ACubismMotion = acubismmotion.ACubismMotion;
|
||||
import { ACubismMotion } from './acubismmotion';
|
||||
import { CubismMotionQueueEntry } from './cubismmotionqueueentry';
|
||||
import { csmVector, iterator } from '../type/csmvector';
|
||||
import { CubismModel } from '../model/cubismmodel';
|
||||
import { csmString } from '../type/csmstring';
|
||||
|
||||
export namespace Live2DCubismFramework {
|
||||
/**
|
||||
* モーション再生の管理
|
||||
*
|
||||
* モーション再生の管理用クラス。CubismMotionモーションなどACubismMotionのサブクラスを再生するために使用する。
|
||||
*
|
||||
* @note 再生中に別のモーションが StartMotion()された場合は、新しいモーションに滑らかに変化し旧モーションは中断する。
|
||||
* 表情用モーション、体用モーションなどを分けてモーション化した場合など、
|
||||
* 複数のモーションを同時に再生させる場合は、複数のCubismMotionQueueManagerインスタンスを使用する。
|
||||
*/
|
||||
export class CubismMotionQueueManager {
|
||||
/**
|
||||
* モーション再生の管理
|
||||
*
|
||||
* モーション再生の管理用クラス。CubismMotionモーションなどACubismMotionのサブクラスを再生するために使用する。
|
||||
*
|
||||
* @note 再生中に別のモーションが StartMotion()された場合は、新しいモーションに滑らかに変化し旧モーションは中断する。
|
||||
* 表情用モーション、体用モーションなどを分けてモーション化した場合など、
|
||||
* 複数のモーションを同時に再生させる場合は、複数のCubismMotionQueueManagerインスタンスを使用する。
|
||||
* コンストラクタ
|
||||
*/
|
||||
export class CubismMotionQueueManager {
|
||||
/**
|
||||
* コンストラクタ
|
||||
*/
|
||||
public constructor() {
|
||||
this._userTimeSeconds = 0.0;
|
||||
this._eventCallBack = null;
|
||||
this._eventCustomData = null;
|
||||
this._motions = new csmVector<CubismMotionQueueEntry>();
|
||||
public constructor() {
|
||||
this._userTimeSeconds = 0.0;
|
||||
this._eventCallBack = null;
|
||||
this._eventCustomData = null;
|
||||
this._motions = new csmVector<CubismMotionQueueEntry>();
|
||||
}
|
||||
|
||||
/**
|
||||
* デストラクタ
|
||||
*/
|
||||
public release(): void {
|
||||
for (let i = 0; i < this._motions.getSize(); ++i) {
|
||||
if (this._motions.at(i)) {
|
||||
this._motions.at(i).release();
|
||||
this._motions.set(i, void 0);
|
||||
this._motions.set(i, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* デストラクタ
|
||||
*/
|
||||
public release(): void {
|
||||
for (let i = 0; i < this._motions.getSize(); ++i) {
|
||||
if (this._motions.at(i)) {
|
||||
this._motions.at(i).release();
|
||||
this._motions.set(i, void 0);
|
||||
this._motions.set(i, null);
|
||||
}
|
||||
this._motions = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定したモーションの開始
|
||||
*
|
||||
* 指定したモーションを開始する。同じタイプのモーションが既にある場合は、既存のモーションに終了フラグを立て、フェードアウトを開始させる。
|
||||
*
|
||||
* @param motion 開始するモーション
|
||||
* @param autoDelete 再生が終了したモーションのインスタンスを削除するなら true
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
* @return 開始したモーションの識別番号を返す。個別のモーションが終了したか否かを判定するIsFinished()の引数で使用する。開始できない時は「-1」
|
||||
*/
|
||||
public startMotion(
|
||||
motion: ACubismMotion,
|
||||
autoDelete: boolean,
|
||||
userTimeSeconds: number
|
||||
): CubismMotionQueueEntryHandle {
|
||||
if (motion == null) {
|
||||
return InvalidMotionQueueEntryHandleValue;
|
||||
}
|
||||
|
||||
let motionQueueEntry: CubismMotionQueueEntry = null;
|
||||
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
for (let i = 0; i < this._motions.getSize(); ++i) {
|
||||
motionQueueEntry = this._motions.at(i);
|
||||
if (motionQueueEntry == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this._motions = null;
|
||||
motionQueueEntry.setFadeOut(motionQueueEntry._motion.getFadeOutTime()); // フェードアウト設定
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定したモーションの開始
|
||||
*
|
||||
* 指定したモーションを開始する。同じタイプのモーションが既にある場合は、既存のモーションに終了フラグを立て、フェードアウトを開始させる。
|
||||
*
|
||||
* @param motion 開始するモーション
|
||||
* @param autoDelete 再生が終了したモーションのインスタンスを削除するなら true
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
* @return 開始したモーションの識別番号を返す。個別のモーションが終了したか否かを判定するIsFinished()の引数で使用する。開始できない時は「-1」
|
||||
*/
|
||||
public startMotion(
|
||||
motion: ACubismMotion,
|
||||
autoDelete: boolean,
|
||||
userTimeSeconds: number
|
||||
): CubismMotionQueueEntryHandle {
|
||||
motionQueueEntry = new CubismMotionQueueEntry(); // 終了時に破棄する
|
||||
motionQueueEntry._autoDelete = autoDelete;
|
||||
motionQueueEntry._motion = motion;
|
||||
|
||||
this._motions.pushBack(motionQueueEntry);
|
||||
|
||||
return motionQueueEntry._motionQueueEntryHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全てのモーションの終了の確認
|
||||
* @return true 全て終了している
|
||||
* @return false 終了していない
|
||||
*/
|
||||
public isFinished(): boolean {
|
||||
// ------- 処理を行う -------
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
|
||||
for (
|
||||
let ite: iterator<CubismMotionQueueEntry> = this._motions.begin();
|
||||
ite.notEqual(this._motions.end());
|
||||
|
||||
) {
|
||||
let motionQueueEntry: CubismMotionQueueEntry = ite.ptr();
|
||||
|
||||
if (motionQueueEntry == null) {
|
||||
ite = this._motions.erase(ite); // 削除
|
||||
continue;
|
||||
}
|
||||
|
||||
const motion: ACubismMotion = motionQueueEntry._motion;
|
||||
|
||||
if (motion == null) {
|
||||
return InvalidMotionQueueEntryHandleValue;
|
||||
}
|
||||
|
||||
let motionQueueEntry: CubismMotionQueueEntry = null;
|
||||
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
for (let i = 0; i < this._motions.getSize(); ++i) {
|
||||
motionQueueEntry = this._motions.at(i);
|
||||
if (motionQueueEntry == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
motionQueueEntry.setFadeOut(motionQueueEntry._motion.getFadeOutTime()); // フェードアウト設定
|
||||
}
|
||||
|
||||
motionQueueEntry = new CubismMotionQueueEntry(); // 終了時に破棄する
|
||||
motionQueueEntry._autoDelete = autoDelete;
|
||||
motionQueueEntry._motion = motion;
|
||||
|
||||
this._motions.pushBack(motionQueueEntry);
|
||||
|
||||
return motionQueueEntry._motionQueueEntryHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全てのモーションの終了の確認
|
||||
* @return true 全て終了している
|
||||
* @return false 終了していない
|
||||
*/
|
||||
public isFinished(): boolean {
|
||||
// ------- 処理を行う -------
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
|
||||
for (
|
||||
let ite: iterator<CubismMotionQueueEntry> = this._motions.begin();
|
||||
ite.notEqual(this._motions.end());
|
||||
|
||||
) {
|
||||
let motionQueueEntry: CubismMotionQueueEntry = ite.ptr();
|
||||
|
||||
if (motionQueueEntry == null) {
|
||||
ite = this._motions.erase(ite); // 削除
|
||||
continue;
|
||||
}
|
||||
|
||||
const motion: ACubismMotion = motionQueueEntry._motion;
|
||||
|
||||
if (motion == null) {
|
||||
motionQueueEntry.release();
|
||||
motionQueueEntry = void 0;
|
||||
motionQueueEntry = null;
|
||||
ite = this._motions.erase(ite); // 削除
|
||||
continue;
|
||||
}
|
||||
|
||||
// ----- 終了済みの処理があれば削除する ------
|
||||
if (!motionQueueEntry.isFinished()) {
|
||||
return false;
|
||||
} else {
|
||||
ite.preIncrement();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定したモーションの終了の確認
|
||||
* @param motionQueueEntryNumber モーションの識別番号
|
||||
* @return true 全て終了している
|
||||
* @return false 終了していない
|
||||
*/
|
||||
public isFinishedByHandle(
|
||||
motionQueueEntryNumber: CubismMotionQueueEntryHandle
|
||||
): boolean {
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
for (
|
||||
let ite: iterator<CubismMotionQueueEntry> = this._motions.begin();
|
||||
ite.notEqual(this._motions.end());
|
||||
ite.increment()
|
||||
) {
|
||||
const motionQueueEntry: CubismMotionQueueEntry = ite.ptr();
|
||||
|
||||
if (motionQueueEntry == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
motionQueueEntry._motionQueueEntryHandle == motionQueueEntryNumber &&
|
||||
!motionQueueEntry.isFinished()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全てのモーションを停止する
|
||||
*/
|
||||
public stopAllMotions(): void {
|
||||
// ------- 処理を行う -------
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
|
||||
for (
|
||||
let ite: iterator<CubismMotionQueueEntry> = this._motions.begin();
|
||||
ite.notEqual(this._motions.end());
|
||||
|
||||
) {
|
||||
let motionQueueEntry: CubismMotionQueueEntry = ite.ptr();
|
||||
|
||||
if (motionQueueEntry == null) {
|
||||
ite = this._motions.erase(ite);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// ----- 終了済みの処理があれば削除する ------
|
||||
motionQueueEntry.release();
|
||||
motionQueueEntry = void 0;
|
||||
motionQueueEntry = null;
|
||||
ite = this._motions.erase(ite); // 削除
|
||||
continue;
|
||||
}
|
||||
|
||||
// ----- 終了済みの処理があれば削除する ------
|
||||
if (!motionQueueEntry.isFinished()) {
|
||||
return false;
|
||||
} else {
|
||||
ite.preIncrement();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定したCubismMotionQueueEntryの取得
|
||||
|
||||
* @param motionQueueEntryNumber モーションの識別番号
|
||||
* @return 指定したCubismMotionQueueEntry
|
||||
* @return null 見つからなかった
|
||||
*/
|
||||
public getCubismMotionQueueEntry(
|
||||
motionQueueEntryNumber: any
|
||||
): CubismMotionQueueEntry {
|
||||
//------- 処理を行う -------
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
for (
|
||||
let ite: iterator<CubismMotionQueueEntry> = this._motions.begin();
|
||||
ite.notEqual(this._motions.end());
|
||||
ite.preIncrement()
|
||||
) {
|
||||
const motionQueueEntry: CubismMotionQueueEntry = ite.ptr();
|
||||
|
||||
if (motionQueueEntry == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
motionQueueEntry._motionQueueEntryHandle == motionQueueEntryNumber
|
||||
) {
|
||||
return motionQueueEntry;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* イベントを受け取るCallbackの登録
|
||||
*
|
||||
* @param callback コールバック関数
|
||||
* @param customData コールバックに返されるデータ
|
||||
*/
|
||||
public setEventCallback(
|
||||
callback: CubismMotionEventFunction,
|
||||
customData: any = null
|
||||
): void {
|
||||
this._eventCallBack = callback;
|
||||
this._eventCustomData = customData;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションを更新して、モデルにパラメータ値を反映する。
|
||||
*
|
||||
* @param model 対象のモデル
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
* @return true モデルへパラメータ値の反映あり
|
||||
* @return false モデルへパラメータ値の反映なし(モーションの変化なし)
|
||||
*/
|
||||
public doUpdateMotion(
|
||||
model: CubismModel,
|
||||
userTimeSeconds: number
|
||||
): boolean {
|
||||
let updated = false;
|
||||
|
||||
// ------- 処理を行う --------
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
|
||||
for (
|
||||
let ite: iterator<CubismMotionQueueEntry> = this._motions.begin();
|
||||
ite.notEqual(this._motions.end());
|
||||
|
||||
) {
|
||||
let motionQueueEntry: CubismMotionQueueEntry = ite.ptr();
|
||||
|
||||
if (motionQueueEntry == null) {
|
||||
ite = this._motions.erase(ite); // 削除
|
||||
continue;
|
||||
}
|
||||
|
||||
const motion: ACubismMotion = motionQueueEntry._motion;
|
||||
|
||||
if (motion == null) {
|
||||
motionQueueEntry.release();
|
||||
motionQueueEntry = void 0;
|
||||
motionQueueEntry = null;
|
||||
ite = this._motions.erase(ite); // 削除
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// ------ 値を反映する ------
|
||||
motion.updateParameters(model, motionQueueEntry, userTimeSeconds);
|
||||
updated = true;
|
||||
|
||||
// ------ ユーザトリガーイベントを検査する ----
|
||||
const firedList: csmVector<csmString> = motion.getFiredEvent(
|
||||
motionQueueEntry.getLastCheckEventSeconds() -
|
||||
motionQueueEntry.getStartTime(),
|
||||
userTimeSeconds - motionQueueEntry.getStartTime()
|
||||
);
|
||||
|
||||
for (let i = 0; i < firedList.getSize(); ++i) {
|
||||
this._eventCallBack(this, firedList.at(i), this._eventCustomData);
|
||||
}
|
||||
|
||||
motionQueueEntry.setLastCheckEventSeconds(userTimeSeconds);
|
||||
|
||||
// ------ 終了済みの処理があれば削除する ------
|
||||
if (motionQueueEntry.isFinished()) {
|
||||
motionQueueEntry.release();
|
||||
motionQueueEntry = void 0;
|
||||
motionQueueEntry = null;
|
||||
ite = this._motions.erase(ite); // 削除
|
||||
} else {
|
||||
if (motionQueueEntry.isTriggeredFadeOut()) {
|
||||
motionQueueEntry.startFadeOut(
|
||||
motionQueueEntry.getFadeOutSeconds(),
|
||||
userTimeSeconds
|
||||
);
|
||||
}
|
||||
ite.preIncrement();
|
||||
}
|
||||
}
|
||||
|
||||
return updated;
|
||||
}
|
||||
_userTimeSeconds: number; // デルタ時間の積算値[秒]
|
||||
|
||||
_motions: csmVector<CubismMotionQueueEntry>; // モーション
|
||||
_eventCallBack: CubismMotionEventFunction; // コールバック関数
|
||||
_eventCustomData: any; // コールバックに戻されるデータ
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* イベントのコールバック関数を定義
|
||||
*
|
||||
* イベントのコールバックに登録できる関数の型情報
|
||||
* @param caller 発火したイベントを再生させたCubismMotionQueueManager
|
||||
* @param eventValue 発火したイベントの文字列データ
|
||||
* @param customData コールバックに返される登録時に指定されたデータ
|
||||
* 指定したモーションの終了の確認
|
||||
* @param motionQueueEntryNumber モーションの識別番号
|
||||
* @return true 全て終了している
|
||||
* @return false 終了していない
|
||||
*/
|
||||
export interface CubismMotionEventFunction {
|
||||
(
|
||||
caller: CubismMotionQueueManager,
|
||||
eventValue: csmString,
|
||||
customData: any
|
||||
): void;
|
||||
public isFinishedByHandle(
|
||||
motionQueueEntryNumber: CubismMotionQueueEntryHandle
|
||||
): boolean {
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
for (
|
||||
let ite: iterator<CubismMotionQueueEntry> = this._motions.begin();
|
||||
ite.notEqual(this._motions.end());
|
||||
ite.increment()
|
||||
) {
|
||||
const motionQueueEntry: CubismMotionQueueEntry = ite.ptr();
|
||||
|
||||
if (motionQueueEntry == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
motionQueueEntry._motionQueueEntryHandle == motionQueueEntryNumber &&
|
||||
!motionQueueEntry.isFinished()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの識別番号
|
||||
*
|
||||
* モーションの識別番号の定義
|
||||
* 全てのモーションを停止する
|
||||
*/
|
||||
export declare type CubismMotionQueueEntryHandle = any;
|
||||
export const InvalidMotionQueueEntryHandleValue: CubismMotionQueueEntryHandle = -1;
|
||||
public stopAllMotions(): void {
|
||||
// ------- 処理を行う -------
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
|
||||
for (
|
||||
let ite: iterator<CubismMotionQueueEntry> = this._motions.begin();
|
||||
ite.notEqual(this._motions.end());
|
||||
|
||||
) {
|
||||
let motionQueueEntry: CubismMotionQueueEntry = ite.ptr();
|
||||
|
||||
if (motionQueueEntry == null) {
|
||||
ite = this._motions.erase(ite);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// ----- 終了済みの処理があれば削除する ------
|
||||
motionQueueEntry.release();
|
||||
motionQueueEntry = void 0;
|
||||
motionQueueEntry = null;
|
||||
ite = this._motions.erase(ite); // 削除
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定したCubismMotionQueueEntryの取得
|
||||
|
||||
* @param motionQueueEntryNumber モーションの識別番号
|
||||
* @return 指定したCubismMotionQueueEntry
|
||||
* @return null 見つからなかった
|
||||
*/
|
||||
public getCubismMotionQueueEntry(
|
||||
motionQueueEntryNumber: any
|
||||
): CubismMotionQueueEntry {
|
||||
//------- 処理を行う -------
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
for (
|
||||
let ite: iterator<CubismMotionQueueEntry> = this._motions.begin();
|
||||
ite.notEqual(this._motions.end());
|
||||
ite.preIncrement()
|
||||
) {
|
||||
const motionQueueEntry: CubismMotionQueueEntry = ite.ptr();
|
||||
|
||||
if (motionQueueEntry == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (motionQueueEntry._motionQueueEntryHandle == motionQueueEntryNumber) {
|
||||
return motionQueueEntry;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* イベントを受け取るCallbackの登録
|
||||
*
|
||||
* @param callback コールバック関数
|
||||
* @param customData コールバックに返されるデータ
|
||||
*/
|
||||
public setEventCallback(
|
||||
callback: CubismMotionEventFunction,
|
||||
customData: any = null
|
||||
): void {
|
||||
this._eventCallBack = callback;
|
||||
this._eventCustomData = customData;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションを更新して、モデルにパラメータ値を反映する。
|
||||
*
|
||||
* @param model 対象のモデル
|
||||
* @param userTimeSeconds デルタ時間の積算値[秒]
|
||||
* @return true モデルへパラメータ値の反映あり
|
||||
* @return false モデルへパラメータ値の反映なし(モーションの変化なし)
|
||||
*/
|
||||
public doUpdateMotion(model: CubismModel, userTimeSeconds: number): boolean {
|
||||
let updated = false;
|
||||
|
||||
// ------- 処理を行う --------
|
||||
// 既にモーションがあれば終了フラグを立てる
|
||||
|
||||
for (
|
||||
let ite: iterator<CubismMotionQueueEntry> = this._motions.begin();
|
||||
ite.notEqual(this._motions.end());
|
||||
|
||||
) {
|
||||
let motionQueueEntry: CubismMotionQueueEntry = ite.ptr();
|
||||
|
||||
if (motionQueueEntry == null) {
|
||||
ite = this._motions.erase(ite); // 削除
|
||||
continue;
|
||||
}
|
||||
|
||||
const motion: ACubismMotion = motionQueueEntry._motion;
|
||||
|
||||
if (motion == null) {
|
||||
motionQueueEntry.release();
|
||||
motionQueueEntry = void 0;
|
||||
motionQueueEntry = null;
|
||||
ite = this._motions.erase(ite); // 削除
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// ------ 値を反映する ------
|
||||
motion.updateParameters(model, motionQueueEntry, userTimeSeconds);
|
||||
updated = true;
|
||||
|
||||
// ------ ユーザトリガーイベントを検査する ----
|
||||
const firedList: csmVector<csmString> = motion.getFiredEvent(
|
||||
motionQueueEntry.getLastCheckEventSeconds() -
|
||||
motionQueueEntry.getStartTime(),
|
||||
userTimeSeconds - motionQueueEntry.getStartTime()
|
||||
);
|
||||
|
||||
for (let i = 0; i < firedList.getSize(); ++i) {
|
||||
this._eventCallBack(this, firedList.at(i), this._eventCustomData);
|
||||
}
|
||||
|
||||
motionQueueEntry.setLastCheckEventSeconds(userTimeSeconds);
|
||||
|
||||
// ------ 終了済みの処理があれば削除する ------
|
||||
if (motionQueueEntry.isFinished()) {
|
||||
motionQueueEntry.release();
|
||||
motionQueueEntry = void 0;
|
||||
motionQueueEntry = null;
|
||||
ite = this._motions.erase(ite); // 削除
|
||||
} else {
|
||||
if (motionQueueEntry.isTriggeredFadeOut()) {
|
||||
motionQueueEntry.startFadeOut(
|
||||
motionQueueEntry.getFadeOutSeconds(),
|
||||
userTimeSeconds
|
||||
);
|
||||
}
|
||||
ite.preIncrement();
|
||||
}
|
||||
}
|
||||
|
||||
return updated;
|
||||
}
|
||||
_userTimeSeconds: number; // デルタ時間の積算値[秒]
|
||||
|
||||
_motions: csmVector<CubismMotionQueueEntry>; // モーション
|
||||
_eventCallBack: CubismMotionEventFunction; // コールバック関数
|
||||
_eventCustomData: any; // コールバックに戻されるデータ
|
||||
}
|
||||
|
||||
/**
|
||||
* イベントのコールバック関数を定義
|
||||
*
|
||||
* イベントのコールバックに登録できる関数の型情報
|
||||
* @param caller 発火したイベントを再生させたCubismMotionQueueManager
|
||||
* @param eventValue 発火したイベントの文字列データ
|
||||
* @param customData コールバックに返される登録時に指定されたデータ
|
||||
*/
|
||||
export interface CubismMotionEventFunction {
|
||||
(
|
||||
caller: CubismMotionQueueManager,
|
||||
eventValue: csmString,
|
||||
customData: any
|
||||
): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* モーションの識別番号
|
||||
*
|
||||
* モーションの識別番号の定義
|
||||
*/
|
||||
export declare type CubismMotionQueueEntryHandle = any;
|
||||
export const InvalidMotionQueueEntryHandleValue: CubismMotionQueueEntryHandle = -1;
|
||||
|
||||
// Namespace definition for compatibility.
|
||||
import * as $ from './cubismmotionqueuemanager';
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
export namespace Live2DCubismFramework {
|
||||
export const CubismMotionQueueManager = $.CubismMotionQueueManager;
|
||||
export type CubismMotionQueueManager = $.CubismMotionQueueManager;
|
||||
export const InvalidMotionQueueEntryHandleValue =
|
||||
$.InvalidMotionQueueEntryHandleValue;
|
||||
export type CubismMotionQueueEntryHandle = $.CubismMotionQueueEntryHandle;
|
||||
export type CubismMotionEventFunction = $.CubismMotionEventFunction;
|
||||
}
|
||||
|
Reference in New Issue
Block a user