- Home /
How to Generate flat uvs
Hello. I was wondering how to generate uvs that are flat across an object. That is, I have a decal that is generated around the objects that are within it, but the uvs are relative to the rotation of the projector. I was wondering how to generate the uvs so that it ignored the rotation and simply generated them as if the decal was a simple plane. Thanks in advance!
Edit:
Sorry for any confusion. First of all, 'projector' was a poor choice of words, I did not mean the projector component in unity. I am in fact using a modified version of the Bootcamp Decal system, if that clears up any conjecture. That decal system uses the local positive Z to define the direction of the decal. But lets say for a second that we have a cube. if the cube is at a rotation of (0, 0, 0), and the decal is facing down, the decal is projected on the top face of the cube. If, however, I was to, say, move the decal so that part of it's bounds is outside of the cube. Now, some of the decal is generated on the side face of the cube. But the uvs of the Side face of the cube are wrong, they are stretched out infinitely. I want it so that the uvs are mapped so that the texture simply drops onto the decal mesh as if it where a flat, 2D plane.
Sorry about the confusion!! I just fixed(hopefully) that!!!
Answer by Wolfram · Jun 15, 2012 at 08:49 PM
If your decal is implemented using a Projector, this will not be possible, since the Projector knows nothing about the shape of the object that it hits.
If it is a Projector, which rotation(s) are the problem? Only the "forward"/Z-direction? If so, why is the Projector rotated around that axis in the first place?
If you create your decal mesh yourself, which somehow adapts the object's shape, you'd need to compute the uvs along with the vertices. But you would have to assume some kind of mathematical projection for non-planar meshes.
If I misinterpreted your question entirely, please provide a snapshot of the situation :o)
EDIT: Revised version according to your edit of the question:
Well, that's a very complicated task, generally only with solutions for very special cases (a cube might be relatively simple), or using special heuristics/assumptions about the model onto which you want to display the decal, since you need some topological information about the mesh of that model (where are the edges, are there more than one, what if the planar decal (imagine it as a piece of paper) cannot be wrapped seamlessly onto the object (imagine a cube corner, as opposed to an edge, or a sphere), and so on). An extreme case related to a solution is actual cloth simulation.
You could actually do use a projector, and project the decal onto your object. But I guess that's still not what you like, since it only works for meshes generally oriented towards the projector, and it would still distort the decal somewhat, even when rotating the projector around the edge.
Here is an interesting suggestion for the "wrap around one corner" case, which might suffice, depending on your usecase: http://forum.unity3d.com/threads/2562-blood-splatter?p=719943&viewfull=1#post719943
Hey that was me! Awesome!
You know, there is actually a nice blog post somewhere from a guy who bothered to write dynamic decals that bend around corners. {wouldn't really call them 'decals" then, I don't think -- too complex!} unfortunately, I can't find it at the moment.