As part of my current project, I need to generate hashes for meshes in Unity. These are used to later check whether the mesh content has changed. Due to interface considerations, the hash unfortunately has to be in form of a string.
My current approach looks like this:
public override string GetHash()
{
StringBuilder hash = new StringBuilder();
hash.Append("v");
foreach (Vector3 val in this.v)
{
hash.Append(val.ToString());
}
hash.Append("n");
foreach (Vector3 val in this.n)
{
hash.Append(val.ToString());
}
hash.Append("u");
foreach (Vector2 val in this.u)
{
hash.Append(val.ToString());
}
hash.Append("v");
foreach (int val in this.t)
{
hash.Append(val.ToString());
}
return hash.ToString();
}
This has turned out to be a significant bottleneck, primarily due to the Vector3.ToString()-calls. (about 4-5ms for the cube primitive).
Are there more performant ways to hash meshes that are still sensitive to small changes in the mesh?