fix: zero scale on outfit destroys transform data (#577)

Closes: #574
This commit is contained in:
bd_ 2023-12-26 16:10:38 +09:00 committed by GitHub
parent e6ffd04110
commit 93aa4db3e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,7 +50,7 @@ namespace nadena.dev.modular_avatar.core.armature_lock
}
}
//[BurstCompile]
[BurstCompile]
struct ComputePosition : IJobParallelFor
{
[ReadOnly] public NativeArray<BoneStaticData> _boneStatic;
@ -115,6 +115,8 @@ namespace nadena.dev.modular_avatar.core.armature_lock
_baseParentBones = new Transform[mergeToBase.Count];
_mergeParentBones = new Transform[mergeToBase.Count];
try
{
for (int i = 0; i < mergeToBase.Count; i++)
{
var (mergeBone, baseBone) = mergeToBase[i];
@ -126,6 +128,12 @@ namespace nadena.dev.modular_avatar.core.armature_lock
throw new Exception("Can't handle root objects");
}
if (SmallScale(mergeParent.localScale) || SmallScale(mergeBone.localScale) ||
SmallScale(baseBone.localScale))
{
throw new Exception("Can't handle near-zero scale bones");
}
_baseBones[i] = baseBone;
_mergeBones[i] = mergeBone;
_baseParentBones[i] = baseParent;
@ -161,6 +169,18 @@ namespace nadena.dev.modular_avatar.core.armature_lock
_mat_r = mat_l
};
}
}
catch (Exception e)
{
_boneStaticData.Dispose();
_mergeSavedState.Dispose();
_baseState.Dispose();
_mergeState.Dispose();
_fault.Dispose();
_wroteAny.Dispose();
throw e;
}
_baseBonesAccessor = new TransformAccessArray(_baseBones);
_mergeBonesAccessor = new TransformAccessArray(_mergeBones);
@ -170,6 +190,13 @@ namespace nadena.dev.modular_avatar.core.armature_lock
#endif
}
private bool SmallScale(Vector3 scale)
{
var epsilon = 0.000001f;
return (scale.x < epsilon || scale.y < epsilon || scale.z < epsilon);
}
private bool DoCompute(out JobHandle handle)
{
handle = default;