- Home /
Cube shows image same on all sides?
hey, im new to the program, im working with a cube that shows a tree.png image. when i rotate the game n it shows the other side of the cube its upside down. a few sides of the cube shows the tree upright but other sides show it upside down, how do i make it so the cube shows the image upright on all 4 sides.
thanks heap
Answer by AlucardJay · Jan 09, 2013 at 12:30 PM
This is a copy of my answer Here : http://answers.unity3d.com/questions/306959/uv-mapping.html
I have listed all the ways to custom UV map a unity cube here : http://answers.unity3d.com/questions/294165/apply-uv-coordinates-to-unity-cube-by-script.html
Imagine looking at the front of the cube, the first 4 vertices are arranged like so
// 2 --- 3
// | |
// | |
// 0 --- 1
then the UV's are mapped as follows :
theUVs[2] = Vector2( 0, 1 );
theUVs[3] = Vector2( 1, 1 );
theUVs[0] = Vector2( 0, 0 );
theUVs[1] = Vector2( 1, 0 );
// 2 3 0 1 Front
// 6 7 10 11 Back
// 19 17 16 18 Left
// 23 21 20 22 Right
// 4 5 8 9 Top
// 15 13 12 14 Bottom
So where the UV's for Vertices 2 is ( 0, 1 ), so is 6, 19, 23, 4, 15.
You can test this by replacing all the zero's with 0.5, then check every face of the cube has the same portion of the image, and rotated the correct way (not inverted) . Note if standing at the origin looking up the positive Z-Axis, Right is your right.
for example this script would map the TOP of the cube to any UV coordinates of a texture you like :
#pragma strict
// TOP
function Start()
{
// Get the mesh
var theMesh : Mesh;
theMesh = this.transform.GetComponent(MeshFilter).mesh as Mesh;
// Now store a local reference for the UVs
var theUVs : Vector2[] = new Vector2[theMesh.uv.Length];
theUVs = theMesh.uv;
// set UV co-ordinates
theUVs[4] = Vector2( 0.5, 1.0 );
theUVs[5] = Vector2( 1.0, 1.0 );
theUVs[8] = Vector2( 0.5, 0.5 );
theUVs[9] = Vector2( 1.0, 0.5 );
// Assign the mesh its new UVs
theMesh.uv = theUVs;
}
don't reinvent the light bulb. Just download the right model in the first place. You didn't deal with mesh tangents. They are used in bump mapping and need to be updated when you change the UV's. I don't understand the math to it, but it makes a big difference.
That is interesting. As just (some of) the UVs are re-assigned, wouldn't the tangents remain persistent? This point wasn't raised on the last 2 questions I gave this answer for. With custom procedural meshes I pass my whole mesh to TangentSolver by Eric5h5
http://forum.unity3d.com/threads/38984-How-to-Calculate-$$anonymous$$esh-Tangents
http://answers.unity3d.com/questions/7789/calculating-tangents-vector4.html
to the OP : I just wanted to know if you saw this, tried it, and what you thought (had alot of answers recently with no response).
I don't feel like stepping through the math to figure out how they use the UV's, but I noticed that they used the texture coordinates in this post of code at lines 17, 34-36,45-48.
Answer by tosi · Jan 09, 2013 at 11:36 AM
I don't know, if there is an easy way in Unity. But you could model a cube in your favorite 3d modelling program and adjust the texture mapping there. After that you import the cube into Unity.
Your answer
