1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 beta is now available for download.
    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!