mel - Auto Pixel Density Texture Generator(autoPDTG)

Calculates the appropriate texture resolution for mesh(s) at a uniform pixel density.
Why? How? you may ask, long story...
Since a major factor in GPU performance in games is texture memory and it can be difficult enough for one artist to simply guess the optimal size of a texture for each asset he or she makes, let alone many artist guessing uniformly, there is a need to accurately calculate & automate the appropriate texture resolutions for a project....:)
How - By dividing the 3d surface area of a mesh by its UV surface area you get a adjusted surface area ratio. The square root of that gets you a resolution for an image. Multiply that by your desired pixel density for the project and you have a base texture resolution! In this script I also round to nearest power of 2 size before taking a UV snapshot and attaching that file to the file texture node of the evaluated mesh. The base resolution before rounding is also printed in the script window in case the artist wants to use that to information to justify higher detail priority.
In this example I ignored the closest power of 2 rounding to show the accuracy.

Note: This script isn't perfect, it assumes only 1 material per mesh chunk and there is already a material assigned to the mesh with a fileTextureNode attached (all of which is assured by our in-house work flow). I would have been reluctant to release the source publicly but I received help for the heavy math portions of the script...giving back to the community:)

to use;
source script,
select your mesh(s)
type autoPDTG; in command line
if your scene is saved the output UV maps automatically go in the the same directory as the scene, otherwise you'll need to specify where to put them