djPFXUVs for maya now has a UI and does grass

david | python,rendering | Saturday, July 28th, 2012

A while back I posted a script called djPFXUVs that could be used to quickly re-layout uv's for paintFX leafs to help with the task of building and assigning more interesting textures. Today I thought I'd share an updated version of that script, which as you can see here, even has a UI.

djPFXUVs UI

Support for multiple uv sets

A new feature is the option to choose a source and optional target UV set, where the target can be either the source, any other existing set or a new one. This means textures for various material attributes do not need to be sharing the same uv's. You could use one uv set for diffuse color and another for reflectivity, and thus create even more variations amongst leave textures.

New Grass Layout Mode

UI showing grass mode

Grass Layout Mode does not create a tiled layout like the leaf modes. Instead each shell (ie each blade of grass) is scaled to the specified blade width and then randomly positioned along the U-axis in the primary uv quadrant. Here is an example showing before...

grass_uvsBefore.jpg

The nice thing about the way the original paintFX uvs are layed out is the way the tallest blades use the full V-axis while shorter blades use relatively less. djPFXUVs maintains this height relationship, so after grass layout with blade width = 0.5 we get something like this...

grass_uvsAfter.jpg

In the above image I just selected a few shells to give a clearer picture of what is happening. With thousands of blades of grass distributed randomly, all you'd see would just be a mass of lines.

Here is a snapshot of the hypershade showing a simple example of how you could take advantage of this new uv layout.

hypershade snapshot

 

colorMain is a rampTexture set to "U Ramp". Because blade of grassĀ  is randomly distributed somewhere in the U-axis, each blade will be textured with a narrow strip of this ramp and the gradation seen in this snapshot will be barely noticeable on a single blade. This ramp therefore can be thought of as a kind of probability distribution. The narrow brown strip to the right of the ramp means approximately 10% of the grass blades will get that brown color, the rest will be various shades of green.

colorBase is a rampTexture set to "V Ramp". I am using this to create a variation along the length of the grass. My grass will be browner near the base.

colorBaseMask is a rampTexture with some noise added.

I combine colorBase over colorMain using colorBaseMask in a layeredTexture (colorLayers) and the result is used as the color in a phong material. This is just a simple example. Nothing fancy. If you wanted photoreal grass you would need to make a bit more effort, but I think this example helps illustrate the idea behind grass layout mode.

Here is a quick render

grassTestRender.jpg

You can find djPFXUVs on my downloads page. This is a python script. To use it you'll need to put djPFXUVs.py somewhere in you scripts path, then run the following:

import djPFXUVs
djPFXUVs.layoutUI()

18 Comments »

  1. Amazing script! Thank you for doing this!

    Comment by Schmidt — October 9, 2012 @ 8:39 pm

  2. Hello, I came upon your fantastic script a little while ago, and it has been an absolute lifesaver so far! Unfortunately I recently ran into an issue that I so far have been unable to troubleshoot, and I was hoping that you might have a solution. As it stands, whenever the frame number changes in my scene, the UV's on my trees revert back to their original state before running the script. I would greatly appreciate any insight you might have regarding this problem. Thank you again for your otherwise amazingly helpful tool.

    Comment by BubbaRay — October 17, 2012 @ 7:51 am

  3. I've been asked this same questions a few times, and since I do have a workable solution I wrote it up in a blog post here... http://www.djx.com.au/blog/2012/10/17/djpfxuvs-with-history/

    I'm glad you are getting some use from the script, by the way, and thanks for your kind words.

    David

    Comment by david — October 17, 2012 @ 11:29 pm

  4. Thank you for doing this!

    Comment by antonyyen — December 20, 2012 @ 6:40 pm

  5. Hi David,

    Can you please tell where exactly we need to copy the script. I have tried but failed to run the script.
    I am copying the script at following place in my local drive

    C:\Program Files\Autodesk\Maya2013\scripts\others

    Let me know where I am wrong.

    Thanks
    Rupinder

    Comment by truerswalia — October 4, 2013 @ 7:29 pm

  6. You probably need to set up your python sys.path to point to that folder. Better still, use a different folder. I always advise people not to use the maya install folders. You should use one of your local scripts folders, which on windows would be something like
    C:\Users\david\Documents\maya\2013-x64\scripts

    If you do want to use a folder that maya does not see by default you can easily add it to the system path with the following lines of python...

    import sys
    p="C:/myCustomScripts"
    if p not in sys.path: sys.path.append(p)

    Comment by david — October 4, 2013 @ 10:00 pm

  7. Hi David,

    I have been using your script so often with Onyx trees. There are some trees which have leaves with a few different poly counts and UV layouts. The version of the script I have been using sometimes tears or stretches the UVs when placing them in the 3x3 grid. Is there a way to execute this script on these leaves to prevent the tearing.

    Thanks for all the support you have been providing!
    --Jeff

    Comment by jferrucci10 — October 26, 2013 @ 3:19 pm

  8. I think that my script is making the assumption that the uv's start off inside one tile. Could it be that the onyx leaves are covering more than 1 tile? Thats the only thing I can think of that would explain the stretching. If you can send me a simple scene that demonstrates the problem I can probably figure out a workaround.

    Comment by david — October 27, 2013 @ 3:43 pm

  9. Very easy to use

    Comment by zss — December 23, 2013 @ 9:11 pm

  10. nice````

    Comment by yubaqi — November 5, 2014 @ 12:05 am

  11. Anyone willing to break it down to a newbie how to install this thing? I have just begun learning Maya and this was referenced in a tutorial that I purchased and cannot figure this out. I am using mac os.

    I have been entering the information explained above via the scripts editor. I have managed to seemingly get the script to load in the editor, and when I hit execute it spits out a long list of information indicating it is loaded. My trouble is figuring out what to do from there... once it was executed, I went ahead and tried to create a new shelf item. Whatever I create it flipped up to the shelf but when I click it nothing happens and it doesnt look like the shelf item in the tutorial I am working on. I cannot get the UI so that I can continue and use this script. I have placed a copy of the script in the /Library/Preferences/Maya...Scripts area, restarted maya, and made an invalid icon on my shelf that does nothing. Please help! Whenever I enter what the author mentioned to "run" at the end of this section, it just gives me an error (still trying to run it from the script editor panel...) Please help me! Thanks in advance.

    Comment by ididit86 — February 14, 2015 @ 11:01 pm

  12. With problems like this you need to provide a bit more info to get the help you need. First I need to know the steps you took to install and run the script. (Remember I do not have the tutorial). Second I need to see the error message that maya spits out in the script editor. Without that info I am just guessing.

    However, forget the shelf for a moment (you dont need it). To run the script all you need to do is the following...

    Put djPFXUVs.py somewhere in you scripts path, then run the following in a python tab in the script editor:

    import djPFXUVs
    djPFXUVs.layoutUI()

    Its case-sensitive so make sure you get that right too.
    If you dont know where the scripts path is... then ask another mac user - because I dont know either, but google tells me /Users/Shared/Autodesk/Maya/(Version)/scripts where you replace (Version) with an appropriate version folder name.

    good luck
    David

    Comment by david — February 15, 2015 @ 12:41 am

  13. Hi there,

    Been using the script for a while and it NEVER saves the UV's properly.

    If I create a tree/grass, set up my textures and run the script it will create the 3x3 UV layout perfectly fine.

    But if I close and re-open the file then all the UV's are set back to their Maya default and it is an absolute nightmare> I'm not going to waste my time re-running the script on every piece of foliage.

    Any ideas?

    Comment by sandford — March 26, 2015 @ 7:33 am

  14. Sounds to me like you kept the paintFX history. If so, changing frames or reopening the scene will recreate the UV's. Try deleting history before running the script.
    If that fixes your problem, but you also want to keep history, then you will need to use the attribute transfer workaround. Let me know. I can dig up an older comment where I explain this in full.

    David

    Comment by david — March 26, 2015 @ 8:40 am

  15. Yeah the history is causing issues, never had this problem before but since I want to keep the animation enabled on my trees, could you have a search for that workaround?

    It would be much appreciated!

    PS: I had to register for your site via proxy server because the Sabre system was banning my IP instantly :/

    Comment by sandford — March 29, 2015 @ 3:52 am

  16. Here you go...
    http://www.djx.com.au/blog/2012/10/17/djpfxuvs-with-history/

    The Sabre thing is probably beyond my control. I need it because my site got hacked so many times. Sorry for the incovenience. I guess it doesnt matter now that you found a workaround (ie proxy).

    Comment by david — March 29, 2015 @ 11:03 am

  17. Thanks for the workaround.

    Unfortunately saving out a file with trees like that murdered the file and Maya crashes and gets stuck loading the file on 98%.

    God, Maya sucks. File is only 330mb aswell. >_>

    Comment by sandford — March 30, 2015 @ 5:38 am

  18. Another approach is to simply break this complex task into 2 parts. In many (probably most) studios, this would be the standard workflow. Export a geo cache from the animation scene and apply the cache to matching geo in the render scene - except in the render scene, the history has been deleted and the uv's have been layed out before you import the cache.

    Comment by david — March 30, 2015 @ 10:38 pm

RSS feed for comments on this post.

Leave a comment

You must be logged in to post a comment.

Powered by WordPress | Based on a theme by Roy Tanck