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
1
Question by qarchi21 · Oct 31, 2013 at 10:53 PM · c#cubeuvvectorprimitives

code generated cube uv map for each sub mesh

so i have built a cube using code (rather then spawning in from 3d modelling like maya or using the primitives unity has)

i understand how to actually set the uvs

1 2,6 5
0 3,7 4 < these correspond to the vertices as if you saw them on a uv map i.e 0 = new vector(0,0) << first one in array the numbers show where they are in the uv map.

 BUvs = new Vector2[8] {
   new Vector2(0,0),new Vector2(0,1),
   new Vector2(0.5f,1),new Vector2(0.5f,0),
   new Vector2(1,1),new Vector2(1,0),
   new Vector2(0.5f,0),new Vector2(0.5f,1) 
 };


anyway the textures... look.... ok i guess but realistically

is there a way to assign submeshes to different uv sets?

i.e each face on the cube is a sub mesh with its own texture but if i could assign front and back face to a uv and right and left to uv2 so on then it would make it look a lot better

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Oct 31, 2013 at 11:31 PM

As weird as it may sound, you actually need 24 vertices to make a cube. That's because uvs and normals are vertex attributes: the normals are different for each face, and the uvs are also different in many vertices. The normals are the worst case: each face must have its own 4 vertices, thus you need 6 x 4 vertices in order to accomodate all the different normals.

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 qarchi21 · Oct 31, 2013 at 11:45 PM 0
Share

not at all you need 8 , now to do what i want to do i might need that many im not sure yet thats why im asking

you can use 8 because of the way the normals work in unity and the way trigs are done,

when you generate a mesh in unity with code you define where the normals point by the way you set the trig i.e 0,1,2 will have different normals then 2,1,0 (the opposite normals)so on so forth

which is all you need with for a cube now with uvs i was hoping there was a way around it because you can have more then one set of uvs for a mesh, i was hoping you might be able to have uvs for submeshes

avatar image aldonaletto · Nov 01, 2013 at 12:41 AM 1
Share

You're confusing winding order with normals: the winding order defines which's the front face, while the normals are vertex attributes used for lighting purposes: the shader must know each vertex's normal in order to calculate how the light reflects on the surface. If you don't assign normals, all shaders except the unlit ones will complain that "Shader wants normals, but mesh doesn't have them".

Submeshes don't have different uv arrays: there's only one common uv array for all submeshes in the mesh, as well as only one vertices array, one normals array etc. Each submesh has its own triangles array, which picks vertices (and uvs, and normals etc.) from the common array. You could have a submesh for each face, but this would still result in 24 vertices (and 24 uvs, 24 normals etc.), and in a higher cost since each submesh has its own material. Actually, the only reason for using submeshes is the possibility of "painting" each submesh with a different material - but a single mesh with 24 vertices and a single material is way more efficient.

avatar image qarchi21 · Nov 01, 2013 at 10:10 AM 0
Share

sorry i had to type fast and im not good at explaining,

so your saying the only way i can get equal uvs on each side of the cube is by making each face have seperate vertices....

avatar image aldonaletto · Nov 01, 2013 at 06:13 PM 0
Share

You must use separate vertices whenever the other attributes are different. If ou had only to worry about uvs, you could even share some vertices where the uvs are equal (what dependes on how the texture is mapped), but the normals always require 24 vertices in a cube because they differ at the corners - exactly where the vertex position is the same for 3 faces. In the end, making a cube with 24 vertices is the best alternative: you're free to assign the right uv to each corner, and also to correctly define the normals (don't underestimate normals: a mesh with wrong normals looks terribly ugly when illu$$anonymous$$ated).

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

16 People are following this question.

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

Related Questions

Automatic UV Mapping for a Cube in C# 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

[C#] how to add a primitive in this script??? 3 Answers

Find extreme points of rotated gameObjects? (screenshot example) 2 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