- Home /
UV map on an arch/ color issue
Hi boys and girls, I tried to play with the UV map but unfortunately i can't take the results i want. I built an arch (a Mesh) in which i applied it a crimson color all around it (Color(0.902, 0.188, 0.0784, 0.5)), but in most points of it the color becomes black and looks quite strange. I want to imply it the exact color of the Color function, anyone can help me with this task? Thanx in advance.
Here's the code:
function Start () {
var X:float = 0;
var Z:float = 0;
var tmpobj : GameObject = new GameObject();
var mf: MeshFilter = tmpobj.AddComponent(MeshFilter);
tmpobj.AddComponent(MeshRenderer);
tmpobj.name = "Arch";
tmpobj.renderer.material.color = Color(0.902, 0.188, 0.0784, 0.5);
var verts: Vector3[] = new Vector3[14];
var uv: Vector2[] = new Vector2[14];
var normals: Vector3[] = new Vector3[14];
var tri: int[] = new int[72]; //3 vertices * 12 triangles = 36 * 2 (duplicate triangles for the back face) =72
//vertices positioning
verts[0] = new Vector3(X - 1.9, 2.5, Z + 3.777); //P1
verts[1] = new Vector3(X - 1.9, 2, Z + 3.777); //P2
verts[2] = new Vector3(X - 1.35, 2, Z + 3.777); //P3
verts[3] = new Vector3(X - 1.35, 3.5, Z + 3.777); //P4
verts[4] = new Vector3(X - 3.5, 3.5, Z + 3.777); //P5
verts[5] = new Vector3(X - 3.5, 2, Z + 3.777); //P6
verts[6] = new Vector3(X - 2.95, 2, Z + 3.777); //P7
verts[7] = new Vector3(X - 2.95, 2.5, Z + 3.777); //P8
verts[8] = new Vector3(X - 2.9, 2.8, Z + 3.777); //P9
verts[9] = new Vector3(X - 2.75, 3, Z + 3.777); //P10
verts[10] = new Vector3(X - 2.55, 3.1, Z + 3.777); //P11
verts[11] = new Vector3(X - 2.3, 3.1, Z + 3.777); //P12
verts[12] = new Vector3(X - 2.1, 3, Z + 3.777); //P13
verts[13] = new Vector3(X - 1.95, 2.8, Z + 3.777); //P14
uv[0] = new Vector2(0, 0.3);
uv[1] = new Vector2(0.2, 0);
uv[2] = new Vector2(0, 0);
uv[3] = new Vector2(0, 1);
uv[4] = new Vector2(1, 1);
uv[5] = new Vector2(1, 0);
uv[6] = new Vector2(0.8, 0);
uv[7] = new Vector2(0.8, 0.3);
uv[8] = new Vector2(0.75, 0.5);
uv[9] = new Vector2(0.65, 0.7);
uv[10] = new Vector2(0.6, 0.9);
uv[11] = new Vector2(0.4, 0.9);
uv[12] = new Vector2(0.45, 0.7);
uv[13] = new Vector2(0.35, 0.5);
//triangles
tri[0] = 0;
tri[1] = 1;
tri[2] = 2;
tri[3] = 0;
tri[4] = 2;
tri[5] = 3;
tri[6] = 0;
tri[7] = 3;
tri[8] = 13;
tri[9] = 13;
tri[10] = 3;
tri[11] = 12;
tri[12] = 12;
tri[13] = 3;
tri[14] = 11;
tri[15] = 11;
tri[16] = 3;
tri[17] = 4;
tri[18] = 11;
tri[19] = 4;
tri[20] = 10;
tri[21] = 10;
tri[22] = 4;
tri[23] = 9;
tri[24] = 9;
tri[25] = 4;
tri[26] = 8;
tri[27] = 8;
tri[28] = 4;
tri[29] = 7;
tri[30] = 7;
tri[31] = 4;
tri[32] = 5;
tri[33] = 7;
tri[34] = 5;
tri[35] = 6;
tri[36] = 0;
tri[37] = 2;
tri[38] = 1;
tri[39] = 0;
tri[40] = 3;
tri[41] = 2;
tri[42] = 13;
tri[43] = 3;
tri[44] = 0;
tri[45] = 12;
tri[46] = 3;
tri[47] = 13;
tri[48] = 11;
tri[49] = 3;
tri[50] = 12;
tri[51] = 10;
tri[52] = 3;
tri[53] = 11;
tri[54] = 10;
tri[55] = 4;
tri[56] = 3;
tri[57] = 9;
tri[58] = 4;
tri[59] = 10;
tri[60] = 8;
tri[61] = 4;
tri[62] = 9;
tri[63] = 7;
tri[64] = 4;
tri[65] = 8;
tri[66] = 7;
tri[67] = 5;
tri[68] = 4;
tri[69] = 7;
tri[70] = 6;
tri[71] = 5;
var mesh: Mesh = new Mesh();
mesh.name = "Arch";
mesh.vertices = verts;
mesh.triangles = tri;
mesh.uv = uv;
mesh.normals = normals;
mesh.RecalculateNormals();
mf.mesh = mesh;
}
Answer by ScroodgeM · Jul 27, 2012 at 02:20 PM
remove this:
mesh.RecalculateNormals();
insert this:
//normals normals[0] = new Vector3(0, 0, 1); normals[1] = new Vector3(0, 0, 1); normals[2] = new Vector3(0, 0, 1); normals[3] = new Vector3(0, 0, 1); normals[4] = new Vector3(0, 0, 1); normals[5] = new Vector3(0, 0, 1); normals[6] = new Vector3(0, 0, 1); normals[7] = new Vector3(0, 0, 1); normals[8] = new Vector3(0, 0, 1); normals[9] = new Vector3(0, 0, 1); normals[10] = new Vector3(0, 0, 1); normals[11] = new Vector3(0, 0, 1); normals[12] = new Vector3(0, 0, 1); normals[13] = new Vector3(0, 0, 1);
important note
if you want your object can be lighted from both sides you should create two sets of vertices with normals to opposite sides. and be carefull to automatically calc normals on flat objects
Thank you for your time and ur solution. Should i keep the uv mapping as it is? I tried ur option with or without the UV mapping and i saw no changes at all.
Plus: When i turn the camera to the X axis i see the arch becomes black and loosing its color. I want to keep it crimson, as it looks in the front.
uv mapping is used for texturing only. so if you will not use a texture - you needn't a UV mapping
When i see my mesh from the back it's completely black. I don't want this to happen. How can i fix this?
solution 1 - use unlit/illum shader that doesn't interact lighting
solution 2 - use two sets of vertices and triangles, two sets must have opposite directed normals
solution 3 - use shader that calculates lighting from both sides
Answer by Bunny83 · Jul 27, 2012 at 03:02 PM
If you want the exact color, make sure you don't use any shader that contains lighting. Use a self-illum shader. You don't need normals in this case.
when you create your mesh, you have to use either a $$anonymous$$eshRenderer + $$anonymous$$eshFilter or a Skinned$$anonymous$$eshRenderer. The Renderer needs a $$anonymous$$aterial that is used to display the mesh. If you don't have it already, you need to create your own material and assign it to the renderer. On this material you can select which shader it should use.
I just saw you create the $$anonymous$$F +$$anonymous$$R at runtime, well, you have to create a $$anonymous$$aterial and pick your desired shader.
edit
Ins$$anonymous$$d of just setting the color, you should do something like:
var mat = new $$anonymous$$aterial (Shader.Find ("Self-Illu$$anonymous$$/Diffuse"));
mat.color = Color(0.902, 0.188, 0.0784, 0.5);
tmpobj.renderer.material = mat;
And remove the whole normal stuff. Setting an uninitialized normals array doesn't make much sense anyway. Recalculate normals have trouble because you re-use the same vertices for the opposite triangles. The calculated surface angles will just be a mess.
Is there a good reason why you create such a "quite complex" mesh via a hardcoded script? Why not building the mesh in an external application?
I knew i had easier and much less complicated ways to make that mesh but i had to do it this way. :/
Anyway thank you very much for ur time and about the knowledge u gave me. :)