验证.motion3.json的一致性
最終更新: 2025年5月15日
Cubism SDK可以在导入.motion3.json前验证模型是否包含因篡改而导致的无效数据。
如果需要导入未指定的.motion3.json文件,建议在使用CubismMotion生成副本前确认要导入的.motion3.json文件的一致性。
但是,请注意一致性验证可能会影响性能。
为了验证模型一致性,SDK for Unity使用Framework的CubismMotion3Json.HasConsistency(),其他则使用Framework的CubismMotionJson::HasConsistency()。
Cubism SDK for Native中的CubismMotion::Parse()仅在启用CSM_DEBUG宏时,才会在导入模型时验证.motion3.json文件的一致性。
// Cubism SDK for Native
void CubismMotion::Parse(const csmByte* motionJson, const csmSizeInt size)
{
_motionData = CSM_NEW CubismMotionData;
CubismMotionJson* json = CSM_NEW CubismMotionJson(motionJson, size);
if (!json->IsValid())
{
CSM_DELETE(json);
return;
}
#if CSM_DEBUG
json->HasConsistency();
#endif
…
CSM_DELETE(json);
}
Cubism SDK for Web中的CubismMotion.parse()仅当CubismMotion._debugMode为true时,才会在导入模型时验证.motion3.json文件的一致性。
// Cubism SDK for Web
public parse(motionJson: ArrayBuffer, size: number): void {
...
if (shouldCheckMotionConsistency) {
const consistency = json.hasConsistency();
if (!consistency) {
json.release();
CubismLogError('Inconsistent motion3.json.');
return;
}
}
...
可以使用CubismMotion.setDebugMode()变更CubismMotion._debugMode。
Cubism SDK for Java中的CubismMotion.parse()仅当CubismFrameworkConfig.CSM_DEBUG为true时,才会在导入模型时验证.motion3.json文件的一致性。
// Cubism SDK for Java
private void parse(byte[] motionJson, boolean shouldCheckMotionConsistency) {
...
if (shouldCheckMotionConsistency) {
boolean consistency = json.hasConsistency();
if (!consistency) {
CubismDebug.cubismLogError("Inconsistent motion3.json.");
return;
}
}
...
Cubism SDK for Unity中的CubismMotion3Json.ToAnimationClip()仅当shouldCheckMotionConsistency为true时入.motion3.json时验证文件的一致性。
// Cubism SDK for Unity
public AnimationClip ToAnimationClip(AnimationClip animationClip, bool shouldImportAsOriginalWorkflow = false, bool shouldClearAnimationCurves = false
, bool isCallFormModelJson = false, CubismPose3Json poseJson = null)
{
...
if (shouldCheckMotionConsistency)
{
var consistency = cubismMotion3Json.HasConsistency();
if (!consistency)
{
return null;
}
}
...