- Home /
Mesh.colors and Mesh.SetTriangleStrip - what do they do?
This question is a two parter. I am trying to explore all that you can do with meshes, and I've come across two things that I just don't understand.
The first is Mesh.Color. It sets vertex colors - what exactly does that mean? I added a script that sets colors for a mesh, and I see no visual change. I've come across a couple tidbits that mention that certain shaders can use the vertex colors - is there any documentation on how to do this? Bonus points if someone can give me a simple unlit or diffuse shader that applies the color to each vertex so we can see the colors visually.
The second is Mesh.SetTriangleStrip. There is literally no documentation for this. I'm guessing it refers to [this][1]. So how do you define the triangle strip, and how do you define the verts so the triangle strip can use them?
Thanks to anyone that can help me figure these out. If someone can provide information, I'll be sure to pester Unity to get it added to their documentation. I'll also create a blog post so people can find it in a google search. [1]: http://en.wikipedia.org/wiki/Triangle_strip
Answer by Eric5h5 · Dec 02, 2011 at 03:22 AM
Vertex colors sets colors for each vertex in a mesh. You need a shader that uses vertex colors to see them. Features that are undocumented means that they aren't officially supported, and can change at any time, which means you're generally better off not using them. So, please don't pester them about it. (Pester them about entries in the documentation that exist, but consist of a single line of cryptic text with no examples. ;) ) Mesh.Optimize() creates triangle strips, so you can probably use that instead.
Thanks @Eric5h5
I did a search for "unity shader that uses vertex colors" and finally came across a shader example that you submitted:
Hopefully that'll be all I need.
As for the second part, even if triangle strips aren't supported, our need is so great that I'm going to try and implement them, and fall back to other methods later if necessary. We're creating a combined mesh of global scientific data with roughly 2.8 million hexagons / 20 million verts that ends up requiring 280 game objects to be instantiated. This takes us about 15 seconds to read in and create, and requires 200$$anonymous$$ of memory per mesh.
I'll try looking into $$anonymous$$esh.optimize, but I'm guessing that would significantly slow things down. We're creating a regular grid, so it's an ideal case for doing the triangle strip ourselves. If you or anyone else could explain the very basics of defining a triangle strip I can take it from there.
$$anonymous$$ost or all of the particle shaders use vertex colors (that's how different particles can have different colors).
Sure, here's how a triangle strip works ;)
I'm not sure if and how Unity handles "degenerated strips" since there's no documentation about it and i've never used it in Unity ;)
Strips normally require a continous triangle strip so for each additional triangle you need only one extra index value because it uses the two last indices. Note: in a strip the winding order changes every triangle.
Just found a great paper about Unity and Triangle strips:
Your answer