- Home /
Change texture of individual triangle on a mesh?
I need to know if there is a way to change the texture of an individual triangle on a mesh, rather than the entire mesh itself. And, if so, how could this be done? I have tried a few different techniques, and do not want to use SetPixels() because I don't want to change the original texture. Any ideas?
there is almost certainly a much, much easier way to do what you are trying to achieve.
why not explain what your goal is here?
Answer by Eric5h5 · Oct 11, 2012 at 04:46 AM
Change the appropriate UVs in the mesh that correspond to the triangle you want to change. Keep in mind that no vertices for any triangles can be shared if you want that method to work (i.e., all vertices must be unique).
As for SetPixels, you don't need to change the original texture if you use that; just instantiate the texture first and change the instance.
Answer by karl_ · Oct 11, 2012 at 05:04 AM
You could use `SetTriangles()` to create a subMesh for that triangle, allowing it to have a separate material.
Answer by aldonaletto · Oct 11, 2012 at 05:12 AM
Maybe you could do this with some UV tricks. You could for instance make a kind of atlas - a texture divided in two, where the lower part is the regular image, and the upper part is the alternative texture; make the UV map entirely in the lower part (y between 0 and 0.5), and simply add 0.5 to the y coordinate of each UV pair of the desired triangle when you want to change its texture to the alternate image. For this to work, the triangles should have individual vertices (shared vertices like those used in Unity's primitives would produce horrible images in the adjacent triangles!)
Another possibility is to use some specialized shader that mixes two (or more) textures according to a mask, like the terrain splat shader - you should modify the mask to control which texture appears on a given area.