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 juoni · Jun 23, 2013 at 12:45 AM · packtextures

Can we affect the packing order when using Texture2D.PackTextures

Hello fellow Unity3d Users,

First off, thanks for taking the time to look at this post.

[The issue] I'm using Texture2D.PackTextures(textures[],0) All of the textures I'm packing are the same Width(256) and Height(256). I've added each texture to an array in the order In which they need to be, however the order always breaks, resulting in 1 or 2 frames of the animation being offset vertically and/or horizontally.

-Juoni

[edit - Little Angel]

      //The Atlas were we're storing our textures
     Texture2D atlas = null;
     
     //The Locations of our textures on the atlas
     Rect[] rects;
     
     //The textures we're going to back
     List<Texture2D> temptextures = new List<Texture2D>();
     
     //The width and hight our our textures
     int[] texturesize = new int[2];

     //Add textures for each Animations
     //to the atlas
     foreach (PsiAnimation psianim in LoadChosenAnimations())
     {
         temptextures.AddRange(psianim.GetAnimation);
         Debug.Log(psianim.AnimationName);
     }

     //Add The required width and high
     //to the atlas
     //for each texture
     Texture2D[] texturearry = new Texture2D[temptextures.Count];
     foreach (Texture2D t in temptextures)
     {
         texturearry = ArrayHelper.AddItemToArray<Texture2D>(texturearry, t);
         Debug.Log(t.name);
         texturesize[0] += t.width;
         texturesize[1] += t.height;
     }
  

     //Make the atlast the size needed
     atlas = new Texture2D(texturesize[0], texturesize[1]);
 

if(DEBUG)

    Debug.Log(atlas.width + atlas.height);
     Debug.Log(texturesize[0].ToString() +" : w| h " + texturesize[1].ToString());

endif

     //Store the coords of each texture
     rects = atlas.PackTextures( texturearry,padding);
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 Adam-Buckner ♦♦ · Jun 22, 2013 at 09:13 PM 0
Share

So, you are asking:

"Is there any way to control the order and location that textures are packed into a new atlas?"

Correct?

avatar image juoni · Jun 22, 2013 at 09:43 PM 0
Share

Correct, I have code snippets if needed.

avatar image Adam-Buckner ♦♦ · Jun 22, 2013 at 09:46 PM 0
Share

Code could help, if you don't $$anonymous$$d - just in case...

avatar image juoni · Jun 22, 2013 at 09:52 PM 0
Share
 <code>//The Atlas were we're storing our textures
     Texture2D atlas = null;
     
     //The Locations of our textures on the atlas
     Rect[] rects;
     
     //The textures we're going to back
     List<Texture2D> temptextures = new List<Texture2D>();
     
     //The width and hight our our textures
     int[] texturesize = new int[2];

     //Add textures for each Animations
     //to the atlas
     foreach (PsiAnimation psianim in LoadChosenAnimations())
     {
         temptextures.AddRange(psianim.GetAnimation);
         Debug.Log(psianim.AnimationName);
     }

     //Add The required width and high
     //to the atlas
     //for each texture
     Texture2D[] texturearry = new Texture2D[temptextures.Count];
     foreach (Texture2D t in temptextures)
     {
         texturearry = ArrayHelper.AddItemToArray<Texture2D>(texturearry, t);
         Debug.Log(t.name);
         texturesize[0] += t.width;
         texturesize[1] += t.height;
     }
  

     //$$anonymous$$ake the atlast the size needed
     atlas = new Texture2D(texturesize[0], texturesize[1]);
 

if(DEBUG)

    Debug.Log(atlas.width + atlas.height);
     Debug.Log(texturesize[0].ToString() +" : w| h " + texturesize[1].ToString());

endif

     //Store the coords of each texture
     rects = atlas.PackTextures( texturearry,padding);</code>

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Aithoneku · Feb 18, 2014 at 01:24 PM

AFAIK no, you can not.

But the rects returned by PackTextures is what you can use - it's relative position (UV coordinates) of each texture in the atlas so you can use these to run your animation - rects[0] contains position of first frame, rects[1] second frame etc.

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

17 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

Related Questions

Have there been changes to PackTextures in 5.6 ? Seeing Artifacts in Scene which disappear in 5.5 0 Answers

Procedural Mesh with visible seams 0 Answers

Packed textures "flicker" in distance 1 Answer

Packing Height Map with Normal 0 Answers

PackTexture doesn't work in flash platform? 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