Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 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!