Disable automatic triangle stripping on model import, for the N:th time :)

Hi,

I’ve been fighting with triangle stripping / performance related issues with our game on lower end devices.

We have a bunch of grass objects which need to be rendered as separate polygons. There’s 18 triangles per grass patch, all individual polygons and no transparency, so there’s practically no way to make an efficient triangle strip out of them. Rendering similar grass with transparency tricks does not look good and kills the performance totally on low-end devices.

Now, in a case like this (yes, a rare case, I admit!) it looks like Unity’s built-in triangle stripper produces absolutely horrible results. The 18 triangles per object explodes to a whopping 106 triangles (!) which is 6x the original amount, no matter what we do.

After some frustration and fighting with the mesh/vertex order/trying to combine UV’s etc without luck I wrote a small piece of script which simply copies the vertices, triangles and UVs to a new mesh and does not try to optimize it in any way. Apparently this removes the bad stripping or something, because this drops the runtime polygon amount to 18 triangles per object (checked from the runtime rendered polygon amount), and it also seems to push the game performace up for a few FPS.

Anyway, calling the following code for each generated grass patch is far from efficient solution (because there’s some runtime generated grass too), so I’m asking if there’s ANY way of disabling the automatic triangle stripping during the FBX import, and getting the raw triangle list into Unity? If this is not possible yet, I’m humbly asking if this feature could be added?

Another useful feature would be a way of defining my own strips for the meshes, because my gut feeling is that Unity’s built-in stripper is far from optimal.

	/**
	 *
	 */
	void Reload()
	{
		MeshFilter f = GetComponent<MeshFilter>();
		Vector3[] ver = f.mesh.vertices;
		Vector3[] m_vertices = new Vector3[ver.Length];
		
		for (int a = 0; a < ver.Length; a++)
		{
			m_vertices[a] = ver[a];	
		}
		
		int[] tri = f.mesh.triangles;
		int[] m_triangles = new int[tri.Length];
		for (int a = 0; a < tri.Length; a++)
		{
			m_triangles[a] = tri[a];	
		}

		Vector2[] uv = f.mesh.uv;
		Vector2[] m_uv = new Vector2[uv.Length];
		for (int a = 0; a < uv.Length; a++)
		{
			m_uv[a] = uv[a];	
		}
		
		f.mesh.Clear();
		f.mesh.vertices = m_vertices;
		f.mesh.triangles = m_triangles;
		f.mesh.uv = m_uv;
		f.mesh.RecalculateBounds();
	}

br,
Sami Arola
Technical Director
Ookoohko Oy


+1 for this, it may be a bit of an edge case, but Unity’s model optimizer seems to occasionally mess with polygons which are manually ordered for bottom-to-top rendering in a single draw call, which is very useful when using single-mesh 2d models to avoid z-sorting issues. Check out http://forum.unity3d.com/threads/74196-Doing-2D-animation-with-3d-package/page3.

I’ve also added a suggestion for this option: http://feedback.unity3d.com/forums/15792-unity/suggestions/2220316-importing-disable-automatic-model-optimization-on

Have you had any luck since posting? I’m trying a littany of approaches, and will keep the earlier thread up to date with my findings.

Thanks!

Added a script to replace optimized polygon ordering to the Unify Wiki: http://www.unifycommunity.com/wiki/index.php?title=PolyOrderFixupOnImport