Change mesh translation for future placements

Hi,

I have an object that I imported with several meshes. Some of them have nontrivial translations, and I would like to bake those translations in. The code I wrote was this :

private static void NormalizeMesh(MeshFilter mf)
    {
        Transform transform = mf.transform;
        if (transform.localPosition != Vector3.zero ||
            transform.localRotation != Quaternion.identity ||
            transform.localScale != Vector3.one)
        {
            Vector3[] vertices = mf.sharedMesh.vertices;
            Vector3[] normals = mf.sharedMesh.normals;
            for (int i = 0; i < mf.sharedMesh.vertexCount; i++)
            {
                vertices _= transform.TransformPoint(vertices*);*_
 <em><em>normals _= transform.TransformDirection(normals*);*_</em></em>
 <em><em>_*//Tangents? UVs?*_</em></em>
 <em><em>_*}*_</em></em>
 <em><em>_*mf.sharedMesh.vertices = vertices;*_</em></em>
 <em><em>_*mf.sharedMesh.normals = normals;*_</em></em>
 <em><em>_*mf.transform.localPosition = Vector3.zero;*_</em></em>
 <em><em>_*mf.transform.localRotation = Quaternion.identity;*_</em></em>
 <em><em>_*mf.transform.localScale = Vector3.one;*_</em></em>
 <em><em>_*}*_</em></em>
<em><em>_*```*_</em></em>
<em><em>_*<p>I want to be able to do this only once per mesh, and that the next time that I add the object to the scene hierarchy it will already be fixed.*_</em></em>
<em><em>_*The code that I wrote takes care of the mesh for good, but it only takes care of the translation for the instance that I added.*_</em></em>
<em><em>_*This is because the sharedMesh gets saved back to the model, but the changes to the mesh filter don't get changed - the next time I will add the model, the vertices will be baked but the transform will remain the original one.</p>*_</em></em>
<em><em>_*<p>Is there a way to modify the mesh's transform for future insertions into the scene?</p>*_</em></em>

You could save it as a prefab at the end of your script.

Call your function in AssetPostprocessor.OnPostprocessModel and modify the shared mesh.