UNPKG

@petkoneo/phaser3-rex-plugins

Version:
195 lines 7.73 kB
"use strict"; /** * Copyright(c) Live2D Inc. All rights reserved. * * Use of this source code is governed by the Live2D Open Software license * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. */ var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); var csmvector_1 = require("../type/csmvector"); /** * 自動まばたき機能 * * 自動まばたき機能を提供する。 */ var CubismEyeBlink = /** @class */ (function () { /** * コンストラクタ * @param modelSetting モデルの設定情報 */ function CubismEyeBlink(modelSetting) { this._blinkingState = EyeState.EyeState_First; this._nextBlinkingTime = 0.0; this._stateStartTimeSeconds = 0.0; this._blinkingIntervalSeconds = 4.0; this._closingSeconds = 0.1; this._closedSeconds = 0.05; this._openingSeconds = 0.15; this._userTimeSeconds = 0.0; this._parameterIds = new csmvector_1.csmVector(); if (modelSetting == null) { return; } for (var i = 0; i < modelSetting.getEyeBlinkParameterCount(); ++i) { this._parameterIds.pushBack(modelSetting.getEyeBlinkParameterId(i)); } } /** * インスタンスを作成する * @param modelSetting モデルの設定情報 * @return 作成されたインスタンス * @note 引数がNULLの場合、パラメータIDが設定されていない空のインスタンスを作成する。 */ CubismEyeBlink.create = function (modelSetting) { if (modelSetting === void 0) { modelSetting = null; } return new CubismEyeBlink(modelSetting); }; /** * インスタンスの破棄 * @param eyeBlink 対象のCubismEyeBlink */ CubismEyeBlink.delete = function (eyeBlink) { if (eyeBlink != null) { eyeBlink = null; } }; /** * まばたきの間隔の設定 * @param blinkingInterval まばたきの間隔の時間[秒] */ CubismEyeBlink.prototype.setBlinkingInterval = function (blinkingInterval) { this._blinkingIntervalSeconds = blinkingInterval; }; /** * まばたきのモーションの詳細設定 * @param closing まぶたを閉じる動作の所要時間[秒] * @param closed まぶたを閉じている動作の所要時間[秒] * @param opening まぶたを開く動作の所要時間[秒] */ CubismEyeBlink.prototype.setBlinkingSetting = function (closing, closed, opening) { this._closingSeconds = closing; this._closedSeconds = closed; this._openingSeconds = opening; }; /** * まばたきさせるパラメータIDのリストの設定 * @param parameterIds パラメータのIDのリスト */ CubismEyeBlink.prototype.setParameterIds = function (parameterIds) { this._parameterIds = parameterIds; }; /** * まばたきさせるパラメータIDのリストの取得 * @return パラメータIDのリスト */ CubismEyeBlink.prototype.getParameterIds = function () { return this._parameterIds; }; /** * モデルのパラメータの更新 * @param model 対象のモデル * @param deltaTimeSeconds デルタ時間[秒] */ CubismEyeBlink.prototype.updateParameters = function (model, deltaTimeSeconds) { this._userTimeSeconds += deltaTimeSeconds; var parameterValue; var t = 0.0; switch (this._blinkingState) { case EyeState.EyeState_Closing: t = (this._userTimeSeconds - this._stateStartTimeSeconds) / this._closingSeconds; if (t >= 1.0) { t = 1.0; this._blinkingState = EyeState.EyeState_Closed; this._stateStartTimeSeconds = this._userTimeSeconds; } parameterValue = 1.0 - t; break; case EyeState.EyeState_Closed: t = (this._userTimeSeconds - this._stateStartTimeSeconds) / this._closedSeconds; if (t >= 1.0) { this._blinkingState = EyeState.EyeState_Opening; this._stateStartTimeSeconds = this._userTimeSeconds; } parameterValue = 0.0; break; case EyeState.EyeState_Opening: t = (this._userTimeSeconds - this._stateStartTimeSeconds) / this._openingSeconds; if (t >= 1.0) { t = 1.0; this._blinkingState = EyeState.EyeState_Interval; this._nextBlinkingTime = this.determinNextBlinkingTiming(); } parameterValue = t; break; case EyeState.EyeState_Interval: if (this._nextBlinkingTime < this._userTimeSeconds) { this._blinkingState = EyeState.EyeState_Closing; this._stateStartTimeSeconds = this._userTimeSeconds; } parameterValue = 1.0; break; case EyeState.EyeState_First: default: this._blinkingState = EyeState.EyeState_Interval; this._nextBlinkingTime = this.determinNextBlinkingTiming(); parameterValue = 1.0; break; } if (!CubismEyeBlink.CloseIfZero) { parameterValue = -parameterValue; } for (var i = 0; i < this._parameterIds.getSize(); ++i) { model.setParameterValueById(this._parameterIds.at(i), parameterValue); } }; /** * 次の瞬きのタイミングの決定 * * @return 次のまばたきを行う時刻[秒] */ CubismEyeBlink.prototype.determinNextBlinkingTiming = function () { var r = Math.random(); return (this._userTimeSeconds + r * (2.0 * this._blinkingIntervalSeconds - 1.0)); }; /** * IDで指定された目のパラメータが、0のときに閉じるなら true 、1の時に閉じるなら false 。 */ CubismEyeBlink.CloseIfZero = true; return CubismEyeBlink; }()); exports.CubismEyeBlink = CubismEyeBlink; /** * まばたきの状態 * * まばたきの状態を表す列挙型 */ var EyeState; (function (EyeState) { EyeState[EyeState["EyeState_First"] = 0] = "EyeState_First"; EyeState[EyeState["EyeState_Interval"] = 1] = "EyeState_Interval"; EyeState[EyeState["EyeState_Closing"] = 2] = "EyeState_Closing"; EyeState[EyeState["EyeState_Closed"] = 3] = "EyeState_Closed"; EyeState[EyeState["EyeState_Opening"] = 4] = "EyeState_Opening"; // まぶたが開いていく途中の状態 })(EyeState = exports.EyeState || (exports.EyeState = {})); // Namespace definition for compatibility. var $ = __importStar(require("./cubismeyeblink")); // eslint-disable-next-line @typescript-eslint/no-namespace var Live2DCubismFramework; (function (Live2DCubismFramework) { Live2DCubismFramework.CubismEyeBlink = $.CubismEyeBlink; Live2DCubismFramework.EyeState = $.EyeState; })(Live2DCubismFramework = exports.Live2DCubismFramework || (exports.Live2DCubismFramework = {})); //# sourceMappingURL=cubismeyeblink.js.map