Skip to content

Commit

Permalink
Merge pull request #12 from Live2D/feature/improve_performance
Browse files Browse the repository at this point in the history
Improve performance.
  • Loading branch information
itoh-at-live2d-com authored Oct 25, 2018
2 parents 8e44d4e + c8506e9 commit bc9f30a
Show file tree
Hide file tree
Showing 56 changed files with 1,443 additions and 1,483 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.ts text
*.js text
*.json text
*.html text
*.md text
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.idea/

node_modules/

/Core/*
!Please copy cubism core for web
Sample/TypeScript/Demo/dist/
2 changes: 1 addition & 1 deletion Framework/cubismdefaultparameterid.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
Expand Down
2 changes: 1 addition & 1 deletion Framework/cubismframeworkconfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
Expand Down
5 changes: 3 additions & 2 deletions Framework/cubismmodelsettingjson.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
Expand All @@ -11,6 +11,7 @@ import {Live2DCubismFramework as cubismid} from "./id/cubismid";
import {Live2DCubismFramework as cubismjson} from "./utils/cubismjson";
import {Live2DCubismFramework as csmmap} from"./type/csmmap";
import csmMap = csmmap.csmMap;
import iterator = csmmap.iterator;
import CubismFramework = cubismframework.CubismFramework;
import CubismIdHandle = cubismid.CubismIdHandle;
import CubismJson = cubismjson.CubismJson;
Expand Down Expand Up @@ -396,7 +397,7 @@ export namespace Live2DCubismFramework

let ret: boolean = false;

for(const ite: csmMap.iterator<string, Value> = map.begin(); ite.notEqual(map.end()); ite.preIncrement())
for(const ite: iterator<string, Value> = map.begin(); ite.notEqual(map.end()); ite.preIncrement())
{
outLayoutMap.setValue(ite.ptr().first, ite.ptr().second.toFloat());
ret = true;
Expand Down
84 changes: 41 additions & 43 deletions Framework/effect/cubismbreath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
Expand Down Expand Up @@ -37,15 +37,17 @@ export namespace Live2DCubismFramework
*/
public static delete(instance: CubismBreath): void
{
instance = void 0;
instance = null;
if(instance != null)
{
instance = null;
}
}

/**
* 呼吸のパラメータの紐づけ
* @param breathParameters 呼吸を紐づけたいパラメータのリスト
*/
public setParameters(breathParameters: csmVector<CubismBreath.BreathParameterData>): void
public setParameters(breathParameters: csmVector<BreathParameterData>): void
{
this._breathParameters = breathParameters;
}
Expand All @@ -54,7 +56,7 @@ export namespace Live2DCubismFramework
* 呼吸に紐づいているパラメータの取得
* @return 呼吸に紐づいているパラメータのリスト
*/
public getParameters(): csmVector<CubismBreath.BreathParameterData>
public getParameters(): csmVector<BreathParameterData>
{
return this._breathParameters;
}
Expand All @@ -72,7 +74,7 @@ export namespace Live2DCubismFramework

for(let i: number = 0; i < this._breathParameters.getSize(); ++i)
{
let data: CubismBreath.BreathParameterData = this._breathParameters.at(i);
let data: BreathParameterData = this._breathParameters.at(i);

model.addParameterValueById(
data.parameterId,
Expand All @@ -91,50 +93,46 @@ export namespace Live2DCubismFramework
this._currentTime = 0.0;
}

_breathParameters: csmVector<CubismBreath.BreathParameterData>; // 呼吸にひもづいているパラメータのリスト
_breathParameters: csmVector<BreathParameterData>; // 呼吸にひもづいているパラメータのリスト
_currentTime: number; // 積算時間[秒]
}

export namespace CubismBreath
/**
* 呼吸のパラメータ情報
*/
export class BreathParameterData
{
/**
* 呼吸のパラメータ情報
* コンストラクタ
* @param parameterId 呼吸をひもづけるパラメータID
* @param offset 呼吸を正弦波としたときの、波のオフセット
* @param peak 呼吸を正弦波としたときの、波の高さ
* @param cycle 呼吸を正弦波としたときの、波の周期
* @param weight パラメータへの重み
*/
export class BreathParameterData
constructor(parameterId?: CubismIdHandle, offset?: number, peak?: number, cycle?: number, weight?: number)
{
/**
* コンストラクタ
* @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; // パラメータへの重み
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; // パラメータへの重み
}
}
63 changes: 31 additions & 32 deletions Framework/effect/cubismeyeblink.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
Expand Down Expand Up @@ -40,8 +40,10 @@ export namespace Live2DCubismFramework
*/
public static delete(eyeBlink: CubismEyeBlink): void
{
eyeBlink = void 0;
eyeBlink = null;
if(eyeBlink != null)
{
eyeBlink = null;
}
}

/**
Expand Down Expand Up @@ -97,57 +99,57 @@ export namespace Live2DCubismFramework

switch(this._blinkingState)
{
case CubismEyeBlink.EyeState.EyeState_Closing:
case EyeState.EyeState_Closing:
t = ((this._userTimeSeconds - this._stateStartTimeSeconds) / this._closingSeconds);

if(t >= 1.0)
{
t = 1.0;
this._blinkingState = CubismEyeBlink.EyeState.EyeState_Closed;
this._blinkingState = EyeState.EyeState_Closed;
this._stateStartTimeSeconds = this._userTimeSeconds;
}

parameterValue = 1.0 - t;

break;
case CubismEyeBlink.EyeState.EyeState_Closed:
case EyeState.EyeState_Closed:
t = ((this._userTimeSeconds - this._stateStartTimeSeconds) / this._closedSeconds);

if(t >= 1.0)
{
this._blinkingState = CubismEyeBlink.EyeState.EyeState_Opening;
this._blinkingState = EyeState.EyeState_Opening;
this._stateStartTimeSeconds = this._userTimeSeconds;
}

parameterValue = 0.0;

break;
case CubismEyeBlink.EyeState.EyeState_Opening:
case EyeState.EyeState_Opening:
t = ((this._userTimeSeconds - this._stateStartTimeSeconds) / this._openingSeconds);

if(t >= 1.0)
{
t = 1.0;
this._blinkingState = CubismEyeBlink.EyeState.EyeState_Interval;
this._blinkingState = EyeState.EyeState_Interval;
this._nextBlinkingTime = this.determinNextBlinkingTiming();
}

parameterValue = t;

break;
case CubismEyeBlink.EyeState.EyeState_Interval:
case EyeState.EyeState_Interval:
if(this._nextBlinkingTime < this._userTimeSeconds)
{
this._blinkingState = CubismEyeBlink.EyeState.EyeState_Closing;
this._blinkingState = EyeState.EyeState_Closing;
this._stateStartTimeSeconds = this._userTimeSeconds;
}

parameterValue = 1.0;

break;
case CubismEyeBlink.EyeState.EyeState_First:
case EyeState.EyeState_First:
default:
this._blinkingState = CubismEyeBlink.EyeState.EyeState_Interval;
this._blinkingState = EyeState.EyeState_Interval;
this._nextBlinkingTime = this.determinNextBlinkingTiming();

parameterValue = 1.0;
Expand All @@ -171,7 +173,7 @@ export namespace Live2DCubismFramework
*/
public constructor(modelSetting: ICubismModelSetting)
{
this._blinkingState = CubismEyeBlink.EyeState.EyeState_First;
this._blinkingState = EyeState.EyeState_First;
this._nextBlinkingTime = 0.0;
this._stateStartTimeSeconds = 0.0;
this._blinkingIntervalSeconds = 4.0;
Expand Down Expand Up @@ -212,27 +214,24 @@ export namespace Live2DCubismFramework
_closedSeconds: number; // まぶたを閉じている動作の所要時間[秒]
_openingSeconds: number; // まぶたを開く動作の所要時間[秒]
_userTimeSeconds: number; // デルタ時間の積算値[秒]
}

export namespace CubismEyeBlink
{
/**
* まばたきの状態
*
* まばたきの状態を表す列挙型
*/
export enum EyeState
{
EyeState_First = 0, // 初期状態
EyeState_Interval, // まばたきしていない状態
EyeState_Closing, // まぶたが閉じていく途中の状態
EyeState_Closed, // まぶたが閉じている状態
EyeState_Opening // まぶたが開いていく途中の状態
}

/**
* IDで指定された目のパラメータが、0のときに閉じるなら true 、1の時に閉じるなら false 。
*/
export const CloseIfZero = true;
static readonly CloseIfZero: boolean = true;
}

/**
* まばたきの状態
*
* まばたきの状態を表す列挙型
*/
export enum EyeState
{
EyeState_First = 0, // 初期状態
EyeState_Interval, // まばたきしていない状態
EyeState_Closing, // まぶたが閉じていく途中の状態
EyeState_Closed, // まぶたが閉じている状態
EyeState_Opening // まぶたが開いていく途中の状態
}
}
Loading

0 comments on commit bc9f30a

Please sign in to comment.