Home Technical Talk

texel density corrector tool for maya?

polycount sponsor
Offline / Send Message
malcolm polycount sponsor
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.

Replies

  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    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.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    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.
  • malcolm
    Offline / Send Message
    malcolm polycount sponsor
    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..
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    OK, here's a high level overview...

    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:
    1. Get selected UVs, or if none are selected, work with the whole object.
    2. 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).
    3. 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.
    4. 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.
    5. 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.
    6. 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.
    7. 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 ).
    8. The scale factor we need is the square root of the ( first result / second result ).
    9. You can then scale each shell by their respective factor. Everything should come out perfectly consistent!
    Cheers,
    -MoP
  • Sa74n
    Offline / Send Message
    Sa74n polycounter lvl 18
    if you're not able to write your own mel script, use this one. works like a charm. there's a free 'light' version or a pro version for purchase.

    http://www.renderheads.com/portfolio/UVAutoRatio/
  • malcolm
    Offline / Send Message
    malcolm polycount sponsor
    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.
  • Marine
    Offline / Send Message
    Marine polycounter lvl 19
    it scales the shells to the size of the last selected piece
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    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!
  • malcolm
    Offline / Send Message
    malcolm polycount sponsor
    Yeah we're going to have our tools guy write a custom one. We're still on 2008 so a couple of the commands you mentioned do not exist yet for us.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    FYI, I wrote mine for 2008.
  • malcolm
    Offline / Send Message
    malcolm polycount sponsor
    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.
Sign In or Register to comment.