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 MountDoomTeam · Dec 18, 2012 at 03:28 PM · texturecubeuvs

remapping cube UVs

if I make a cube 10 times smaller, and so I want to make the UV remap also 10 times smaller, I remap all the ones on the cube to 0.1, except when I do it it looks like it's and one colour / one pixel?

                     ns = 10;
                     var mesh : Mesh = cube.GetComponent(MeshFilter).mesh;//change the square so that the UVs map okay
                         var vertices : Vector3[]  = mesh.vertices;
                         var uvs : Vector2[] = new Vector2[vertices.Length];
 
                         for (var i = 0 ; i < uvs.Length; i++){
                             if ( uvs[i].x  == 1 ){ uvs[i].x  =  1/ns ;}
                             if ( uvs[i].y  == 1 ){ uvs[i].y  =  1/ns ;}
                         }
                         mesh.uv = uvs;
 


alt text

Comment
Add comment · Show 1
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 MountDoomTeam · Dec 20, 2012 at 07:33 PM 0
Share

any ideas? I've added a picture, as you can see, the UVs are 1/10th of the texture but the texture is only one pixel of colour. Am I missing something obvious?

1 Reply

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

Answer by Bunny83 · Dec 20, 2012 at 08:15 PM

Yes, you're missing that an integer divided by an integer will result in an integer. 1 / 10 == 0

Try this:

     for (var i = 0 ; i < uvs.Length; i++)
     {
         if ( uvs[i].x  == 1 ){ uvs[i].x  =  1.0/ns; }
         if ( uvs[i].y  == 1 ){ uvs[i].y  =  1.0/ns; }
     }
Comment
Add comment · Show 5 · 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 MountDoomTeam · Dec 22, 2012 at 04:26 PM 0
Share

is there a way to make the UV length equals to the edge of the box? for example if the edge is 0.5, to set the UV also at 0, 0.5?

avatar image Bunny83 · Dec 22, 2012 at 04:46 PM 0
Share

I'm not sure what you mean. What do you mean by UV length? UV coordinates are always between 0 and 1. They can be greater or lower, but in this case the texture's wrapmode needs to be set to repeat so the texture would tile across the mesh.

The UV mapping is usually done in a modelling application and not in Untiy. You need to be more specific what you want to do and how the UVs look at the moment.

avatar image MountDoomTeam · Dec 25, 2012 at 09:33 AM 0
Share

sorry I meant is there a way to find the length in between 2 related UVs in space and remap the 1 figure according to that length? for example to keep the same material on lots of irregular shape boxes.Thank you!:)

avatar image Bunny83 · Dec 25, 2012 at 11:40 AM 0
Share

Your last comment makes it even more unclear :)

The UV coordinates of a vertex are relative to the texture space of the mesh. A texture space is a 2d space and it covers the texture. Those coordinates are not related to world or local space coordinates of the mesh. Every mesh has it's own texture space.

You might want to use a world coordinates to texture space mapping. In this case you have to define two world space axis which can be used to project the 3d vertex position into 2d texture coordinates.

I'm not explaining that in detail here (I'm still writing on a tablet), but here's a link to the Half-life's map format which uses a similar method.

$$anonymous$$aybe I will post an example when I'm back home (this might take some days :) )

avatar image MountDoomTeam · Dec 26, 2012 at 02:37 PM 0
Share

Thanks! i figured it out now. the UV's arrays each correspond to a vertex array, i.e. vector2 mesh.uv[1] = vector 3 mesh.vertices[1] so i can find the spacial position from the vertex.transform position and then i can see which axis and distance between 2 vertex arrays and if they are on the axis line x y z they are on the same edge of a cube so i can measure the distance and resize the UVs. i was confused because i couldnt figure it at first. thanks

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

10 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

Related Questions

Apply texture to a bar (cube) 2 Answers

How to add my texture to a cube? 2 Answers

How do UVs work? 1 Answer

Coin shine 1 Answer

Is there a way to wrap a texture around a side of a cube? 1 Answer


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