Added range check for blendShape

This commit is contained in:
ousttrue
2018-08-02 16:59:48 +09:00
parent c8d45a8eed
commit e324bfa711
4 changed files with 26 additions and 3 deletions

View File

@@ -10,6 +10,11 @@ namespace VRM
public String RelativePath;
public int Index;
public float Weight;
public override string ToString()
{
return string.Format("{0}[{1}]=>{2}", RelativePath, Index, Weight);
}
}
[Serializable]

View File

@@ -62,10 +62,18 @@ namespace VRM
}
if (target != null)
{
m_blendShapeSetterMap.Add(binding, x =>
if (binding.Index >= 0 && binding.Index < target.sharedMesh.blendShapeCount)
{
m_blendShapeSetterMap.Add(binding, x =>
{
target.SetBlendShapeWeight(binding.Index, x);
});
}
else
{
Debug.LogWarningFormat("Invalid blendshape binding: {0}: {1}", target.name, binding);
}
}
else
{

View File

@@ -147,7 +147,17 @@ namespace VRM
{
if (x.RelativePath == Path)
{
SkinnedMeshRenderer.SetBlendShapeWeight(x.Index, x.Weight * weight);
if(x.Index>=0 && x.Index < SkinnedMeshRenderer.sharedMesh.blendShapeCount)
{
SkinnedMeshRenderer.SetBlendShapeWeight(x.Index, x.Weight * weight);
}
else
{
Debug.LogWarningFormat("Out of range {0}: 0 <= {1} < {2}",
SkinnedMeshRenderer.name,
x.Index,
SkinnedMeshRenderer.sharedMesh.blendShapeCount);
}
}
}
}

Submodule UniGLTF updated: 03a4b678fc...00452b9dc8