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 Kordanor · Feb 24, 2013 at 04:27 PM · tilesisometricwalls

Bottom-texture of code generated cube does not draw

Heya, I am generating cubes with my code (actually these are walls, but should not make a difference here) and I can't find the reason why the bottom is not drawn. While it is not crucial for the project itself (you won't be able to see the bottom of the wall anyways) I'd like to know if there is an mistake in my code which I can't find. I marked the spot where I suspect the error with "NEEDS CORRECTION!"

                 vertices[tileCounter*24+00]    = leftBtmFront;
                 vertices[tileCounter*24+01]    = rightBtmFront;
                 vertices[tileCounter*24+02]    = leftTopFront;
                 vertices[tileCounter*24+03]    = leftBtmBack;
                 vertices[tileCounter*24+04]    = rightBtmBack;
                 vertices[tileCounter*24+05]    = rightTopFront;
                 vertices[tileCounter*24+06]    = leftTopBack;
                 vertices[tileCounter*24+07]    = rightTopBack;
                 
                 vertices[tileCounter*24+08]    = leftBtmFront;
                 vertices[tileCounter*24+09]    = rightBtmFront;
                 vertices[tileCounter*24+10]    = leftTopFront;
                 vertices[tileCounter*24+11]    = leftBtmBack;
                 vertices[tileCounter*24+12]    = rightBtmBack;
                 vertices[tileCounter*24+13]    = rightTopFront;
                 vertices[tileCounter*24+14]    = leftTopBack;
                 vertices[tileCounter*24+15]    = rightTopBack;
                 
                 vertices[tileCounter*24+16]    = leftBtmFront;
                 vertices[tileCounter*24+17]    = rightBtmFront;
                 vertices[tileCounter*24+18]    = leftTopFront;
                 vertices[tileCounter*24+19]    = leftBtmBack;
                 vertices[tileCounter*24+20]    = rightBtmBack;
                 vertices[tileCounter*24+21]    = rightTopFront;
                 vertices[tileCounter*24+22]    = leftTopBack;
                 vertices[tileCounter*24+23]    = rightTopBack;
                 
                 //front and back
                 uv[tileCounter*24+00]    =new Vector2(0,0);//linksUntenVorn
                 uv[tileCounter*24+01]    =new Vector2(1,0);//rechtsUntenVorn
                 uv[tileCounter*24+02]    =new Vector2(0,1);//linksObenVorn
                 uv[tileCounter*24+03]    =new Vector2(0,0);//linksUntenHinten
                 uv[tileCounter*24+04]    =new Vector2(1,0);//rechtsUntenHinten
                 uv[tileCounter*24+05]    =new Vector2(1,1);//rechtsObenVorn
                 uv[tileCounter*24+06]    =new Vector2(0,1);//linksObenHinten
                 uv[tileCounter*24+07]    =new Vector2(1,1);//rechtsObenHinten
                 //left and right
                 uv[tileCounter*24+08]    =new Vector2(1,0);//rechtsuntenvorn1,0
                 uv[tileCounter*24+09]    =new Vector2(1,0);//rechtsuntenhinten1,0 
                 uv[tileCounter*24+10]    =new Vector2(1,1);//rechtsobenvorn1,1
                 uv[tileCounter*24+11]    =new Vector2(0,0);//linksuntenvorn0,0
                 uv[tileCounter*24+12]    =new Vector2(0,0);//linksuntenhinten0,0
                 uv[tileCounter*24+13]    =new Vector2(1,1);//rechtsobenhinten1,1
                 uv[tileCounter*24+14]    =new Vector2(0,1);//linksobenvorn0,1
                 uv[tileCounter*24+15]    =new Vector2(0,1);//linksobenhinten0,1
                 //top and bottom
                 //************************NEEDS CORRECTION!*************bottom not displayed correctly
                 uv[tileCounter*24+16]    =new Vector2(0,0);//linksUntenHinten-0,0
                 uv[tileCounter*24+17]    =new Vector2(0,1);//rechtsUntenhinten-0,1
                 uv[tileCounter*24+19]    =new Vector2(1,0);//linksObenhinten-1,0
                 uv[tileCounter*24+20]    =new Vector2(1,1);//rechtsObenHinten-1,1
                 //************************NEEDS CORRECTION!*************
                 
                 
                 uv[tileCounter*24+18]    =new Vector2(0,0);//linksUntenVorn0,0
                 
                 uv[tileCounter*24+21]    =new Vector2(1,0);//rechtsUntenVorn1,0
                 uv[tileCounter*24+22]    =new Vector2(0,1);//linksObenVorn0,1
                 uv[tileCounter*24+23]    =new Vector2(1,1);//rechtsObenVorn1,1
                 
                 triangles[tileCounter*36+00]    =00+tileCounter*24;//leftBtmFront
                 triangles[tileCounter*36+01]    =02+tileCounter*24;//leftTopFront
                 triangles[tileCounter*36+02]    =01+tileCounter*24;//rightBtmFront
                 triangles[tileCounter*36+03]    =01+tileCounter*24;//rightBtmFront
                 triangles[tileCounter*36+04]    =02+tileCounter*24;//leftTopFront
                 triangles[tileCounter*36+05]    =05+tileCounter*24;//rightTopFront;
                 triangles[tileCounter*36+06]    =03+tileCounter*24;//leftBtmBack;
                 triangles[tileCounter*36+07]    =00+tileCounter*24;//leftBtmFront
                 triangles[tileCounter*36+08]    =01+tileCounter*24;//rightBtmFront
                 triangles[tileCounter*36+09]    =01+tileCounter*24;//rightBtmFront
                 triangles[tileCounter*36+10]    =04+tileCounter*24;//rightBtmBack;
                 triangles[tileCounter*36+11]    =03+tileCounter*24;//leftBtmBack;
                 
                 triangles[tileCounter*36+12]    =08+tileCounter*24;//leftBtmFront
                 triangles[tileCounter*36+13]    =11+tileCounter*24;//leftBtmBack
                 triangles[tileCounter*36+14]    =10+tileCounter*24;//leftTopFront
                 triangles[tileCounter*36+15]    =10+tileCounter*24;//leftTopFront
                 triangles[tileCounter*36+16]    =11+tileCounter*24;//leftBtmBack;
                 triangles[tileCounter*36+17]    =14+tileCounter*24;//leftTopBack
                 triangles[tileCounter*36+18]    =09+tileCounter*24;//rightBtmFront
                 triangles[tileCounter*36+19]    =13+tileCounter*24;//rightTopFront;
                 triangles[tileCounter*36+20]    =12+tileCounter*24;//rightBtmBack;
                 triangles[tileCounter*36+21]    =13+tileCounter*24;//rightTopBack
                 triangles[tileCounter*36+22]    =15+tileCounter*24;//rightTopBack
                 triangles[tileCounter*36+23]    =12+tileCounter*24;//rightBtmBack;
                 
                 triangles[tileCounter*36+24]    =22+tileCounter*24;//leftTopBack
                 triangles[tileCounter*36+25]    =19+tileCounter*24;//leftBtmBack;
                 triangles[tileCounter*36+26]    =20+tileCounter*24;//rightBtmBack;
                 triangles[tileCounter*36+27]    =22+tileCounter*24;//leftTopBack
                 triangles[tileCounter*36+28]    =20+tileCounter*24;//rightBtmBack;
                 triangles[tileCounter*36+29]    =23+tileCounter*24;//rightTopBack
                 triangles[tileCounter*36+30]    =22+tileCounter*24;//leftTopBack
                 triangles[tileCounter*36+31]    =21+tileCounter*24;//rightTopFront;
                 triangles[tileCounter*36+32]    =18+tileCounter*24;//leftTopFront
                 triangles[tileCounter*36+33]    =23+tileCounter*24;//rightTopBack
                 triangles[tileCounter*36+34]    =21+tileCounter*24;//rightTopFront;
                 triangles[tileCounter*36+35]    =22+tileCounter*24;//leftTopBack

For now I am only using a little image and not an image map which will be added later. So it does not matter if the image is displayed mirrored. For now I only want that it is displayed at all.

In unity it looks like this: alt text

unity-bottom.jpg (35.9 kB)
Comment
Add comment · Show 4
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 robertbu · Feb 24, 2013 at 04:43 PM 0
Share

Is it not drawing at all, or is the UV messed up? I cannot tell from the image. Typically if a side not showing at all is due to you walking the triangles backwards. The direction you walk the vertices for a triangle deter$$anonymous$$es the normal, and you likely have your normal pointing inwards.

avatar image Kordanor · Feb 24, 2013 at 05:31 PM 0
Share

The model draws perfectly, but the texture is missing. Look on the lower picture first. There you see the left, the right and the top of the "cube" - all with a texture. Then look on the upper picture which shows the bottom of the "cube". This should actually look exactly like the top as it uses the same picture and the same uv range (0x0 to 1x1).

avatar image robertbu · Feb 24, 2013 at 05:46 PM 0
Share

I understand. Assu$$anonymous$$g the UV is correct, like I indicated in my previous comment you need to wind your triangles for the bottom in the opposite direction. If the winding is backwards, then the surface normal for those two triangles will be up inside the box rather than down so the surface will not show.

avatar image Kordanor · Feb 24, 2013 at 06:01 PM 0
Share

Yes, I understand what you mean, but this is not the case here, as the bottom is shown (in the upper picture), just without the texture. I changed the UV map a couple of times to try out different things. But it always stays as it can be seen in the picture.

All the code can be found in my initial post (besides of the exact positions and the object creation stuff).

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Feb 24, 2013 at 08:43 PM

I started with a cube with a diffuse shader, a texture and a point light positioned to the "front" left. I then used the script below to apply your mesh to the cube. If your code is correct, then the cube should remain unchanged. What I found was problems in four of the six sides. Only the problems in the bottom and back are obvious in flat lighting. I thought maybe you had a different definition of front, but the best result was with the vertices defined below (and it matched fairly well with your image).

 Mesh MakeMesh()
 {
 
         Mesh mesh = new Mesh();
 
         Vector3 leftBtmFront  = new Vector3(-.5f, -.5f, -.5f);
         Vector3 rightBtmFront = new Vector3( .5f, -.5f, -.5f);
         Vector3 leftTopFront  = new Vector3(-.5f,  .5f, -.5f);
         Vector3 rightTopFront = new Vector3( .5f,  .5f, -.5f);
         Vector3 leftBtmBack   = new Vector3(-.5f, -.5f,  .5f);
         Vector3 rightBtmBack  = new Vector3( .5f, -.5f,  .5f);
         Vector3 leftTopBack   = new Vector3(-.5f,  .5f,  .5f);
         Vector3 rightTopBack  = new Vector3( .5f,  .5f,  .5f);
 
         int tileCounter = 0;
         Vector3[] vertices = new Vector3[24];
         Vector2[] uv = new Vector2[24];
         int[] triangles = new int[36];
 
         // Your code here
 
         mesh.vertices = vertices;
         mesh.triangles = triangles;
         mesh.uv = uv;
         mesh.RecalculateNormals();
         return mesh;
 }

An approach is to take this code and with a simple cube build one face at a time until you get each right.

Comment
Add comment · 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

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

9 People are following this question.

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

Related Questions

A node in a childnode? 1 Answer

How to count Tiles in a sourinding Area around an Object? 1 Answer

Can isometric tiles be rotated? 0 Answers

How to fix glitch between walls? With pic. 1 Answer

sliding rows of tiles in 3D 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