- Home /
Where is the submesh Reference of vertex/triangle?
A triangle or vertex has to have a Reference in which submesh it should be rendered? A Reference in which vertex Group he is in. If i have two materials attached to a the Object, it has to know which material to use in which area of the Object. Is it in the MeshFilter.mesh.something....? or MeshRenderer.something ? Where can i find this Information in Skript?
I want to know it, because i want to move a triangle with skript from rendering with one material to rendering with another secound material.
Answer by Bunny83 · Aug 20, 2021 at 11:08 PM
Well a Mesh only has a sinle Vertex buffer that is shared by the whole mesh and all submeshes. It's only thr triangles that belong to certain submeshes. It may be that certain vertices are only used / referenced by a particular submesh, but several triangles from different submeshes can use the same vertices is applicable.
The Mesh class of course has the triangles array, however this is a collapsed array of all submeshes. What you want to do is use GetTriangles to get an array with only the triangles from a particular submesh and of course SetTriangles to set the triangles for a submesh.
Note that GetTriangles and SetTriangles also support Lists which you can reuse if you need to read or write the triangles frequently.
Finally I should point out that Unity also supports different mesh topologies than triangles. It also supports Quads and triangle strips. It also supports lines or points, though those are rarely used. Points are handy if you have a geometry shader that produces additional geometry for each point. However that's a quite advanced topic. Anyways in order to read or write the indices of a different topology you should use GetIndices and SetIndices. There's also the GetTopology method that allows you to figure out the topology of a certain submesh.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Fixing mesh normals 1 Answer
Procedural mesh slows down scene 0 Answers
Unity not properly rendering mesh faces 1 Answer
Submesh creation from script 3 Answers