Merge pull request #3 from cocor-au-lait/feature/avoid-namespace

Avoiding needless namespace syntax to simplify imports
master
wada 2021-01-06 11:30:07 +09:00 committed by GitHub
commit c80e158a66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 13534 additions and 13421 deletions

View File

@ -23,7 +23,6 @@ rules:
- error - error
- allow: - allow:
- constructors - constructors
'@typescript-eslint/no-namespace': warn
'no-fallthrough': warn 'no-fallthrough': warn
'@typescript-eslint/unbound-method': off '@typescript-eslint/unbound-method': off
'no-inner-declarations': off 'no-inner-declarations': off

1
.gitignore vendored
View File

@ -10,4 +10,5 @@ dist/
# Exclude some VSCode setting files. # Exclude some VSCode setting files.
.vscode/* .vscode/*
!/.vscode/extensions.json !/.vscode/extensions.json
!/.vscode/settings.json
!/.vscode/tasks.json !/.vscode/tasks.json

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"typescript.tsdk": "./node_modules/typescript/lib"
}

View File

@ -3,8 +3,8 @@
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"test": "tsc --noEmit", "test": "tsc --noEmit",
"lint": "eslint src -f codeframe --ext .ts", "lint": "eslint src --ext .ts",
"lint:fix": "eslint src -f codeframe --ext .ts --fix", "lint:fix": "eslint src --ext .ts --fix",
"clean": "rimraf dist" "clean": "rimraf dist"
}, },
"devDependencies": { "devDependencies": {

View File

@ -10,56 +10,109 @@
* <br> * <br>
* https://docs.live2d.com/cubism-editor-manual/standard-parametor-list/ * https://docs.live2d.com/cubism-editor-manual/standard-parametor-list/
*/ */
export namespace Live2DCubismFramework { export const CubismDefaultParameterId = Object.freeze<Record<string, string>>({
// パーツID // パーツID
export const HitAreaPrefix = 'HitArea'; HitAreaPrefix: 'HitArea',
export const HitAreaHead = 'Head'; HitAreaHead: 'Head',
export const HitAreaBody = 'Body'; HitAreaBody: 'Body',
export const PartsIdCore = 'Parts01Core'; PartsIdCore: 'Parts01Core',
export const PartsArmPrefix = 'Parts01Arm_'; PartsArmPrefix: 'Parts01Arm_',
export const PartsArmLPrefix = 'Parts01ArmL_'; PartsArmLPrefix: 'Parts01ArmL_',
export const PartsArmRPrefix = 'Parts01ArmR_'; PartsArmRPrefix: 'Parts01ArmR_',
// パラメータID // パラメータID
export const ParamAngleX = 'ParamAngleX'; ParamAngleX: 'ParamAngleX',
export const ParamAngleY = 'ParamAngleY'; ParamAngleY: 'ParamAngleY',
export const ParamAngleZ = 'ParamAngleZ'; ParamAngleZ: 'ParamAngleZ',
export const ParamEyeLOpen = 'ParamEyeLOpen'; ParamEyeLOpen: 'ParamEyeLOpen',
export const ParamEyeLSmile = 'ParamEyeLSmile'; ParamEyeLSmile: 'ParamEyeLSmile',
export const ParamEyeROpen = 'ParamEyeROpen'; ParamEyeROpen: 'ParamEyeROpen',
export const ParamEyeRSmile = 'ParamEyeRSmile'; ParamEyeRSmile: 'ParamEyeRSmile',
export const ParamEyeBallX = 'ParamEyeBallX'; ParamEyeBallX: 'ParamEyeBallX',
export const ParamEyeBallY = 'ParamEyeBallY'; ParamEyeBallY: 'ParamEyeBallY',
export const ParamEyeBallForm = 'ParamEyeBallForm'; ParamEyeBallForm: 'ParamEyeBallForm',
export const ParamBrowLY = 'ParamBrowLY'; ParamBrowLY: 'ParamBrowLY',
export const ParamBrowRY = 'ParamBrowRY'; ParamBrowRY: 'ParamBrowRY',
export const ParamBrowLX = 'ParamBrowLX'; ParamBrowLX: 'ParamBrowLX',
export const ParamBrowRX = 'ParamBrowRX'; ParamBrowRX: 'ParamBrowRX',
export const ParamBrowLAngle = 'ParamBrowLAngle'; ParamBrowLAngle: 'ParamBrowLAngle',
export const ParamBrowRAngle = 'ParamBrowRAngle'; ParamBrowRAngle: 'ParamBrowRAngle',
export const ParamBrowLForm = 'ParamBrowLForm'; ParamBrowLForm: 'ParamBrowLForm',
export const ParamBrowRForm = 'ParamBrowRForm'; ParamBrowRForm: 'ParamBrowRForm',
export const ParamMouthForm = 'ParamMouthForm'; ParamMouthForm: 'ParamMouthForm',
export const ParamMouthOpenY = 'ParamMouthOpenY'; ParamMouthOpenY: 'ParamMouthOpenY',
export const ParamCheek = 'ParamCheek'; ParamCheek: 'ParamCheek',
export const ParamBodyAngleX = 'ParamBodyAngleX'; ParamBodyAngleX: 'ParamBodyAngleX',
export const ParamBodyAngleY = 'ParamBodyAngleY'; ParamBodyAngleY: 'ParamBodyAngleY',
export const ParamBodyAngleZ = 'ParamBodyAngleZ'; ParamBodyAngleZ: 'ParamBodyAngleZ',
export const ParamBreath = 'ParamBreath'; ParamBreath: 'ParamBreath',
export const ParamArmLA = 'ParamArmLA'; ParamArmLA: 'ParamArmLA',
export const ParamArmRA = 'ParamArmRA'; ParamArmRA: 'ParamArmRA',
export const ParamArmLB = 'ParamArmLB'; ParamArmLB: 'ParamArmLB',
export const ParamArmRB = 'ParamArmRB'; ParamArmRB: 'ParamArmRB',
export const ParamHandL = 'ParamHandL'; ParamHandL: 'ParamHandL',
export const ParamHandR = 'ParamHandR'; ParamHandR: 'ParamHandR',
export const ParamHairFront = 'ParamHairFront'; ParamHairFront: 'ParamHairFront',
export const ParamHairSide = 'ParamHairSide'; ParamHairSide: 'ParamHairSide',
export const ParamHairBack = 'ParamHairBack'; ParamHairBack: 'ParamHairBack',
export const ParamHairFluffy = 'ParamHairFluffy'; ParamHairFluffy: 'ParamHairFluffy',
export const ParamShoulderY = 'ParamShoulderY'; ParamShoulderY: 'ParamShoulderY',
export const ParamBustX = 'ParamBustX'; ParamBustX: 'ParamBustX',
export const ParamBustY = 'ParamBustY'; ParamBustY: 'ParamBustY',
export const ParamBaseX = 'ParamBaseX'; ParamBaseX: 'ParamBaseX',
export const ParamBaseY = 'ParamBaseY'; ParamBaseY: 'ParamBaseY',
export const ParamNONE = 'NONE:'; ParamNONE: 'NONE:'
});
// Namespace definition for compatibility.
import * as $ from './cubismdefaultparameterid';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const HitAreaBody = $.CubismDefaultParameterId.HitAreaBody;
export const HitAreaHead = $.CubismDefaultParameterId.HitAreaHead;
export const HitAreaPrefix = $.CubismDefaultParameterId.HitAreaPrefix;
export const ParamAngleX = $.CubismDefaultParameterId.ParamAngleX;
export const ParamAngleY = $.CubismDefaultParameterId.ParamAngleY;
export const ParamAngleZ = $.CubismDefaultParameterId.ParamAngleZ;
export const ParamArmLA = $.CubismDefaultParameterId.ParamArmLA;
export const ParamArmLB = $.CubismDefaultParameterId.ParamArmLB;
export const ParamArmRA = $.CubismDefaultParameterId.ParamArmRA;
export const ParamArmRB = $.CubismDefaultParameterId.ParamArmRB;
export const ParamBaseX = $.CubismDefaultParameterId.ParamBaseX;
export const ParamBaseY = $.CubismDefaultParameterId.ParamBaseY;
export const ParamBodyAngleX = $.CubismDefaultParameterId.ParamBodyAngleX;
export const ParamBodyAngleY = $.CubismDefaultParameterId.ParamBodyAngleY;
export const ParamBodyAngleZ = $.CubismDefaultParameterId.ParamBodyAngleZ;
export const ParamBreath = $.CubismDefaultParameterId.ParamBreath;
export const ParamBrowLAngle = $.CubismDefaultParameterId.ParamBrowLAngle;
export const ParamBrowLForm = $.CubismDefaultParameterId.ParamBrowLForm;
export const ParamBrowLX = $.CubismDefaultParameterId.ParamBrowLX;
export const ParamBrowLY = $.CubismDefaultParameterId.ParamBrowLY;
export const ParamBrowRAngle = $.CubismDefaultParameterId.ParamBrowRAngle;
export const ParamBrowRForm = $.CubismDefaultParameterId.ParamBrowRForm;
export const ParamBrowRX = $.CubismDefaultParameterId.ParamBrowRX;
export const ParamBrowRY = $.CubismDefaultParameterId.ParamBrowRY;
export const ParamBustX = $.CubismDefaultParameterId.ParamBustX;
export const ParamBustY = $.CubismDefaultParameterId.ParamBustY;
export const ParamCheek = $.CubismDefaultParameterId.ParamCheek;
export const ParamEyeBallForm = $.CubismDefaultParameterId.ParamEyeBallForm;
export const ParamEyeBallX = $.CubismDefaultParameterId.ParamEyeBallX;
export const ParamEyeBallY = $.CubismDefaultParameterId.ParamEyeBallY;
export const ParamEyeLOpen = $.CubismDefaultParameterId.ParamEyeLOpen;
export const ParamEyeLSmile = $.CubismDefaultParameterId.ParamEyeLSmile;
export const ParamEyeROpen = $.CubismDefaultParameterId.ParamEyeROpen;
export const ParamEyeRSmile = $.CubismDefaultParameterId.ParamEyeRSmile;
export const ParamHairBack = $.CubismDefaultParameterId.ParamHairBack;
export const ParamHairFluffy = $.CubismDefaultParameterId.ParamHairFluffy;
export const ParamHairFront = $.CubismDefaultParameterId.ParamHairFront;
export const ParamHairSide = $.CubismDefaultParameterId.ParamHairSide;
export const ParamHandL = $.CubismDefaultParameterId.ParamHandL;
export const ParamHandR = $.CubismDefaultParameterId.ParamHandR;
export const ParamMouthForm = $.CubismDefaultParameterId.ParamMouthForm;
export const ParamMouthOpenY = $.CubismDefaultParameterId.ParamMouthOpenY;
export const ParamNONE = $.CubismDefaultParameterId.ParamNONE;
export const ParamShoulderY = $.CubismDefaultParameterId.ParamShoulderY;
export const PartsArmLPrefix = $.CubismDefaultParameterId.PartsArmLPrefix;
export const PartsArmPrefix = $.CubismDefaultParameterId.PartsArmPrefix;
export const PartsArmRPrefix = $.CubismDefaultParameterId.PartsArmRPrefix;
export const PartsIdCore = $.CubismDefaultParameterId.PartsIdCore;
} }

File diff suppressed because it is too large Load Diff

View File

@ -5,120 +5,120 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as csmvector } from '../type/csmvector'; import { CubismIdHandle } from '../id/cubismid';
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel'; import { CubismModel } from '../model/cubismmodel';
import { Live2DCubismFramework as cubismid } from '../id/cubismid'; import { csmVector } from '../type/csmvector';
import CubismIdHandle = cubismid.CubismIdHandle;
import CubismModel = cubismmodel.CubismModel;
import csmVector = csmvector.csmVector;
export namespace Live2DCubismFramework { /**
*
*
*
*/
export class CubismBreath {
/** /**
* *
*
*
*/ */
export class CubismBreath { public static create(): CubismBreath {
/** return new CubismBreath();
*
*/
public static create(): CubismBreath {
return new CubismBreath();
}
/**
*
* @param instance CubismBreath
*/
public static delete(instance: CubismBreath): void {
if (instance != null) {
instance = null;
}
}
/**
*
* @param breathParameters
*/
public setParameters(
breathParameters: csmVector<BreathParameterData>
): void {
this._breathParameters = breathParameters;
}
/**
*
* @return
*/
public getParameters(): csmVector<BreathParameterData> {
return this._breathParameters;
}
/**
*
* @param model
* @param deltaTimeSeconds []
*/
public updateParameters(
model: CubismModel,
deltaTimeSeconds: number
): void {
this._currentTime += deltaTimeSeconds;
const t: number = this._currentTime * 2.0 * 3.14159;
for (let i = 0; i < this._breathParameters.getSize(); ++i) {
const data: BreathParameterData = this._breathParameters.at(i);
model.addParameterValueById(
data.parameterId,
data.offset + data.peak * Math.sin(t / data.cycle),
data.weight
);
}
}
/**
*
*/
public constructor() {
this._currentTime = 0.0;
}
_breathParameters: csmVector<BreathParameterData>; // 呼吸にひもづいているパラメータのリスト
_currentTime: number; // 積算時間[秒]
} }
/** /**
* *
* @param instance CubismBreath
*/ */
export class BreathParameterData { public static delete(instance: CubismBreath): void {
/** if (instance != null) {
* instance = null;
* @param parameterId ID
* @param offset
* @param peak
* @param cycle
* @param weight
*/
constructor(
parameterId?: CubismIdHandle,
offset?: number,
peak?: number,
cycle?: number,
weight?: number
) {
this.parameterId = parameterId == undefined ? null : parameterId;
this.offset = offset == undefined ? 0.0 : offset;
this.peak = peak == undefined ? 0.0 : peak;
this.cycle = cycle == undefined ? 0.0 : cycle;
this.weight = weight == undefined ? 0.0 : weight;
} }
parameterId: CubismIdHandle; // 呼吸をひもづけるパラメータID\
offset: number; // 呼吸を正弦波としたときの、波のオフセット
peak: number; // 呼吸を正弦波としたときの、波の高さ
cycle: number; // 呼吸を正弦波としたときの、波の周期
weight: number; // パラメータへの重み
} }
/**
*
* @param breathParameters
*/
public setParameters(breathParameters: csmVector<BreathParameterData>): void {
this._breathParameters = breathParameters;
}
/**
*
* @return
*/
public getParameters(): csmVector<BreathParameterData> {
return this._breathParameters;
}
/**
*
* @param model
* @param deltaTimeSeconds []
*/
public updateParameters(model: CubismModel, deltaTimeSeconds: number): void {
this._currentTime += deltaTimeSeconds;
const t: number = this._currentTime * 2.0 * 3.14159;
for (let i = 0; i < this._breathParameters.getSize(); ++i) {
const data: BreathParameterData = this._breathParameters.at(i);
model.addParameterValueById(
data.parameterId,
data.offset + data.peak * Math.sin(t / data.cycle),
data.weight
);
}
}
/**
*
*/
public constructor() {
this._currentTime = 0.0;
}
_breathParameters: csmVector<BreathParameterData>; // 呼吸にひもづいているパラメータのリスト
_currentTime: number; // 積算時間[秒]
}
/**
*
*/
export class BreathParameterData {
/**
*
* @param parameterId ID
* @param offset
* @param peak
* @param cycle
* @param weight
*/
constructor(
parameterId?: CubismIdHandle,
offset?: number,
peak?: number,
cycle?: number,
weight?: number
) {
this.parameterId = parameterId == undefined ? null : parameterId;
this.offset = offset == undefined ? 0.0 : offset;
this.peak = peak == undefined ? 0.0 : peak;
this.cycle = cycle == undefined ? 0.0 : cycle;
this.weight = weight == undefined ? 0.0 : weight;
}
parameterId: CubismIdHandle; // 呼吸をひもづけるパラメータID\
offset: number; // 呼吸を正弦波としたときの、波のオフセット
peak: number; // 呼吸を正弦波としたときの、波の高さ
cycle: number; // 呼吸を正弦波としたときの、波の周期
weight: number; // パラメータへの重み
}
// Namespace definition for compatibility.
import * as $ from './cubismbreath';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const BreathParameterData = $.BreathParameterData;
export type BreathParameterData = $.BreathParameterData;
export const CubismBreath = $.CubismBreath;
export type CubismBreath = $.CubismBreath;
} }

View File

@ -5,228 +5,229 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as csmvector } from '../type/csmvector'; import { ICubismModelSetting } from '../icubismmodelsetting';
import { Live2DCubismFramework as icubismmodelsetting } from '../icubismmodelsetting'; import { CubismIdHandle } from '../id/cubismid';
import { Live2DCubismFramework as cubismid } from '../id/cubismid'; import { CubismModel } from '../model/cubismmodel';
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel'; import { csmVector } from '../type/csmvector';
import CubismModel = cubismmodel.CubismModel;
import CubismIdHandle = cubismid.CubismIdHandle;
import ICubismModelSetting = icubismmodelsetting.ICubismModelSetting;
import csmVector = csmvector.csmVector;
export namespace Live2DCubismFramework { /**
*
*
*
*/
export class CubismEyeBlink {
/** /**
* *
* * @param modelSetting
* * @return
* @note NULLID
*/ */
export class CubismEyeBlink { public static create(
/** modelSetting: ICubismModelSetting = null
* ): CubismEyeBlink {
* @param modelSetting return new CubismEyeBlink(modelSetting);
* @return }
* @note NULLID
*/ /**
public static create( *
modelSetting: ICubismModelSetting = null * @param eyeBlink CubismEyeBlink
): CubismEyeBlink { */
return new CubismEyeBlink(modelSetting); public static delete(eyeBlink: CubismEyeBlink): void {
if (eyeBlink != null) {
eyeBlink = null;
} }
}
/** /**
* *
* @param eyeBlink CubismEyeBlink * @param blinkingInterval []
*/ */
public static delete(eyeBlink: CubismEyeBlink): void { public setBlinkingInterval(blinkingInterval: number): void {
if (eyeBlink != null) { this._blinkingIntervalSeconds = blinkingInterval;
eyeBlink = null; }
}
}
/** /**
* *
* @param blinkingInterval [] * @param closing []
*/ * @param closed []
public setBlinkingInterval(blinkingInterval: number): void { * @param opening []
this._blinkingIntervalSeconds = blinkingInterval; */
} public setBlinkingSetting(
closing: number,
closed: number,
opening: number
): void {
this._closingSeconds = closing;
this._closedSeconds = closed;
this._openingSeconds = opening;
}
/** /**
* * ID
* @param closing [] * @param parameterIds ID
* @param closed [] */
* @param opening [] public setParameterIds(parameterIds: csmVector<CubismIdHandle>): void {
*/ this._parameterIds = parameterIds;
public setBlinkingSetting( }
closing: number,
closed: number,
opening: number
): void {
this._closingSeconds = closing;
this._closedSeconds = closed;
this._openingSeconds = opening;
}
/** /**
* ID * ID
* @param parameterIds ID * @return ID
*/ */
public setParameterIds(parameterIds: csmVector<CubismIdHandle>): void { public getParameterIds(): csmVector<CubismIdHandle> {
this._parameterIds = parameterIds; return this._parameterIds;
} }
/** /**
* ID *
* @return ID * @param model
*/ * @param deltaTimeSeconds []
public getParameterIds(): csmVector<CubismIdHandle> { */
return this._parameterIds; public updateParameters(model: CubismModel, deltaTimeSeconds: number): void {
} this._userTimeSeconds += deltaTimeSeconds;
let parameterValue: number;
let t = 0.0;
/** switch (this._blinkingState) {
* case EyeState.EyeState_Closing:
* @param model t =
* @param deltaTimeSeconds [] (this._userTimeSeconds - this._stateStartTimeSeconds) /
*/ this._closingSeconds;
public updateParameters(
model: CubismModel,
deltaTimeSeconds: number
): void {
this._userTimeSeconds += deltaTimeSeconds;
let parameterValue: number;
let t = 0.0;
switch (this._blinkingState) { if (t >= 1.0) {
case EyeState.EyeState_Closing: t = 1.0;
t = this._blinkingState = EyeState.EyeState_Closed;
(this._userTimeSeconds - this._stateStartTimeSeconds) / this._stateStartTimeSeconds = this._userTimeSeconds;
this._closingSeconds; }
if (t >= 1.0) { parameterValue = 1.0 - t;
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;
break; if (t >= 1.0) {
case EyeState.EyeState_Closed: this._blinkingState = EyeState.EyeState_Opening;
t = this._stateStartTimeSeconds = this._userTimeSeconds;
(this._userTimeSeconds - this._stateStartTimeSeconds) / }
this._closedSeconds;
if (t >= 1.0) { parameterValue = 0.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;
break; if (t >= 1.0) {
case EyeState.EyeState_Opening: t = 1.0;
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._blinkingState = EyeState.EyeState_Interval;
this._nextBlinkingTime = this.determinNextBlinkingTiming(); this._nextBlinkingTime = this.determinNextBlinkingTiming();
}
parameterValue = 1.0; parameterValue = t;
break;
}
if (!CubismEyeBlink.CloseIfZero) { break;
parameterValue = -parameterValue; case EyeState.EyeState_Interval:
} if (this._nextBlinkingTime < this._userTimeSeconds) {
this._blinkingState = EyeState.EyeState_Closing;
this._stateStartTimeSeconds = this._userTimeSeconds;
}
for (let i = 0; i < this._parameterIds.getSize(); ++i) { parameterValue = 1.0;
model.setParameterValueById(this._parameterIds.at(i), parameterValue);
} break;
case EyeState.EyeState_First:
default:
this._blinkingState = EyeState.EyeState_Interval;
this._nextBlinkingTime = this.determinNextBlinkingTiming();
parameterValue = 1.0;
break;
} }
/** if (!CubismEyeBlink.CloseIfZero) {
* parameterValue = -parameterValue;
* @param modelSetting
*/
public constructor(modelSetting: ICubismModelSetting) {
this._blinkingState = EyeState.EyeState_First;
this._nextBlinkingTime = 0.0;
this._stateStartTimeSeconds = 0.0;
this._blinkingIntervalSeconds = 4.0;
this._closingSeconds = 0.1;
this._closedSeconds = 0.05;
this._openingSeconds = 0.15;
this._userTimeSeconds = 0.0;
this._parameterIds = new csmVector<CubismIdHandle>();
if (modelSetting == null) {
return;
}
for (let i = 0; i < modelSetting.getEyeBlinkParameterCount(); ++i) {
this._parameterIds.pushBack(modelSetting.getEyeBlinkParameterId(i));
}
} }
/** for (let i = 0; i < this._parameterIds.getSize(); ++i) {
* model.setParameterValueById(this._parameterIds.at(i), parameterValue);
*
* @return []
*/
public determinNextBlinkingTiming(): number {
const r: number = Math.random();
return (
this._userTimeSeconds + r * (2.0 * this._blinkingIntervalSeconds - 1.0)
);
} }
_blinkingState: number; // 現在の状態
_parameterIds: csmVector<CubismIdHandle>; // 操作対象のパラメータのIDのリスト
_nextBlinkingTime: number; // 次のまばたきの時刻[秒]
_stateStartTimeSeconds: number; // 現在の状態が開始した時刻[秒]
_blinkingIntervalSeconds: number; // まばたきの間隔[秒]
_closingSeconds: number; // まぶたを閉じる動作の所要時間[秒]
_closedSeconds: number; // まぶたを閉じている動作の所要時間[秒]
_openingSeconds: number; // まぶたを開く動作の所要時間[秒]
_userTimeSeconds: number; // デルタ時間の積算値[秒]
/**
* ID0 true 1 false
*/
static readonly CloseIfZero: boolean = true;
} }
/** /**
* *
* * @param modelSetting
*
*/ */
export enum EyeState { public constructor(modelSetting: ICubismModelSetting) {
EyeState_First = 0, // 初期状態 this._blinkingState = EyeState.EyeState_First;
EyeState_Interval, // まばたきしていない状態 this._nextBlinkingTime = 0.0;
EyeState_Closing, // まぶたが閉じていく途中の状態 this._stateStartTimeSeconds = 0.0;
EyeState_Closed, // まぶたが閉じている状態 this._blinkingIntervalSeconds = 4.0;
EyeState_Opening // まぶたが開いていく途中の状態 this._closingSeconds = 0.1;
this._closedSeconds = 0.05;
this._openingSeconds = 0.15;
this._userTimeSeconds = 0.0;
this._parameterIds = new csmVector<CubismIdHandle>();
if (modelSetting == null) {
return;
}
for (let i = 0; i < modelSetting.getEyeBlinkParameterCount(); ++i) {
this._parameterIds.pushBack(modelSetting.getEyeBlinkParameterId(i));
}
} }
/**
*
*
* @return []
*/
public determinNextBlinkingTiming(): number {
const r: number = Math.random();
return (
this._userTimeSeconds + r * (2.0 * this._blinkingIntervalSeconds - 1.0)
);
}
_blinkingState: number; // 現在の状態
_parameterIds: csmVector<CubismIdHandle>; // 操作対象のパラメータのIDのリスト
_nextBlinkingTime: number; // 次のまばたきの時刻[秒]
_stateStartTimeSeconds: number; // 現在の状態が開始した時刻[秒]
_blinkingIntervalSeconds: number; // まばたきの間隔[秒]
_closingSeconds: number; // まぶたを閉じる動作の所要時間[秒]
_closedSeconds: number; // まぶたを閉じている動作の所要時間[秒]
_openingSeconds: number; // まぶたを開く動作の所要時間[秒]
_userTimeSeconds: number; // デルタ時間の積算値[秒]
/**
* ID0 true 1 false
*/
static readonly CloseIfZero: boolean = true;
}
/**
*
*
*
*/
export enum EyeState {
EyeState_First = 0, // 初期状態
EyeState_Interval, // まばたきしていない状態
EyeState_Closing, // まぶたが閉じていく途中の状態
EyeState_Closed, // まぶたが閉じている状態
EyeState_Opening // まぶたが開いていく途中の状態
}
// Namespace definition for compatibility.
import * as $ from './cubismeyeblink';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismEyeBlink = $.CubismEyeBlink;
export type CubismEyeBlink = $.CubismEyeBlink;
export const EyeState = $.EyeState;
export type EyeState = $.EyeState;
} }

View File

@ -5,352 +5,322 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * 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 { CubismIdHandle } from '../id/cubismid';
import { Live2DCubismFramework as csmvector } from '../type/csmvector'; import { CubismFramework } from '../live2dcubismframework';
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel'; import { CubismModel } from '../model/cubismmodel';
import { Live2DCubismFramework as cubismframework } from '../live2dcubismframework'; import { csmVector, iterator } from '../type/csmvector';
import { Live2DCubismFramework as cubismjson } from '../utils/cubismjson'; import { CubismJson, Value } from '../utils/cubismjson';
import CubismIdHandle = cubismid.CubismIdHandle;
import csmVector = csmvector.csmVector;
import iterator = csmvector.iterator;
import CubismModel = cubismmodel.CubismModel;
import CubismFramework = cubismframework.CubismFramework;
import CubismJson = cubismjson.CubismJson;
import Value = cubismjson.Value;
export namespace Live2DCubismFramework { const Epsilon = 0.001;
const Epsilon = 0.001; const DefaultFadeInSeconds = 0.5;
const DefaultFadeInSeconds = 0.5;
// Pose.jsonのタグ // Pose.jsonのタグ
const FadeIn = 'FadeInTime'; const FadeIn = 'FadeInTime';
const Link = 'Link'; const Link = 'Link';
const Groups = 'Groups'; const Groups = 'Groups';
const Id = 'Id'; const Id = 'Id';
/**
*
*
*
*/
export class CubismPose {
/** /**
* *
* * @param pose3json pose3.json
* * @param size pose3.json[byte]
* @return
*/ */
export class CubismPose { public static create(pose3json: ArrayBuffer, size: number): CubismPose {
/** const ret: CubismPose = new CubismPose();
* const json: CubismJson = CubismJson.create(pose3json, size);
* @param pose3json pose3.json const root: Value = json.getRoot();
* @param size pose3.json[byte]
* @return
*/
public static create(pose3json: ArrayBuffer, size: number): CubismPose {
const ret: CubismPose = new CubismPose();
const json: CubismJson = CubismJson.create(pose3json, size);
const root: Value = json.getRoot();
// フェード時間の指定 // フェード時間の指定
if (!root.getValueByString(FadeIn).isNull()) { if (!root.getValueByString(FadeIn).isNull()) {
ret._fadeTimeSeconds = root ret._fadeTimeSeconds = root
.getValueByString(FadeIn) .getValueByString(FadeIn)
.toFloat(DefaultFadeInSeconds); .toFloat(DefaultFadeInSeconds);
if (ret._fadeTimeSeconds <= 0.0) { if (ret._fadeTimeSeconds <= 0.0) {
ret._fadeTimeSeconds = DefaultFadeInSeconds; ret._fadeTimeSeconds = DefaultFadeInSeconds;
}
}
// パーツグループ
const poseListInfo: Value = root.getValueByString(Groups);
const poseCount: number = poseListInfo.getSize();
for (let poseIndex = 0; poseIndex < poseCount; ++poseIndex) {
const idListInfo: Value = poseListInfo.getValueByIndex(poseIndex);
const idCount: number = idListInfo.getSize();
let groupCount = 0;
for (let groupIndex = 0; groupIndex < idCount; ++groupIndex) {
const partInfo: Value = idListInfo.getValueByIndex(groupIndex);
const partData: PartData = new PartData();
const parameterId: CubismIdHandle = CubismFramework.getIdManager().getId(
partInfo.getValueByString(Id).getRawString()
);
partData.partId = parameterId;
// リンクするパーツの設定
if (!partInfo.getValueByString(Link).isNull()) {
const linkListInfo: Value = partInfo.getValueByString(Link);
const linkCount: number = linkListInfo.getSize();
for (let linkIndex = 0; linkIndex < linkCount; ++linkIndex) {
const linkPart: PartData = new PartData();
const linkId: CubismIdHandle = CubismFramework.getIdManager().getId(
linkListInfo.getValueByIndex(linkIndex).getString()
);
linkPart.partId = linkId;
partData.link.pushBack(linkPart);
}
}
ret._partGroups.pushBack(partData.clone());
++groupCount;
}
ret._partGroupCounts.pushBack(groupCount);
}
CubismJson.delete(json);
return ret;
}
/**
*
* @param pose CubismPose
*/
public static delete(pose: CubismPose): void {
if (pose != null) {
pose = null;
} }
} }
/** // パーツグループ
* const poseListInfo: Value = root.getValueByString(Groups);
* @param model const poseCount: number = poseListInfo.getSize();
* @param deltaTimeSeconds []
*/ for (let poseIndex = 0; poseIndex < poseCount; ++poseIndex) {
public updateParameters( const idListInfo: Value = poseListInfo.getValueByIndex(poseIndex);
model: CubismModel, const idCount: number = idListInfo.getSize();
deltaTimeSeconds: number let groupCount = 0;
): void {
// 前回のモデルと同じでない場合は初期化が必要 for (let groupIndex = 0; groupIndex < idCount; ++groupIndex) {
if (model != this._lastModel) { const partInfo: Value = idListInfo.getValueByIndex(groupIndex);
// パラメータインデックスの初期化 const partData: PartData = new PartData();
this.reset(model); const parameterId: CubismIdHandle = CubismFramework.getIdManager().getId(
partInfo.getValueByString(Id).getRawString()
);
partData.partId = parameterId;
// リンクするパーツの設定
if (!partInfo.getValueByString(Link).isNull()) {
const linkListInfo: Value = partInfo.getValueByString(Link);
const linkCount: number = linkListInfo.getSize();
for (let linkIndex = 0; linkIndex < linkCount; ++linkIndex) {
const linkPart: PartData = new PartData();
const linkId: CubismIdHandle = CubismFramework.getIdManager().getId(
linkListInfo.getValueByIndex(linkIndex).getString()
);
linkPart.partId = linkId;
partData.link.pushBack(linkPart);
}
}
ret._partGroups.pushBack(partData.clone());
++groupCount;
} }
this._lastModel = model; ret._partGroupCounts.pushBack(groupCount);
// 設定から時間を変更すると、経過時間がマイナスになる事があるので、経過時間0として対応
if (deltaTimeSeconds < 0.0) {
deltaTimeSeconds = 0.0;
}
let beginIndex = 0;
for (let i = 0; i < this._partGroupCounts.getSize(); i++) {
const partGroupCount: number = this._partGroupCounts.at(i);
this.doFade(model, deltaTimeSeconds, beginIndex, partGroupCount);
beginIndex += partGroupCount;
}
this.copyPartOpacities(model);
} }
/** CubismJson.delete(json);
*
* @param model
* @note 0
*/
public reset(model: CubismModel): void {
let beginIndex = 0;
for (let i = 0; i < this._partGroupCounts.getSize(); ++i) { return ret;
const groupCount: number = this._partGroupCounts.at(i);
for (let j: number = beginIndex; j < beginIndex + groupCount; ++j) {
this._partGroups.at(j).initialize(model);
const partsIndex: number = this._partGroups.at(j).partIndex;
const paramIndex: number = this._partGroups.at(j).parameterIndex;
if (partsIndex < 0) {
continue;
}
model.setPartOpacityByIndex(partsIndex, j == beginIndex ? 1.0 : 0.0);
model.setParameterValueByIndex(
paramIndex,
j == beginIndex ? 1.0 : 0.0
);
for (let k = 0; k < this._partGroups.at(j).link.getSize(); ++k) {
this._partGroups
.at(j)
.link.at(k)
.initialize(model);
}
}
beginIndex += groupCount;
}
}
/**
*
*
* @param model
*/
public copyPartOpacities(model: CubismModel): void {
for (
let groupIndex = 0;
groupIndex < this._partGroups.getSize();
++groupIndex
) {
const partData: PartData = this._partGroups.at(groupIndex);
if (partData.link.getSize() == 0) {
continue; // 連動するパラメータはない
}
const partIndex: number = this._partGroups.at(groupIndex).partIndex;
const opacity: number = model.getPartOpacityByIndex(partIndex);
for (
let linkIndex = 0;
linkIndex < partData.link.getSize();
++linkIndex
) {
const linkPart: PartData = partData.link.at(linkIndex);
const linkPartIndex: number = linkPart.partIndex;
if (linkPartIndex < 0) {
continue;
}
model.setPartOpacityByIndex(linkPartIndex, opacity);
}
}
}
/**
*
* @param model
* @param deltaTimeSeconds []
* @param beginIndex
* @param partGroupCount
*/
public doFade(
model: CubismModel,
deltaTimeSeconds: number,
beginIndex: number,
partGroupCount: number
): void {
let visiblePartIndex = -1;
let newOpacity = 1.0;
const phi = 0.5;
const backOpacityThreshold = 0.15;
// 現在、表示状態になっているパーツを取得
for (let i: number = beginIndex; i < beginIndex + partGroupCount; ++i) {
const partIndex: number = this._partGroups.at(i).partIndex;
const paramIndex: number = this._partGroups.at(i).parameterIndex;
if (model.getParameterValueByIndex(paramIndex) > Epsilon) {
if (visiblePartIndex >= 0) {
break;
}
visiblePartIndex = i;
newOpacity = model.getPartOpacityByIndex(partIndex);
// 新しい不透明度を計算
newOpacity += deltaTimeSeconds / this._fadeTimeSeconds;
if (newOpacity > 1.0) {
newOpacity = 1.0;
}
}
}
if (visiblePartIndex < 0) {
visiblePartIndex = 0;
newOpacity = 1.0;
}
// 表示パーツ、非表示パーツの不透明度を設定する
for (let i: number = beginIndex; i < beginIndex + partGroupCount; ++i) {
const partsIndex: number = this._partGroups.at(i).partIndex;
// 表示パーツの設定
if (visiblePartIndex == i) {
model.setPartOpacityByIndex(partsIndex, newOpacity); // 先に設定
}
// 非表示パーツの設定
else {
let opacity: number = model.getPartOpacityByIndex(partsIndex);
let a1: number; // 計算によって求められる不透明度
if (newOpacity < phi) {
a1 = (newOpacity * (phi - 1)) / phi + 1.0; // (0,1),(phi,phi)を通る直線式
} else {
a1 = ((1 - newOpacity) * phi) / (1.0 - phi); // (1,0),(phi,phi)を通る直線式
}
// 背景の見える割合を制限する場合
const backOpacity: number = (1.0 - a1) * (1.0 - newOpacity);
if (backOpacity > backOpacityThreshold) {
a1 = 1.0 - backOpacityThreshold / (1.0 - newOpacity);
}
if (opacity > a1) {
opacity = a1; // 計算の不透明度よりも大きければ(濃ければ)不透明度を上げる
}
model.setPartOpacityByIndex(partsIndex, opacity);
}
}
}
/**
*
*/
public constructor() {
this._fadeTimeSeconds = DefaultFadeInSeconds;
this._lastModel = null;
this._partGroups = new csmVector<PartData>();
this._partGroupCounts = new csmVector<number>();
}
_partGroups: csmVector<PartData>; // パーツグループ
_partGroupCounts: csmVector<number>; // それぞれのパーツグループの個数
_fadeTimeSeconds: number; // フェード時間[秒]
_lastModel: CubismModel; // 前回操作したモデル
} }
/** /**
* *
* @param pose CubismPose
*/ */
export class PartData { public static delete(pose: CubismPose): void {
/** if (pose != null) {
* pose = null;
*/ }
constructor(v?: PartData) { }
this.parameterIndex = 0;
this.partIndex = 0;
this.link = new csmVector<PartData>();
if (v != undefined) { /**
this.partId = v.partId; *
* @param model
* @param deltaTimeSeconds []
*/
public updateParameters(model: CubismModel, deltaTimeSeconds: number): void {
// 前回のモデルと同じでない場合は初期化が必要
if (model != this._lastModel) {
// パラメータインデックスの初期化
this.reset(model);
}
for ( this._lastModel = model;
const ite: iterator<PartData> = v.link.begin();
ite.notEqual(v.link.end()); // 設定から時間を変更すると、経過時間がマイナスになる事があるので、経過時間0として対応
ite.preIncrement() if (deltaTimeSeconds < 0.0) {
) { deltaTimeSeconds = 0.0;
this.link.pushBack(ite.ptr().clone()); }
let beginIndex = 0;
for (let i = 0; i < this._partGroupCounts.getSize(); i++) {
const partGroupCount: number = this._partGroupCounts.at(i);
this.doFade(model, deltaTimeSeconds, beginIndex, partGroupCount);
beginIndex += partGroupCount;
}
this.copyPartOpacities(model);
}
/**
*
* @param model
* @note 0
*/
public reset(model: CubismModel): void {
let beginIndex = 0;
for (let i = 0; i < this._partGroupCounts.getSize(); ++i) {
const groupCount: number = this._partGroupCounts.at(i);
for (let j: number = beginIndex; j < beginIndex + groupCount; ++j) {
this._partGroups.at(j).initialize(model);
const partsIndex: number = this._partGroups.at(j).partIndex;
const paramIndex: number = this._partGroups.at(j).parameterIndex;
if (partsIndex < 0) {
continue;
}
model.setPartOpacityByIndex(partsIndex, j == beginIndex ? 1.0 : 0.0);
model.setParameterValueByIndex(paramIndex, j == beginIndex ? 1.0 : 0.0);
for (let k = 0; k < this._partGroups.at(j).link.getSize(); ++k) {
this._partGroups
.at(j)
.link.at(k)
.initialize(model);
}
}
beginIndex += groupCount;
}
}
/**
*
*
* @param model
*/
public copyPartOpacities(model: CubismModel): void {
for (
let groupIndex = 0;
groupIndex < this._partGroups.getSize();
++groupIndex
) {
const partData: PartData = this._partGroups.at(groupIndex);
if (partData.link.getSize() == 0) {
continue; // 連動するパラメータはない
}
const partIndex: number = this._partGroups.at(groupIndex).partIndex;
const opacity: number = model.getPartOpacityByIndex(partIndex);
for (
let linkIndex = 0;
linkIndex < partData.link.getSize();
++linkIndex
) {
const linkPart: PartData = partData.link.at(linkIndex);
const linkPartIndex: number = linkPart.partIndex;
if (linkPartIndex < 0) {
continue;
}
model.setPartOpacityByIndex(linkPartIndex, opacity);
}
}
}
/**
*
* @param model
* @param deltaTimeSeconds []
* @param beginIndex
* @param partGroupCount
*/
public doFade(
model: CubismModel,
deltaTimeSeconds: number,
beginIndex: number,
partGroupCount: number
): void {
let visiblePartIndex = -1;
let newOpacity = 1.0;
const phi = 0.5;
const backOpacityThreshold = 0.15;
// 現在、表示状態になっているパーツを取得
for (let i: number = beginIndex; i < beginIndex + partGroupCount; ++i) {
const partIndex: number = this._partGroups.at(i).partIndex;
const paramIndex: number = this._partGroups.at(i).parameterIndex;
if (model.getParameterValueByIndex(paramIndex) > Epsilon) {
if (visiblePartIndex >= 0) {
break;
}
visiblePartIndex = i;
newOpacity = model.getPartOpacityByIndex(partIndex);
// 新しい不透明度を計算
newOpacity += deltaTimeSeconds / this._fadeTimeSeconds;
if (newOpacity > 1.0) {
newOpacity = 1.0;
} }
} }
} }
/** if (visiblePartIndex < 0) {
* = visiblePartIndex = 0;
*/ newOpacity = 1.0;
public assignment(v: PartData): PartData { }
// 表示パーツ、非表示パーツの不透明度を設定する
for (let i: number = beginIndex; i < beginIndex + partGroupCount; ++i) {
const partsIndex: number = this._partGroups.at(i).partIndex;
// 表示パーツの設定
if (visiblePartIndex == i) {
model.setPartOpacityByIndex(partsIndex, newOpacity); // 先に設定
}
// 非表示パーツの設定
else {
let opacity: number = model.getPartOpacityByIndex(partsIndex);
let a1: number; // 計算によって求められる不透明度
if (newOpacity < phi) {
a1 = (newOpacity * (phi - 1)) / phi + 1.0; // (0,1),(phi,phi)を通る直線式
} else {
a1 = ((1 - newOpacity) * phi) / (1.0 - phi); // (1,0),(phi,phi)を通る直線式
}
// 背景の見える割合を制限する場合
const backOpacity: number = (1.0 - a1) * (1.0 - newOpacity);
if (backOpacity > backOpacityThreshold) {
a1 = 1.0 - backOpacityThreshold / (1.0 - newOpacity);
}
if (opacity > a1) {
opacity = a1; // 計算の不透明度よりも大きければ(濃ければ)不透明度を上げる
}
model.setPartOpacityByIndex(partsIndex, opacity);
}
}
}
/**
*
*/
public constructor() {
this._fadeTimeSeconds = DefaultFadeInSeconds;
this._lastModel = null;
this._partGroups = new csmVector<PartData>();
this._partGroupCounts = new csmVector<number>();
}
_partGroups: csmVector<PartData>; // パーツグループ
_partGroupCounts: csmVector<number>; // それぞれのパーツグループの個数
_fadeTimeSeconds: number; // フェード時間[秒]
_lastModel: CubismModel; // 前回操作したモデル
}
/**
*
*/
export class PartData {
/**
*
*/
constructor(v?: PartData) {
this.parameterIndex = 0;
this.partIndex = 0;
this.link = new csmVector<PartData>();
if (v != undefined) {
this.partId = v.partId; this.partId = v.partId;
for ( for (
@ -360,46 +330,71 @@ export namespace Live2DCubismFramework {
) { ) {
this.link.pushBack(ite.ptr().clone()); this.link.pushBack(ite.ptr().clone());
} }
return this;
} }
/**
*
* @param model 使
*/
public initialize(model: CubismModel): void {
this.parameterIndex = model.getParameterIndex(this.partId);
this.partIndex = model.getPartIndex(this.partId);
model.setParameterValueByIndex(this.parameterIndex, 1);
}
/**
*
*/
public clone(): PartData {
const clonePartData: PartData = new PartData();
clonePartData.partId = this.partId;
clonePartData.parameterIndex = this.parameterIndex;
clonePartData.partIndex = this.partIndex;
clonePartData.link = new csmVector<PartData>();
for (
let ite: iterator<PartData> = this.link.begin();
ite.notEqual(this.link.end());
ite.increment()
) {
clonePartData.link.pushBack(ite.ptr().clone());
}
return clonePartData;
}
partId: CubismIdHandle; // パーツID
parameterIndex: number; // パラメータのインデックス
partIndex: number; // パーツのインデックス
link: csmVector<PartData>; // 連動するパラメータ
} }
/**
* =
*/
public assignment(v: PartData): PartData {
this.partId = v.partId;
for (
const ite: iterator<PartData> = v.link.begin();
ite.notEqual(v.link.end());
ite.preIncrement()
) {
this.link.pushBack(ite.ptr().clone());
}
return this;
}
/**
*
* @param model 使
*/
public initialize(model: CubismModel): void {
this.parameterIndex = model.getParameterIndex(this.partId);
this.partIndex = model.getPartIndex(this.partId);
model.setParameterValueByIndex(this.parameterIndex, 1);
}
/**
*
*/
public clone(): PartData {
const clonePartData: PartData = new PartData();
clonePartData.partId = this.partId;
clonePartData.parameterIndex = this.parameterIndex;
clonePartData.partIndex = this.partIndex;
clonePartData.link = new csmVector<PartData>();
for (
let ite: iterator<PartData> = this.link.begin();
ite.notEqual(this.link.end());
ite.increment()
) {
clonePartData.link.pushBack(ite.ptr().clone());
}
return clonePartData;
}
partId: CubismIdHandle; // パーツID
parameterIndex: number; // パラメータのインデックス
partIndex: number; // パーツのインデックス
link: csmVector<PartData>; // 連動するパラメータ
}
// Namespace definition for compatibility.
import * as $ from './cubismpose';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismPose = $.CubismPose;
export type CubismPose = $.CubismPose;
export const PartData = $.PartData;
export type PartData = $.PartData;
} }

View File

@ -5,41 +5,47 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
export namespace Live2DCubismFramework { /**
*
*
*
*
*/
export abstract class ICubismAllocator {
/** /**
* *
* *
* * @param size
* * @return '0'
*/ */
export abstract class ICubismAllocator { public abstract allocate(size: number): any;
/**
*
*
* @param size
* @return '0'
*/
public abstract allocate(size: number): any;
/** /**
* *
* *
* @param memory * @param memory
*/ */
public abstract deallocate(memory: any): void; public abstract deallocate(memory: any): void;
/** /**
* *
* @param size * @param size
* @param alignment * @param alignment
* @return '0' * @return '0'
*/ */
public abstract allocateAligned(size: number, alignment: number): any; public abstract allocateAligned(size: number, alignment: number): any;
/** /**
* *
* @param alignedMemory * @param alignedMemory
*/ */
public abstract deallocateAligned(alignedMemory: any): void; public abstract deallocateAligned(alignedMemory: any): void;
} }
// Namespace definition for compatibility.
import * as $ from './icubismallcator';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const ICubismAllocator = $.ICubismAllocator;
export type ICubismAllocator = $.ICubismAllocator;
} }

View File

@ -5,195 +5,199 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * 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 { CubismIdHandle } from './id/cubismid';
import { Live2DCubismFramework as csmmap } from './type/csmmap'; import { csmMap } from './type/csmmap';
import csmMap = csmmap.csmMap;
import CubismIdHandle = cubismid.CubismIdHandle;
export namespace Live2DCubismFramework { /**
*
*
*
*/
export abstract class ICubismModelSetting {
/** /**
* * Moc
* * @return Moc
*
*/ */
export abstract class ICubismModelSetting { public abstract getModelFileName(): string;
/**
* Moc
* @return Moc
*/
public abstract getModelFileName(): string;
/** /**
* 使 * 使
* *
*/ */
public abstract getTextureCount(): number; public abstract getTextureCount(): number;
/** /**
* *
* @return * @return
*/ */
public abstract getTextureDirectory(): string; public abstract getTextureDirectory(): string;
/** /**
* 使 * 使
* @param index * @param index
* @return * @return
*/ */
public abstract getTextureFileName(index: number): string; public abstract getTextureFileName(index: number): string;
/** /**
* *
* @return * @return
*/ */
public abstract getHitAreasCount(): number; public abstract getHitAreasCount(): number;
/** /**
* ID * ID
* *
* @param index index * @param index index
* @return ID * @return ID
*/ */
public abstract getHitAreaId(index: number): CubismIdHandle; public abstract getHitAreaId(index: number): CubismIdHandle;
/** /**
* *
* @param index * @param index
* @return * @return
*/ */
public abstract getHitAreaName(index: number): string; public abstract getHitAreaName(index: number): string;
/** /**
* *
* @return * @return
*/ */
public abstract getPhysicsFileName(): string; public abstract getPhysicsFileName(): string;
/** /**
* *
* @return * @return
*/ */
public abstract getPoseFileName(): string; public abstract getPoseFileName(): string;
/** /**
* *
* @return * @return
*/ */
public abstract getExpressionCount(): number; public abstract getExpressionCount(): number;
/** /**
* *
* @param index * @param index
* @return * @return
*/ */
public abstract getExpressionName(index: number): string; public abstract getExpressionName(index: number): string;
/** /**
* *
* @param index * @param index
* @return * @return
*/ */
public abstract getExpressionFileName(index: number): string; public abstract getExpressionFileName(index: number): string;
/** /**
* *
* @return * @return
*/ */
public abstract getMotionGroupCount(): number; public abstract getMotionGroupCount(): number;
/** /**
* *
* @param index * @param index
* @return * @return
*/ */
public abstract getMotionGroupName(index: number): string; public abstract getMotionGroupName(index: number): string;
/** /**
* *
* @param groupName * @param groupName
* @return * @return
*/ */
public abstract getMotionCount(groupName: string): number; public abstract getMotionCount(groupName: string): number;
/** /**
* *
* @param groupName * @param groupName
* @param index * @param index
* @return * @return
*/ */
public abstract getMotionFileName(groupName: string, index: number): string; public abstract getMotionFileName(groupName: string, index: number): string;
/** /**
* *
* @param groupName * @param groupName
* @param index * @param index
* @return * @return
*/ */
public abstract getMotionSoundFileName( public abstract getMotionSoundFileName(
groupName: string, groupName: string,
index: number index: number
): string; ): string;
/** /**
* *
* @param groupName * @param groupName
* @param index * @param index
* @return [] * @return []
*/ */
public abstract getMotionFadeInTimeValue( public abstract getMotionFadeInTimeValue(
groupName: string, groupName: string,
index: number index: number
): number; ): number;
/** /**
* *
* @param groupName * @param groupName
* @param index * @param index
* @return [] * @return []
*/ */
public abstract getMotionFadeOutTimeValue( public abstract getMotionFadeOutTimeValue(
groupName: string, groupName: string,
index: number index: number
): number; ): number;
/** /**
* *
* @return * @return
*/ */
public abstract getUserDataFile(): string; public abstract getUserDataFile(): string;
/** /**
* *
* @param outLayoutMap csmMap * @param outLayoutMap csmMap
* @return true * @return true
* @return false * @return false
*/ */
public abstract getLayoutMap(outLayoutMap: csmMap<string, number>): boolean; public abstract getLayoutMap(outLayoutMap: csmMap<string, number>): boolean;
/** /**
* *
* @return * @return
*/ */
public abstract getEyeBlinkParameterCount(): number; public abstract getEyeBlinkParameterCount(): number;
/** /**
* ID * ID
* @param index * @param index
* @return ID * @return ID
*/ */
public abstract getEyeBlinkParameterId(index: number): CubismIdHandle; public abstract getEyeBlinkParameterId(index: number): CubismIdHandle;
/** /**
* *
* @return * @return
*/ */
public abstract getLipSyncParameterCount(): number; public abstract getLipSyncParameterCount(): number;
/** /**
* *
* @param index * @param index
* @return ID * @return ID
*/ */
public abstract getLipSyncParameterId(index: number): CubismIdHandle; public abstract getLipSyncParameterId(index: number): CubismIdHandle;
} }
// Namespace definition for compatibility.
import * as $ from './icubismmodelsetting';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const ICubismModelSetting = $.ICubismModelSetting;
export type ICubismModelSetting = $.ICubismModelSetting;
} }

View File

@ -5,69 +5,75 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as csmstring } from '../type/csmstring'; import { csmString } from '../type/csmstring';
import csmString = csmstring.csmString;
export namespace Live2DCubismFramework { /**
* Drawable
*
* Drawable
*/
export class CubismId {
/** /**
* Drawable * ID
*
* Drawable
*/ */
export class CubismId { public getString(): csmString {
/** return this._id;
* ID
*/
public getString(): csmString {
return this._id;
}
/**
*
*/
public constructor(id: string | csmString) {
if (typeof id === 'string') {
this._id = new csmString(id);
return;
}
this._id = id;
}
/**
* id
* @param c id
* @return true,false
*/
public isEqual(c: string | csmString | CubismId): boolean {
if (typeof c === 'string') {
return this._id.isEqual(c);
} else if (c instanceof csmString) {
return this._id.isEqual(c.s);
} else if (c instanceof CubismId) {
return this._id.isEqual(c._id.s);
}
return false;
}
/**
* id
* @param c id
* @return true,false
*/
public isNotEqual(c: string | csmString | CubismId): boolean {
if (typeof c == 'string') {
return !this._id.isEqual(c);
} else if (c instanceof csmString) {
return !this._id.isEqual(c.s);
} else if (c instanceof CubismId) {
return !this._id.isEqual(c._id.s);
}
return false;
}
private _id: csmString; // ID名
} }
export declare type CubismIdHandle = CubismId; /**
*
*/
public constructor(id: string | csmString) {
if (typeof id === 'string') {
this._id = new csmString(id);
return;
}
this._id = id;
}
/**
* id
* @param c id
* @return true,false
*/
public isEqual(c: string | csmString | CubismId): boolean {
if (typeof c === 'string') {
return this._id.isEqual(c);
} else if (c instanceof csmString) {
return this._id.isEqual(c.s);
} else if (c instanceof CubismId) {
return this._id.isEqual(c._id.s);
}
return false;
}
/**
* id
* @param c id
* @return true,false
*/
public isNotEqual(c: string | csmString | CubismId): boolean {
if (typeof c == 'string') {
return !this._id.isEqual(c);
} else if (c instanceof csmString) {
return !this._id.isEqual(c.s);
} else if (c instanceof CubismId) {
return !this._id.isEqual(c._id.s);
}
return false;
}
private _id: csmString; // ID名
}
export declare type CubismIdHandle = CubismId;
// Namespace definition for compatibility.
import * as $ from './cubismid';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismId = $.CubismId;
export type CubismId = $.CubismId;
export type CubismIdHandle = $.CubismIdHandle;
} }

View File

@ -5,114 +5,117 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as csmvector } from '../type/csmvector'; import { csmString } from '../type/csmstring';
import { Live2DCubismFramework as cubismid } from './cubismid'; import { csmVector } from '../type/csmvector';
import { Live2DCubismFramework as csmstring } from '../type/csmstring'; import { CubismId } from './cubismid';
import csmString = csmstring.csmString;
import CubismId = cubismid.CubismId;
import csmVector = csmvector.csmVector;
export namespace Live2DCubismFramework { /**
* ID
*
* ID
*/
export class CubismIdManager {
/** /**
* ID *
*
* ID
*/ */
export class CubismIdManager { public constructor() {
/** this._ids = new csmVector<CubismId>();
*
*/
public constructor() {
this._ids = new csmVector<CubismId>();
}
/**
*
*/
public release(): void {
for (let i = 0; i < this._ids.getSize(); ++i) {
this._ids.set(i, void 0);
}
this._ids = null;
}
/**
* ID
*
* @param ids ID
* @param count ID
*/
public registerIds(ids: string[] | csmString[]): void {
for (let i = 0; i < ids.length; i++) {
this.registerId(ids[i]);
}
}
/**
* ID
*
* @param id ID
*/
public registerId(id: string | csmString): CubismId {
let result: CubismId = null;
if ('string' == typeof id) {
if ((result = this.findId(id)) != null) {
return result;
}
result = new CubismId(id);
this._ids.pushBack(result);
} else {
return this.registerId(id.s);
}
return result;
}
/**
* IDID
*
* @param id ID
*/
public getId(id: csmString | string): CubismId {
return this.registerId(id);
}
/**
* IDID
*
* @return true
* @return false
*/
public isExist(id: csmString | string): boolean {
if ('string' == typeof id) {
return this.findId(id) != null;
}
return this.isExist(id.s);
}
/**
* IDID
*
* @param id ID
* @return IDNULL
*/
private findId(id: string): CubismId {
for (let i = 0; i < this._ids.getSize(); ++i) {
if (
this._ids
.at(i)
.getString()
.isEqual(id)
) {
return this._ids.at(i);
}
}
return null;
}
private _ids: csmVector<CubismId>; // 登録されているIDのリスト
} }
/**
*
*/
public release(): void {
for (let i = 0; i < this._ids.getSize(); ++i) {
this._ids.set(i, void 0);
}
this._ids = null;
}
/**
* ID
*
* @param ids ID
* @param count ID
*/
public registerIds(ids: string[] | csmString[]): void {
for (let i = 0; i < ids.length; i++) {
this.registerId(ids[i]);
}
}
/**
* ID
*
* @param id ID
*/
public registerId(id: string | csmString): CubismId {
let result: CubismId = null;
if ('string' == typeof id) {
if ((result = this.findId(id)) != null) {
return result;
}
result = new CubismId(id);
this._ids.pushBack(result);
} else {
return this.registerId(id.s);
}
return result;
}
/**
* IDID
*
* @param id ID
*/
public getId(id: csmString | string): CubismId {
return this.registerId(id);
}
/**
* IDID
*
* @return true
* @return false
*/
public isExist(id: csmString | string): boolean {
if ('string' == typeof id) {
return this.findId(id) != null;
}
return this.isExist(id.s);
}
/**
* IDID
*
* @param id ID
* @return IDNULL
*/
private findId(id: string): CubismId {
for (let i = 0; i < this._ids.getSize(); ++i) {
if (
this._ids
.at(i)
.getString()
.isEqual(id)
) {
return this._ids.at(i);
}
}
return null;
}
private _ids: csmVector<CubismId>; // 登録されているIDのリスト
}
// Namespace definition for compatibility.
import * as $ from './cubismidmanager';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismIdManager = $.CubismIdManager;
export type CubismIdManager = $.CubismIdManager;
} }

View File

@ -5,17 +5,14 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * 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 { CubismIdManager } from './id/cubismidmanager';
import { Live2DCubismFramework as cubismidmanager } from './id/cubismidmanager'; import { CubismRenderer } from './rendering/cubismrenderer';
import { Live2DCubismFramework as cubismrenderer } from './rendering/cubismrenderer';
import { import {
CSM_ASSERT,
CubismLogInfo, CubismLogInfo,
CubismLogWarning, CubismLogWarning
CSM_ASSERT
} from './utils/cubismdebug'; } from './utils/cubismdebug';
import Value = cubismjson.Value; import { Value } from './utils/cubismjson';
import CubismIdManager = cubismidmanager.CubismIdManager;
import CubismRenderer = cubismrenderer.CubismRenderer;
export function strtod(s: string, endPtr: string[]): number { export function strtod(s: string, endPtr: string[]): number {
let index = 0; let index = 0;
@ -47,211 +44,209 @@ export function strtod(s: string, endPtr: string[]): number {
return d; return d;
} }
export namespace Live2DCubismFramework { // ファイルスコープの変数を初期化
// ファイルスコープの変数を初期化
let s_isStarted = false; let s_isStarted = false;
let s_isInitialized = false; let s_isInitialized = false;
let s_option: Option = null; let s_option: Option = null;
let s_cubismIdManager: CubismIdManager = null; let s_cubismIdManager: CubismIdManager = null;
/** /**
* Framework使 * Framework使
*/ */
export namespace Constant { export const Constant = Object.freeze<Record<string, number>>({
export const vertexOffset = 0; // メッシュ頂点のオフセット値 vertexOffset: 0, // メッシュ頂点のオフセット値
export const vertexStep = 2; // メッシュ頂点のステップ値 vertexStep: 2 // メッシュ頂点のステップ値
});
export function csmDelete<T>(address: T): void {
if (!address) {
return;
} }
export function csmDelete<T>(address: T): void { address = void 0;
if (!address) { }
/**
* Live2D Cubism SDK Original Workflow SDK
* CubismFramework.initialize()CubismFramework.dispose()
*/
export class CubismFramework {
/**
* Cubism FrameworkAPI使
* API
*
*
* @param option Option
*
* @return true
*/
public static startUp(option: Option = null): boolean {
if (s_isStarted) {
CubismLogInfo('CubismFramework.startUp() is already done.');
return s_isStarted;
}
s_option = option;
if (s_option != null) {
Live2DCubismCore.Logging.csmSetLogFunction(s_option.logFunction);
}
s_isStarted = true;
// Live2D Cubism Coreバージョン情報を表示
if (s_isStarted) {
const version: number = Live2DCubismCore.Version.csmGetVersion();
const major: number = (version & 0xff000000) >> 24;
const minor: number = (version & 0x00ff0000) >> 16;
const patch: number = version & 0x0000ffff;
const versionNumber: number = version;
CubismLogInfo(
`Live2D Cubism Core version: {0}.{1}.{2} ({3})`,
('00' + major).slice(-2),
('00' + minor).slice(-2),
('0000' + patch).slice(-4),
versionNumber
);
}
CubismLogInfo('CubismFramework.startUp() is complete.');
return s_isStarted;
}
/**
* StartUp()CubismFramework
* Dispose()CubismFramework
*/
public static cleanUp(): void {
s_isStarted = false;
s_isInitialized = false;
s_option = null;
s_cubismIdManager = null;
}
/**
* Cubism Framework<br>
* Initialize()Dispose()
*/
public static initialize(): void {
CSM_ASSERT(s_isStarted);
if (!s_isStarted) {
CubismLogWarning('CubismFramework is not started.');
return; return;
} }
address = void 0; // --- s_isInitializedによる連続初期化ガード ---
// 連続してリソース確保が行われないようにする。
// 再度Initialize()するには先にDispose()を実行する必要がある。
if (s_isInitialized) {
CubismLogWarning(
'CubismFramework.initialize() skipped, already initialized.'
);
return;
}
//---- static 初期化 ----
Value.staticInitializeNotForClientCall();
s_cubismIdManager = new CubismIdManager();
s_isInitialized = true;
CubismLogInfo('CubismFramework.initialize() is complete.');
} }
/** /**
* Live2D Cubism SDK Original Workflow SDK * Cubism Framework
* CubismFramework.initialize()CubismFramework.dispose() *
*
*/ */
export class CubismFramework { public static dispose(): void {
/** CSM_ASSERT(s_isStarted);
* Cubism FrameworkAPI使 if (!s_isStarted) {
* API CubismLogWarning('CubismFramework is not started.');
* return;
*
* @param option Option
*
* @return true
*/
public static startUp(option: Option = null): boolean {
if (s_isStarted) {
CubismLogInfo('CubismFramework.startUp() is already done.');
return s_isStarted;
}
s_option = option;
if (s_option != null) {
Live2DCubismCore.Logging.csmSetLogFunction(s_option.logFunction);
}
s_isStarted = true;
// Live2D Cubism Coreバージョン情報を表示
if (s_isStarted) {
const version: number = Live2DCubismCore.Version.csmGetVersion();
const major: number = (version & 0xff000000) >> 24;
const minor: number = (version & 0x00ff0000) >> 16;
const patch: number = version & 0x0000ffff;
const versionNumber: number = version;
CubismLogInfo(
`Live2D Cubism Core version: {0}.{1}.{2} ({3})`,
('00' + major).slice(-2),
('00' + minor).slice(-2),
('0000' + patch).slice(-4),
versionNumber
);
}
CubismLogInfo('CubismFramework.startUp() is complete.');
return s_isStarted;
} }
/** // --- s_isInitializedによる未初期化解放ガード ---
* StartUp()CubismFramework // dispose()するには先にinitialize()を実行する必要がある。
* Dispose()CubismFramework if (!s_isInitialized) {
*/ // false...リソース未確保の場合
public static cleanUp(): void { CubismLogWarning('CubismFramework.dispose() skipped, not initialized.');
s_isStarted = false; return;
s_isInitialized = false;
s_option = null;
s_cubismIdManager = null;
} }
/** Value.staticReleaseNotForClientCall();
* Cubism Framework<br>
* Initialize()Dispose()
*/
public static initialize(): void {
CSM_ASSERT(s_isStarted);
if (!s_isStarted) {
CubismLogWarning('CubismFramework is not started.');
return;
}
// --- s_isInitializedによる連続初期化ガード --- s_cubismIdManager.release();
// 連続してリソース確保が行われないようにする。 s_cubismIdManager = null;
// 再度Initialize()するには先にDispose()を実行する必要がある。
if (s_isInitialized) {
CubismLogWarning(
'CubismFramework.initialize() skipped, already initialized.'
);
return;
}
//---- static 初期化 ---- // レンダラの静的リソース(シェーダプログラム他)を解放する
Value.staticInitializeNotForClientCall(); CubismRenderer.staticRelease();
s_cubismIdManager = new CubismIdManager(); s_isInitialized = false;
s_isInitialized = true; CubismLogInfo('CubismFramework.dispose() is complete.');
CubismLogInfo('CubismFramework.initialize() is complete.');
}
/**
* Cubism Framework
*
*
*/
public static dispose(): void {
CSM_ASSERT(s_isStarted);
if (!s_isStarted) {
CubismLogWarning('CubismFramework is not started.');
return;
}
// --- s_isInitializedによる未初期化解放ガード ---
// dispose()するには先にinitialize()を実行する必要がある。
if (!s_isInitialized) {
// false...リソース未確保の場合
CubismLogWarning('CubismFramework.dispose() skipped, not initialized.');
return;
}
Value.staticReleaseNotForClientCall();
s_cubismIdManager.release();
s_cubismIdManager = null;
// レンダラの静的リソース(シェーダプログラム他)を解放する
CubismRenderer.staticRelease();
s_isInitialized = false;
CubismLogInfo('CubismFramework.dispose() is complete.');
}
/**
* Cubism FrameworkAPI使
* @return API使true
*/
public static isStarted(): boolean {
return s_isStarted;
}
/**
* Cubism Framework
* @return true
*/
public static isInitialized(): boolean {
return s_isInitialized;
}
/**
* Core API
*
* @praram message
*/
public static coreLogFunction(message: string): void {
// Return if logging not possible.
if (!Live2DCubismCore.Logging.csmGetLogFunction()) {
return;
}
Live2DCubismCore.Logging.csmGetLogFunction()(message);
}
/**
*
*
* @return
*/
public static getLoggingLevel(): LogLevel {
if (s_option != null) {
return s_option.loggingLevel;
}
return LogLevel.LogLevel_Off;
}
/**
* ID
* @return CubismManager
*/
public static getIdManager(): CubismIdManager {
return s_cubismIdManager;
}
/**
* 使
*
*/
private constructor() {}
} }
/**
* Cubism FrameworkAPI使
* @return API使true
*/
public static isStarted(): boolean {
return s_isStarted;
}
/**
* Cubism Framework
* @return true
*/
public static isInitialized(): boolean {
return s_isInitialized;
}
/**
* Core API
*
* @praram message
*/
public static coreLogFunction(message: string): void {
// Return if logging not possible.
if (!Live2DCubismCore.Logging.csmGetLogFunction()) {
return;
}
Live2DCubismCore.Logging.csmGetLogFunction()(message);
}
/**
*
*
* @return
*/
public static getLoggingLevel(): LogLevel {
if (s_option != null) {
return s_option.loggingLevel;
}
return LogLevel.LogLevel_Off;
}
/**
* ID
* @return CubismManager
*/
public static getIdManager(): CubismIdManager {
return s_cubismIdManager;
}
/**
* 使
*
*/
private constructor() {}
} }
export class Option { export class Option {
@ -270,3 +265,13 @@ export enum LogLevel {
LogLevel_Error, // エラーログ LogLevel_Error, // エラーログ
LogLevel_Off // ログ出力無効 LogLevel_Off // ログ出力無効
} }
// Namespace definition for compatibility.
import * as $ from './live2dcubismframework';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const Constant = $.Constant;
export const csmDelete = $.csmDelete;
export const CubismFramework = $.CubismFramework;
export type CubismFramework = $.CubismFramework;
}

View File

@ -5,191 +5,196 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as cubismvector2 } from './cubismvector2'; import { CubismVector2 } from './cubismvector2';
import CubismVector2 = cubismvector2.CubismVector2;
export namespace Live2DCubismFramework { /**
* 使
*/
export class CubismMath {
/** /**
* 使 *
*
* @param value
* @param min
* @param max
* @return
*/ */
export class CubismMath { static range(value: number, min: number, max: number): number {
/** if (value < min) {
* value = min;
* } else if (value > max) {
* @param value value = max;
* @param min
* @param max
* @return
*/
static range(value: number, min: number, max: number): number {
if (value < min) {
value = min;
} else if (value > max) {
value = max;
}
return value;
} }
/** return value;
*
*
* @param x
* @return sin(x)
*/
static sin(x: number): number {
return Math.sin(x);
}
/**
*
*
* @param x ()
* @return cos(x)
*/
static cos(x: number): number {
return Math.cos(x);
}
/**
*
*
* @param x
* @return
*/
static abs(x: number): number {
return Math.abs(x);
}
/**
* ()
* @param x ->
* @return
*/
static sqrt(x: number): number {
return Math.sqrt(x);
}
/**
*
*
*
* @param value
* @return
*/
static getEasingSine(value: number): number {
if (value < 0.0) {
return 0.0;
} else if (value > 1.0) {
return 1.0;
}
return 0.5 - 0.5 * this.cos(value * Math.PI);
}
/**
*
*
* @param left
* @param right
* @return
*/
static max(left: number, right: number): number {
return left > right ? left : right;
}
/**
*
*
* @param left
* @param right
* @return
*/
static min(left: number, right: number): number {
return left > right ? right : left;
}
/**
*
*
* @param degrees
* @return
*/
static degreesToRadian(degrees: number): number {
return (degrees / 180.0) * Math.PI;
}
/**
*
*
* @param radian
* @return
*/
static radianToDegrees(radian: number): number {
return (radian * 180.0) / Math.PI;
}
/**
*
*
* @param from
* @param to
* @return
*/
static directionToRadian(from: CubismVector2, to: CubismVector2): number {
const q1: number = Math.atan2(to.y, to.x);
const q2: number = Math.atan2(from.y, from.x);
let ret: number = q1 - q2;
while (ret < -Math.PI) {
ret += Math.PI * 2.0;
}
while (ret > Math.PI) {
ret -= Math.PI * 2.0;
}
return ret;
}
/**
*
*
* @param from
* @param to
* @return
*/
static directionToDegrees(from: CubismVector2, to: CubismVector2): number {
const radian: number = this.directionToRadian(from, to);
let degree: number = this.radianToDegrees(radian);
if (to.x - from.x > 0.0) {
degree = -degree;
}
return degree;
}
/**
*
*
* @param totalAngle
* @return
*/
static radianToDirection(totalAngle: number): CubismVector2 {
const ret: CubismVector2 = new CubismVector2();
ret.x = this.sin(totalAngle);
ret.y = this.cos(totalAngle);
return ret;
}
/**
*
*/
private constructor() {}
} }
/**
*
*
* @param x
* @return sin(x)
*/
static sin(x: number): number {
return Math.sin(x);
}
/**
*
*
* @param x ()
* @return cos(x)
*/
static cos(x: number): number {
return Math.cos(x);
}
/**
*
*
* @param x
* @return
*/
static abs(x: number): number {
return Math.abs(x);
}
/**
* ()
* @param x ->
* @return
*/
static sqrt(x: number): number {
return Math.sqrt(x);
}
/**
*
*
*
* @param value
* @return
*/
static getEasingSine(value: number): number {
if (value < 0.0) {
return 0.0;
} else if (value > 1.0) {
return 1.0;
}
return 0.5 - 0.5 * this.cos(value * Math.PI);
}
/**
*
*
* @param left
* @param right
* @return
*/
static max(left: number, right: number): number {
return left > right ? left : right;
}
/**
*
*
* @param left
* @param right
* @return
*/
static min(left: number, right: number): number {
return left > right ? right : left;
}
/**
*
*
* @param degrees
* @return
*/
static degreesToRadian(degrees: number): number {
return (degrees / 180.0) * Math.PI;
}
/**
*
*
* @param radian
* @return
*/
static radianToDegrees(radian: number): number {
return (radian * 180.0) / Math.PI;
}
/**
*
*
* @param from
* @param to
* @return
*/
static directionToRadian(from: CubismVector2, to: CubismVector2): number {
const q1: number = Math.atan2(to.y, to.x);
const q2: number = Math.atan2(from.y, from.x);
let ret: number = q1 - q2;
while (ret < -Math.PI) {
ret += Math.PI * 2.0;
}
while (ret > Math.PI) {
ret -= Math.PI * 2.0;
}
return ret;
}
/**
*
*
* @param from
* @param to
* @return
*/
static directionToDegrees(from: CubismVector2, to: CubismVector2): number {
const radian: number = this.directionToRadian(from, to);
let degree: number = this.radianToDegrees(radian);
if (to.x - from.x > 0.0) {
degree = -degree;
}
return degree;
}
/**
*
*
* @param totalAngle
* @return
*/
static radianToDirection(totalAngle: number): CubismVector2 {
const ret: CubismVector2 = new CubismVector2();
ret.x = this.sin(totalAngle);
ret.y = this.cos(totalAngle);
return ret;
}
/**
*
*/
private constructor() {}
}
// Namespace definition for compatibility.
import * as $ from './cubismmath';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismMath = $.CubismMath;
export type CubismMath = $.CubismMath;
} }

View File

@ -5,304 +5,310 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
export namespace Live2DCubismFramework { /**
* 4x4
*
* 4x4便
*/
export class CubismMatrix44 {
/** /**
* 4x4 *
*
* 4x4便
*/ */
export class CubismMatrix44 { public constructor() {
/** this._tr = new Float32Array(16); // 4 * 4のサイズ
* this.loadIdentity();
*/ }
public constructor() {
this._tr = new Float32Array(16); // 4 * 4のサイズ
this.loadIdentity();
}
/** /**
* *
* *
* @param a a * @param a a
* @param b b * @param b b
* @return * @return
*/ */
public static multiply( public static multiply(
a: Float32Array, a: Float32Array,
b: Float32Array, b: Float32Array,
dst: Float32Array dst: Float32Array
): void { ): void {
const c: Float32Array = new Float32Array([ const c: Float32Array = new Float32Array([
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0 0.0
]); ]);
const n = 4; const n = 4;
for (let i = 0; i < n; ++i) { for (let i = 0; i < n; ++i) {
for (let j = 0; j < n; ++j) { for (let j = 0; j < n; ++j) {
for (let k = 0; k < n; ++k) { for (let k = 0; k < n; ++k) {
c[j + i * 4] += a[k + i * 4] * b[j + k * 4]; c[j + i * 4] += a[k + i * 4] * b[j + k * 4];
}
} }
} }
for (let i = 0; i < 16; ++i) {
dst[i] = c[i];
}
} }
/** for (let i = 0; i < 16; ++i) {
* dst[i] = c[i];
*/
public loadIdentity(): void {
const c: Float32Array = new Float32Array([
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
]);
this.setMatrix(c);
} }
/**
*
*
* @param tr 164x4
*/
public setMatrix(tr: Float32Array): void {
for (let i = 0; i < 16; ++i) {
this._tr[i] = tr[i];
}
}
/**
*
*
* @return 164x4
*/
public getArray(): Float32Array {
return this._tr;
}
/**
* X
* @return X
*/
public getScaleX(): number {
return this._tr[0];
}
/**
* Y
*
* @return Y
*/
public getScaleY(): number {
return this._tr[5];
}
/**
* X
* @return X
*/
public getTranslateX(): number {
return this._tr[12];
}
/**
* Y
* @return Y
*/
public getTranslateY(): number {
return this._tr[13];
}
/**
* X
*
* @param src X
* @return X
*/
public transformX(src: number): number {
return this._tr[0] * src + this._tr[12];
}
/**
* Y
*
* @param src Y
* @return Y
*/
public transformY(src: number): number {
return this._tr[5] * src + this._tr[13];
}
/**
* X
*/
public invertTransformX(src: number): number {
return (src - this._tr[12]) / this._tr[0];
}
/**
* Y
*/
public invertTransformY(src: number): number {
return (src - this._tr[13]) / this._tr[5];
}
/**
*
*
*
*
* @param x X
* @param y Y
*/
public translateRelative(x: number, y: number): void {
const tr1: Float32Array = new Float32Array([
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
x,
y,
0.0,
1.0
]);
CubismMatrix44.multiply(tr1, this._tr, this._tr);
}
/**
*
*
*
*
* @param x X
* @param y y
*/
public translate(x: number, y: number): void {
this._tr[12] = x;
this._tr[13] = y;
}
/**
* X
*
* @param x X
*/
public translateX(x: number): void {
this._tr[12] = x;
}
/**
* Y
*
* @param y Y
*/
public translateY(y: number): void {
this._tr[13] = y;
}
/**
*
*
* @param x X
* @param y Y
*/
public scaleRelative(x: number, y: number): void {
const tr1: Float32Array = new Float32Array([
x,
0.0,
0.0,
0.0,
0.0,
y,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
]);
CubismMatrix44.multiply(tr1, this._tr, this._tr);
}
/**
*
*
* @param x X
* @param y Y
*/
public scale(x: number, y: number): void {
this._tr[0] = x;
this._tr[5] = y;
}
/**
*
*
* @param m
*/
public multiplyByMatrix(m: CubismMatrix44): void {
CubismMatrix44.multiply(m.getArray(), this._tr, this._tr);
}
/**
*
*/
public clone(): CubismMatrix44 {
const cloneMatrix: CubismMatrix44 = new CubismMatrix44();
for (let i = 0; i < this._tr.length; i++) {
cloneMatrix._tr[i] = this._tr[i];
}
return cloneMatrix;
}
protected _tr: Float32Array; // 4x4行列データ
} }
/**
*
*/
public loadIdentity(): void {
const c: Float32Array = new Float32Array([
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
]);
this.setMatrix(c);
}
/**
*
*
* @param tr 164x4
*/
public setMatrix(tr: Float32Array): void {
for (let i = 0; i < 16; ++i) {
this._tr[i] = tr[i];
}
}
/**
*
*
* @return 164x4
*/
public getArray(): Float32Array {
return this._tr;
}
/**
* X
* @return X
*/
public getScaleX(): number {
return this._tr[0];
}
/**
* Y
*
* @return Y
*/
public getScaleY(): number {
return this._tr[5];
}
/**
* X
* @return X
*/
public getTranslateX(): number {
return this._tr[12];
}
/**
* Y
* @return Y
*/
public getTranslateY(): number {
return this._tr[13];
}
/**
* X
*
* @param src X
* @return X
*/
public transformX(src: number): number {
return this._tr[0] * src + this._tr[12];
}
/**
* Y
*
* @param src Y
* @return Y
*/
public transformY(src: number): number {
return this._tr[5] * src + this._tr[13];
}
/**
* X
*/
public invertTransformX(src: number): number {
return (src - this._tr[12]) / this._tr[0];
}
/**
* Y
*/
public invertTransformY(src: number): number {
return (src - this._tr[13]) / this._tr[5];
}
/**
*
*
*
*
* @param x X
* @param y Y
*/
public translateRelative(x: number, y: number): void {
const tr1: Float32Array = new Float32Array([
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
x,
y,
0.0,
1.0
]);
CubismMatrix44.multiply(tr1, this._tr, this._tr);
}
/**
*
*
*
*
* @param x X
* @param y y
*/
public translate(x: number, y: number): void {
this._tr[12] = x;
this._tr[13] = y;
}
/**
* X
*
* @param x X
*/
public translateX(x: number): void {
this._tr[12] = x;
}
/**
* Y
*
* @param y Y
*/
public translateY(y: number): void {
this._tr[13] = y;
}
/**
*
*
* @param x X
* @param y Y
*/
public scaleRelative(x: number, y: number): void {
const tr1: Float32Array = new Float32Array([
x,
0.0,
0.0,
0.0,
0.0,
y,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
]);
CubismMatrix44.multiply(tr1, this._tr, this._tr);
}
/**
*
*
* @param x X
* @param y Y
*/
public scale(x: number, y: number): void {
this._tr[0] = x;
this._tr[5] = y;
}
/**
*
*
* @param m
*/
public multiplyByMatrix(m: CubismMatrix44): void {
CubismMatrix44.multiply(m.getArray(), this._tr, this._tr);
}
/**
*
*/
public clone(): CubismMatrix44 {
const cloneMatrix: CubismMatrix44 = new CubismMatrix44();
for (let i = 0; i < this._tr.length; i++) {
cloneMatrix._tr[i] = this._tr[i];
}
return cloneMatrix;
}
protected _tr: Float32Array; // 4x4行列データ
}
// Namespace definition for compatibility.
import * as $ from './cubismmatrix44';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismMatrix44 = $.CubismMatrix44;
export type CubismMatrix44 = $.CubismMatrix44;
} }

View File

@ -5,219 +5,222 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as csmmap } from '../type/csmmap'; import { csmMap, iterator } from '../type/csmmap';
import { Live2DCubismFramework as cubismmatrix44 } from './cubismmatrix44'; import { CubismMatrix44 } from './cubismmatrix44';
import csmMap = csmmap.csmMap;
import iterator = csmmap.iterator;
import CubismMatrix44 = cubismmatrix44.CubismMatrix44;
export namespace Live2DCubismFramework { /**
* 4x4
*
* 4x4
*/
export class CubismModelMatrix extends CubismMatrix44 {
/** /**
* 4x4 *
* *
* 4x4 * @param w
* @param h
*/ */
export class CubismModelMatrix extends CubismMatrix44 { constructor(w?: number, h?: number) {
/** super();
*
*
* @param w
* @param h
*/
constructor(w?: number, h?: number) {
super();
this._width = w !== undefined ? w : 0.0; this._width = w !== undefined ? w : 0.0;
this._height = h !== undefined ? h : 0.0; this._height = h !== undefined ? h : 0.0;
this.setHeight(1.0); this.setHeight(1.0);
}
/**
*
*
* @param w
*/
public setWidth(w: number): void {
const scaleX: number = w / this._width;
const scaleY: number = scaleX;
this.scale(scaleX, scaleY);
}
/**
*
* @param h
*/
public setHeight(h: number): void {
const scaleX: number = h / this._height;
const scaleY: number = scaleX;
this.scale(scaleX, scaleY);
}
/**
*
*
* @param x X
* @param y Y
*/
public setPosition(x: number, y: number): void {
this.translate(x, y);
}
/**
*
*
* @param x X
* @param y Y
*
* @note widthheight
*/
public setCenterPosition(x: number, y: number) {
this.centerX(x);
this.centerY(y);
}
/**
*
*
* @param y Y
*/
public top(y: number): void {
this.setY(y);
}
/**
*
*
* @param y Y
*/
public bottom(y: number) {
const h: number = this._height * this.getScaleY();
this.translateY(y - h);
}
/**
*
*
* @param x X
*/
public left(x: number): void {
this.setX(x);
}
/**
*
*
* @param x X
*/
public right(x: number): void {
const w = this._width * this.getScaleX();
this.translateX(x - w);
}
/**
* X
*
* @param x X
*/
public centerX(x: number): void {
const w = this._width * this.getScaleX();
this.translateX(x - w / 2.0);
}
/**
* X
*
* @param x X
*/
public setX(x: number): void {
this.translateX(x);
}
/**
* Y
*
* @param y Y
*/
public centerY(y: number): void {
const h: number = this._height * this.getScaleY();
this.translateY(y - h / 2.0);
}
/**
* Y
*
* @param y Y
*/
public setY(y: number): void {
this.translateY(y);
}
/**
*
*
* @param layout
*/
public setupFromLayout(layout: csmMap<string, number>): void {
const keyWidth = 'width';
const keyHeight = 'height';
const keyX = 'x';
const keyY = 'y';
const keyCenterX = 'center_x';
const keyCenterY = 'center_y';
const keyTop = 'top';
const keyBottom = 'bottom';
const keyLeft = 'left';
const keyRight = 'right';
for (
const ite: iterator<string, number> = layout.begin();
ite.notEqual(layout.end());
ite.preIncrement()
) {
const key: string = ite.ptr().first;
const value: number = ite.ptr().second;
if (key == keyWidth) {
this.setWidth(value);
} else if (key == keyHeight) {
this.setHeight(value);
}
}
for (
const ite: iterator<string, number> = layout.begin();
ite.notEqual(layout.end());
ite.preIncrement()
) {
const key: string = ite.ptr().first;
const value: number = ite.ptr().second;
if (key == keyX) {
this.setX(value);
} else if (key == keyY) {
this.setY(value);
} else if (key == keyCenterX) {
this.centerX(value);
} else if (key == keyCenterY) {
this.centerY(value);
} else if (key == keyTop) {
this.top(value);
} else if (key == keyBottom) {
this.bottom(value);
} else if (key == keyLeft) {
this.left(value);
} else if (key == keyRight) {
this.right(value);
}
}
}
private _width: number; // 横幅
private _height: number; // 縦幅
} }
/**
*
*
* @param w
*/
public setWidth(w: number): void {
const scaleX: number = w / this._width;
const scaleY: number = scaleX;
this.scale(scaleX, scaleY);
}
/**
*
* @param h
*/
public setHeight(h: number): void {
const scaleX: number = h / this._height;
const scaleY: number = scaleX;
this.scale(scaleX, scaleY);
}
/**
*
*
* @param x X
* @param y Y
*/
public setPosition(x: number, y: number): void {
this.translate(x, y);
}
/**
*
*
* @param x X
* @param y Y
*
* @note widthheight
*/
public setCenterPosition(x: number, y: number) {
this.centerX(x);
this.centerY(y);
}
/**
*
*
* @param y Y
*/
public top(y: number): void {
this.setY(y);
}
/**
*
*
* @param y Y
*/
public bottom(y: number) {
const h: number = this._height * this.getScaleY();
this.translateY(y - h);
}
/**
*
*
* @param x X
*/
public left(x: number): void {
this.setX(x);
}
/**
*
*
* @param x X
*/
public right(x: number): void {
const w = this._width * this.getScaleX();
this.translateX(x - w);
}
/**
* X
*
* @param x X
*/
public centerX(x: number): void {
const w = this._width * this.getScaleX();
this.translateX(x - w / 2.0);
}
/**
* X
*
* @param x X
*/
public setX(x: number): void {
this.translateX(x);
}
/**
* Y
*
* @param y Y
*/
public centerY(y: number): void {
const h: number = this._height * this.getScaleY();
this.translateY(y - h / 2.0);
}
/**
* Y
*
* @param y Y
*/
public setY(y: number): void {
this.translateY(y);
}
/**
*
*
* @param layout
*/
public setupFromLayout(layout: csmMap<string, number>): void {
const keyWidth = 'width';
const keyHeight = 'height';
const keyX = 'x';
const keyY = 'y';
const keyCenterX = 'center_x';
const keyCenterY = 'center_y';
const keyTop = 'top';
const keyBottom = 'bottom';
const keyLeft = 'left';
const keyRight = 'right';
for (
const ite: iterator<string, number> = layout.begin();
ite.notEqual(layout.end());
ite.preIncrement()
) {
const key: string = ite.ptr().first;
const value: number = ite.ptr().second;
if (key == keyWidth) {
this.setWidth(value);
} else if (key == keyHeight) {
this.setHeight(value);
}
}
for (
const ite: iterator<string, number> = layout.begin();
ite.notEqual(layout.end());
ite.preIncrement()
) {
const key: string = ite.ptr().first;
const value: number = ite.ptr().second;
if (key == keyX) {
this.setX(value);
} else if (key == keyY) {
this.setY(value);
} else if (key == keyCenterX) {
this.centerX(value);
} else if (key == keyCenterY) {
this.centerY(value);
} else if (key == keyTop) {
this.top(value);
} else if (key == keyBottom) {
this.bottom(value);
} else if (key == keyLeft) {
this.left(value);
} else if (key == keyRight) {
this.right(value);
}
}
}
private _width: number; // 横幅
private _height: number; // 縦幅
}
// Namespace definition for compatibility.
import * as $ from './cubismmodelmatrix';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismModelMatrix = $.CubismModelMatrix;
export type CubismModelMatrix = $.CubismModelMatrix;
} }

View File

@ -5,160 +5,165 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as cubismmath } from './cubismmath'; import { CubismMath } from './cubismmath';
import CubismMath = cubismmath.CubismMath;
export namespace Live2DCubismFramework { const FrameRate = 30;
const FrameRate = 30; const Epsilon = 0.01;
const Epsilon = 0.01;
/**
*
*
*
*/
export class CubismTargetPoint {
/**
*
*/
public constructor() {
this._faceTargetX = 0.0;
this._faceTargetY = 0.0;
this._faceX = 0.0;
this._faceY = 0.0;
this._faceVX = 0.0;
this._faceVY = 0.0;
this._lastTimeSeconds = 0.0;
this._userTimeSeconds = 0.0;
}
/** /**
* *
*
*
*/ */
export class CubismTargetPoint { public update(deltaTimeSeconds: number): void {
/** // デルタ時間を加算する
* this._userTimeSeconds += deltaTimeSeconds;
*/
public constructor() {
this._faceTargetX = 0.0;
this._faceTargetY = 0.0;
this._faceX = 0.0;
this._faceY = 0.0;
this._faceVX = 0.0;
this._faceVY = 0.0;
this._lastTimeSeconds = 0.0;
this._userTimeSeconds = 0.0;
}
/** // 首を中央から左右に振るときの平均的な速さは 秒速度。加速・減速を考慮して、その2倍を最高速度とする
* // 顔の振り具合を、中央0.0)から、左右は(+-1.0)とする
*/ const faceParamMaxV: number = 40.0 / 10.0; // 7.5秒間に40分移動(5.3/sc)
public update(deltaTimeSeconds: number): void { const maxV: number = (faceParamMaxV * 1.0) / FrameRate; // 1frameあたりに変化できる速度の上限
// デルタ時間を加算する
this._userTimeSeconds += deltaTimeSeconds;
// 首を中央から左右に振るときの平均的な速さは 秒速度。加速・減速を考慮して、その2倍を最高速度とする if (this._lastTimeSeconds == 0.0) {
// 顔の振り具合を、中央0.0)から、左右は(+-1.0)とする
const faceParamMaxV: number = 40.0 / 10.0; // 7.5秒間に40分移動(5.3/sc)
const maxV: number = (faceParamMaxV * 1.0) / FrameRate; // 1frameあたりに変化できる速度の上限
if (this._lastTimeSeconds == 0.0) {
this._lastTimeSeconds = this._userTimeSeconds;
return;
}
const deltaTimeWeight: number =
(this._userTimeSeconds - this._lastTimeSeconds) * FrameRate;
this._lastTimeSeconds = this._userTimeSeconds; this._lastTimeSeconds = this._userTimeSeconds;
return;
}
// 最高速度になるまでの時間を const deltaTimeWeight: number =
const timeToMaxSpeed = 0.15; (this._userTimeSeconds - this._lastTimeSeconds) * FrameRate;
const frameToMaxSpeed: number = timeToMaxSpeed * FrameRate; // sec * frame/sec this._lastTimeSeconds = this._userTimeSeconds;
const maxA: number = (deltaTimeWeight * maxV) / frameToMaxSpeed; // 1frameあたりの加速度
// 目指す向きは、dx, dy方向のベクトルとなる // 最高速度になるまでの時間を
const dx: number = this._faceTargetX - this._faceX; const timeToMaxSpeed = 0.15;
const dy: number = this._faceTargetY - this._faceY; const frameToMaxSpeed: number = timeToMaxSpeed * FrameRate; // sec * frame/sec
const maxA: number = (deltaTimeWeight * maxV) / frameToMaxSpeed; // 1frameあたりの加速度
if (CubismMath.abs(dx) <= Epsilon && CubismMath.abs(dy) <= Epsilon) { // 目指す向きは、dx, dy方向のベクトルとなる
return; // 変化なし const dx: number = this._faceTargetX - this._faceX;
const dy: number = this._faceTargetY - this._faceY;
if (CubismMath.abs(dx) <= Epsilon && CubismMath.abs(dy) <= Epsilon) {
return; // 変化なし
}
// 速度の最大よりも大きい場合は、速度を落とす
const d: number = CubismMath.sqrt(dx * dx + dy * dy);
// 進行方向の最大速度ベクトル
const vx: number = (maxV * dx) / d;
const vy: number = (maxV * dy) / d;
// 現在の速度から、新規速度への変化(加速度)を求める
let ax: number = vx - this._faceVX;
let ay: number = vy - this._faceVY;
const a: number = CubismMath.sqrt(ax * ax + ay * ay);
// 加速のとき
if (a < -maxA || a > maxA) {
ax *= maxA / a;
ay *= maxA / a;
}
// 加速度を元の速度に足して、新速度とする
this._faceVX += ax;
this._faceVY += ay;
// 目的の方向に近づいたとき、滑らかに減速するための処理
// 設定された加速度で止まる事の出来る距離と速度の関係から
// 現在とりうる最高速度を計算し、それ以上の時は速度を落とす
// ※本来、人間は筋力で力(加速度)を調整できるため、より自由度が高いが、簡単な処理で済ませている
{
// 加速度、速度、距離の関係式。
// 2 6 2 3
// sqrt(a t + 16 a h t - 8 a h) - a t
// v = --------------------------------------
// 2
// 4 t - 2
// (t=1)
// 時刻tは、あらかじめ加速度、速度を1/60(フレームレート、単位なし)で
// 考えているので、tとして消してよい※未検証
const maxV: number =
0.5 *
(CubismMath.sqrt(maxA * maxA + 16.0 * maxA * d - 8.0 * maxA * d) -
maxA);
const curV: number = CubismMath.sqrt(
this._faceVX * this._faceVX + this._faceVY * this._faceVY
);
if (curV > maxV) {
// 現在の速度 > 最高速度のとき、最高速度まで減速
this._faceVX *= maxV / curV;
this._faceVY *= maxV / curV;
} }
// 速度の最大よりも大きい場合は、速度を落とす
const d: number = CubismMath.sqrt(dx * dx + dy * dy);
// 進行方向の最大速度ベクトル
const vx: number = (maxV * dx) / d;
const vy: number = (maxV * dy) / d;
// 現在の速度から、新規速度への変化(加速度)を求める
let ax: number = vx - this._faceVX;
let ay: number = vy - this._faceVY;
const a: number = CubismMath.sqrt(ax * ax + ay * ay);
// 加速のとき
if (a < -maxA || a > maxA) {
ax *= maxA / a;
ay *= maxA / a;
}
// 加速度を元の速度に足して、新速度とする
this._faceVX += ax;
this._faceVY += ay;
// 目的の方向に近づいたとき、滑らかに減速するための処理
// 設定された加速度で止まる事の出来る距離と速度の関係から
// 現在とりうる最高速度を計算し、それ以上の時は速度を落とす
// ※本来、人間は筋力で力(加速度)を調整できるため、より自由度が高いが、簡単な処理で済ませている
{
// 加速度、速度、距離の関係式。
// 2 6 2 3
// sqrt(a t + 16 a h t - 8 a h) - a t
// v = --------------------------------------
// 2
// 4 t - 2
// (t=1)
// 時刻tは、あらかじめ加速度、速度を1/60(フレームレート、単位なし)で
// 考えているので、tとして消してよい※未検証
const maxV: number =
0.5 *
(CubismMath.sqrt(maxA * maxA + 16.0 * maxA * d - 8.0 * maxA * d) -
maxA);
const curV: number = CubismMath.sqrt(
this._faceVX * this._faceVX + this._faceVY * this._faceVY
);
if (curV > maxV) {
// 現在の速度 > 最高速度のとき、最高速度まで減速
this._faceVX *= maxV / curV;
this._faceVY *= maxV / curV;
}
}
this._faceX += this._faceVX;
this._faceY += this._faceVY;
} }
/** this._faceX += this._faceVX;
* X this._faceY += this._faceVY;
*
* @return X-1.0 ~ 1.0
*/
public getX(): number {
return this._faceX;
}
/**
* Y
*
* @return Y-1.0 ~ 1.0
*/
public getY(): number {
return this._faceY;
}
/**
*
*
* @param x X-1.0 ~ 1.0
* @param y Y-1.0 ~ 1.0
*/
public set(x: number, y: number): void {
this._faceTargetX = x;
this._faceTargetY = y;
}
private _faceTargetX: number; // 顔の向きのX目標値この値に近づいていく
private _faceTargetY: number; // 顔の向きのY目標値この値に近づいていく
private _faceX: number; // 顔の向きX-1.0 ~ 1.0
private _faceY: number; // 顔の向きY-1.0 ~ 1.0
private _faceVX: number; // 顔の向きの変化速度X
private _faceVY: number; // 顔の向きの変化速度Y
private _lastTimeSeconds: number; // 最後の実行時間[秒]
private _userTimeSeconds: number; // デルタ時間の積算値[秒]
} }
/**
* X
*
* @return X-1.0 ~ 1.0
*/
public getX(): number {
return this._faceX;
}
/**
* Y
*
* @return Y-1.0 ~ 1.0
*/
public getY(): number {
return this._faceY;
}
/**
*
*
* @param x X-1.0 ~ 1.0
* @param y Y-1.0 ~ 1.0
*/
public set(x: number, y: number): void {
this._faceTargetX = x;
this._faceTargetY = y;
}
private _faceTargetX: number; // 顔の向きのX目標値この値に近づいていく
private _faceTargetY: number; // 顔の向きのY目標値この値に近づいていく
private _faceX: number; // 顔の向きX-1.0 ~ 1.0
private _faceY: number; // 顔の向きY-1.0 ~ 1.0
private _faceVX: number; // 顔の向きの変化速度X
private _faceVY: number; // 顔の向きの変化速度Y
private _lastTimeSeconds: number; // 最後の実行時間[秒]
private _userTimeSeconds: number; // デルタ時間の積算値[秒]
}
// Namespace definition for compatibility.
import * as $ from './cubismtargetpoint';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismTargetPoint = $.CubismTargetPoint;
export type CubismTargetPoint = $.CubismTargetPoint;
} }

View File

@ -5,159 +5,165 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
export namespace Live2DCubismFramework { /**
* 2
*
* 2
*/
export class CubismVector2 {
/** /**
* 2 *
*
* 2
*/ */
export class CubismVector2 { public constructor(public x?: number, public y?: number) {
/** this.x = x == undefined ? 0.0 : x;
*
*/
public constructor(public x?: number, public y?: number) {
this.x = x == undefined ? 0.0 : x;
this.y = y == undefined ? 0.0 : y; this.y = y == undefined ? 0.0 : y;
} }
/** /**
* *
* *
* @param vector2 * @param vector2
* @return * @return
*/ */
public add(vector2: CubismVector2): CubismVector2 { public add(vector2: CubismVector2): CubismVector2 {
const ret: CubismVector2 = new CubismVector2(0.0, 0.0); const ret: CubismVector2 = new CubismVector2(0.0, 0.0);
ret.x = this.x + vector2.x; ret.x = this.x + vector2.x;
ret.y = this.y + vector2.y; ret.y = this.y + vector2.y;
return ret; return ret;
} }
/** /**
* *
* *
* @param vector2 * @param vector2
* @return * @return
*/ */
public substract(vector2: CubismVector2): CubismVector2 { public substract(vector2: CubismVector2): CubismVector2 {
const ret: CubismVector2 = new CubismVector2(0.0, 0.0); const ret: CubismVector2 = new CubismVector2(0.0, 0.0);
ret.x = this.x - vector2.x; ret.x = this.x - vector2.x;
ret.y = this.y - vector2.y; ret.y = this.y - vector2.y;
return ret; return ret;
} }
/** /**
* *
* *
* @param vector2 * @param vector2
* @return * @return
*/ */
public multiply(vector2: CubismVector2): CubismVector2 { public multiply(vector2: CubismVector2): CubismVector2 {
const ret: CubismVector2 = new CubismVector2(0.0, 0.0); const ret: CubismVector2 = new CubismVector2(0.0, 0.0);
ret.x = this.x * vector2.x; ret.x = this.x * vector2.x;
ret.y = this.y * vector2.y; ret.y = this.y * vector2.y;
return ret; return ret;
} }
/** /**
* () * ()
* *
* @param scalar * @param scalar
* @return * @return
*/ */
public multiplyByScaler(scalar: number): CubismVector2 { public multiplyByScaler(scalar: number): CubismVector2 {
return this.multiply(new CubismVector2(scalar, scalar)); return this.multiply(new CubismVector2(scalar, scalar));
} }
/** /**
* *
* *
* @param vector2 * @param vector2
* @return * @return
*/ */
public division(vector2: CubismVector2): CubismVector2 { public division(vector2: CubismVector2): CubismVector2 {
const ret: CubismVector2 = new CubismVector2(0.0, 0.0); const ret: CubismVector2 = new CubismVector2(0.0, 0.0);
ret.x = this.x / vector2.x; ret.x = this.x / vector2.x;
ret.y = this.y / vector2.y; ret.y = this.y / vector2.y;
return ret; return ret;
} }
/** /**
* () * ()
* *
* @param scalar * @param scalar
* @return * @return
*/ */
public divisionByScalar(scalar: number): CubismVector2 { public divisionByScalar(scalar: number): CubismVector2 {
return this.division(new CubismVector2(scalar, scalar)); return this.division(new CubismVector2(scalar, scalar));
} }
/** /**
* *
* *
* @return * @return
*/ */
public getLength(): number { public getLength(): number {
return Math.sqrt(this.x * this.x + this.y * this.y); return Math.sqrt(this.x * this.x + this.y * this.y);
} }
/** /**
* *
* *
* @param a * @param a
* @return * @return
*/ */
public getDistanceWith(a: CubismVector2): number { public getDistanceWith(a: CubismVector2): number {
return Math.sqrt( return Math.sqrt(
(this.x - a.x) * (this.x - a.x) + (this.y - a.y) * (this.y - a.y) (this.x - a.x) * (this.x - a.x) + (this.y - a.y) * (this.y - a.y)
); );
} }
/** /**
* *
* *
* @param a * @param a
* @return * @return
*/ */
public dot(a: CubismVector2): number { public dot(a: CubismVector2): number {
return this.x * a.x + this.y * a.y; return this.x * a.x + this.y * a.y;
} }
/** /**
* *
*/ */
public normalize(): void { public normalize(): void {
const length: number = Math.pow(this.x * this.x + this.y * this.y, 0.5); const length: number = Math.pow(this.x * this.x + this.y * this.y, 0.5);
this.x = this.x / length; this.x = this.x / length;
this.y = this.y / length; this.y = this.y / length;
} }
/** /**
* *
* *
* *
* *
* @param rhs * @param rhs
* @return true * @return true
* @return false * @return false
*/ */
public isEqual(rhs: CubismVector2): boolean { public isEqual(rhs: CubismVector2): boolean {
return this.x == rhs.x && this.y == rhs.y; return this.x == rhs.x && this.y == rhs.y;
} }
/** /**
* *
* *
* *
* *
* @param rhs * @param rhs
* @return true * @return true
* @return false * @return false
*/ */
public isNotEqual(rhs: CubismVector2): boolean { public isNotEqual(rhs: CubismVector2): boolean {
return !this.isEqual(rhs); return !this.isEqual(rhs);
}
} }
} }
// Namespace definition for compatibility.
import * as $ from './cubismvector2';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismVector2 = $.CubismVector2;
export type CubismVector2 = $.CubismVector2;
}

View File

@ -5,333 +5,335 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as cubismmatrix44 } from './cubismmatrix44'; import { CubismMatrix44 } from './cubismmatrix44';
import CubismMatrix44 = cubismmatrix44.CubismMatrix44;
export namespace Live2DCubismFramework { /**
* 使便4x4
*
* 使便4x4
*/
export class CubismViewMatrix extends CubismMatrix44 {
/** /**
* 使便4x4 *
*
* 使便4x4
*/ */
export class CubismViewMatrix extends CubismMatrix44 { public constructor() {
/** super();
* this._screenLeft = 0.0;
*/ this._screenRight = 0.0;
public constructor() { this._screenTop = 0.0;
super(); this._screenBottom = 0.0;
this._screenLeft = 0.0; this._maxLeft = 0.0;
this._screenRight = 0.0; this._maxRight = 0.0;
this._screenTop = 0.0; this._maxTop = 0.0;
this._screenBottom = 0.0; this._maxBottom = 0.0;
this._maxLeft = 0.0; this._maxScale = 0.0;
this._maxRight = 0.0; this._minScale = 0.0;
this._maxTop = 0.0;
this._maxBottom = 0.0;
this._maxScale = 0.0;
this._minScale = 0.0;
}
/**
* 調
*
* @param x X
* @param y Y
*/
public adjustTranslate(x: number, y: number): void {
if (this._tr[0] * this._maxLeft + (this._tr[12] + x) > this._screenLeft) {
x = this._screenLeft - this._tr[0] * this._maxLeft - this._tr[12];
}
if (
this._tr[0] * this._maxRight + (this._tr[12] + x) <
this._screenRight
) {
x = this._screenRight - this._tr[0] * this._maxRight - this._tr[12];
}
if (this._tr[5] * this._maxTop + (this._tr[13] + y) < this._screenTop) {
y = this._screenTop - this._tr[5] * this._maxTop - this._tr[13];
}
if (
this._tr[5] * this._maxBottom + (this._tr[13] + y) >
this._screenBottom
) {
y = this._screenBottom - this._tr[5] * this._maxBottom - this._tr[13];
}
const tr1: Float32Array = new Float32Array([
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
x,
y,
0.0,
1.0
]);
CubismMatrix44.multiply(tr1, this._tr, this._tr);
}
/**
* 調
*
* @param cx X
* @param cy Y
* @param scale
*/
public adjustScale(cx: number, cy: number, scale: number): void {
const maxScale: number = this.getMaxScale();
const minScale: number = this.getMinScale();
const targetScale = scale * this._tr[0];
if (targetScale < minScale) {
if (this._tr[0] > 0.0) {
scale = minScale / this._tr[0];
}
} else if (targetScale > maxScale) {
if (this._tr[0] > 0.0) {
scale = maxScale / this._tr[0];
}
}
const tr1: Float32Array = new Float32Array([
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
cx,
cy,
0.0,
1.0
]);
const tr2: Float32Array = new Float32Array([
scale,
0.0,
0.0,
0.0,
0.0,
scale,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
]);
const tr3: Float32Array = new Float32Array([
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
-cx,
-cy,
0.0,
1.0
]);
CubismMatrix44.multiply(tr3, this._tr, this._tr);
CubismMatrix44.multiply(tr2, this._tr, this._tr);
CubismMatrix44.multiply(tr1, this._tr, this._tr);
}
/**
*
*
* @param left X
* @param right X
* @param bottom Y
* @param top Y
*/
public setScreenRect(
left: number,
right: number,
bottom: number,
top: number
): void {
this._screenLeft = left;
this._screenRight = right;
this._screenBottom = bottom;
this._screenTop = top;
}
/**
*
* @param left X
* @param right X
* @param bottom Y
* @param top Y
*/
public setMaxScreenRect(
left: number,
right: number,
bottom: number,
top: number
): void {
this._maxLeft = left;
this._maxRight = right;
this._maxTop = top;
this._maxBottom = bottom;
}
/**
*
* @param maxScale
*/
public setMaxScale(maxScale: number): void {
this._maxScale = maxScale;
}
/**
*
* @param minScale
*/
public setMinScale(minScale: number): void {
this._minScale = minScale;
}
/**
*
* @return
*/
public getMaxScale(): number {
return this._maxScale;
}
/**
*
* @return
*/
public getMinScale(): number {
return this._minScale;
}
/**
*
*
* @return true
* @return false
*/
public isMaxScale(): boolean {
return this.getScaleX() >= this._maxScale;
}
/**
*
*
* @return true
* @return false
*/
public isMinScale(): boolean {
return this.getScaleX() <= this._minScale;
}
/**
*
* @return X
*/
public getScreenLeft(): number {
return this._screenLeft;
}
/**
*
* @return X
*/
public getScreenRight(): number {
return this._screenRight;
}
/**
* Y
* @return Y
*/
public getScreenBottom(): number {
return this._screenBottom;
}
/**
* Y
* @return Y
*/
public getScreenTop(): number {
return this._screenTop;
}
/**
* X
* @return X
*/
public getMaxLeft(): number {
return this._maxLeft;
}
/**
* X
* @return X
*/
public getMaxRight(): number {
return this._maxRight;
}
/**
* Y
* @return Y
*/
public getMaxBottom(): number {
return this._maxBottom;
}
/**
* Y
* @return Y
*/
public getMaxTop(): number {
return this._maxTop;
}
private _screenLeft: number; // デバイスに対応する論理座標上の範囲左辺X軸位置
private _screenRight: number; // デバイスに対応する論理座標上の範囲右辺X軸位置
private _screenTop: number; // デバイスに対応する論理座標上の範囲上辺Y軸位置
private _screenBottom: number; // デバイスに対応する論理座標上の範囲下辺Y軸位置
private _maxLeft: number; // 論理座標上の移動可能範囲左辺X軸位置
private _maxRight: number; // 論理座標上の移動可能範囲右辺X軸位置
private _maxTop: number; // 論理座標上の移動可能範囲上辺Y軸位置
private _maxBottom: number; // 論理座標上の移動可能範囲下辺Y軸位置
private _maxScale: number; // 拡大率の最大値
private _minScale: number; // 拡大率の最小値
} }
/**
* 調
*
* @param x X
* @param y Y
*/
public adjustTranslate(x: number, y: number): void {
if (this._tr[0] * this._maxLeft + (this._tr[12] + x) > this._screenLeft) {
x = this._screenLeft - this._tr[0] * this._maxLeft - this._tr[12];
}
if (this._tr[0] * this._maxRight + (this._tr[12] + x) < this._screenRight) {
x = this._screenRight - this._tr[0] * this._maxRight - this._tr[12];
}
if (this._tr[5] * this._maxTop + (this._tr[13] + y) < this._screenTop) {
y = this._screenTop - this._tr[5] * this._maxTop - this._tr[13];
}
if (
this._tr[5] * this._maxBottom + (this._tr[13] + y) >
this._screenBottom
) {
y = this._screenBottom - this._tr[5] * this._maxBottom - this._tr[13];
}
const tr1: Float32Array = new Float32Array([
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
x,
y,
0.0,
1.0
]);
CubismMatrix44.multiply(tr1, this._tr, this._tr);
}
/**
* 調
*
* @param cx X
* @param cy Y
* @param scale
*/
public adjustScale(cx: number, cy: number, scale: number): void {
const maxScale: number = this.getMaxScale();
const minScale: number = this.getMinScale();
const targetScale = scale * this._tr[0];
if (targetScale < minScale) {
if (this._tr[0] > 0.0) {
scale = minScale / this._tr[0];
}
} else if (targetScale > maxScale) {
if (this._tr[0] > 0.0) {
scale = maxScale / this._tr[0];
}
}
const tr1: Float32Array = new Float32Array([
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
cx,
cy,
0.0,
1.0
]);
const tr2: Float32Array = new Float32Array([
scale,
0.0,
0.0,
0.0,
0.0,
scale,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
]);
const tr3: Float32Array = new Float32Array([
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
-cx,
-cy,
0.0,
1.0
]);
CubismMatrix44.multiply(tr3, this._tr, this._tr);
CubismMatrix44.multiply(tr2, this._tr, this._tr);
CubismMatrix44.multiply(tr1, this._tr, this._tr);
}
/**
*
*
* @param left X
* @param right X
* @param bottom Y
* @param top Y
*/
public setScreenRect(
left: number,
right: number,
bottom: number,
top: number
): void {
this._screenLeft = left;
this._screenRight = right;
this._screenBottom = bottom;
this._screenTop = top;
}
/**
*
* @param left X
* @param right X
* @param bottom Y
* @param top Y
*/
public setMaxScreenRect(
left: number,
right: number,
bottom: number,
top: number
): void {
this._maxLeft = left;
this._maxRight = right;
this._maxTop = top;
this._maxBottom = bottom;
}
/**
*
* @param maxScale
*/
public setMaxScale(maxScale: number): void {
this._maxScale = maxScale;
}
/**
*
* @param minScale
*/
public setMinScale(minScale: number): void {
this._minScale = minScale;
}
/**
*
* @return
*/
public getMaxScale(): number {
return this._maxScale;
}
/**
*
* @return
*/
public getMinScale(): number {
return this._minScale;
}
/**
*
*
* @return true
* @return false
*/
public isMaxScale(): boolean {
return this.getScaleX() >= this._maxScale;
}
/**
*
*
* @return true
* @return false
*/
public isMinScale(): boolean {
return this.getScaleX() <= this._minScale;
}
/**
*
* @return X
*/
public getScreenLeft(): number {
return this._screenLeft;
}
/**
*
* @return X
*/
public getScreenRight(): number {
return this._screenRight;
}
/**
* Y
* @return Y
*/
public getScreenBottom(): number {
return this._screenBottom;
}
/**
* Y
* @return Y
*/
public getScreenTop(): number {
return this._screenTop;
}
/**
* X
* @return X
*/
public getMaxLeft(): number {
return this._maxLeft;
}
/**
* X
* @return X
*/
public getMaxRight(): number {
return this._maxRight;
}
/**
* Y
* @return Y
*/
public getMaxBottom(): number {
return this._maxBottom;
}
/**
* Y
* @return Y
*/
public getMaxTop(): number {
return this._maxTop;
}
private _screenLeft: number; // デバイスに対応する論理座標上の範囲左辺X軸位置
private _screenRight: number; // デバイスに対応する論理座標上の範囲右辺X軸位置
private _screenTop: number; // デバイスに対応する論理座標上の範囲上辺Y軸位置
private _screenBottom: number; // デバイスに対応する論理座標上の範囲下辺Y軸位置
private _maxLeft: number; // 論理座標上の移動可能範囲左辺X軸位置
private _maxRight: number; // 論理座標上の移動可能範囲右辺X軸位置
private _maxTop: number; // 論理座標上の移動可能範囲上辺Y軸位置
private _maxBottom: number; // 論理座標上の移動可能範囲下辺Y軸位置
private _maxScale: number; // 拡大率の最大値
private _minScale: number; // 拡大率の最小値
}
// Namespace definition for compatibility.
import * as $ from './cubismviewmatrix';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismViewMatrix = $.CubismViewMatrix;
export type CubismViewMatrix = $.CubismViewMatrix;
} }

View File

@ -5,96 +5,101 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as cubismmodel } from './cubismmodel';
import CubismModel = cubismmodel.CubismModel;
import { CSM_ASSERT } from '../utils/cubismdebug'; import { CSM_ASSERT } from '../utils/cubismdebug';
import { CubismModel } from './cubismmodel';
export namespace Live2DCubismFramework { /**
* Moc
*
* Moc
*/
export class CubismMoc {
/** /**
* Moc * Moc
*
* Moc
*/ */
export class CubismMoc { public static create(mocBytes: ArrayBuffer): CubismMoc {
/** let cubismMoc: CubismMoc = null;
* Moc const moc: Live2DCubismCore.Moc = Live2DCubismCore.Moc.fromArrayBuffer(
*/ mocBytes
public static create(mocBytes: ArrayBuffer): CubismMoc { );
let cubismMoc: CubismMoc = null;
const moc: Live2DCubismCore.Moc = Live2DCubismCore.Moc.fromArrayBuffer(
mocBytes
);
if (moc) { if (moc) {
cubismMoc = new CubismMoc(moc); cubismMoc = new CubismMoc(moc);
}
return cubismMoc;
} }
/** return cubismMoc;
* Moc
*
* Moc
*/
public static delete(moc: CubismMoc): void {
moc._moc._release();
moc._moc = null;
moc = null;
}
/**
*
*
* @return Moc
*/
createModel(): CubismModel {
let cubismModel: CubismModel = null;
const model: Live2DCubismCore.Model = Live2DCubismCore.Model.fromMoc(
this._moc
);
if (model) {
cubismModel = new CubismModel(model);
cubismModel.initialize();
++this._modelCount;
}
return cubismModel;
}
/**
*
*/
deleteModel(model: CubismModel): void {
if (model != null) {
model.release();
model = null;
--this._modelCount;
}
}
/**
*
*/
private constructor(moc: Live2DCubismCore.Moc) {
this._moc = moc;
this._modelCount = 0;
}
/**
*
*/
public release(): void {
CSM_ASSERT(this._modelCount == 0);
this._moc._release();
this._moc = null;
}
_moc: Live2DCubismCore.Moc; // Mocデータ
_modelCount: number; // Mocデータから作られたモデルの個数
} }
/**
* Moc
*
* Moc
*/
public static delete(moc: CubismMoc): void {
moc._moc._release();
moc._moc = null;
moc = null;
}
/**
*
*
* @return Moc
*/
createModel(): CubismModel {
let cubismModel: CubismModel = null;
const model: Live2DCubismCore.Model = Live2DCubismCore.Model.fromMoc(
this._moc
);
if (model) {
cubismModel = new CubismModel(model);
cubismModel.initialize();
++this._modelCount;
}
return cubismModel;
}
/**
*
*/
deleteModel(model: CubismModel): void {
if (model != null) {
model.release();
model = null;
--this._modelCount;
}
}
/**
*
*/
private constructor(moc: Live2DCubismCore.Moc) {
this._moc = moc;
this._modelCount = 0;
}
/**
*
*/
public release(): void {
CSM_ASSERT(this._modelCount == 0);
this._moc._release();
this._moc = null;
}
_moc: Live2DCubismCore.Moc; // Mocデータ
_modelCount: number; // Mocデータから作られたモデルの個数
}
// Namespace definition for compatibility.
import * as $ from './cubismmoc';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismMoc = $.CubismMoc;
export type CubismMoc = $.CubismMoc;
} }

File diff suppressed because it is too large Load Diff

View File

@ -5,132 +5,132 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as cubismmodeluserdatajson } from './cubismmodeluserdatajson'; import { CubismIdHandle } from '../id/cubismid';
import { Live2DCubismFramework as cubismid } from '../id/cubismid'; import { CubismFramework } from '../live2dcubismframework';
import { Live2DCubismFramework as csmstring } from '../type/csmstring'; import { csmString } from '../type/csmstring';
import { Live2DCubismFramework as csmvector } from '../type/csmvector'; import { csmVector } from '../type/csmvector';
import { Live2DCubismFramework as cubismframework } from '../live2dcubismframework'; import { CubismModelUserDataJson } from './cubismmodeluserdatajson';
import CubismFramework = cubismframework.CubismFramework;
import csmVector = csmvector.csmVector;
import csmString = csmstring.csmString;
import CubismIdHandle = cubismid.CubismIdHandle;
import CubismModelUserDataJson = cubismmodeluserdatajson.CubismModelUserDataJson;
export namespace Live2DCubismFramework { const ArtMesh = 'ArtMesh';
const ArtMesh = 'ArtMesh';
/** /**
* *
* *
* Json * Json
*/ */
export class CubismModelUserDataNode { export class CubismModelUserDataNode {
targetType: CubismIdHandle; // ユーザーデータターゲットタイプ targetType: CubismIdHandle; // ユーザーデータターゲットタイプ
targetId: CubismIdHandle; // ユーザーデータターゲットのID targetId: CubismIdHandle; // ユーザーデータターゲットのID
value: csmString; // ユーザーデータ value: csmString; // ユーザーデータ
} }
/** /**
* *
* *
* *
*/ */
export class CubismModelUserData { export class CubismModelUserData {
/** /**
* *
* *
* @param buffer userdata3.json * @param buffer userdata3.json
* @param size * @param size
* @return * @return
*/ */
public static create( public static create(buffer: ArrayBuffer, size: number): CubismModelUserData {
buffer: ArrayBuffer, const ret: CubismModelUserData = new CubismModelUserData();
size: number
): CubismModelUserData { ret.parseUserData(buffer, size);
const ret: CubismModelUserData = new CubismModelUserData();
return ret;
ret.parseUserData(buffer, size); }
return ret; /**
} *
*
/** * @param modelUserData
* */
* public static delete(modelUserData: CubismModelUserData): void {
* @param modelUserData if (modelUserData != null) {
*/ modelUserData.release();
public static delete(modelUserData: CubismModelUserData): void { modelUserData = null;
if (modelUserData != null) { }
modelUserData.release(); }
modelUserData = null;
} /**
} * ArtMesh
*
/** * @return
* ArtMesh */
* public getArtMeshUserDatas(): csmVector<CubismModelUserDataNode> {
* @return return this._artMeshUserDataNode;
*/ }
public getArtMeshUserDatas(): csmVector<CubismModelUserDataNode> {
return this._artMeshUserDataNode; /**
} * userdata3.json
*
/** * @param buffer userdata3.json
* userdata3.json * @param size
* */
* @param buffer userdata3.json public parseUserData(buffer: ArrayBuffer, size: number): void {
* @param size let json: CubismModelUserDataJson = new CubismModelUserDataJson(
*/ buffer,
public parseUserData(buffer: ArrayBuffer, size: number): void { size
let json: CubismModelUserDataJson = new CubismModelUserDataJson( );
buffer,
size const typeOfArtMesh = CubismFramework.getIdManager().getId(ArtMesh);
); const nodeCount: number = json.getUserDataCount();
const typeOfArtMesh = CubismFramework.getIdManager().getId(ArtMesh); for (let i = 0; i < nodeCount; i++) {
const nodeCount: number = json.getUserDataCount(); const addNode: CubismModelUserDataNode = new CubismModelUserDataNode();
for (let i = 0; i < nodeCount; i++) { addNode.targetId = json.getUserDataId(i);
const addNode: CubismModelUserDataNode = new CubismModelUserDataNode(); addNode.targetType = CubismFramework.getIdManager().getId(
json.getUserDataTargetType(i)
addNode.targetId = json.getUserDataId(i); );
addNode.targetType = CubismFramework.getIdManager().getId( addNode.value = new csmString(json.getUserDataValue(i));
json.getUserDataTargetType(i) this._userDataNodes.pushBack(addNode);
);
addNode.value = new csmString(json.getUserDataValue(i)); if (addNode.targetType == typeOfArtMesh) {
this._userDataNodes.pushBack(addNode); this._artMeshUserDataNode.pushBack(addNode);
}
if (addNode.targetType == typeOfArtMesh) { }
this._artMeshUserDataNode.pushBack(addNode);
} json.release();
} json = void 0;
}
json.release();
json = void 0; /**
} *
*/
/** public constructor() {
* this._userDataNodes = new csmVector<CubismModelUserDataNode>();
*/ this._artMeshUserDataNode = new csmVector<CubismModelUserDataNode>();
public constructor() { }
this._userDataNodes = new csmVector<CubismModelUserDataNode>();
this._artMeshUserDataNode = new csmVector<CubismModelUserDataNode>(); /**
} *
*
/** *
* */
* public release(): void {
* for (let i = 0; i < this._userDataNodes.getSize(); ++i) {
*/ this._userDataNodes.set(i, null);
public release(): void { }
for (let i = 0; i < this._userDataNodes.getSize(); ++i) {
this._userDataNodes.set(i, null); this._userDataNodes = null;
} }
this._userDataNodes = null; private _userDataNodes: csmVector<CubismModelUserDataNode>; // ユーザーデータ構造体配列
} private _artMeshUserDataNode: csmVector<CubismModelUserDataNode>; // 閲覧リストの保持
}
private _userDataNodes: csmVector<CubismModelUserDataNode>; // ユーザーデータ構造体配列
private _artMeshUserDataNode: csmVector<CubismModelUserDataNode>; // 閲覧リストの保持 // Namespace definition for compatibility.
} import * as $ from './cubismmodeluserdata';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismModelUserData = $.CubismModelUserData;
export type CubismModelUserData = $.CubismModelUserData;
export const CubismModelUserDataNode = $.CubismModelUserDataNode;
export type CubismModelUserDataNode = $.CubismModelUserDataNode;
} }

View File

@ -5,110 +5,113 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * 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 { CubismIdHandle } from '../id/cubismid';
import { Live2DCubismFramework as cubismid } from '../id/cubismid'; import { CubismFramework } from '../live2dcubismframework';
import { Live2DCubismFramework as cubismframework } from '../live2dcubismframework'; import { CubismJson } from '../utils/cubismjson';
import CubismFramework = cubismframework.CubismFramework;
import CubismIdHandle = cubismid.CubismIdHandle;
import CubismJson = cubismjson.CubismJson;
export namespace Live2DCubismFramework { const Meta = 'Meta';
const Meta = 'Meta'; const UserDataCount = 'UserDataCount';
const UserDataCount = 'UserDataCount'; const TotalUserDataSize = 'TotalUserDataSize';
const TotalUserDataSize = 'TotalUserDataSize'; const UserData = 'UserData';
const UserData = 'UserData'; const Target = 'Target';
const Target = 'Target'; const Id = 'Id';
const Id = 'Id'; const Value = 'Value';
const Value = 'Value';
export class CubismModelUserDataJson { export class CubismModelUserDataJson {
/** /**
* *
* @param buffer userdata3.json * @param buffer userdata3.json
* @param size * @param size
*/ */
public constructor(buffer: ArrayBuffer, size: number) { public constructor(buffer: ArrayBuffer, size: number) {
this._json = CubismJson.create(buffer, size); this._json = CubismJson.create(buffer, size);
}
/**
*
*/
public release(): void {
CubismJson.delete(this._json);
}
/**
*
* @return
*/
public getUserDataCount(): number {
return this._json
.getRoot()
.getValueByString(Meta)
.getValueByString(UserDataCount)
.toInt();
}
/**
*
*
* @return
*/
public getTotalUserDataSize(): number {
return this._json
.getRoot()
.getValueByString(Meta)
.getValueByString(TotalUserDataSize)
.toInt();
}
/**
*
*
* @return
*/
public getUserDataTargetType(i: number): string {
return this._json
.getRoot()
.getValueByString(UserData)
.getValueByIndex(i)
.getValueByString(Target)
.getRawString();
}
/**
* ID
*
* @param i
* @return ID
*/
public getUserDataId(i: number): CubismIdHandle {
return CubismFramework.getIdManager().getId(
this._json
.getRoot()
.getValueByString(UserData)
.getValueByIndex(i)
.getValueByString(Id)
.getRawString()
);
}
/**
*
*
* @param i
* @return
*/
public getUserDataValue(i: number): string {
return this._json
.getRoot()
.getValueByString(UserData)
.getValueByIndex(i)
.getValueByString(Value)
.getRawString();
}
private _json: CubismJson;
} }
/**
*
*/
public release(): void {
CubismJson.delete(this._json);
}
/**
*
* @return
*/
public getUserDataCount(): number {
return this._json
.getRoot()
.getValueByString(Meta)
.getValueByString(UserDataCount)
.toInt();
}
/**
*
*
* @return
*/
public getTotalUserDataSize(): number {
return this._json
.getRoot()
.getValueByString(Meta)
.getValueByString(TotalUserDataSize)
.toInt();
}
/**
*
*
* @return
*/
public getUserDataTargetType(i: number): string {
return this._json
.getRoot()
.getValueByString(UserData)
.getValueByIndex(i)
.getValueByString(Target)
.getRawString();
}
/**
* ID
*
* @param i
* @return ID
*/
public getUserDataId(i: number): CubismIdHandle {
return CubismFramework.getIdManager().getId(
this._json
.getRoot()
.getValueByString(UserData)
.getValueByIndex(i)
.getValueByString(Id)
.getRawString()
);
}
/**
*
*
* @param i
* @return
*/
public getUserDataValue(i: number): string {
return this._json
.getRoot()
.getValueByString(UserData)
.getValueByIndex(i)
.getValueByString(Value)
.getRawString();
}
private _json: CubismJson;
}
// Namespace definition for compatibility.
import * as $ from './cubismmodeluserdatajson';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismModelUserDataJson = $.CubismModelUserDataJson;
export type CubismModelUserDataJson = $.CubismModelUserDataJson;
} }

View File

@ -5,449 +5,436 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as cubismframework } from '../live2dcubismframework'; import { CubismBreath } from '../effect/cubismbreath';
import { Live2DCubismFramework as cubismmotionmanager } from '../motion/cubismmotionmanager'; import { CubismEyeBlink } from '../effect/cubismeyeblink';
import { Live2DCubismFramework as cubismtargetpoint } from '../math/cubismtargetpoint'; import { CubismPose } from '../effect/cubismpose';
import { Live2DCubismFramework as cubismmodelmatrix } from '../math/cubismmodelmatrix'; import { CubismIdHandle } from '../id/cubismid';
import { Live2DCubismFramework as cubismmoc } from './cubismmoc'; import { Constant } from '../live2dcubismframework';
import { Live2DCubismFramework as cubismmodel } from './cubismmodel'; import { CubismModelMatrix } from '../math/cubismmodelmatrix';
import { Live2DCubismFramework as acubismmotion } from '../motion/acubismmotion'; import { CubismTargetPoint } from '../math/cubismtargetpoint';
import { Live2DCubismFramework as cubismmotion } from '../motion/cubismmotion'; import { ACubismMotion, FinishedMotionCallback } from '../motion/acubismmotion';
import { Live2DCubismFramework as cubismexpressionmotion } from '../motion/cubismexpressionmotion'; import { CubismExpressionMotion } from '../motion/cubismexpressionmotion';
import { Live2DCubismFramework as cubismpose } from '../effect/cubismpose'; import { CubismMotion } from '../motion/cubismmotion';
import { Live2DCubismFramework as cubismmodeluserdata } from './cubismmodeluserdata'; import { CubismMotionManager } from '../motion/cubismmotionmanager';
import { Live2DCubismFramework as cubismphysics } from '../physics/cubismphysics'; import { CubismMotionQueueManager } from '../motion/cubismmotionqueuemanager';
import { Live2DCubismFramework as cubismid } from '../id/cubismid'; import { CubismPhysics } from '../physics/cubismphysics';
import { Live2DCubismFramework as csmstring } from '../type/csmstring'; import { CubismRenderer_WebGL } from '../rendering/cubismrenderer_webgl';
import { Live2DCubismFramework as cubismmotionqueuemanager } from '../motion/cubismmotionqueuemanager'; import { csmString } from '../type/csmstring';
import { Live2DCubismFramework as cubismbreath } from '../effect/cubismbreath';
import { Live2DCubismFramework as cubismeyeblink } from '../effect/cubismeyeblink';
import { Live2DCubismFramework as cubismrenderer_webgl } from '../rendering/cubismrenderer_webgl';
import { CubismLogError, CubismLogInfo } from '../utils/cubismdebug'; import { CubismLogError, CubismLogInfo } from '../utils/cubismdebug';
import CubismRenderer_WebGL = cubismrenderer_webgl.CubismRenderer_WebGL; import { CubismMoc } from './cubismmoc';
import CubismEyeBlink = cubismeyeblink.CubismEyeBlink; import { CubismModel } from './cubismmodel';
import CubismBreath = cubismbreath.CubismBreath; import { CubismModelUserData } from './cubismmodeluserdata';
import CubismMotionQueueManager = cubismmotionqueuemanager.CubismMotionQueueManager;
import csmString = csmstring.csmString;
import Constant = cubismframework.Constant;
import CubismIdHandle = cubismid.CubismIdHandle;
import CubismPhysics = cubismphysics.CubismPhysics;
import CubismModelUserData = cubismmodeluserdata.CubismModelUserData;
import CubismPose = cubismpose.CubismPose;
import CubismExpressionMotion = cubismexpressionmotion.CubismExpressionMotion;
import CubismMotion = cubismmotion.CubismMotion;
import ACubismMotion = acubismmotion.ACubismMotion;
import FinishedMotionCallback = acubismmotion.FinishedMotionCallback;
import CubismModel = cubismmodel.CubismModel;
import CubismMoc = cubismmoc.CubismMoc;
import CubismModelMatrix = cubismmodelmatrix.CubismModelMatrix;
import CubismTargetPoint = cubismtargetpoint.CubismTargetPoint;
import CubismMotionManager = cubismmotionmanager.CubismMotionManager;
export namespace Live2DCubismFramework { /**
* 使
*
* 使
*/
export class CubismUserModel {
/** /**
* 使 *
* *
* 使 *
*
* @return true
* @return false
*/ */
export class CubismUserModel { public isInitialized(): boolean {
/** return this._initialized;
* }
*
* /**
* *
* @return true *
* @return false *
*/ *
public isInitialized(): boolean { * @param v
return this._initialized; */
public setInitialized(v: boolean): void {
this._initialized = v;
}
/**
*
*
*
*
* @return true
* @return false
*/
public isUpdating(): boolean {
return this._updating;
}
/**
*
*
*
*
* @param v
*/
public setUpdating(v: boolean): void {
this._updating = v;
}
/**
*
* @param X
* @param Y
*/
public setDragging(x: number, y: number): void {
this._dragManager.set(x, y);
}
/**
*
* @param x X
* @param y Y
* @param z Z
*/
public setAcceleration(x: number, y: number, z: number): void {
this._accelerationX = x;
this._accelerationY = y;
this._accelerationZ = z;
}
/**
*
* @return
*/
public getModelMatrix(): CubismModelMatrix {
return this._modelMatrix;
}
/**
*
* @param a
*/
public setOpacity(a: number): void {
this._opacity = a;
}
/**
*
* @return
*/
public getOpacity(): number {
return this._opacity;
}
/**
*
*
* @param buffer moc3
*/
public loadModel(buffer: ArrayBuffer) {
this._moc = CubismMoc.create(buffer);
this._model = this._moc.createModel();
this._model.saveParameters();
if (this._moc == null || this._model == null) {
CubismLogError('Failed to CreateModel().');
return;
} }
/** this._modelMatrix = new CubismModelMatrix(
* this._model.getCanvasWidth(),
* this._model.getCanvasHeight()
* );
* }
* @param v
*/ /**
public setInitialized(v: boolean): void { *
this._initialized = v; * @param buffer motion3.json
* @param size
* @param name
* @param onFinishedMotionHandler
* @return
*/
public loadMotion = (
buffer: ArrayBuffer,
size: number,
name: string,
onFinishedMotionHandler?: FinishedMotionCallback
) => CubismMotion.create(buffer, size, onFinishedMotionHandler);
/**
*
* @param buffer exp
* @param size
* @param name
*/
public loadExpression(
buffer: ArrayBuffer,
size: number,
name: string
): ACubismMotion {
return CubismExpressionMotion.create(buffer, size);
}
/**
*
* @param buffer pose3.json
* @param size
*/
public loadPose(buffer: ArrayBuffer, size: number): void {
this._pose = CubismPose.create(buffer, size);
}
/**
*
* @param buffer userdata3.json
* @param size
*/
public loadUserData(buffer: ArrayBuffer, size: number): void {
this._modelUserData = CubismModelUserData.create(buffer, size);
}
/**
*
* @param buffer physics3.json
* @param size
*/
public loadPhysics(buffer: ArrayBuffer, size: number): void {
this._physics = CubismPhysics.create(buffer, size);
}
/**
*
* @param drawableId DrawableID
* @param pointX X
* @param pointY Y
* @return true
* @return false
*/
public isHit(
drawableId: CubismIdHandle,
pointX: number,
pointY: number
): boolean {
const drawIndex: number = this._model.getDrawableIndex(drawableId);
if (drawIndex < 0) {
return false; // 存在しない場合はfalse
} }
/** const count: number = this._model.getDrawableVertexCount(drawIndex);
* const vertices: Float32Array = this._model.getDrawableVertices(drawIndex);
*
*
*
* @return true
* @return false
*/
public isUpdating(): boolean {
return this._updating;
}
/** let left: number = vertices[0];
* let right: number = vertices[0];
* let top: number = vertices[1];
* let bottom: number = vertices[1];
*
* @param v
*/
public setUpdating(v: boolean): void {
this._updating = v;
}
/** for (let j = 1; j < count; ++j) {
* const x = vertices[Constant.vertexOffset + j * Constant.vertexStep];
* @param X const y = vertices[Constant.vertexOffset + j * Constant.vertexStep + 1];
* @param Y
*/
public setDragging(x: number, y: number): void {
this._dragManager.set(x, y);
}
/** if (x < left) {
* left = x; // Min x
* @param x X
* @param y Y
* @param z Z
*/
public setAcceleration(x: number, y: number, z: number): void {
this._accelerationX = x;
this._accelerationY = y;
this._accelerationZ = z;
}
/**
*
* @return
*/
public getModelMatrix(): CubismModelMatrix {
return this._modelMatrix;
}
/**
*
* @param a
*/
public setOpacity(a: number): void {
this._opacity = a;
}
/**
*
* @return
*/
public getOpacity(): number {
return this._opacity;
}
/**
*
*
* @param buffer moc3
*/
public loadModel(buffer: ArrayBuffer) {
this._moc = CubismMoc.create(buffer);
this._model = this._moc.createModel();
this._model.saveParameters();
if (this._moc == null || this._model == null) {
CubismLogError('Failed to CreateModel().');
return;
} }
this._modelMatrix = new CubismModelMatrix( if (x > right) {
this._model.getCanvasWidth(), right = x; // Max x
this._model.getCanvasHeight()
);
}
/**
*
* @param buffer motion3.json
* @param size
* @param name
* @param onFinishedMotionHandler
* @return
*/
public loadMotion = (
buffer: ArrayBuffer,
size: number,
name: string,
onFinishedMotionHandler?: FinishedMotionCallback
) => CubismMotion.create(buffer, size, onFinishedMotionHandler);
/**
*
* @param buffer exp
* @param size
* @param name
*/
public loadExpression(
buffer: ArrayBuffer,
size: number,
name: string
): ACubismMotion {
return CubismExpressionMotion.create(buffer, size);
}
/**
*
* @param buffer pose3.json
* @param size
*/
public loadPose(buffer: ArrayBuffer, size: number): void {
this._pose = CubismPose.create(buffer, size);
}
/**
*
* @param buffer userdata3.json
* @param size
*/
public loadUserData(buffer: ArrayBuffer, size: number): void {
this._modelUserData = CubismModelUserData.create(buffer, size);
}
/**
*
* @param buffer physics3.json
* @param size
*/
public loadPhysics(buffer: ArrayBuffer, size: number): void {
this._physics = CubismPhysics.create(buffer, size);
}
/**
*
* @param drawableId DrawableID
* @param pointX X
* @param pointY Y
* @return true
* @return false
*/
public isHit(
drawableId: CubismIdHandle,
pointX: number,
pointY: number
): boolean {
const drawIndex: number = this._model.getDrawableIndex(drawableId);
if (drawIndex < 0) {
return false; // 存在しない場合はfalse
} }
const count: number = this._model.getDrawableVertexCount(drawIndex); if (y < top) {
const vertices: Float32Array = this._model.getDrawableVertices(drawIndex); top = y; // Min y
let left: number = vertices[0];
let right: number = vertices[0];
let top: number = vertices[1];
let bottom: number = vertices[1];
for (let j = 1; j < count; ++j) {
const x = vertices[Constant.vertexOffset + j * Constant.vertexStep];
const y = vertices[Constant.vertexOffset + j * Constant.vertexStep + 1];
if (x < left) {
left = x; // Min x
}
if (x > right) {
right = x; // Max x
}
if (y < top) {
top = y; // Min y
}
if (y > bottom) {
bottom = y; // Max y
}
} }
const tx: number = this._modelMatrix.invertTransformX(pointX); if (y > bottom) {
const ty: number = this._modelMatrix.invertTransformY(pointY); bottom = y; // Max y
return left <= tx && tx <= right && top <= ty && ty <= bottom;
}
/**
*
* @return
*/
public getModel(): CubismModel {
return this._model;
}
/**
*
* @return
*/
public getRenderer(): CubismRenderer_WebGL {
return this._renderer;
}
/**
*
*/
public createRenderer(): void {
if (this._renderer) {
this.deleteRenderer();
}
this._renderer = new CubismRenderer_WebGL();
this._renderer.initialize(this._model);
}
/**
*
*/
public deleteRenderer(): void {
if (this._renderer != null) {
this._renderer.release();
this._renderer = null;
} }
} }
/** const tx: number = this._modelMatrix.invertTransformX(pointX);
* const ty: number = this._modelMatrix.invertTransformY(pointY);
*
* Event
*
*
*
* @param eventValue
*/
public motionEventFired(eventValue: csmString): void {
CubismLogInfo('{0}', eventValue.s);
}
/** return left <= tx && tx <= right && top <= ty && ty <= bottom;
* }
*
* CubismMotionQueueManagerCallback
* CubismUserModelEventFired
*
* @param caller
* @param eventValue
* @param customData CubismUserModel
*/
public static cubismDefaultMotionEventCallback(
caller: CubismMotionQueueManager,
eventValue: csmString,
customData: CubismUserModel
): void {
const model: CubismUserModel = customData;
if (model != null) { /**
model.motionEventFired(eventValue); *
} * @return
} */
public getModel(): CubismModel {
return this._model;
}
/** /**
* *
*/ * @return
public constructor() { */
// 各変数初期化 public getRenderer(): CubismRenderer_WebGL {
this._moc = null; return this._renderer;
this._model = null; }
this._motionManager = null;
this._expressionManager = null;
this._eyeBlink = null;
this._breath = null;
this._modelMatrix = null;
this._pose = null;
this._dragManager = null;
this._physics = null;
this._modelUserData = null;
this._initialized = false;
this._updating = false;
this._opacity = 1.0;
this._lipsync = true;
this._lastLipSyncValue = 0.0;
this._dragX = 0.0;
this._dragY = 0.0;
this._accelerationX = 0.0;
this._accelerationY = 0.0;
this._accelerationZ = 0.0;
this._debugMode = false;
this._renderer = null;
// モーションマネージャーを作成
this._motionManager = new CubismMotionManager();
this._motionManager.setEventCallback(
CubismUserModel.cubismDefaultMotionEventCallback,
this
);
// 表情マネージャーを作成
this._expressionManager = new CubismMotionManager();
// ドラッグによるアニメーション
this._dragManager = new CubismTargetPoint();
}
/**
*
*/
public release() {
if (this._motionManager != null) {
this._motionManager.release();
this._motionManager = null;
}
if (this._expressionManager != null) {
this._expressionManager.release();
this._expressionManager = null;
}
if (this._moc != null) {
this._moc.deleteModel(this._model);
this._moc.release();
this._moc = null;
}
this._modelMatrix = null;
CubismPose.delete(this._pose);
CubismEyeBlink.delete(this._eyeBlink);
CubismBreath.delete(this._breath);
this._dragManager = null;
CubismPhysics.delete(this._physics);
CubismModelUserData.delete(this._modelUserData);
/**
*
*/
public createRenderer(): void {
if (this._renderer) {
this.deleteRenderer(); this.deleteRenderer();
} }
protected _moc: CubismMoc; // Mocデータ this._renderer = new CubismRenderer_WebGL();
protected _model: CubismModel; // Modelインスタンス this._renderer.initialize(this._model);
protected _motionManager: CubismMotionManager; // モーション管理
protected _expressionManager: CubismMotionManager; // 表情管理
protected _eyeBlink: CubismEyeBlink; // 自動まばたき
protected _breath: CubismBreath; // 呼吸
protected _modelMatrix: CubismModelMatrix; // モデル行列
protected _pose: CubismPose; // ポーズ管理
protected _dragManager: CubismTargetPoint; // マウスドラッグ
protected _physics: CubismPhysics; // 物理演算
protected _modelUserData: CubismModelUserData; // ユーザーデータ
protected _initialized: boolean; // 初期化されたかどうか
protected _updating: boolean; // 更新されたかどうか
protected _opacity: number; // 不透明度
protected _lipsync: boolean; // リップシンクするかどうか
protected _lastLipSyncValue: number; // 最後のリップシンクの制御地
protected _dragX: number; // マウスドラッグのX位置
protected _dragY: number; // マウスドラッグのY位置
protected _accelerationX: number; // X軸方向の加速度
protected _accelerationY: number; // Y軸方向の加速度
protected _accelerationZ: number; // Z軸方向の加速度
protected _debugMode: boolean; // デバッグモードかどうか
private _renderer: CubismRenderer_WebGL; // レンダラ
} }
/**
*
*/
public deleteRenderer(): void {
if (this._renderer != null) {
this._renderer.release();
this._renderer = null;
}
}
/**
*
*
* Event
*
*
*
* @param eventValue
*/
public motionEventFired(eventValue: csmString): void {
CubismLogInfo('{0}', eventValue.s);
}
/**
*
*
* CubismMotionQueueManagerCallback
* CubismUserModelEventFired
*
* @param caller
* @param eventValue
* @param customData CubismUserModel
*/
public static cubismDefaultMotionEventCallback(
caller: CubismMotionQueueManager,
eventValue: csmString,
customData: CubismUserModel
): void {
const model: CubismUserModel = customData;
if (model != null) {
model.motionEventFired(eventValue);
}
}
/**
*
*/
public constructor() {
// 各変数初期化
this._moc = null;
this._model = null;
this._motionManager = null;
this._expressionManager = null;
this._eyeBlink = null;
this._breath = null;
this._modelMatrix = null;
this._pose = null;
this._dragManager = null;
this._physics = null;
this._modelUserData = null;
this._initialized = false;
this._updating = false;
this._opacity = 1.0;
this._lipsync = true;
this._lastLipSyncValue = 0.0;
this._dragX = 0.0;
this._dragY = 0.0;
this._accelerationX = 0.0;
this._accelerationY = 0.0;
this._accelerationZ = 0.0;
this._debugMode = false;
this._renderer = null;
// モーションマネージャーを作成
this._motionManager = new CubismMotionManager();
this._motionManager.setEventCallback(
CubismUserModel.cubismDefaultMotionEventCallback,
this
);
// 表情マネージャーを作成
this._expressionManager = new CubismMotionManager();
// ドラッグによるアニメーション
this._dragManager = new CubismTargetPoint();
}
/**
*
*/
public release() {
if (this._motionManager != null) {
this._motionManager.release();
this._motionManager = null;
}
if (this._expressionManager != null) {
this._expressionManager.release();
this._expressionManager = null;
}
if (this._moc != null) {
this._moc.deleteModel(this._model);
this._moc.release();
this._moc = null;
}
this._modelMatrix = null;
CubismPose.delete(this._pose);
CubismEyeBlink.delete(this._eyeBlink);
CubismBreath.delete(this._breath);
this._dragManager = null;
CubismPhysics.delete(this._physics);
CubismModelUserData.delete(this._modelUserData);
this.deleteRenderer();
}
protected _moc: CubismMoc; // Mocデータ
protected _model: CubismModel; // Modelインスタンス
protected _motionManager: CubismMotionManager; // モーション管理
protected _expressionManager: CubismMotionManager; // 表情管理
protected _eyeBlink: CubismEyeBlink; // 自動まばたき
protected _breath: CubismBreath; // 呼吸
protected _modelMatrix: CubismModelMatrix; // モデル行列
protected _pose: CubismPose; // ポーズ管理
protected _dragManager: CubismTargetPoint; // マウスドラッグ
protected _physics: CubismPhysics; // 物理演算
protected _modelUserData: CubismModelUserData; // ユーザーデータ
protected _initialized: boolean; // 初期化されたかどうか
protected _updating: boolean; // 更新されたかどうか
protected _opacity: number; // 不透明度
protected _lipsync: boolean; // リップシンクするかどうか
protected _lastLipSyncValue: number; // 最後のリップシンクの制御地
protected _dragX: number; // マウスドラッグのX位置
protected _dragY: number; // マウスドラッグのY位置
protected _accelerationX: number; // X軸方向の加速度
protected _accelerationY: number; // Y軸方向の加速度
protected _accelerationZ: number; // Z軸方向の加速度
protected _debugMode: boolean; // デバッグモードかどうか
private _renderer: CubismRenderer_WebGL; // レンダラ
}
// Namespace definition for compatibility.
import * as $ from './cubismusermodel';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismUserModel = $.CubismUserModel;
export type CubismUserModel = $.CubismUserModel;
} }

View File

@ -5,274 +5,276 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * 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 { CubismMath } from '../math/cubismmath';
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel'; import { CubismModel } from '../model/cubismmodel';
import { Live2DCubismFramework as cubismmotionqueueentry } from './cubismmotionqueueentry'; import { csmString } from '../type/csmstring';
import { Live2DCubismFramework as csmstring } from '../type/csmstring'; import { csmVector } from '../type/csmvector';
import { Live2DCubismFramework as csmvector } from '../type/csmvector';
import { CSM_ASSERT } from '../utils/cubismdebug'; import { CSM_ASSERT } from '../utils/cubismdebug';
import csmVector = csmvector.csmVector; import { CubismMotionQueueEntry } from './cubismmotionqueueentry';
import csmString = csmstring.csmString;
import CubismMotionQueueEntry = cubismmotionqueueentry.CubismMotionQueueEntry;
import CubismModel = cubismmodel.CubismModel;
import CubismMath = cubismmath.CubismMath;
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 constructor() {
/** this._fadeInSeconds = -1.0;
* this._fadeOutSeconds = -1.0;
*/ this._weight = 1.0;
public static delete(motion: ACubismMotion): void { this._offsetSeconds = 0.0; // 再生の開始時刻
motion.release(); this._firedEventValues = new csmVector<csmString>();
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;
}
/**
*
*
*
*
*
* @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 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;
}
/**
*
*
*
*
*
* @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;
} }

View File

@ -5,195 +5,195 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as acubismmotion } from './acubismmotion'; import { CubismIdHandle } from '../id/cubismid';
import { Live2DCubismFramework as cubismjson } from '../utils/cubismjson'; import { CubismFramework } from '../live2dcubismframework';
import { Live2DCubismFramework as cubismid } from '../id/cubismid'; import { CubismModel } from '../model/cubismmodel';
import { Live2DCubismFramework as cubismframework } from '../live2dcubismframework'; import { csmVector } from '../type/csmvector';
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel'; import { CubismJson, Value } from '../utils/cubismjson';
import { Live2DCubismFramework as cubismmotionqueueentry } from './cubismmotionqueueentry'; import { ACubismMotion } from './acubismmotion';
import { Live2DCubismFramework as csmvector } from '../type/csmvector'; import { CubismMotionQueueEntry } from './cubismmotionqueueentry';
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;
export namespace Live2DCubismFramework { // exp3.jsonのキーとデフォルト
// exp3.jsonのキーとデフォルト const ExpressionKeyFadeIn = 'FadeInTime';
const ExpressionKeyFadeIn = 'FadeInTime'; const ExpressionKeyFadeOut = 'FadeOutTime';
const ExpressionKeyFadeOut = 'FadeOutTime'; const ExpressionKeyParameters = 'Parameters';
const ExpressionKeyParameters = 'Parameters'; const ExpressionKeyId = 'Id';
const ExpressionKeyId = 'Id'; const ExpressionKeyValue = 'Value';
const ExpressionKeyValue = 'Value'; const ExpressionKeyBlend = 'Blend';
const ExpressionKeyBlend = 'Blend'; const BlendValueAdd = 'Add';
const BlendValueAdd = 'Add'; const BlendValueMultiply = 'Multiply';
const BlendValueMultiply = 'Multiply'; const BlendValueOverwrite = 'Overwrite';
const BlendValueOverwrite = 'Overwrite'; const DefaultFadeTime = 1.0;
const DefaultFadeTime = 1.0;
/**
*
*
*
*/
export class CubismExpressionMotion extends ACubismMotion {
/** /**
* *
* * @param buffer exp
* * @param size
* @return
*/ */
export class CubismExpressionMotion extends ACubismMotion { public static create(
/** buffer: ArrayBuffer,
* size: number
* @param buffer exp ): CubismExpressionMotion {
* @param size const expression: CubismExpressionMotion = new CubismExpressionMotion();
* @return
*/
public static create(
buffer: ArrayBuffer,
size: number
): CubismExpressionMotion {
const expression: CubismExpressionMotion = new CubismExpressionMotion();
const json: CubismJson = CubismJson.create(buffer, size); const json: CubismJson = CubismJson.create(buffer, size);
const root: Value = json.getRoot(); const root: Value = json.getRoot();
expression.setFadeInTime( expression.setFadeInTime(
root.getValueByString(ExpressionKeyFadeIn).toFloat(DefaultFadeTime) root.getValueByString(ExpressionKeyFadeIn).toFloat(DefaultFadeTime)
); // フェードイン ); // フェードイン
expression.setFadeOutTime( expression.setFadeOutTime(
root.getValueByString(ExpressionKeyFadeOut).toFloat(DefaultFadeTime) 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) .getValueByString(ExpressionKeyParameters)
.getSize(); .getValueByIndex(i);
expression._parameters.prepareCapacity(parameterCount); const parameterId: CubismIdHandle = CubismFramework.getIdManager().getId(
param.getValueByString(ExpressionKeyId).getRawString()
); // パラメータID
for (let i = 0; i < parameterCount; ++i) { const value: number = param
const param: Value = root .getValueByString(ExpressionKeyValue)
.getValueByString(ExpressionKeyParameters) .toFloat(); // 値
.getValueByIndex(i);
const parameterId: CubismIdHandle = CubismFramework.getIdManager().getId(
param.getValueByString(ExpressionKeyId).getRawString()
); // パラメータID
const value: number = param // 計算方法の設定
.getValueByString(ExpressionKeyValue) let blendType: ExpressionBlendType;
.toFloat(); // 値
// 計算方法の設定 if (
let blendType: ExpressionBlendType; param.getValueByString(ExpressionKeyBlend).isNull() ||
param.getValueByString(ExpressionKeyBlend).getString() == BlendValueAdd
if ( ) {
param.getValueByString(ExpressionKeyBlend).isNull() || blendType = ExpressionBlendType.ExpressionBlendType_Add;
param.getValueByString(ExpressionKeyBlend).getString() == } else if (
BlendValueAdd param.getValueByString(ExpressionKeyBlend).getString() ==
) { BlendValueMultiply
blendType = ExpressionBlendType.ExpressionBlendType_Add; ) {
} else if ( blendType = ExpressionBlendType.ExpressionBlendType_Multiply;
param.getValueByString(ExpressionKeyBlend).getString() == } else if (
BlendValueMultiply param.getValueByString(ExpressionKeyBlend).getString() ==
) { BlendValueOverwrite
blendType = ExpressionBlendType.ExpressionBlendType_Multiply; ) {
} else if ( blendType = ExpressionBlendType.ExpressionBlendType_Overwrite;
param.getValueByString(ExpressionKeyBlend).getString() == } else {
BlendValueOverwrite // その他 仕様にない値を設定した時は加算モードにすることで復旧
) { blendType = ExpressionBlendType.ExpressionBlendType_Add;
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);
} }
CubismJson.delete(json); // JSONデータは不要になったら削除する // 設定オブジェクトを作成してリストに追加する
return expression; const item: ExpressionParameter = new ExpressionParameter();
item.parameterId = parameterId;
item.blendType = blendType;
item.value = value;
expression._parameters.pushBack(item);
} }
/** CubismJson.delete(json); // JSONデータは不要になったら削除する
* return expression;
* @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>; // 表情のパラメータ情報リスト
} }
/** /**
* *
* @param model
* @param userTimeSeconds []
* @param weight
* @param motionQueueEntry CubismMotionQueueManager
*/ */
export enum ExpressionBlendType { public doUpdateParameters(
ExpressionBlendType_Add = 0, // 加算 model: CubismModel,
ExpressionBlendType_Multiply = 1, // 乗算 userTimeSeconds: number,
ExpressionBlendType_Overwrite = 2 // 上書き 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 { constructor() {
parameterId: CubismIdHandle; // パラメータID super();
blendType: ExpressionBlendType; // パラメータの演算種類
value: number; // 値 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

View File

@ -5,136 +5,152 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * 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 { CubismIdHandle } from '../id/cubismid';
import { Live2DCubismFramework as csmstring } from '../type/csmstring'; import { csmString } from '../type/csmstring';
import { Live2DCubismFramework as csmvector } from '../type/csmvector'; import { csmVector } from '../type/csmvector';
import csmVector = csmvector.csmVector;
import csmString = csmstring.csmString;
import CubismIdHandle = cubismid.CubismIdHandle;
export namespace Live2DCubismFramework { /**
/** * @brief
* @brief *
* *
* */
*/ export enum CubismMotionCurveTarget {
export enum CubismMotionCurveTarget { CubismMotionCurveTarget_Model, // モデルに対して
CubismMotionCurveTarget_Model, // モデルに対して CubismMotionCurveTarget_Parameter, // パラメータに対して
CubismMotionCurveTarget_Parameter, // パラメータに対して CubismMotionCurveTarget_PartOpacity // パーツの不透明度に対して
CubismMotionCurveTarget_PartOpacity // パーツの不透明度に対して }
}
/**
/** * @brief
* @brief *
* *
* */
*/ export enum CubismMotionSegmentType {
export enum CubismMotionSegmentType { CubismMotionSegmentType_Linear = 0, // リニア
CubismMotionSegmentType_Linear = 0, // リニア CubismMotionSegmentType_Bezier = 1, // ベジェ曲線
CubismMotionSegmentType_Bezier = 1, // ベジェ曲線 CubismMotionSegmentType_Stepped = 2, // ステップ
CubismMotionSegmentType_Stepped = 2, // ステップ CubismMotionSegmentType_InverseStepped = 3 // インバースステップ
CubismMotionSegmentType_InverseStepped = 3 // インバースステップ }
}
/**
/** * @brief
* @brief *
* *
* */
*/ export class CubismMotionPoint {
export class CubismMotionPoint { time = 0.0; // 時間[秒]
time = 0.0; // 時間[秒] value = 0.0; // 値
value = 0.0; // 値 }
}
/**
/** *
* *
* * @param points
* @param points * @param time []
* @param time [] */
*/ export interface csmMotionSegmentEvaluationFunction {
export interface csmMotionSegmentEvaluationFunction { (points: CubismMotionPoint[], time: number): number;
(points: CubismMotionPoint[], time: number): number; }
}
/**
/** * @brief
* @brief *
* *
* */
*/ export class CubismMotionSegment {
export class CubismMotionSegment { /**
/** * @brief
* @brief *
* *
* */
*/ public constructor() {
public constructor() { this.evaluate = null;
this.evaluate = null; this.basePointIndex = 0;
this.basePointIndex = 0; this.segmentType = 0;
this.segmentType = 0; }
}
evaluate: csmMotionSegmentEvaluationFunction; // 使用する評価関数
evaluate: csmMotionSegmentEvaluationFunction; // 使用する評価関数 basePointIndex: number; // 最初のセグメントへのインデックス
basePointIndex: number; // 最初のセグメントへのインデックス segmentType: number; // セグメントの種類
segmentType: number; // セグメントの種類 }
}
/**
/** * @brief
* @brief *
* *
* */
*/ export class CubismMotionCurve {
export class CubismMotionCurve { public constructor() {
public constructor() { this.type = CubismMotionCurveTarget.CubismMotionCurveTarget_Model;
this.type = CubismMotionCurveTarget.CubismMotionCurveTarget_Model; this.segmentCount = 0;
this.segmentCount = 0; this.baseSegmentIndex = 0;
this.baseSegmentIndex = 0; this.fadeInTime = 0.0;
this.fadeInTime = 0.0; this.fadeOutTime = 0.0;
this.fadeOutTime = 0.0; }
}
type: CubismMotionCurveTarget; // カーブの種類
type: CubismMotionCurveTarget; // カーブの種類 id: CubismIdHandle; // カーブのID
id: CubismIdHandle; // カーブのID segmentCount: number; // セグメントの個数
segmentCount: number; // セグメントの個数 baseSegmentIndex: number; // 最初のセグメントのインデックス
baseSegmentIndex: number; // 最初のセグメントのインデックス fadeInTime: number; // フェードインにかかる時間[秒]
fadeInTime: number; // フェードインにかかる時間[秒] fadeOutTime: number; // フェードアウトにかかる時間[秒]
fadeOutTime: number; // フェードアウトにかかる時間[秒] }
}
/**
/** *
* */
*/ export class CubismMotionEvent {
export class CubismMotionEvent { fireTime = 0.0;
fireTime = 0.0; value: csmString;
value: csmString; }
}
/**
/** * @brief
* @brief *
* *
* */
*/ export class CubismMotionData {
export class CubismMotionData { public constructor() {
public constructor() { this.duration = 0.0;
this.duration = 0.0; this.loop = false;
this.loop = false; this.curveCount = 0;
this.curveCount = 0; this.eventCount = 0;
this.eventCount = 0; this.fps = 0.0;
this.fps = 0.0;
this.curves = new csmVector<CubismMotionCurve>();
this.curves = new csmVector<CubismMotionCurve>(); this.segments = new csmVector<CubismMotionSegment>();
this.segments = new csmVector<CubismMotionSegment>(); this.points = new csmVector<CubismMotionPoint>();
this.points = new csmVector<CubismMotionPoint>(); this.events = new csmVector<CubismMotionEvent>();
this.events = new csmVector<CubismMotionEvent>(); }
}
duration: number; // モーションの長さ[秒]
duration: number; // モーションの長さ[秒] loop: boolean; // ループするかどうか
loop: boolean; // ループするかどうか curveCount: number; // カーブの個数
curveCount: number; // カーブの個数 eventCount: number; // UserDataの個数
eventCount: number; // UserDataの個数 fps: number; // フレームレート
fps: number; // フレームレート curves: csmVector<CubismMotionCurve>; // カーブのリスト
curves: csmVector<CubismMotionCurve>; // カーブのリスト segments: csmVector<CubismMotionSegment>; // セグメントのリスト
segments: csmVector<CubismMotionSegment>; // セグメントのリスト points: csmVector<CubismMotionPoint>; // ポイントのリスト
points: csmVector<CubismMotionPoint>; // ポイントのリスト events: csmVector<CubismMotionEvent>; // イベントのリスト
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;
} }

View File

@ -5,355 +5,357 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * 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 { CubismIdHandle } from '../id/cubismid';
import { Live2DCubismFramework as cubismid } from '../id/cubismid'; import { CubismFramework } from '../live2dcubismframework';
import { Live2DCubismFramework as cubismframework } from '../live2dcubismframework'; import { csmString } from '../type/csmstring';
import { Live2DCubismFramework as csmstring } from '../type/csmstring'; import { CubismJson } from '../utils/cubismjson';
import csmString = csmstring.csmString;
import CubismFramework = cubismframework.CubismFramework;
import CubismIdHandle = cubismid.CubismIdHandle;
import CubismJson = cubismjson.CubismJson;
export namespace Live2DCubismFramework { // JSON keys
// JSON keys const Meta = 'Meta';
const Meta = 'Meta'; const Duration = 'Duration';
const Duration = 'Duration'; const Loop = 'Loop';
const Loop = 'Loop'; const CurveCount = 'CurveCount';
const CurveCount = 'CurveCount'; const Fps = 'Fps';
const Fps = 'Fps'; const TotalSegmentCount = 'TotalSegmentCount';
const TotalSegmentCount = 'TotalSegmentCount'; const TotalPointCount = 'TotalPointCount';
const TotalPointCount = 'TotalPointCount'; const Curves = 'Curves';
const Curves = 'Curves'; const Target = 'Target';
const Target = 'Target'; const Id = 'Id';
const Id = 'Id'; const FadeInTime = 'FadeInTime';
const FadeInTime = 'FadeInTime'; const FadeOutTime = 'FadeOutTime';
const FadeOutTime = 'FadeOutTime'; const Segments = 'Segments';
const Segments = 'Segments'; const UserData = 'UserData';
const UserData = 'UserData'; const UserDataCount = 'UserDataCount';
const UserDataCount = 'UserDataCount'; const TotalUserDataSize = 'TotalUserDataSize';
const TotalUserDataSize = 'TotalUserDataSize'; const Time = 'Time';
const Time = 'Time'; const Value = 'Value';
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 { public release(): void {
/** CubismJson.delete(this._json);
* }
* @param buffer motion3.json
* @param size
*/
public constructor(buffer: ArrayBuffer, size: number) {
this._json = CubismJson.create(buffer, size);
}
/** /**
* *
*/ * @return []
public release(): void { */
CubismJson.delete(this._json); public getMotionDuration(): number {
} return this._json
.getRoot()
.getValueByString(Meta)
.getValueByString(Duration)
.toFloat();
}
/** /**
* *
* @return [] * @return true
*/ * @return false
public getMotionDuration(): number { */
return this._json public isMotionLoop(): boolean {
.getRoot() return this._json
.getValueByString(Meta) .getRoot()
.getValueByString(Duration) .getValueByString(Meta)
.toFloat(); .getValueByString(Loop)
} .toBoolean();
}
/** /**
* *
* @return true * @return
* @return false */
*/ public getMotionCurveCount(): number {
public isMotionLoop(): boolean { return this._json
return this._json .getRoot()
.getRoot() .getValueByString(Meta)
.getValueByString(Meta) .getValueByString(CurveCount)
.getValueByString(Loop) .toInt();
.toBoolean(); }
}
/** /**
* *
* @return * @return [FPS]
*/ */
public getMotionCurveCount(): number { public getMotionFps(): number {
return this._json return this._json
.getRoot() .getRoot()
.getValueByString(Meta) .getValueByString(Meta)
.getValueByString(CurveCount) .getValueByString(Fps)
.toInt(); .toFloat();
} }
/** /**
* *
* @return [FPS] * @return
*/ */
public getMotionFps(): number { public getMotionTotalSegmentCount(): number {
return this._json return this._json
.getRoot() .getRoot()
.getValueByString(Meta) .getValueByString(Meta)
.getValueByString(Fps) .getValueByString(TotalSegmentCount)
.toFloat(); .toInt();
} }
/** /**
* *
* @return * @return
*/ */
public getMotionTotalSegmentCount(): number { public getMotionTotalPointCount(): number {
return this._json return this._json
.getRoot() .getRoot()
.getValueByString(Meta) .getValueByString(Meta)
.getValueByString(TotalSegmentCount) .getValueByString(TotalPointCount)
.toInt(); .toInt();
} }
/** /**
* *
* @return * @return true
*/ * @return false
public getMotionTotalPointCount(): number { */
return this._json public isExistMotionFadeInTime(): boolean {
.getRoot() return !this._json
.getValueByString(Meta) .getRoot()
.getValueByString(TotalPointCount) .getValueByString(Meta)
.toInt(); .getValueByString(FadeInTime)
} .isNull();
}
/** /**
* *
* @return true * @return true
* @return false * @return false
*/ */
public isExistMotionFadeInTime(): boolean { public isExistMotionFadeOutTime(): boolean {
return !this._json return !this._json
.getRoot() .getRoot()
.getValueByString(Meta) .getValueByString(Meta)
.getValueByString(FadeInTime) .getValueByString(FadeOutTime)
.isNull(); .isNull();
} }
/** /**
* *
* @return true * @return []
* @return false */
*/ public getMotionFadeInTime(): number {
public isExistMotionFadeOutTime(): boolean { return this._json
return !this._json .getRoot()
.getRoot() .getValueByString(Meta)
.getValueByString(Meta) .getValueByString(FadeInTime)
.getValueByString(FadeOutTime) .toFloat();
.isNull(); }
}
/** /**
* *
* @return [] * @return []
*/ */
public getMotionFadeInTime(): number { public getMotionFadeOutTime(): number {
return this._json return this._json
.getRoot() .getRoot()
.getValueByString(Meta) .getValueByString(Meta)
.getValueByString(FadeInTime) .getValueByString(FadeOutTime)
.toFloat(); .toFloat();
} }
/** /**
* *
* @return [] * @param curveIndex
*/ * @return
public getMotionFadeOutTime(): number { */
return this._json public getMotionCurveTarget(curveIndex: number): string {
.getRoot() return this._json
.getValueByString(Meta) .getRoot()
.getValueByString(FadeOutTime) .getValueByString(Curves)
.toFloat(); .getValueByIndex(curveIndex)
} .getValueByString(Target)
.getRawString();
}
/** /**
* * ID
* @param curveIndex * @param curveIndex
* @return * @return ID
*/ */
public getMotionCurveTarget(curveIndex: number): string { public getMotionCurveId(curveIndex: number): CubismIdHandle {
return this._json return CubismFramework.getIdManager().getId(
this._json
.getRoot() .getRoot()
.getValueByString(Curves) .getValueByString(Curves)
.getValueByIndex(curveIndex) .getValueByIndex(curveIndex)
.getValueByString(Target) .getValueByString(Id)
.getRawString(); .getRawString()
} );
}
/** /**
* ID *
* @param curveIndex * @param curveIndex
* @return ID * @return true
*/ * @return false
public getMotionCurveId(curveIndex: number): CubismIdHandle { */
return CubismFramework.getIdManager().getId( public isExistMotionCurveFadeInTime(curveIndex: number): boolean {
this._json return !this._json
.getRoot() .getRoot()
.getValueByString(Curves) .getValueByString(Curves)
.getValueByIndex(curveIndex) .getValueByIndex(curveIndex)
.getValueByString(Id) .getValueByString(FadeInTime)
.getRawString() .isNull();
); }
}
/** /**
* *
* @param curveIndex * @param curveIndex
* @return true * @return true
* @return false * @return false
*/ */
public isExistMotionCurveFadeInTime(curveIndex: number): boolean { public isExistMotionCurveFadeOutTime(curveIndex: number): boolean {
return !this._json return !this._json
.getRoot() .getRoot()
.getValueByString(Curves) .getValueByString(Curves)
.getValueByIndex(curveIndex) .getValueByIndex(curveIndex)
.getValueByString(FadeInTime) .getValueByString(FadeOutTime)
.isNull(); .isNull();
} }
/** /**
* *
* @param curveIndex * @param curveIndex
* @return true * @return []
* @return false */
*/ public getMotionCurveFadeInTime(curveIndex: number): number {
public isExistMotionCurveFadeOutTime(curveIndex: number): boolean { return this._json
return !this._json .getRoot()
.getRoot() .getValueByString(Curves)
.getValueByString(Curves) .getValueByIndex(curveIndex)
.getValueByIndex(curveIndex) .getValueByString(FadeInTime)
.getValueByString(FadeOutTime) .toFloat();
.isNull(); }
}
/** /**
* *
* @param curveIndex * @param curveIndex
* @return [] * @return []
*/ */
public getMotionCurveFadeInTime(curveIndex: number): number { public getMotionCurveFadeOutTime(curveIndex: number): number {
return this._json return this._json
.getRoot() .getRoot()
.getValueByString(Curves) .getValueByString(Curves)
.getValueByIndex(curveIndex) .getValueByIndex(curveIndex)
.getValueByString(FadeInTime) .getValueByString(FadeOutTime)
.toFloat(); .toFloat();
} }
/** /**
* *
* @param curveIndex * @param curveIndex
* @return [] * @return
*/ */
public getMotionCurveFadeOutTime(curveIndex: number): number { public getMotionCurveSegmentCount(curveIndex: number): number {
return this._json return this._json
.getRoot() .getRoot()
.getValueByString(Curves) .getValueByString(Curves)
.getValueByIndex(curveIndex) .getValueByIndex(curveIndex)
.getValueByString(FadeOutTime) .getValueByString(Segments)
.toFloat(); .getVector()
} .getSize();
}
/** /**
* *
* @param curveIndex * @param curveIndex
* @return * @param segmentIndex
*/ * @return
public getMotionCurveSegmentCount(curveIndex: number): number { */
return this._json public getMotionCurveSegment(
.getRoot() curveIndex: number,
.getValueByString(Curves) segmentIndex: number
.getValueByIndex(curveIndex) ): number {
.getValueByString(Segments) return this._json
.getVector() .getRoot()
.getSize(); .getValueByString(Curves)
} .getValueByIndex(curveIndex)
.getValueByString(Segments)
.getValueByIndex(segmentIndex)
.toFloat();
}
/** /**
* *
* @param curveIndex * @return
* @param segmentIndex */
* @return public getEventCount(): number {
*/ return this._json
public getMotionCurveSegment( .getRoot()
curveIndex: number, .getValueByString(Meta)
segmentIndex: number .getValueByString(UserDataCount)
): number { .toInt();
return this._json }
.getRoot()
.getValueByString(Curves)
.getValueByIndex(curveIndex)
.getValueByString(Segments)
.getValueByIndex(segmentIndex)
.toFloat();
}
/** /**
* *
* @return * @return
*/ */
public getEventCount(): number { public getTotalEventValueSize(): number {
return this._json return this._json
.getRoot() .getRoot()
.getValueByString(Meta) .getValueByString(Meta)
.getValueByString(UserDataCount) .getValueByString(TotalUserDataSize)
.toInt(); .toInt();
} }
/** /**
* *
* @return * @param userDataIndex
*/ * @return []
public getTotalEventValueSize(): number { */
return this._json public getEventTime(userDataIndex: number): number {
.getRoot() return this._json
.getValueByString(Meta) .getRoot()
.getValueByString(TotalUserDataSize) .getValueByString(UserData)
.toInt(); .getValueByIndex(userDataIndex)
} .getValueByString(Time)
.toInt();
}
/** /**
* *
* @param userDataIndex * @param userDataIndex
* @return [] * @return
*/ */
public getEventTime(userDataIndex: number): number { public getEventValue(userDataIndex: number): csmString {
return this._json return new csmString(
this._json
.getRoot() .getRoot()
.getValueByString(UserData) .getValueByString(UserData)
.getValueByIndex(userDataIndex) .getValueByIndex(userDataIndex)
.getValueByString(Time) .getValueByString(Value)
.toInt(); .getRawString()
} );
/**
*
* @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のデータ
} }
_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;
} }

View File

@ -5,120 +5,122 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as cubismmotionqueuemanager } from './cubismmotionqueuemanager'; import { CubismModel } from '../model/cubismmodel';
import { Live2DCubismFramework as acubismmotion } from './acubismmotion'; import { ACubismMotion } from './acubismmotion';
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel'; import {
import CubismMotionQueueEntryHandle = cubismmotionqueuemanager.CubismMotionQueueEntryHandle; CubismMotionQueueEntryHandle,
import CubismModel = cubismmodel.CubismModel; CubismMotionQueueManager
import ACubismMotion = acubismmotion.ACubismMotion; } from './cubismmotionqueuemanager';
import CubismMotionQueueManager = cubismmotionqueuemanager.CubismMotionQueueManager;
export namespace Live2DCubismFramework { /**
*
*
*
*/
export class CubismMotionManager extends CubismMotionQueueManager {
/** /**
* *
*
*
*/ */
export class CubismMotionManager extends CubismMotionQueueManager { public constructor() {
/** super();
* this._currentPriority = 0;
*/ this._reservePriority = 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になる。モーションファイルを別スレッドで読み込むときの機能。
} }
/**
*
* @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;
} }

View File

@ -5,245 +5,249 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as acubismmotion } from './acubismmotion'; import { ACubismMotion } from './acubismmotion';
import { Live2DCubismFramework as cubismmotionqueuemanager } from './cubismmotionqueuemanager'; import { CubismMotionQueueEntryHandle } from './cubismmotionqueuemanager';
import CubismMotionQueueEntryHandle = cubismmotionqueuemanager.CubismMotionQueueEntryHandle;
import ACubismMotion = acubismmotion.ACubismMotion;
export namespace Live2DCubismFramework { /**
* CubismMotionQueueManager
*/
export class CubismMotionQueueEntry {
/** /**
* CubismMotionQueueManager *
*/ */
export class CubismMotionQueueEntry { public constructor() {
/** this._autoDelete = false;
* this._motion = null;
*/ this._available = true;
public constructor() { this._finished = false;
this._autoDelete = false; this._started = false;
this._motion = null; this._startTimeSeconds = -1.0;
this._available = true; this._fadeInStartTimeSeconds = 0.0;
this._finished = false; this._endTimeSeconds = -1.0;
this._started = false; this._stateTimeSeconds = 0.0;
this._startTimeSeconds = -1.0; this._stateWeight = 0.0;
this._fadeInStartTimeSeconds = 0.0; this._lastEventCheckSeconds = 0.0;
this._endTimeSeconds = -1.0; this._motionQueueEntryHandle = this;
this._stateTimeSeconds = 0.0; this._fadeOutSeconds = 0.0;
this._stateWeight = 0.0; this._isTriggeredFadeOut = false;
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 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;
} }

View File

@ -5,346 +5,345 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as acubismmotion } from './acubismmotion'; import { ACubismMotion } from './acubismmotion';
import { Live2DCubismFramework as cubismmotionqueueentry } from './cubismmotionqueueentry'; import { CubismMotionQueueEntry } from './cubismmotionqueueentry';
import { Live2DCubismFramework as csmvector } from '../type/csmvector'; import { csmVector, iterator } from '../type/csmvector';
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel'; import { CubismModel } from '../model/cubismmodel';
import { Live2DCubismFramework as csmstring } from '../type/csmstring'; import { 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;
export namespace Live2DCubismFramework { /**
*
*
* CubismMotionACubismMotion使
*
* @note StartMotion()
*
* CubismMotionQueueManager使
*/
export class CubismMotionQueueManager {
/** /**
* *
*
* CubismMotionACubismMotion使
*
* @note StartMotion()
*
* CubismMotionQueueManager使
*/ */
export class CubismMotionQueueManager { public constructor() {
/** this._userTimeSeconds = 0.0;
* this._eventCallBack = null;
*/ this._eventCustomData = null;
public constructor() { this._motions = new csmVector<CubismMotionQueueEntry>();
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);
}
} }
/** this._motions = 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); * @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()); // フェードアウト設定
} }
/** motionQueueEntry = new CubismMotionQueueEntry(); // 終了時に破棄する
* motionQueueEntry._autoDelete = autoDelete;
* motionQueueEntry._motion = motion;
*
* this._motions.pushBack(motionQueueEntry);
* @param motion
* @param autoDelete true return motionQueueEntry._motionQueueEntryHandle;
* @param userTimeSeconds [] }
* @return IsFinished()使-1
*/ /**
public startMotion( *
motion: ACubismMotion, * @return true
autoDelete: boolean, * @return false
userTimeSeconds: number */
): CubismMotionQueueEntryHandle { 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) { 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.release();
motionQueueEntry = void 0; motionQueueEntry = void 0;
motionQueueEntry = null; motionQueueEntry = null;
ite = this._motions.erase(ite); // 削除 ite = this._motions.erase(ite); // 削除
continue;
}
// ----- 終了済みの処理があれば削除する ------
if (!motionQueueEntry.isFinished()) {
return false;
} else {
ite.preIncrement();
} }
} }
/** return true;
* 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 motionQueueEntryNumber
* * @return true
* @param caller CubismMotionQueueManager * @return false
* @param eventValue
* @param customData
*/ */
export interface CubismMotionEventFunction { public isFinishedByHandle(
( motionQueueEntryNumber: CubismMotionQueueEntryHandle
caller: CubismMotionQueueManager, ): boolean {
eventValue: csmString, // 既にモーションがあれば終了フラグを立てる
customData: any for (
): void; 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; public stopAllMotions(): void {
export const InvalidMotionQueueEntryHandleValue: CubismMotionQueueEntryHandle = -1; // ------- 処理を行う -------
// 既にモーションがあれば終了フラグを立てる
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;
} }

File diff suppressed because it is too large Load Diff

View File

@ -5,221 +5,245 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as cubismvector2 } from '../math/cubismvector2'; import { CubismIdHandle } from '../id/cubismid';
import { Live2DCubismFramework as cubismid } from '../id/cubismid'; import { CubismVector2 } from '../math/cubismvector2';
import { Live2DCubismFramework as csmvector } from '../type/csmvector'; import { csmVector } from '../type/csmvector';
import csmVector = csmvector.csmVector;
import CubismIdHandle = cubismid.CubismIdHandle;
import CubismVector2 = cubismvector2.CubismVector2;
export namespace Live2DCubismFramework { /**
/** *
* */
*/ export enum CubismPhysicsTargetType {
export enum CubismPhysicsTargetType { CubismPhysicsTargetType_Parameter // パラメータに対して適用
CubismPhysicsTargetType_Parameter // パラメータに対して適用 }
}
/**
/** *
* */
*/ export enum CubismPhysicsSource {
export enum CubismPhysicsSource { CubismPhysicsSource_X, // X軸の位置から
CubismPhysicsSource_X, // X軸の位置から CubismPhysicsSource_Y, // Y軸の位置から
CubismPhysicsSource_Y, // Y軸の位置から CubismPhysicsSource_Angle // 角度から
CubismPhysicsSource_Angle // 角度から }
}
/**
/** * @brief 使
* @brief 使 *
* * 使
* 使 */
*/ export class PhysicsJsonEffectiveForces {
export class PhysicsJsonEffectiveForces { constructor() {
constructor() { this.gravity = new CubismVector2(0, 0);
this.gravity = new CubismVector2(0, 0); this.wind = new CubismVector2(0, 0);
this.wind = new CubismVector2(0, 0); }
} gravity: CubismVector2; // 重力
gravity: CubismVector2; // 重力 wind: CubismVector2; // 風
wind: CubismVector2; // 風 }
}
/**
/** *
* */
*/ export class CubismPhysicsParameter {
export class CubismPhysicsParameter { id: CubismIdHandle; // パラメータ
id: CubismIdHandle; // パラメータ targetType: CubismPhysicsTargetType; // 適用先の種類
targetType: CubismPhysicsTargetType; // 適用先の種類 }
}
/**
/** *
* */
*/ export class CubismPhysicsNormalization {
export class CubismPhysicsNormalization { minimum: number; // 最大値
minimum: number; // 最大値 maximum: number; // 最小値
maximum: number; // 最小値 defalut: number; // デフォルト値
defalut: number; // デフォルト値 }
}
/**
/** * 使
* 使 */
*/ export class CubismPhysicsParticle {
export class CubismPhysicsParticle { constructor() {
constructor() { this.initialPosition = new CubismVector2(0, 0);
this.initialPosition = new CubismVector2(0, 0); this.position = new CubismVector2(0, 0);
this.position = new CubismVector2(0, 0); this.lastPosition = new CubismVector2(0, 0);
this.lastPosition = new CubismVector2(0, 0); this.lastGravity = new CubismVector2(0, 0);
this.lastGravity = new CubismVector2(0, 0); this.force = new CubismVector2(0, 0);
this.force = new CubismVector2(0, 0); this.velocity = new CubismVector2(0, 0);
this.velocity = new CubismVector2(0, 0); }
}
initialPosition: CubismVector2; // 初期位置
initialPosition: CubismVector2; // 初期位置 mobility: number; // 動きやすさ
mobility: number; // 動きやすさ delay: number; // 遅れ
delay: number; // 遅れ acceleration: number; // 加速度
acceleration: number; // 加速度 radius: number; // 距離
radius: number; // 距離 position: CubismVector2; // 現在の位置
position: CubismVector2; // 現在の位置 lastPosition: CubismVector2; // 最後の位置
lastPosition: CubismVector2; // 最後の位置 lastGravity: CubismVector2; // 最後の重力
lastGravity: CubismVector2; // 最後の重力 force: CubismVector2; // 現在かかっている力
force: CubismVector2; // 現在かかっている力 velocity: CubismVector2; // 現在の速度
velocity: CubismVector2; // 現在の速度 }
}
/**
/** *
* */
*/ export class CubismPhysicsSubRig {
export class CubismPhysicsSubRig { constructor() {
constructor() { this.normalizationPosition = new CubismPhysicsNormalization();
this.normalizationPosition = new CubismPhysicsNormalization(); this.normalizationAngle = new CubismPhysicsNormalization();
this.normalizationAngle = new CubismPhysicsNormalization(); }
} inputCount: number; // 入力の個数
inputCount: number; // 入力の個数 outputCount: number; // 出力の個数
outputCount: number; // 出力の個数 particleCount: number; // 物理点の個数
particleCount: number; // 物理点の個数 baseInputIndex: number; // 入力の最初のインデックス
baseInputIndex: number; // 入力の最初のインデックス baseOutputIndex: number; // 出力の最初のインデックス
baseOutputIndex: number; // 出力の最初のインデックス baseParticleIndex: number; // 物理点の最初のインデックス
baseParticleIndex: number; // 物理点の最初のインデックス normalizationPosition: CubismPhysicsNormalization; // 正規化された位置
normalizationPosition: CubismPhysicsNormalization; // 正規化された位置 normalizationAngle: CubismPhysicsNormalization; // 正規化された角度
normalizationAngle: CubismPhysicsNormalization; // 正規化された角度 }
}
/**
/** *
* * @param targetTranslation // 演算結果の移動値
* @param targetTranslation // 演算結果の移動値 * @param targetAngle // 演算結果の角度
* @param targetAngle // 演算結果の角度 * @param value // パラメータの値
* @param value // パラメータの値 * @param parameterMinimunValue // パラメータの最小値
* @param parameterMinimunValue // パラメータの最小値 * @param parameterMaximumValue // パラメータの最大値
* @param parameterMaximumValue // パラメータの最大値 * @param parameterDefaultValue // パラメータのデフォルト値
* @param parameterDefaultValue // パラメータのデフォルト値 * @param normalizationPosition // 正規化された位置
* @param normalizationPosition // 正規化された位置 * @param normalizationAngle // 正規化された角度
* @param normalizationAngle // 正規化された角度 * @param isInverted // 値が反転されているか?
* @param isInverted // 値が反転されているか? * @param weight // 重み
* @param weight // 重み */
*/ export interface normalizedPhysicsParameterValueGetter {
export interface normalizedPhysicsParameterValueGetter { (
( targetTranslation: CubismVector2,
targetTranslation: CubismVector2, targetAngle: { angle: number },
targetAngle: { angle: number }, value: number,
value: number, parameterMinimunValue: number,
parameterMinimunValue: number, parameterMaximumValue: number,
parameterMaximumValue: number, parameterDefaultValue: number,
parameterDefaultValue: number, normalizationPosition: CubismPhysicsNormalization,
normalizationPosition: CubismPhysicsNormalization, normalizationAngle: CubismPhysicsNormalization,
normalizationAngle: CubismPhysicsNormalization, isInverted: boolean,
isInverted: boolean, weight: number
weight: number ): void;
): void; }
}
/**
/** *
* * @param translation
* @param translation * @param particles
* @param particles * @param isInverted
* @param isInverted * @param parentGravity
* @param parentGravity * @return
* @return */
*/ export interface physicsValueGetter {
export interface physicsValueGetter { (
( translation: CubismVector2,
translation: CubismVector2, particles: CubismPhysicsParticle[],
particles: CubismPhysicsParticle[], particleIndex: number,
particleIndex: number, isInverted: boolean,
isInverted: boolean, parentGravity: CubismVector2
parentGravity: CubismVector2 ): number;
): number; }
}
/**
/** *
* * @param translationScale
* @param translationScale * @param angleScale
* @param angleScale * @return
* @return */
*/ export interface physicsScaleGetter {
export interface physicsScaleGetter { (translationScale: CubismVector2, angleScale: number): number;
(translationScale: CubismVector2, angleScale: number): number; }
}
/**
/** *
* */
*/ export class CubismPhysicsInput {
export class CubismPhysicsInput { constructor() {
constructor() { this.source = new CubismPhysicsParameter();
this.source = new CubismPhysicsParameter(); }
} source: CubismPhysicsParameter; // 入力元のパラメータ
source: CubismPhysicsParameter; // 入力元のパラメータ sourceParameterIndex: number; // 入力元のパラメータのインデックス
sourceParameterIndex: number; // 入力元のパラメータのインデックス weight: number; // 重み
weight: number; // 重み type: number; // 入力の種類
type: number; // 入力の種類 reflect: boolean; // 値が反転されているかどうか
reflect: boolean; // 値が反転されているかどうか getNormalizedParameterValue: normalizedPhysicsParameterValueGetter; // 正規化されたパラメータ値の取得関数
getNormalizedParameterValue: normalizedPhysicsParameterValueGetter; // 正規化されたパラメータ値の取得関数 }
}
/**
/** * @brief
* @brief *
* *
* */
*/ export class CubismPhysicsOutput {
export class CubismPhysicsOutput { constructor() {
constructor() { this.destination = new CubismPhysicsParameter();
this.destination = new CubismPhysicsParameter(); this.translationScale = new CubismVector2(0, 0);
this.translationScale = new CubismVector2(0, 0); }
}
destination: CubismPhysicsParameter; // 出力先のパラメータ
destination: CubismPhysicsParameter; // 出力先のパラメータ destinationParameterIndex: number; // 出力先のパラメータのインデックス
destinationParameterIndex: number; // 出力先のパラメータのインデックス vertexIndex: number; // 振り子のインデックス
vertexIndex: number; // 振り子のインデックス translationScale: CubismVector2; // 移動値のスケール
translationScale: CubismVector2; // 移動値のスケール angleScale: number; // 角度のスケール
angleScale: number; // 角度のスケール weight: number; // 重み
weight: number; // 重み type: CubismPhysicsSource; // 出力の種類
type: CubismPhysicsSource; // 出力の種類 reflect: boolean; // 値が反転されているかどうか
reflect: boolean; // 値が反転されているかどうか valueBelowMinimum: number; // 最小値を下回った時の値
valueBelowMinimum: number; // 最小値を下回った時の値 valueExceededMaximum: number; // 最大値をこえた時の値
valueExceededMaximum: number; // 最大値をこえた時の値 getValue: physicsValueGetter; // 物理演算の値の取得関数
getValue: physicsValueGetter; // 物理演算の値の取得関数 getScale: physicsScaleGetter; // 物理演算のスケール値の取得関数
getScale: physicsScaleGetter; // 物理演算のスケール値の取得関数 }
}
/**
/** * @brief
* @brief *
* *
* */
*/ export class CubismPhysicsRig {
export class CubismPhysicsRig { constructor() {
constructor() { this.settings = new csmVector<CubismPhysicsSubRig>();
this.settings = new csmVector<CubismPhysicsSubRig>(); this.inputs = new csmVector<CubismPhysicsInput>();
this.inputs = new csmVector<CubismPhysicsInput>(); this.outputs = new csmVector<CubismPhysicsOutput>();
this.outputs = new csmVector<CubismPhysicsOutput>(); this.particles = new csmVector<CubismPhysicsParticle>();
this.particles = new csmVector<CubismPhysicsParticle>(); this.gravity = new CubismVector2(0, 0);
this.gravity = new CubismVector2(0, 0); this.wind = new CubismVector2(0, 0);
this.wind = new CubismVector2(0, 0); }
}
subRigCount: number; // 物理演算の物理点の個数
subRigCount: number; // 物理演算の物理点の個数 settings: csmVector<CubismPhysicsSubRig>; // 物理演算の物理点の管理のリスト
settings: csmVector<CubismPhysicsSubRig>; // 物理演算の物理点の管理のリスト inputs: csmVector<CubismPhysicsInput>; // 物理演算の入力のリスト
inputs: csmVector<CubismPhysicsInput>; // 物理演算の入力のリスト outputs: csmVector<CubismPhysicsOutput>; // 物理演算の出力のリスト
outputs: csmVector<CubismPhysicsOutput>; // 物理演算の出力のリスト particles: csmVector<CubismPhysicsParticle>; // 物理演算の物理点のリスト
particles: csmVector<CubismPhysicsParticle>; // 物理演算の物理点のリスト gravity: CubismVector2; // 重力
gravity: CubismVector2; // 重力 wind: CubismVector2; // 風
wind: CubismVector2; // 風 }
}
// Namespace definition for compatibility.
import * as $ from './cubismphysicsinternal';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismPhysicsInput = $.CubismPhysicsInput;
export type CubismPhysicsInput = $.CubismPhysicsInput;
export const CubismPhysicsNormalization = $.CubismPhysicsNormalization;
export type CubismPhysicsNormalization = $.CubismPhysicsNormalization;
export const CubismPhysicsOutput = $.CubismPhysicsOutput;
export type CubismPhysicsOutput = $.CubismPhysicsOutput;
export const CubismPhysicsParameter = $.CubismPhysicsParameter;
export type CubismPhysicsParameter = $.CubismPhysicsParameter;
export const CubismPhysicsParticle = $.CubismPhysicsParticle;
export type CubismPhysicsParticle = $.CubismPhysicsParticle;
export const CubismPhysicsRig = $.CubismPhysicsRig;
export type CubismPhysicsRig = $.CubismPhysicsRig;
export const CubismPhysicsSource = $.CubismPhysicsSource;
export type CubismPhysicsSource = $.CubismPhysicsSource;
export const CubismPhysicsSubRig = $.CubismPhysicsSubRig;
export type CubismPhysicsSubRig = $.CubismPhysicsSubRig;
export const CubismPhysicsTargetType = $.CubismPhysicsTargetType;
export type CubismPhysicsTargetType = $.CubismPhysicsTargetType;
export const PhysicsJsonEffectiveForces = $.PhysicsJsonEffectiveForces;
export type PhysicsJsonEffectiveForces = $.PhysicsJsonEffectiveForces;
export type normalizedPhysicsParameterValueGetter = $.normalizedPhysicsParameterValueGetter;
export type physicsScaleGetter = $.physicsScaleGetter;
export type physicsValueGetter = $.physicsValueGetter;
} }

File diff suppressed because it is too large Load Diff

View File

@ -5,263 +5,271 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import { Live2DCubismFramework as cubismmatrix44 } from '../math/cubismmatrix44'; import { CubismMatrix44 } from '../math/cubismmatrix44';
import { Live2DCubismFramework as cubismmodel } from '../model/cubismmodel'; import { CubismModel } from '../model/cubismmodel';
import CubismModel = cubismmodel.CubismModel;
import CubismMatrix44 = cubismmatrix44.CubismMatrix44;
export namespace Live2DCubismFramework { /**
*
*
*
*/
export abstract class CubismRenderer {
/** /**
* *
* *
* * @return
*/ */
export abstract class CubismRenderer { public static create(): CubismRenderer {
/** return null;
*
*
* @return
*/
public static create(): CubismRenderer {
return null;
}
/**
*
*/
public static delete(renderer: CubismRenderer): void {
renderer = null;
}
/**
*
*
* @param model
*/
public initialize(model: CubismModel): void {
this._model = model;
}
/**
*
*/
public drawModel(): void {
if (this.getModel() == null) return;
this.doDrawModel();
}
/**
* Model-View-Projection
*
* @param matrix44 Model-View-Projection
*/
public setMvpMatrix(matrix44: CubismMatrix44): void {
this._mvpMatrix4x4.setMatrix(matrix44.getArray());
}
/**
* Model-View-Projection
* @return Model-View-Projection
*/
public getMvpMatrix(): CubismMatrix44 {
return this._mvpMatrix4x4;
}
/**
*
* 0.0~1.01.0
* @param red
* @param green
* @param blue
* @param alpha α
*/
public setModelColor(
red: number,
green: number,
blue: number,
alpha: number
): void {
if (red < 0.0) {
red = 0.0;
} else if (red > 1.0) {
red = 1.0;
}
if (green < 0.0) {
green = 0.0;
} else if (green > 1.0) {
green = 1.0;
}
if (blue < 0.0) {
blue = 0.0;
} else if (blue > 1.0) {
blue = 1.0;
}
if (alpha < 0.0) {
alpha = 0.0;
} else if (alpha > 1.0) {
alpha = 1.0;
}
this._modelColor.R = red;
this._modelColor.G = green;
this._modelColor.B = blue;
this._modelColor.A = alpha;
}
/**
*
* 0.0~1.0(1.0)
*
* @return RGBA
*/
public getModelColor(): CubismTextureColor {
return JSON.parse(JSON.stringify(this._modelColor));
}
/**
* α
* truefalse
*/
public setIsPremultipliedAlpha(enable: boolean): void {
this._isPremultipliedAlpha = enable;
}
/**
* α
* @return true α
* @return false α
*/
public isPremultipliedAlpha(): boolean {
return this._isPremultipliedAlpha;
}
/**
*
* truefalse
*/
public setIsCulling(culling: boolean): void {
this._isCulling = culling;
}
/**
*
* @return true
* @return false
*/
public isCulling(): boolean {
return this._isCulling;
}
/**
*
*
* @param n
*/
public setAnisotropy(n: number): void {
this._anisortopy = n;
}
/**
*
* @return
*/
public getAnisotropy(): number {
return this._anisortopy;
}
/**
*
* @return
*/
public getModel(): CubismModel {
return this._model;
}
/**
*
*/
protected constructor() {
this._isCulling = false;
this._isPremultipliedAlpha = false;
this._anisortopy = 0.0;
this._model = null;
this._modelColor = new CubismTextureColor();
// 単位行列に初期化
this._mvpMatrix4x4 = new CubismMatrix44();
this._mvpMatrix4x4.loadIdentity();
}
/**
*
*/
public abstract doDrawModel(): void;
/**
*
*
* @param textureNo
* @param indexCount
* @param vertexCount
* @param indexArray
* @param vertexArray
* @param uvArray uv
* @param opacity
* @param colorBlendMode
* @param invertedMask 使使
*/
public abstract drawMesh(
textureNo: number,
indexCount: number,
vertexCount: number,
indexArray: Uint16Array,
vertexArray: Float32Array,
uvArray: Float32Array,
opacity: number,
colorBlendMode: CubismBlendMode,
invertedMask: boolean
): void;
/**
*
*/
public static staticRelease: Function;
protected _mvpMatrix4x4: CubismMatrix44; // Model-View-Projection 行列
protected _modelColor: CubismTextureColor; // モデル自体のカラーRGBA
protected _isCulling: boolean; // カリングが有効ならtrue
protected _isPremultipliedAlpha: boolean; // 乗算済みαならtrue
protected _anisortopy: any; // テクスチャの異方性フィルタリングのパラメータ
protected _model: CubismModel; // レンダリング対象のモデル
}
export enum CubismBlendMode {
CubismBlendMode_Normal = 0, // 通常
CubismBlendMode_Additive = 1, // 加算
CubismBlendMode_Multiplicative = 2 // 乗算
} }
/** /**
* RGBA *
*/ */
export class CubismTextureColor { public static delete(renderer: CubismRenderer): void {
/** renderer = null;
* }
*/
constructor() { /**
this.R = 1.0; *
this.G = 1.0; *
this.B = 1.0; * @param model
this.A = 1.0; */
public initialize(model: CubismModel): void {
this._model = model;
}
/**
*
*/
public drawModel(): void {
if (this.getModel() == null) return;
this.doDrawModel();
}
/**
* Model-View-Projection
*
* @param matrix44 Model-View-Projection
*/
public setMvpMatrix(matrix44: CubismMatrix44): void {
this._mvpMatrix4x4.setMatrix(matrix44.getArray());
}
/**
* Model-View-Projection
* @return Model-View-Projection
*/
public getMvpMatrix(): CubismMatrix44 {
return this._mvpMatrix4x4;
}
/**
*
* 0.0~1.01.0
* @param red
* @param green
* @param blue
* @param alpha α
*/
public setModelColor(
red: number,
green: number,
blue: number,
alpha: number
): void {
if (red < 0.0) {
red = 0.0;
} else if (red > 1.0) {
red = 1.0;
} }
R: number; // 赤チャンネル if (green < 0.0) {
G: number; // 緑チャンネル green = 0.0;
B: number; // 青チャンネル } else if (green > 1.0) {
A: number; // αチャンネル green = 1.0;
}
if (blue < 0.0) {
blue = 0.0;
} else if (blue > 1.0) {
blue = 1.0;
}
if (alpha < 0.0) {
alpha = 0.0;
} else if (alpha > 1.0) {
alpha = 1.0;
}
this._modelColor.R = red;
this._modelColor.G = green;
this._modelColor.B = blue;
this._modelColor.A = alpha;
} }
/**
*
* 0.0~1.0(1.0)
*
* @return RGBA
*/
public getModelColor(): CubismTextureColor {
return JSON.parse(JSON.stringify(this._modelColor));
}
/**
* α
* truefalse
*/
public setIsPremultipliedAlpha(enable: boolean): void {
this._isPremultipliedAlpha = enable;
}
/**
* α
* @return true α
* @return false α
*/
public isPremultipliedAlpha(): boolean {
return this._isPremultipliedAlpha;
}
/**
*
* truefalse
*/
public setIsCulling(culling: boolean): void {
this._isCulling = culling;
}
/**
*
* @return true
* @return false
*/
public isCulling(): boolean {
return this._isCulling;
}
/**
*
*
* @param n
*/
public setAnisotropy(n: number): void {
this._anisortopy = n;
}
/**
*
* @return
*/
public getAnisotropy(): number {
return this._anisortopy;
}
/**
*
* @return
*/
public getModel(): CubismModel {
return this._model;
}
/**
*
*/
protected constructor() {
this._isCulling = false;
this._isPremultipliedAlpha = false;
this._anisortopy = 0.0;
this._model = null;
this._modelColor = new CubismTextureColor();
// 単位行列に初期化
this._mvpMatrix4x4 = new CubismMatrix44();
this._mvpMatrix4x4.loadIdentity();
}
/**
*
*/
public abstract doDrawModel(): void;
/**
*
*
* @param textureNo
* @param indexCount
* @param vertexCount
* @param indexArray
* @param vertexArray
* @param uvArray uv
* @param opacity
* @param colorBlendMode
* @param invertedMask 使使
*/
public abstract drawMesh(
textureNo: number,
indexCount: number,
vertexCount: number,
indexArray: Uint16Array,
vertexArray: Float32Array,
uvArray: Float32Array,
opacity: number,
colorBlendMode: CubismBlendMode,
invertedMask: boolean
): void;
/**
*
*/
public static staticRelease: Function;
protected _mvpMatrix4x4: CubismMatrix44; // Model-View-Projection 行列
protected _modelColor: CubismTextureColor; // モデル自体のカラーRGBA
protected _isCulling: boolean; // カリングが有効ならtrue
protected _isPremultipliedAlpha: boolean; // 乗算済みαならtrue
protected _anisortopy: any; // テクスチャの異方性フィルタリングのパラメータ
protected _model: CubismModel; // レンダリング対象のモデル
}
export enum CubismBlendMode {
CubismBlendMode_Normal = 0, // 通常
CubismBlendMode_Additive = 1, // 加算
CubismBlendMode_Multiplicative = 2 // 乗算
}
/**
* RGBA
*/
export class CubismTextureColor {
/**
*
*/
constructor() {
this.R = 1.0;
this.G = 1.0;
this.B = 1.0;
this.A = 1.0;
}
R: number; // 赤チャンネル
G: number; // 緑チャンネル
B: number; // 青チャンネル
A: number; // αチャンネル
}
// Namespace definition for compatibility.
import * as $ from './cubismrenderer';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismBlendMode = $.CubismBlendMode;
export type CubismBlendMode = $.CubismBlendMode;
export const CubismRenderer = $.CubismRenderer;
export type CubismRenderer = $.CubismRenderer;
export const CubismTextureColor = $.CubismTextureColor;
export type CubismTextureColor = $.CubismTextureColor;
} }

File diff suppressed because it is too large Load Diff

View File

@ -7,299 +7,309 @@
import { CubismLogDebug } from '../utils/cubismdebug'; import { CubismLogDebug } from '../utils/cubismdebug';
export namespace Live2DCubismFramework { /**
* Key-Value
* csmMap使
*/
export class csmPair<_KeyT, _ValT> {
/** /**
* Key-Value *
* csmMap使 * @param key Key
* @param value Value
*/ */
export class csmPair<_KeyT, _ValT> { public constructor(key?: _KeyT, value?: _ValT) {
/** this.first = key == undefined ? null : key;
*
* @param key Key
* @param value Value
*/
public constructor(key?: _KeyT, value?: _ValT) {
this.first = key == undefined ? null : key;
this.second = value == undefined ? null : value; this.second = value == undefined ? null : value;
}
public first: _KeyT; // keyとして用いる変数
public second: _ValT; // valueとして用いる変数
} }
public first: _KeyT; // keyとして用いる変数
public second: _ValT; // valueとして用いる変数
}
/**
*
*/
export class csmMap<_KeyT, _ValT> {
/** /**
* *
* @param size
*/ */
export class csmMap<_KeyT, _ValT> { public constructor(size?: number) {
/** if (size != undefined) {
* if (size < 1) {
* @param size
*/
public constructor(size?: number) {
if (size != undefined) {
if (size < 1) {
this._keyValues = [];
this._dummyValue = null;
this._size = 0;
} else {
this._keyValues = new Array(size);
this._size = size;
}
} else {
this._keyValues = []; this._keyValues = [];
this._dummyValue = null; this._dummyValue = null;
this._size = 0; this._size = 0;
}
}
/**
*
*/
public release() {
this.clear();
}
/**
*
* @param key
*/
public appendKey(key: _KeyT): void {
// 新しくKey/Valueのペアを作る
this.prepareCapacity(this._size + 1, false); // 1つ以上入る隙間を作る
// 新しいkey/valueのインデックスは_size
this._keyValues[this._size] = new csmPair<_KeyT, _ValT>(key);
this._size += 1;
}
/**
* [key](get)
* @param key Value
*/
public getValue(key: _KeyT): _ValT {
let found = -1;
for (let i = 0; i < this._size; i++) {
if (this._keyValues[i].first == key) {
found = i;
break;
}
}
if (found >= 0) {
return this._keyValues[found].second;
} else { } else {
this.appendKey(key); // 新規キーを追加 this._keyValues = new Array(size);
return this._keyValues[this._size - 1].second; this._size = size;
} }
} } else {
/**
* [key](set)
* @param key Value
* @param value Value
*/
public setValue(key: _KeyT, value: _ValT): void {
let found = -1;
for (let i = 0; i < this._size; i++) {
if (this._keyValues[i].first == key) {
found = i;
break;
}
}
if (found >= 0) {
this._keyValues[found].second = value;
} else {
this.appendKey(key); // 新規キーを追加
this._keyValues[this._size - 1].second = value;
}
}
/**
* Key
* @param key key
* @return true key
* @return false key
*/
public isExist(key: _KeyT): boolean {
for (let i = 0; i < this._size; i++) {
if (this._keyValues[i].first == key) {
return true;
}
}
return false;
}
/**
* keyValue
*/
public clear(): void {
this._keyValues = void 0;
this._keyValues = null;
this._keyValues = []; this._keyValues = [];
this._dummyValue = null;
this._size = 0; this._size = 0;
} }
/**
*
*
* @return
*/
public getSize(): number {
return this._size;
}
/**
*
* @param newSize
* @param fitToSize truefalse2
*/
public prepareCapacity(newSize: number, fitToSize: boolean): void {
if (newSize > this._keyValues.length) {
if (this._keyValues.length == 0) {
if (!fitToSize && newSize < csmMap.DefaultSize)
newSize = csmMap.DefaultSize;
this._keyValues.length = newSize;
} else {
if (!fitToSize && newSize < this._keyValues.length * 2)
newSize = this._keyValues.length * 2;
this._keyValues.length = newSize;
}
}
}
/**
*
*/
public begin(): iterator<_KeyT, _ValT> {
const ite: iterator<_KeyT, _ValT> = new iterator<_KeyT, _ValT>(this, 0);
return ite;
}
/**
*
*/
public end(): iterator<_KeyT, _ValT> {
const ite: iterator<_KeyT, _ValT> = new iterator<_KeyT, _ValT>(
this,
this._size
); // 終了
return ite;
}
/**
*
*
* @param ite
*/
public erase(ite: iterator<_KeyT, _ValT>): iterator<_KeyT, _ValT> {
const index: number = ite._index;
if (index < 0 || this._size <= index) {
return ite; // 削除範囲外
}
// 削除
this._keyValues.splice(index, 1);
--this._size;
const ite2: iterator<_KeyT, _ValT> = new iterator<_KeyT, _ValT>(
this,
index
); // 終了
return ite2;
}
/**
* 32
*/
public dumpAsInt() {
for (let i = 0; i < this._size; i++) {
CubismLogDebug('{0} ,', this._keyValues[i]);
CubismLogDebug('\n');
}
}
public static readonly DefaultSize = 10; // コンテナの初期化のデフォルトサイズ
public _keyValues: csmPair<_KeyT, _ValT>[]; // key-valueペアの配列
public _dummyValue: _ValT; // 空の値を返す為のダミー
public _size: number; // コンテナの要素数
} }
/** /**
* csmMap<T> *
*/ */
export class iterator<_KeyT, _ValT> { public release() {
/** this.clear();
*
*/
constructor(v?: csmMap<_KeyT, _ValT>, idx?: number) {
this._map = v != undefined ? v : new csmMap<_KeyT, _ValT>();
this._index = idx != undefined ? idx : 0;
}
/**
* =
*/
public set(ite: iterator<_KeyT, _ValT>): iterator<_KeyT, _ValT> {
this._index = ite._index;
this._map = ite._map;
return this;
}
/**
* ++
*/
public preIncrement(): iterator<_KeyT, _ValT> {
++this._index;
return this;
}
/**
* --
*/
public preDecrement(): iterator<_KeyT, _ValT> {
--this._index;
return this;
}
/**
* ++
*/
public increment(): iterator<_KeyT, _ValT> {
const iteold = new iterator<_KeyT, _ValT>(this._map, this._index++); // 古い値を保存
return iteold;
}
/**
* --
*/
public decrement(): iterator<_KeyT, _ValT> {
const iteold = new iterator<_KeyT, _ValT>(this._map, this._index); // 古い値を保存
this._map = iteold._map;
this._index = iteold._index;
return this;
}
/**
* *
*/
public ptr(): csmPair<_KeyT, _ValT> {
return this._map._keyValues[this._index];
}
/**
* !=
*/
public notEqual(ite: iterator<_KeyT, _ValT>): boolean {
return this._index != ite._index || this._map != ite._map;
}
_index: number; // コンテナのインデックス値
_map: csmMap<_KeyT, _ValT>; // コンテナ
} }
/**
*
* @param key
*/
public appendKey(key: _KeyT): void {
// 新しくKey/Valueのペアを作る
this.prepareCapacity(this._size + 1, false); // 1つ以上入る隙間を作る
// 新しいkey/valueのインデックスは_size
this._keyValues[this._size] = new csmPair<_KeyT, _ValT>(key);
this._size += 1;
}
/**
* [key](get)
* @param key Value
*/
public getValue(key: _KeyT): _ValT {
let found = -1;
for (let i = 0; i < this._size; i++) {
if (this._keyValues[i].first == key) {
found = i;
break;
}
}
if (found >= 0) {
return this._keyValues[found].second;
} else {
this.appendKey(key); // 新規キーを追加
return this._keyValues[this._size - 1].second;
}
}
/**
* [key](set)
* @param key Value
* @param value Value
*/
public setValue(key: _KeyT, value: _ValT): void {
let found = -1;
for (let i = 0; i < this._size; i++) {
if (this._keyValues[i].first == key) {
found = i;
break;
}
}
if (found >= 0) {
this._keyValues[found].second = value;
} else {
this.appendKey(key); // 新規キーを追加
this._keyValues[this._size - 1].second = value;
}
}
/**
* Key
* @param key key
* @return true key
* @return false key
*/
public isExist(key: _KeyT): boolean {
for (let i = 0; i < this._size; i++) {
if (this._keyValues[i].first == key) {
return true;
}
}
return false;
}
/**
* keyValue
*/
public clear(): void {
this._keyValues = void 0;
this._keyValues = null;
this._keyValues = [];
this._size = 0;
}
/**
*
*
* @return
*/
public getSize(): number {
return this._size;
}
/**
*
* @param newSize
* @param fitToSize truefalse2
*/
public prepareCapacity(newSize: number, fitToSize: boolean): void {
if (newSize > this._keyValues.length) {
if (this._keyValues.length == 0) {
if (!fitToSize && newSize < csmMap.DefaultSize)
newSize = csmMap.DefaultSize;
this._keyValues.length = newSize;
} else {
if (!fitToSize && newSize < this._keyValues.length * 2)
newSize = this._keyValues.length * 2;
this._keyValues.length = newSize;
}
}
}
/**
*
*/
public begin(): iterator<_KeyT, _ValT> {
const ite: iterator<_KeyT, _ValT> = new iterator<_KeyT, _ValT>(this, 0);
return ite;
}
/**
*
*/
public end(): iterator<_KeyT, _ValT> {
const ite: iterator<_KeyT, _ValT> = new iterator<_KeyT, _ValT>(
this,
this._size
); // 終了
return ite;
}
/**
*
*
* @param ite
*/
public erase(ite: iterator<_KeyT, _ValT>): iterator<_KeyT, _ValT> {
const index: number = ite._index;
if (index < 0 || this._size <= index) {
return ite; // 削除範囲外
}
// 削除
this._keyValues.splice(index, 1);
--this._size;
const ite2: iterator<_KeyT, _ValT> = new iterator<_KeyT, _ValT>(
this,
index
); // 終了
return ite2;
}
/**
* 32
*/
public dumpAsInt() {
for (let i = 0; i < this._size; i++) {
CubismLogDebug('{0} ,', this._keyValues[i]);
CubismLogDebug('\n');
}
}
public static readonly DefaultSize = 10; // コンテナの初期化のデフォルトサイズ
public _keyValues: csmPair<_KeyT, _ValT>[]; // key-valueペアの配列
public _dummyValue: _ValT; // 空の値を返す為のダミー
public _size: number; // コンテナの要素数
}
/**
* csmMap<T>
*/
export class iterator<_KeyT, _ValT> {
/**
*
*/
constructor(v?: csmMap<_KeyT, _ValT>, idx?: number) {
this._map = v != undefined ? v : new csmMap<_KeyT, _ValT>();
this._index = idx != undefined ? idx : 0;
}
/**
* =
*/
public set(ite: iterator<_KeyT, _ValT>): iterator<_KeyT, _ValT> {
this._index = ite._index;
this._map = ite._map;
return this;
}
/**
* ++
*/
public preIncrement(): iterator<_KeyT, _ValT> {
++this._index;
return this;
}
/**
* --
*/
public preDecrement(): iterator<_KeyT, _ValT> {
--this._index;
return this;
}
/**
* ++
*/
public increment(): iterator<_KeyT, _ValT> {
const iteold = new iterator<_KeyT, _ValT>(this._map, this._index++); // 古い値を保存
return iteold;
}
/**
* --
*/
public decrement(): iterator<_KeyT, _ValT> {
const iteold = new iterator<_KeyT, _ValT>(this._map, this._index); // 古い値を保存
this._map = iteold._map;
this._index = iteold._index;
return this;
}
/**
* *
*/
public ptr(): csmPair<_KeyT, _ValT> {
return this._map._keyValues[this._index];
}
/**
* !=
*/
public notEqual(ite: iterator<_KeyT, _ValT>): boolean {
return this._index != ite._index || this._map != ite._map;
}
_index: number; // コンテナのインデックス値
_map: csmMap<_KeyT, _ValT>; // コンテナ
}
// Namespace definition for compatibility.
import * as $ from './csmmap';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const csmMap = $.csmMap;
export type csmMap<K, V> = $.csmMap<K, V>;
export const csmPair = $.csmPair;
export type csmPair<K, V> = $.csmPair<K, V>;
export const iterator = $.iterator;
export type iterator<K, V> = $.iterator<K, V>;
} }

View File

@ -5,79 +5,85 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
export namespace Live2DCubismFramework { /**
* float
*/
export class csmRect {
/** /**
* float *
* @param x X
* @param y Y
* @param w
* @param h
*/ */
export class csmRect { public constructor(x?: number, y?: number, w?: number, h?: number) {
/** this.x = x;
* this.y = y;
* @param x X this.width = w;
* @param y Y this.height = h;
* @param w
* @param h
*/
public constructor(x?: number, y?: number, w?: number, h?: number) {
this.x = x;
this.y = y;
this.width = w;
this.height = h;
}
/**
* X
*/
public getCenterX(): number {
return this.x + 0.5 * this.width;
}
/**
* Y
*/
public getCenterY(): number {
return this.y + 0.5 * this.height;
}
/**
* X
*/
public getRight(): number {
return this.x + this.width;
}
/**
* Y
*/
public getBottom(): number {
return this.y + this.height;
}
/**
*
* @param r
*/
public setRect(r: csmRect): void {
this.x = r.x;
this.y = r.y;
this.width = r.width;
this.height = r.height;
}
/**
*
* @param w
* @param h
*/
public expand(w: number, h: number) {
this.x -= w;
this.y -= h;
this.width += w * 2.0;
this.height += h * 2.0;
}
public x: number; // 左端X座標
public y: number; // 上端Y座標
public width: number; // 幅
public height: number; // 高さ
} }
/**
* X
*/
public getCenterX(): number {
return this.x + 0.5 * this.width;
}
/**
* Y
*/
public getCenterY(): number {
return this.y + 0.5 * this.height;
}
/**
* X
*/
public getRight(): number {
return this.x + this.width;
}
/**
* Y
*/
public getBottom(): number {
return this.y + this.height;
}
/**
*
* @param r
*/
public setRect(r: csmRect): void {
this.x = r.x;
this.y = r.y;
this.width = r.width;
this.height = r.height;
}
/**
*
* @param w
* @param h
*/
public expand(w: number, h: number) {
this.x -= w;
this.y -= h;
this.width += w * 2.0;
this.height += h * 2.0;
}
public x: number; // 左端X座標
public y: number; // 上端Y座標
public width: number; // 幅
public height: number; // 高さ
}
// Namespace definition for compatibility.
import * as $ from './csmrectf';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const csmRect = $.csmRect;
export type csmRect = $.csmRect;
} }

View File

@ -5,97 +5,103 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
export namespace Live2DCubismFramework { /**
*
*/
export class csmString {
/** /**
* *
*
* @param c
* @return
*/ */
export class csmString { public append(c: string, length?: number): csmString {
/** this.s += length !== undefined ? c.substr(0, length) : c;
*
*
* @param c
* @return
*/
public append(c: string, length?: number): csmString {
this.s += length !== undefined ? c.substr(0, length) : c;
return this; return this;
}
/**
*
* @param length
* @param v
* @return
*/
public expansion(length: number, v: string): csmString {
for (let i = 0; i < length; i++) {
this.append(v);
}
return this;
}
/**
*
*/
public getBytes(): number {
return encodeURIComponent(this.s).replace(/%../g, 'x').length;
}
/**
*
*/
public getLength(): number {
return this.s.length;
}
/**
* <
* @param s
* @return true:
* @return false:
*/
public isLess(s: csmString): boolean {
return this.s < s.s;
}
/**
* >
* @param s
* @return true:
* @return false:
*/
public isGreat(s: csmString): boolean {
return this.s > s.s;
}
/**
* ==
* @param s
* @return true:
* @return false:
*/
public isEqual(s: string): boolean {
return this.s == s;
}
/**
*
* @return true:
* @return false:
*/
public isEmpty(): boolean {
return this.s.length == 0;
}
/**
*
*/
public constructor(s: string) {
this.s = s;
}
s: string;
} }
/**
*
* @param length
* @param v
* @return
*/
public expansion(length: number, v: string): csmString {
for (let i = 0; i < length; i++) {
this.append(v);
}
return this;
}
/**
*
*/
public getBytes(): number {
return encodeURIComponent(this.s).replace(/%../g, 'x').length;
}
/**
*
*/
public getLength(): number {
return this.s.length;
}
/**
* <
* @param s
* @return true:
* @return false:
*/
public isLess(s: csmString): boolean {
return this.s < s.s;
}
/**
* >
* @param s
* @return true:
* @return false:
*/
public isGreat(s: csmString): boolean {
return this.s > s.s;
}
/**
* ==
* @param s
* @return true:
* @return false:
*/
public isEqual(s: string): boolean {
return this.s == s;
}
/**
*
* @return true:
* @return false:
*/
public isEmpty(): boolean {
return this.s.length == 0;
}
/**
*
*/
public constructor(s: string) {
this.s = s;
}
s: string;
}
// Namespace definition for compatibility.
import * as $ from './csmstring';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const csmString = $.csmString;
export type csmString = $.csmString;
} }

View File

@ -5,340 +5,348 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
export namespace Live2DCubismFramework { /**
*
*/
export class csmVector<T> {
/** /**
* *
* @param iniitalCapacity _capacity * sizeof(T)
* @param zeroClear true0
*/ */
export class csmVector<T> { constructor(initialCapacity = 0) {
/** if (initialCapacity < 1) {
* this._ptr = [];
* @param iniitalCapacity _capacity * sizeof(T) this._capacity = 0;
* @param zeroClear true0 this._size = 0;
*/ } else {
constructor(initialCapacity = 0) { this._ptr = new Array(initialCapacity);
if (initialCapacity < 1) { this._capacity = initialCapacity;
this._ptr = [];
this._capacity = 0;
this._size = 0;
} else {
this._ptr = new Array(initialCapacity);
this._capacity = initialCapacity;
this._size = 0;
}
}
/**
*
*/
public at(index: number): T {
return this._ptr[index];
}
/**
*
* @param index
* @param value
*/
public set(index: number, value: T): void {
this._ptr[index] = value;
}
/**
*
*/
public get(offset = 0): T[] {
const ret: T[] = new Array<T>();
for (let i = offset; i < this._size; i++) {
ret.push(this._ptr[i]);
}
return ret;
}
/**
* pushBack
* @param value PushBack
*/
public pushBack(value: T): void {
if (this._size >= this._capacity) {
this.prepareCapacity(
this._capacity == 0 ? csmVector.s_defaultSize : this._capacity * 2
);
}
this._ptr[this._size++] = value;
}
/**
*
*/
public clear(): void {
this._ptr.length = 0;
this._size = 0; this._size = 0;
} }
}
/** /**
* *
* @return */
*/ public at(index: number): T {
public getSize(): number { return this._ptr[index];
return this._size; }
/**
*
* @param index
* @param value
*/
public set(index: number, value: T): void {
this._ptr[index] = value;
}
/**
*
*/
public get(offset = 0): T[] {
const ret: T[] = new Array<T>();
for (let i = offset; i < this._size; i++) {
ret.push(this._ptr[i]);
}
return ret;
}
/**
* pushBack
* @param value PushBack
*/
public pushBack(value: T): void {
if (this._size >= this._capacity) {
this.prepareCapacity(
this._capacity == 0 ? csmVector.s_defaultSize : this._capacity * 2
);
} }
/** this._ptr[this._size++] = value;
* }
* @param newSize
* @param value
*/
public assign(newSize: number, value: T): void {
const curSize = this._size;
if (curSize < newSize) { /**
this.prepareCapacity(newSize); // capacity更新 *
} */
public clear(): void {
this._ptr.length = 0;
this._size = 0;
}
for (let i = 0; i < newSize; i++) { /**
this._ptr[i] = value; *
} * @return
*/
public getSize(): number {
return this._size;
}
this._size = newSize; /**
*
* @param newSize
* @param value
*/
public assign(newSize: number, value: T): void {
const curSize = this._size;
if (curSize < newSize) {
this.prepareCapacity(newSize); // capacity更新
} }
/** for (let i = 0; i < newSize; i++) {
* this._ptr[i] = value;
*/
public resize(newSize: number, value: T = null): void {
this.updateSize(newSize, value, true);
} }
/** this._size = newSize;
* }
*/
public updateSize(
newSize: number,
value: any = null,
callPlacementNew = true
): void {
const curSize: number = this._size;
if (curSize < newSize) { /**
this.prepareCapacity(newSize); // capacity更新 *
*/
public resize(newSize: number, value: T = null): void {
this.updateSize(newSize, value, true);
}
if (callPlacementNew) { /**
for (let i: number = this._size; i < newSize; i++) { *
if (typeof value == 'function') { */
// new public updateSize(
this._ptr[i] = JSON.parse(JSON.stringify(new value())); newSize: number,
} // プリミティブ型なので値渡し value: any = null,
else { callPlacementNew = true
this._ptr[i] = value; ): void {
} const curSize: number = this._size;
}
} else { if (curSize < newSize) {
for (let i: number = this._size; i < newSize; i++) { this.prepareCapacity(newSize); // capacity更新
if (callPlacementNew) {
for (let i: number = this._size; i < newSize; i++) {
if (typeof value == 'function') {
// new
this._ptr[i] = JSON.parse(JSON.stringify(new value()));
} // プリミティブ型なので値渡し
else {
this._ptr[i] = value; this._ptr[i] = value;
} }
} }
} else { } else {
// newSize <= this._size for (let i: number = this._size; i < newSize; i++) {
//--- this._ptr[i] = value;
const sub = this._size - newSize;
this._ptr.splice(this._size - sub, sub); // 不要なので破棄する
}
this._size = newSize;
}
/**
*
* @param position
* @param begin
* @param end
*/
public insert(
position: iterator<T>,
begin: iterator<T>,
end: iterator<T>
): void {
let dstSi: number = position._index;
const srcSi: number = begin._index;
const srcEi: number = end._index;
const addCount: number = srcEi - srcSi;
this.prepareCapacity(this._size + addCount);
// 挿入用の既存データをシフトして隙間を作る
const addSize = this._size - dstSi;
if (addSize > 0) {
for (let i = 0; i < addSize; i++) {
this._ptr.splice(dstSi + i, 0, null);
} }
} }
} else {
for (let i: number = srcSi; i < srcEi; i++, dstSi++) { // newSize <= this._size
this._ptr[dstSi] = begin._vector._ptr[i]; //---
} const sub = this._size - newSize;
this._ptr.splice(this._size - sub, sub); // 不要なので破棄する
this._size = this._size + addCount;
} }
this._size = newSize;
/**
*
* @param index
* @return true
* @return false
*/
public remove(index: number): boolean {
if (index < 0 || this._size <= index) {
return false; // 削除範囲外
}
this._ptr.splice(index, 1);
--this._size;
return true;
}
/**
*
* @param ite
*/
public erase(ite: iterator<T>): iterator<T> {
const index: number = ite._index;
if (index < 0 || this._size <= index) {
return ite; // 削除範囲外
}
// 削除
this._ptr.splice(index, 1);
--this._size;
const ite2: iterator<T> = new iterator<T>(this, index); // 終了
return ite2;
}
/**
*
* @param newSize .
*/
public prepareCapacity(newSize: number): void {
if (newSize > this._capacity) {
if (this._capacity == 0) {
this._ptr = new Array(newSize);
this._capacity = newSize;
} else {
this._ptr.length = newSize;
this._capacity = newSize;
}
}
}
/**
*
*/
public begin(): iterator<T> {
const ite: iterator<T> =
this._size == 0 ? this.end() : new iterator<T>(this, 0);
return ite;
}
/**
*
*/
public end(): iterator<T> {
const ite: iterator<T> = new iterator<T>(this, this._size);
return ite;
}
public getOffset(offset: number): csmVector<T> {
const newVector = new csmVector<T>();
newVector._ptr = this.get(offset);
newVector._size = this.get(offset).length;
newVector._capacity = this.get(offset).length;
return newVector;
}
_ptr: T[]; // コンテナの先頭アドレス
_size: number; // コンテナの要素数
_capacity: number; // コンテナのキャパシティ
static readonly s_defaultSize = 10; // コンテナ初期化のデフォルトサイズ
} }
export class iterator<T> { /**
/** *
* * @param position
*/ * @param begin
public constructor(v?: csmVector<T>, index?: number) { * @param end
this._vector = v != undefined ? v : null; */
this._index = index != undefined ? index : 0; public insert(
position: iterator<T>,
begin: iterator<T>,
end: iterator<T>
): void {
let dstSi: number = position._index;
const srcSi: number = begin._index;
const srcEi: number = end._index;
const addCount: number = srcEi - srcSi;
this.prepareCapacity(this._size + addCount);
// 挿入用の既存データをシフトして隙間を作る
const addSize = this._size - dstSi;
if (addSize > 0) {
for (let i = 0; i < addSize; i++) {
this._ptr.splice(dstSi + i, 0, null);
}
} }
/** for (let i: number = srcSi; i < srcEi; i++, dstSi++) {
* this._ptr[dstSi] = begin._vector._ptr[i];
*/
public set(ite: iterator<T>): iterator<T> {
this._index = ite._index;
this._vector = ite._vector;
return this;
} }
/** this._size = this._size + addCount;
* ++
*/
public preIncrement(): iterator<T> {
++this._index;
return this;
}
/**
* --
*/
public preDecrement(): iterator<T> {
--this._index;
return this;
}
/**
* ++
*/
public increment(): iterator<T> {
const iteold = new iterator<T>(this._vector, this._index++); // 古い値を保存
return iteold;
}
/**
* --
*/
public decrement(): iterator<T> {
const iteold = new iterator<T>(this._vector, this._index--); // 古い値を保存
return iteold;
}
/**
* ptr
*/
public ptr(): T {
return this._vector._ptr[this._index];
}
/**
* =
*/
public substitution(ite: iterator<T>): iterator<T> {
this._index = ite._index;
this._vector = ite._vector;
return this;
}
/**
* !=
*/
public notEqual(ite: iterator<T>): boolean {
return this._index != ite._index || this._vector != ite._vector;
}
_index: number; // コンテナのインデックス値
_vector: csmVector<T>; // コンテナ
} }
/**
*
* @param index
* @return true
* @return false
*/
public remove(index: number): boolean {
if (index < 0 || this._size <= index) {
return false; // 削除範囲外
}
this._ptr.splice(index, 1);
--this._size;
return true;
}
/**
*
* @param ite
*/
public erase(ite: iterator<T>): iterator<T> {
const index: number = ite._index;
if (index < 0 || this._size <= index) {
return ite; // 削除範囲外
}
// 削除
this._ptr.splice(index, 1);
--this._size;
const ite2: iterator<T> = new iterator<T>(this, index); // 終了
return ite2;
}
/**
*
* @param newSize .
*/
public prepareCapacity(newSize: number): void {
if (newSize > this._capacity) {
if (this._capacity == 0) {
this._ptr = new Array(newSize);
this._capacity = newSize;
} else {
this._ptr.length = newSize;
this._capacity = newSize;
}
}
}
/**
*
*/
public begin(): iterator<T> {
const ite: iterator<T> =
this._size == 0 ? this.end() : new iterator<T>(this, 0);
return ite;
}
/**
*
*/
public end(): iterator<T> {
const ite: iterator<T> = new iterator<T>(this, this._size);
return ite;
}
public getOffset(offset: number): csmVector<T> {
const newVector = new csmVector<T>();
newVector._ptr = this.get(offset);
newVector._size = this.get(offset).length;
newVector._capacity = this.get(offset).length;
return newVector;
}
_ptr: T[]; // コンテナの先頭アドレス
_size: number; // コンテナの要素数
_capacity: number; // コンテナのキャパシティ
static readonly s_defaultSize = 10; // コンテナ初期化のデフォルトサイズ
}
export class iterator<T> {
/**
*
*/
public constructor(v?: csmVector<T>, index?: number) {
this._vector = v != undefined ? v : null;
this._index = index != undefined ? index : 0;
}
/**
*
*/
public set(ite: iterator<T>): iterator<T> {
this._index = ite._index;
this._vector = ite._vector;
return this;
}
/**
* ++
*/
public preIncrement(): iterator<T> {
++this._index;
return this;
}
/**
* --
*/
public preDecrement(): iterator<T> {
--this._index;
return this;
}
/**
* ++
*/
public increment(): iterator<T> {
const iteold = new iterator<T>(this._vector, this._index++); // 古い値を保存
return iteold;
}
/**
* --
*/
public decrement(): iterator<T> {
const iteold = new iterator<T>(this._vector, this._index--); // 古い値を保存
return iteold;
}
/**
* ptr
*/
public ptr(): T {
return this._vector._ptr[this._index];
}
/**
* =
*/
public substitution(ite: iterator<T>): iterator<T> {
this._index = ite._index;
this._vector = ite._vector;
return this;
}
/**
* !=
*/
public notEqual(ite: iterator<T>): boolean {
return this._index != ite._index || this._vector != ite._vector;
}
_index: number; // コンテナのインデックス値
_vector: csmVector<T>; // コンテナ
}
// Namespace definition for compatibility.
import * as $ from './csmvector';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const csmVector = $.csmVector;
export type csmVector<T> = $.csmVector<T>;
export const iterator = $.iterator;
export type iterator<T> = $.iterator<T>;
} }

View File

@ -5,21 +5,18 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
import {
Live2DCubismFramework as cubismframework,
LogLevel
} from '../live2dcubismframework';
import { import {
CSM_LOG_LEVEL, CSM_LOG_LEVEL,
CSM_LOG_LEVEL_VERBOSE,
CSM_LOG_LEVEL_DEBUG, CSM_LOG_LEVEL_DEBUG,
CSM_LOG_LEVEL_ERROR,
CSM_LOG_LEVEL_INFO, CSM_LOG_LEVEL_INFO,
CSM_LOG_LEVEL_WARNING, CSM_LOG_LEVEL_VERBOSE,
CSM_LOG_LEVEL_ERROR CSM_LOG_LEVEL_WARNING
} from '../cubismframeworkconfig'; } from '../cubismframeworkconfig';
import { CubismFramework, LogLevel } from '../live2dcubismframework';
export const CubismLogPrint = (level: LogLevel, fmt: string, args: any[]) => { export const CubismLogPrint = (level: LogLevel, fmt: string, args: any[]) => {
Live2DCubismFramework.CubismDebug.print(level, '[CSM]' + fmt, args); CubismDebug.print(level, '[CSM]' + fmt, args);
}; };
export const CubismLogPrintIn = (level: LogLevel, fmt: string, args: any[]) => { export const CubismLogPrintIn = (level: LogLevel, fmt: string, args: any[]) => {
@ -98,69 +95,68 @@ if (CSM_LOG_LEVEL <= CSM_LOG_LEVEL_VERBOSE) {
}; };
} }
//------------ LIVE2D NAMESPACE ------------ /**
export namespace Live2DCubismFramework { *
*
*/
export class CubismDebug {
/** /**
* *
* * CubismFramework.initialize()
*
* @param logLevel
* @param format
* @param args
*/ */
export class CubismDebug { public static print(logLevel: LogLevel, format: string, args?: any[]): void {
/** // オプションで設定されたログ出力レベルを下回る場合はログに出さない
* if (logLevel < CubismFramework.getLoggingLevel()) {
* CubismFramework.initialize() return;
*
* @param logLevel
* @param format
* @param args
*/
public static print(
logLevel: LogLevel,
format: string,
args?: any[]
): void {
// オプションで設定されたログ出力レベルを下回る場合はログに出さない
if (logLevel < cubismframework.CubismFramework.getLoggingLevel()) {
return;
}
const logPrint: Live2DCubismCore.csmLogFunction =
cubismframework.CubismFramework.coreLogFunction;
if (!logPrint) return;
const buffer: string = format.replace(/\{(\d+)\}/g, (m, k) => {
return args[k];
});
logPrint(buffer);
} }
/** const logPrint: Live2DCubismCore.csmLogFunction =
* CubismFramework.coreLogFunction;
* CubismFramework.initialize()
*
* @param logLevel
* @param data
* @param length
*/
public static dumpBytes(
logLevel: LogLevel,
data: Uint8Array,
length: number
): void {
for (let i = 0; i < length; i++) {
if (i % 16 == 0 && i > 0) this.print(logLevel, '\n');
else if (i % 8 == 0 && i > 0) this.print(logLevel, ' ');
this.print(logLevel, '{0} ', [data[i] & 0xff]);
}
this.print(logLevel, '\n'); if (!logPrint) return;
}
/** const buffer: string = format.replace(/\{(\d+)\}/g, (m, k) => {
* private return args[k];
*/ });
private constructor() {} logPrint(buffer);
} }
/**
*
* CubismFramework.initialize()
*
* @param logLevel
* @param data
* @param length
*/
public static dumpBytes(
logLevel: LogLevel,
data: Uint8Array,
length: number
): void {
for (let i = 0; i < length; i++) {
if (i % 16 == 0 && i > 0) this.print(logLevel, '\n');
else if (i % 8 == 0 && i > 0) this.print(logLevel, ' ');
this.print(logLevel, '{0} ', [data[i] & 0xff]);
}
this.print(logLevel, '\n');
}
/**
* private
*/
private constructor() {}
} }
//------------ LIVE2D NAMESPACE ------------ // Namespace definition for compatibility.
import * as $ from './cubismdebug';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismDebug = $.CubismDebug;
export type CubismDebug = $.CubismDebug;
}

File diff suppressed because it is too large Load Diff

View File

@ -5,119 +5,125 @@
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/ */
export namespace Live2DCubismFramework { export class CubismString {
export class CubismString { /**
/** *
* * @param format
* @param format * @param ...args
* @param ...args * @return
* @return */
*/ public static getFormatedString(format: string, ...args: any[]): string {
public static getFormatedString(format: string, ...args: any[]): string { const ret: string = format;
const ret: string = format; return ret.replace(
return ret.replace( /\{(\d+)\}/g,
/\{(\d+)\}/g, (
( m,
m, k // m="{0}", k="0"
k // m="{0}", k="0" ) => {
) => { return args[k];
return args[k];
}
);
}
/**
* textstartWord
* @param test
* @param startWord
* @return true textstartWord
* @return false textstartWord
*/
public static isStartWith(text: string, startWord: string): boolean {
let textIndex = 0;
let startWordIndex = 0;
while (startWord[startWordIndex] != '\0') {
if (
text[textIndex] == '\0' ||
text[textIndex++] != startWord[startWordIndex++]
) {
return false;
}
} }
return false; );
}
/**
* textstartWord
* @param test
* @param startWord
* @return true textstartWord
* @return false textstartWord
*/
public static isStartWith(text: string, startWord: string): boolean {
let textIndex = 0;
let startWordIndex = 0;
while (startWord[startWordIndex] != '\0') {
if (
text[textIndex] == '\0' ||
text[textIndex++] != startWord[startWordIndex++]
) {
return false;
}
}
return false;
}
/**
* position
*
* @param string
* @param length
* @param position
* @param outEndPos (-1)
* @return
*/
public static stringToFloat(
string: string,
length: number,
position: number,
outEndPos: number[]
): number {
let i: number = position;
let minus = false; // マイナスフラグ
let period = false;
let v1 = 0;
//負号の確認
let c: number = parseInt(string[i]);
if (c < 0) {
minus = true;
i++;
} }
/** //整数部の確認
* position for (; i < length; i++) {
* const c = string[i];
* @param string if (0 <= parseInt(c) && parseInt(c) <= 9) {
* @param length v1 = v1 * 10 + (parseInt(c) - 0);
* @param position } else if (c == '.') {
* @param outEndPos (-1) period = true;
* @return
*/
public static stringToFloat(
string: string,
length: number,
position: number,
outEndPos: number[]
): number {
let i: number = position;
let minus = false; // マイナスフラグ
let period = false;
let v1 = 0;
//負号の確認
let c: number = parseInt(string[i]);
if (c < 0) {
minus = true;
i++; i++;
break;
} else {
break;
} }
}
//整数部の確認 //小数部の確認
if (period) {
let mul = 0.1;
for (; i < length; i++) { for (; i < length; i++) {
const c = string[i]; c = parseFloat(string[i]) & 0xff;
if (0 <= parseInt(c) && parseInt(c) <= 9) { if (0 <= c && c <= 9) {
v1 = v1 * 10 + (parseInt(c) - 0); v1 += mul * (c - 0);
} else if (c == '.') {
period = true;
i++;
break;
} else { } else {
break; break;
} }
mul *= 0.1; //一桁下げる
if (!c) break;
} }
//小数部の確認
if (period) {
let mul = 0.1;
for (; i < length; i++) {
c = parseFloat(string[i]) & 0xff;
if (0 <= c && c <= 9) {
v1 += mul * (c - 0);
} else {
break;
}
mul *= 0.1; //一桁下げる
if (!c) break;
}
}
if (i == position) {
//一文字も読み込まなかった場合
outEndPos[0] = -1; //エラー値が入るので呼び出し元で適切な処理を行う
return 0;
}
if (minus) v1 = -v1;
outEndPos[0] = i;
return v1;
} }
/** if (i == position) {
* //一文字も読み込まなかった場合
*/ outEndPos[0] = -1; //エラー値が入るので呼び出し元で適切な処理を行う
private constructor() {} return 0;
}
if (minus) v1 = -v1;
outEndPos[0] = i;
return v1;
} }
/**
*
*/
private constructor() {}
}
// Namespace definition for compatibility.
import * as $ from './cubismstring';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Live2DCubismFramework {
export const CubismString = $.CubismString;
export type CubismString = $.CubismString;
} }