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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by Javity · Mar 16, 2014 at 03:48 AM · textureuv mappinguv coordinatestexture atlas

Why would my texture split across the triangle at runtime?

I am trying to understand basic uv manipulation in Unity. I use Blender and get the fundamentals of using UVs. In this example I have cached the uvs of a Blender quad into an array. I use a conditional to know which uv pair is at which index in the .mesh.uv (seems like the array arrangement in .mesh.uv varies per import!), so I know when I have a given uv pair, then I cache them to a new array so their order makes more sense. For example, I keep the (0,0) at [0], the (0,1) at [1], etc. All I want to do is input a new uv "bounding box" with new uv values across these indices to crop out sections for basic texture atlas effect on the big image. What happens though is my texture crops wierdly across the triangles. I must be missing something obvious. I assume - and I'm big on assumptions :) - that the uvs in Unity should give me a discreet bounding box "cropping" result based on their 0 to 1 axial values. Below is my for loop I run in the Start() and then a function I call under Update to write in any new uv values (they are public exposed for the editor).

 for (var i = 0; i < _targetMesh.uv.Length; i++) {
                         //    Debug.Log ("_UV [" + i + "]: " + _targetMesh.uv [i]);
                         if (_targetMesh.uv [i] == new Vector2 (0, 0)) {
                                 Debug.Log ("we have " + _targetMesh.uv [i] + " at [" + i + "]");
                                 _UVs [0] = _targetMesh.uv [i];
                                 uv00 = _UVs [0];
                         }
                         if (_targetMesh.uv [i] == new Vector2 (0, 1)) {
                                 Debug.Log ("we have " + _targetMesh.uv [i] + " at [" + i + "]");
                                 _UVs [1] = _targetMesh.uv [i];
                                 uv01 = _UVs [1];
                         }
                         if (_targetMesh.uv [i] == new Vector2 (1, 0)) {
                                 Debug.Log ("we have " + _targetMesh.uv [i] + " at [" + i + "]");
                                 _UVs [2] = _targetMesh.uv [i];
                                 uv10 = _UVs [2];
 
                         }
                         if (_targetMesh.uv [i] == new Vector2 (1, 1)) {
                                 Debug.Log ("we have " + _targetMesh.uv [i] + " at [" + i + "]");
                                 _UVs [3] = _targetMesh.uv [i];
                                 uv11 = _UVs [3];
 
                         }

My function:

 private void updateUVs ()
         {
                 _UVs [0] = uv00;
                 _UVs [1] = uv01;
                 _UVs [2] = uv10;
                 _UVs [3] = uv11;
                 _targetMesh.uv = _UVs;
 
         }

alt text (editor view) alt text (runtime view)

I just want to implement some basic texture atlas setup. I'm stumped at the moment and I have poured over the forums/stacks but not seen this specific issue. Seems such a simple task for a quad and 4 verts and 4 uv pairs. Thanks for any input!

editor-view.png (41.3 kB)
runtime wierdness..png (42.9 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

20 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 avatar image avatar image avatar image avatar image

Related Questions

More materials smaller texture size vs less materials bigger texture size 0 Answers

Wrong import of UV from blender 1 Answer

Is it possible to UV map a cylinder without duplicating a column of vertices? 1 Answer

UV mapping tiles on mesh bleeds texture when camera is at certain angle 2 Answers

Assigning UV Map to model at runtime 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