Update to Cubism 4 SDK for Web R5 beta5
This commit is contained in:
@ -24,7 +24,10 @@ export class CubismMoc {
|
||||
|
||||
if (moc) {
|
||||
cubismMoc = new CubismMoc(moc);
|
||||
cubismMoc._mocVersion = Live2DCubismCore.Version.csmGetMocVersion(moc);
|
||||
cubismMoc._mocVersion = Live2DCubismCore.Version.csmGetMocVersion(
|
||||
moc,
|
||||
mocBytes
|
||||
);
|
||||
}
|
||||
|
||||
return cubismMoc;
|
||||
|
@ -129,14 +129,20 @@ export class CubismUserModel {
|
||||
*/
|
||||
public loadModel(buffer: ArrayBuffer) {
|
||||
this._moc = CubismMoc.create(buffer);
|
||||
this._model = this._moc.createModel();
|
||||
this._model.saveParameters();
|
||||
|
||||
if (this._moc == null || this._model == null) {
|
||||
if (this._moc == null) {
|
||||
CubismLogError('Failed to CubismMoc.create().');
|
||||
return;
|
||||
}
|
||||
|
||||
this._model = this._moc.createModel();
|
||||
|
||||
if (this._model == null) {
|
||||
CubismLogError('Failed to CreateModel().');
|
||||
return;
|
||||
}
|
||||
|
||||
this._model.saveParameters();
|
||||
this._modelMatrix = new CubismModelMatrix(
|
||||
this._model.getCanvasWidth(),
|
||||
this._model.getCanvasHeight()
|
||||
|
@ -175,15 +175,17 @@ export class CubismPhysics {
|
||||
currentRigOutput.output.resize(
|
||||
this._physicsRig.settings.at(i).outputCount
|
||||
);
|
||||
this._currentRigOutputs.pushBack(currentRigOutput);
|
||||
|
||||
let previousRigOutput = new PhysicsOutput();
|
||||
previousRigOutput.output.resize(
|
||||
this._physicsRig.settings.at(i).outputCount
|
||||
);
|
||||
this._previousRigOutputs.pushBack(previousRigOutput);
|
||||
|
||||
for (let j = 0; j < this._physicsRig.settings.at(i).outputCount; ++j) {
|
||||
// initialize
|
||||
currentRigOutput.output[j] = 0.0;
|
||||
previousRigOutput.output[j] = 0.0;
|
||||
|
||||
this._physicsRig.outputs.at(outputIndex + j).destinationParameterIndex =
|
||||
-1;
|
||||
this._physicsRig.outputs.at(outputIndex + j).vertexIndex =
|
||||
@ -224,6 +226,10 @@ export class CubismPhysics {
|
||||
this._physicsRig.outputs.at(outputIndex + j).reflect =
|
||||
json.getOutputReflect(i, j);
|
||||
}
|
||||
|
||||
this._currentRigOutputs.pushBack(currentRigOutput);
|
||||
this._previousRigOutputs.pushBack(previousRigOutput);
|
||||
|
||||
outputIndex += this._physicsRig.settings.at(i).outputCount;
|
||||
|
||||
// Particle
|
||||
@ -325,7 +331,16 @@ export class CubismPhysics {
|
||||
parameterMinimumValue = model.getModel().parameters.minimumValues;
|
||||
parameterDefaultValue = model.getModel().parameters.defaultValues;
|
||||
|
||||
this._parameterCache = new Float32Array(model.getParameterCount());
|
||||
if ((this._parameterCache?.length ?? 0) < model.getParameterCount()) {
|
||||
this._parameterCache = new Float32Array(model.getParameterCount());
|
||||
}
|
||||
|
||||
if ((this._parameterInputCache?.length ?? 0) < model.getParameterCount()) {
|
||||
this._parameterInputCache = new Float32Array(model.getParameterCount());
|
||||
for (let j = 0; j < model.getParameterCount(); ++j) {
|
||||
this._parameterInputCache[j] = parameterValue[j];
|
||||
}
|
||||
}
|
||||
|
||||
if (this._physicsRig.fps > 0.0) {
|
||||
physicsDeltaTime = 1.0 / this._physicsRig.fps;
|
||||
@ -350,8 +365,16 @@ export class CubismPhysics {
|
||||
}
|
||||
}
|
||||
|
||||
// 入力キャッシュとパラメータで線形補間してUpdateParticlesするタイミングでの入力を計算する。
|
||||
// Calculate the input at the timing to UpdateParticles by linear interpolation with the _parameterInputCache and parameterValue.
|
||||
// _parameterCacheはグループ間での値の伝搬の役割があるので_parameterInputCacheとの分離が必要。
|
||||
// _parameterCache needs to be separated from _parameterInputCache because of its role in propagating values between groups.
|
||||
const inputWeight = physicsDeltaTime / this._currentRemainTime;
|
||||
for (let j = 0; j < model.getParameterCount(); ++j) {
|
||||
this._parameterCache[j] = parameterValue[j];
|
||||
this._parameterCache[j] =
|
||||
this._parameterInputCache[j] * (1.0 - inputWeight) +
|
||||
parameterValue[j] * inputWeight;
|
||||
this._parameterInputCache[j] = this._parameterCache[j];
|
||||
}
|
||||
|
||||
for (
|
||||
@ -422,16 +445,16 @@ export class CubismPhysics {
|
||||
for (let i = 0; i < currentSetting.outputCount; ++i) {
|
||||
const particleIndex = currentOutput[i].vertexIndex;
|
||||
|
||||
if (currentOutput[i].destinationParameterIndex == -1) {
|
||||
currentOutput[i].destinationParameterIndex =
|
||||
model.getParameterIndex(currentOutput[i].destination.id);
|
||||
}
|
||||
|
||||
if (
|
||||
particleIndex < 1 ||
|
||||
particleIndex >= currentSetting.particleCount
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentOutput[i].destinationParameterIndex == -1) {
|
||||
currentOutput[i].destinationParameterIndex =
|
||||
model.getParameterIndex(currentOutput[i].destination.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
const translation: CubismVector2 = new CubismVector2();
|
||||
@ -518,6 +541,10 @@ export class CubismPhysics {
|
||||
|
||||
// Load input parameters.
|
||||
for (let i = 0; i < currentSetting.outputCount; ++i) {
|
||||
if (currentOutput[i].destinationParameterIndex == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const destinationParameterIndex: number =
|
||||
currentOutput[i].destinationParameterIndex;
|
||||
const outParameterValue: Float32Array =
|
||||
@ -582,6 +609,7 @@ export class CubismPhysics {
|
||||
this._previousRigOutputs = new csmVector<PhysicsOutput>();
|
||||
this._currentRemainTime = 0.0;
|
||||
this._parameterCache = null;
|
||||
this._parameterInputCache = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -652,6 +680,7 @@ export class CubismPhysics {
|
||||
_currentRemainTime: number; ///< 物理演算が処理していない時間
|
||||
|
||||
_parameterCache: Float32Array; ///< Evaluateで利用するパラメータのキャッシュ
|
||||
_parameterInputCache: Float32Array; ///< UpdateParticlesが動くときの入力をキャッシュ
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user