How does Unity know where to render each material? I am at a loss here, the imported mesh (from Blender) has 4 materials and no textures at all, thus there are no UVs which would be my understanding would define where to render what. My guess is that blender maps where each mat is used and then pass that data to Unity on the import process but i have no clue where those data stored (on metadata maybe?) and how do i gain access on them.
Anyway my goal is to find out what material is used on specific world point on said mesh on edit/runtime doesn’t matter.
Thanks in advance, any insight or work around would be appreciated.
I’m not certain about Unity in particular (but reasonably confident, enough I don’t mind having a guess), but I believe the common technique to handle different materials and/or shaders is internally to split the mesh into multiple meshes, with each “sub-mesh” being the parts of that mesh that need to be rendered with a particular material.
If the property can be stored per vertex, like colour, another option can be to do so and use the per vertex property in the shader to produce say varying colours accross a mesh (even without texturing UVs)
No idea, maybe raycast against each submesh and use the closest hit?
Fbx defines more information per vertex or face than is used to render. So it knows which face or verts are mapped to what materials.
Then unity would basically maintain that separation through submeshes as mentioned.
Most likely as a indexed mesh with different ranges of indexes mapped to each material.
Uvs don’t map to materials, they are used as data for a material.
So submesh A uses material X with texture T with uv from vertex V.
Thank ya guys that makes perfect sense, how did i miss it on documentation/ manual eludes me.
Note Mesh.GetTringles(subMeshIndex) will return the triangles associated with each material.