FBX Import Settings on Mesh Assets

From the Project window, clicking on an FBX file brings up the Import Settings in the Inspector panel. In particular, I want to use Optimize Mesh, Weld Vertices and Calculate Normals, which all make my meshes more efficient.

Meshes can also exist in the filesystem as .asset files, but clicking on these brings up a mostly blank Inspector panel with no import options.

So, how do I use the Optimize Mesh / Weld Vertices / Calculate Normals utils on meshes saved as .asset files?

Are those utilities accessible in the Unity API?

Can asset meshes be repackaged back to FBX?

Does anyone have source code for those functions?

Optimize Mesh is: [UnityEditor.MeshUtility.Optimize()][1]

Calculate Normals is: [Mesh.RecalculateNormals()][2]. It doesn’t include smoothing angle option and doesn’t change the number of vertices, but [Unwrapping.GenerateSecondaryUVSet()][3] does. Though I think it only adds vertices and won’t remove them. So first you need:

Weld Vertices I tweaked from a [couple][4] [sources][5]:

public static void WeldVertices(Mesh mesh, float threshold = float.Epsilon) {
	Vector3[] oldVertices = mesh.vertices;
	Color[] oldColors = mesh.colors;
	Vector3[] newVertices = new Vector3[oldVertices.Length];
	Color[] newColors = new Color[oldVertices.Length];
	int[] old2new = new int[oldVertices.Length];
	int newSize = 0;
	
	// make new vertices with no duplicates
	for (int i = 0; i < oldVertices.Length; i++) {
		bool foundMatch = false;
		for (int j = 0; j < newSize; j++) {
			if (Vector3.SqrMagnitude(newVertices[j] - oldVertices*) < threshold) {*

_ if (oldColors.Length >= i + 1 && newColors[j] == oldColors*) {_
_ old2new = j;
foundMatch = true;
}
}
}*_

* if (!foundMatch) {*
* // Add new vertex*
_ newVertices[newSize] = oldVertices*;
if (oldColors.Length >= i + 1) {
newColors[newSize] = oldColors;
}
old2new = newSize;
newSize++;
}
}*_

* // make new triangles*
* int[] oldTris = mesh.triangles;*
* int[] newTris = new int[oldTris.Length];*
* for (int i = 0; i < oldTris.Length; i++) {*
newTris = old2new[oldTris*];*
* }*

* Vector3[] finalVertices = new Vector3[newSize];*
* Color[] finalColors = new Color[newSize];*
* for (int i = 0; i < newSize; i++) {*
finalVertices = newVertices*;*
finalColors = newColors*;*
* }*

* mesh.Clear();*
* mesh.vertices = finalVertices;*
* mesh.colors = finalColors;*
* mesh.triangles = newTris;*
* mesh.uv = null;*
* mesh.uv2 = null;*
}
*[1]: https://docs.unity3d.com/ScriptReference/MeshUtility.Optimize.html*_
[2]: https://docs.unity3d.com/ScriptReference/Mesh.RecalculateNormals.html*_
_[3]: https://docs.unity3d.com/ScriptReference/Unwrapping.GenerateSecondaryUVSet.html*_

_[4]: http://answers.unity3d.com/questions/228841/dynamically-combine-verticies-that-share-the-same.html*_
[5]: http://wiki.unity3d.com/index.php/Mesh_simplification_(for_MeshCollider,_lossless)*