- Home /
apply a box uv mapping to a mesh at runtime
I am looking for any hint how to apply a box uv mapping to a mesh. The documentation example covers just a basic planar mapping and I can not manage how to convert it to a box mapping.
Suppose I put a box primitive onto a scene and when I apply the uv to it:
uvs[j] = Vector2(- vertices[j].x, - vertices[j].z + vertices[j].y); //I get textures except left/right plane
uvs[j] = Vector2(-vertices[j].x - vertices[j].z , vertices[j].y ); //I get textures except top/bottom plane
So I was trying to combine it with try/error method, but no satisfactory results
when you say 'box uvw mapping' what exactly do you mean? Do you mean map the mesh using 6 planes? X+, X-, Y+, Y-, Z+, Z-
Exactly. I mean the mapping, when applied to a cube, you get the textures on all the sides, not one like with planar mapping.
Answer by Rod-Green · Dec 30, 2011 at 08:57 AM
This is a very involved task. Basically you'd need to roll you're own uv autounwrap which is no small feat.
1) you would have to parse the mesh and divide the polygons into groups that align to each respective direction. Basically get the normal of each polygon and determine the axis that it differs least.
2) Map each polygon in each group using a basic planar mapping (see unity tutorial).
3) Stitch grouped polygons to identify unique islands (connected uvs that don't connect to other sets of uvs). It's important not to try and stitch polygons across groups as this will severely complicate the problem.
4) Pack resulting uv islands into the 0 to 1 UV range.
5) Have a coffee.
So before you get upset at me for not giving you just a chunk of code to copy and paste.. I would like to reiterate that all those steps are significant problems in their own. I believe you're going to have to tackle this one a little first. Unless of course there's some sample code out there or someone has already completed this and are willing to share.
Maybe break this question up into 3 or more individual questions?
Thanks, I expected it not to be that difficult, see the updated question. $$anonymous$$y two axis solution can serve my current goal, but I wanted to make it general.
Changing the problem to use only 2 planes or axis ins$$anonymous$$d of 6 doesn't really make things any simpler.. You'll still have to do steps .. 1, 2, 3, 4 and maybe 5.
Would http://unity3d.com/support/documentation/ScriptReference/Unwrapping.html help you at all? Why do you need to unwrap the mesh in realtime?
Thanks again. I need to apply unitaty mapping to meshes with different uv mapping applied on import. If all of them were box mapped I could do with texture rescaling, but some use cylindrical wrapping. Luckily at the moment all the mapped surfaces are vertical, so I can do without top and bottom surfaces and can use my simple code. I just want to toggle the single images and repetitive unitary patterns on the meshes.
Your answer
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Shader and Texture Scrolling depending on Direction 1 Answer
Blender to Unity strange normal import problem (bright spots) 1 Answer
Delete Uv2 of a mesh? 1 Answer
Strange shading on single mesh 1 Answer