Hey there, so we have decided that a 512x512 texture in our game should tile once every 4 units in maya. This keeps the artists working in the same texture scale and reduces texel density issues in game. Does anyone have a tool to take a uv shell or uv shells and figure out how big they are in world space and then scale the uv's to be the correct texel density? Right now we're just doing planar maps with a 4x4 setting which is fine except when you have complicated terrain geo where you have to unfold, then we eyeball it which is not working that great.
I wrote a script to do this at work, it's not hugely complicated. However I am unable to share it here =(
Considering there is some guy charging like $100 for a plugin to do this for Maya, I managed to write one which does the same thing in MEL in about half a day.
there are some sccripts at scriptspot (3dsmax) that do that, maybe with some scripting expierence you can transfer some of that structure to mel.
For example I had a uv-script written in mel which I never saw before and was able to learn and transfer some of the concepts of that script.
Hey mop rather than sharing the script can you share the idea behind it we have an amazing tools artist here but he is baked up writing higher priority tools it would be great if he could whip this out in half a day..
A ratio to aim for (just an integer value, eg. 4 for 4:1 ratio)
The current object's texture width and height. My script defaults to 1024x1024 if the object's material doesn't have a valid texture.
An object with UVs!
Steps:
Get selected UVs, or if none are selected, work with the whole object.
Find the first UV vertex of every UV shell and shove this into an array. I used Python to get this since MEL doesn't support returning UV shell counts or arrays without manipulating the physical selection, which I hate to do (it's slower and more painful).
For each UV shell in the array, find the corresponding polygon component's surface area in world space. There's an existing MEL command for this.
For each UV shell in the array, find the shell's surface area in UV space. You can do this a number of ways, mine is intensely hacky. There's no direct function for getting this so you have to roll your own.
Store the areas of each shell in arrays, one for the geometric area and one for the UV area. This means that your "first UV vert array" will correspond to the same index into each area array.
Now that you have the areas and the shells you can do whatever you need to with them. I have two different functions - one for setting it to an explicit pixel density (based on the integer passed to the function) or if that integer is 0 it will just average all the UV shell sizes.
For the absolute ratio method, multiply the geometric area by the intended area pixel density ( 4^2 in this case ). Also multiply the UV area by the ( texture width * texture height ).
The scale factor we need is the square root of the ( first result / second result ).
You can then scale each shell by their respective factor. Everything should come out perfectly consistent!
Thanks Mop!
Sa74n does that script let you specify which shell you want all the other shells to scale to or does it just make them all the same texel density randomly.
See, I don't believe that plugin is worth £30 ($45-ish i guess)... the free one is alright, but the functionality is limited, especially if you want to quickly make everything a certain texel density. Also it doesn't seem to have any "average size" mode.
I prefer mine
I'd release it for free if I could!
Hmmm, crazy don't know then our tools guy was looking through the help file and couldn't find something he's a smart guy though I'll mention to him that you wrote yours in 2008.
Replies
Considering there is some guy charging like $100 for a plugin to do this for Maya, I managed to write one which does the same thing in MEL in about half a day.
For example I had a uv-script written in mel which I never saw before and was able to learn and transfer some of the concepts of that script.
Things you need:
- A ratio to aim for (just an integer value, eg. 4 for 4:1 ratio)
- The current object's texture width and height. My script defaults to 1024x1024 if the object's material doesn't have a valid texture.
- An object with UVs!
Steps:- Get selected UVs, or if none are selected, work with the whole object.
- Find the first UV vertex of every UV shell and shove this into an array. I used Python to get this since MEL doesn't support returning UV shell counts or arrays without manipulating the physical selection, which I hate to do (it's slower and more painful).
- For each UV shell in the array, find the corresponding polygon component's surface area in world space. There's an existing MEL command for this.
- For each UV shell in the array, find the shell's surface area in UV space. You can do this a number of ways, mine is intensely hacky. There's no direct function for getting this so you have to roll your own.
- Store the areas of each shell in arrays, one for the geometric area and one for the UV area. This means that your "first UV vert array" will correspond to the same index into each area array.
- Now that you have the areas and the shells you can do whatever you need to with them. I have two different functions - one for setting it to an explicit pixel density (based on the integer passed to the function) or if that integer is 0 it will just average all the UV shell sizes.
- For the absolute ratio method, multiply the geometric area by the intended area pixel density ( 4^2 in this case ). Also multiply the UV area by the ( texture width * texture height ).
- The scale factor we need is the square root of the ( first result / second result ).
- You can then scale each shell by their respective factor. Everything should come out perfectly consistent!
Cheers,-MoP
http://www.renderheads.com/portfolio/UVAutoRatio/
Sa74n does that script let you specify which shell you want all the other shells to scale to or does it just make them all the same texel density randomly.
I prefer mine
I'd release it for free if I could!