Skip to content

Commit

Permalink
fix: some rare material swap animation will be broken
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed May 11, 2024
1 parent ddee675 commit a08476b
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions Editor/Processors/RemoveInvalidProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,41 @@ static AnimatablePropertyRegistry()
var materialSlots = mesh.SubMeshes.Sum(y => y.SharedMaterials.Length);
return (prop) =>
{
if (prop.StartsWith("blendShape."))
{
var name = prop.Substring("blendShape.".Length);
int index;

if (TrySubProp(prop, "blendShape", out var name))
return mesh.BlendShapes.FindIndex(b => b.name == name) != -1;
}

if (prop.StartsWith("m_Materials.Array.data["))
{
var index = int.Parse(prop.Substring("m_Materials.Array.data[".Length).TrimEnd(']'));
if (TryArrayIndex(prop, "materials", out index))
return index < materialSlots;
}

if (VProp.IsBlendShapeIndex(prop))
{
var index = VProp.ParseBlendShapeIndex(prop);
return index < mesh.BlendShapes.Count;
}
return VProp.ParseBlendShapeIndex(prop) < mesh.BlendShapes.Count;

return true;
};
});
}

private static bool TrySubProp(string prop, string subProp, out string sub)
{
sub = null;
if (!prop.StartsWith(subProp + '.')) return false;
sub = prop.Substring(subProp.Length + 1);
return true;
}

private static bool TryArrayIndex(string prop, string arrayPropertyName, out int index)
{
index = -1;
if (!prop.StartsWith(arrayPropertyName)) return false;
prop = prop.Substring(arrayPropertyName.Length);
if (!prop.StartsWith(".Array.data[")) return false;
prop = prop.Substring(".Array.data[".Length);
var close = prop.IndexOf(']');
if (close == -1) return false;
if (!int.TryParse(prop.Substring(0, close), out index)) return false;
return true;
}
}
}

0 comments on commit a08476b

Please sign in to comment.