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 Mr.Reaper · Aug 31, 2012 at 11:05 AM · texturepositionatlas

Using information stored in atlas?

Hi, I'm generating an atlas at runtime by combining an array of Texture2D using PackTextures method. Each textures position within the atlas is then stored in an Array. Here is my script:

 static var atlasArray : Array; //Will store positions of each texture within atlas
 var atlas : Texture2D; //This will be the new atlas
 var textures : Texture2D[]; //The array of textures to be baked
 var padding : int = 0;
 var maximumAtlasSize : int = 1024;
    
 function Awake()
 {
     atlas = new Texture2D(1024,1024);
     atlasArray = atlas.PackTextures(textures, padding, maximumAtlasSize);
     
     //Get coords
     print(atlasArray[5]);
 }
 

This will generate the atlas correctly and I can get the position of wanted texture, which will return its x,y,width and height. I would like to use this information to navigate each of my objects to only show its relevant texture within the atlas, but have no idea how to use the information.

I'm now breaking this information up in "x,y" and "width,height" portions by manually setting each objects SetTextureOffset and SetTextureScale. I've tried using GetPixels, SetPixels methods but can't seem to get them to work. Could someone please help me?

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 zyzyx · Aug 31, 2012 at 03:40 PM

In order to use the Info stored in your atlas on a mesh you need to adjust the uvs of the mesh. It would look something like this (C#, not testet). "olduvs" is a Vector2 array to store the original uvs of your mesh:

  public void SetUVs(Rect rect)
     {
         MeshFilter filter = GetComponent<MeshFilter>();
         if (olduv.Length == 0)
             olduv = filter.sharedMesh.uv;
 
         if (filter)
         {
             Vector2[] newuv = new Vector2[olduv.Length];
             for (int i = 0; i < newuv.Length; i++)
             {
                 newuv[i] = new Vector2(
                     olduv[i].x * rect.width + rect.x,
                     olduv[i].y * rect.height + rect.y);
             }
             filter.sharedMesh.uv = newuv;
         }
     }
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

8 People are following this question.

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

Related Questions

How To Apply A Texture Atlas For UI Image Objects? 0 Answers

Splatmapping / blending between two textures in an atlas? 0 Answers

One atlas per scene or one (larger) atlas across multiple scenes? 0 Answers

Repeating Images From an Atlas 0 Answers

How to get textures/sprites from Atlas and use it ? 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