1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

Texture2D.PackTextures maxSize

Discussion in 'Scripting' started by elveatles, Apr 19, 2011.

  1. elveatles

    elveatles

    Joined:
    May 2, 2009
    Posts:
    147
    Hi Unity people,
    I need to use PackTextures at run-time with an unknown amount of textures. How would I be able to tell if the textures are going to be resized if they go over the limit before actually packing the textures?
     
  2. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    You can't without doing the algorithm.

    The best you could probably do is take the number of pixels in each image (width * height) and multiply it by the total pixel count in the max size and consider it full once it surpasses ~90% (depending on the size of the images you are packing into it, larger images require a larger buffer space). If it's over 100% it's definitly full but the 90-100% it's impossible to guaratee without doing the algorithm yourself (though that takes about 0.5 milliseconds or less on an iMac if you want to create your own algorithm to check).

    http://www.blackpawn.com/texts/lightmaps/default.html

    That's the algorithm, and if you precheck it you could save some time not having to do so many modifications to the image. I've replaced PackTextures with something based on that and it came out identically (minus PackTextures not handling vertical padding consistently)
     
    Last edited: Apr 20, 2011
  3. elveatles

    elveatles

    Joined:
    May 2, 2009
    Posts:
    147
    Hi,
    I went without checking on this thread for a while. The information you've given is incredibly helpful. Thank you!