Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by velv · Jul 26, 2012 at 04:21 PM · meshcolormapuv

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;
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image velv · Jul 27, 2012 at 04:35 PM 0
Share

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.

avatar image ScroodgeM · Jul 27, 2012 at 04:37 PM 0
Share

uv mapping is used for texturing only. so if you will not use a texture - you needn't a UV mapping

avatar image velv · Jul 30, 2012 at 01:04 PM 0
Share

When i see my mesh from the back it's completely black. I don't want this to happen. How can i fix this?

avatar image ScroodgeM · Jul 30, 2012 at 01:15 PM 1
Share
  • 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

avatar image
0

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image velv · Jul 27, 2012 at 04:26 PM 0
Share

ok. but how am i supposed to do that?

avatar image Bunny83 · Jul 27, 2012 at 07:56 PM 0
Share

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.

avatar image Bunny83 · Jul 27, 2012 at 07:58 PM 0
Share

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?

avatar image velv · Jul 30, 2012 at 12:00 PM 0
Share

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. :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

Color not appearing on created mesh? (only grey) 2 Answers

What is the most efficient way to sample the color at a point on a mesh? 1 Answer

Meshes not respecting Blender uv maps 3 Answers

To color each single cube from texture 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges