Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Maya MEL grid script for building Unity assets

Discussion in 'Formats & External Tools' started by jbuck, Jun 10, 2009.

  1. jbuck

    jbuck

    Joined:
    Jun 9, 2009
    Posts:
    169
    Greetings all! I build one of these simple MEL scripts for each engine I work with (Unreal3, Torque, Source, Unity) so all artists on the project work with consistent grid setting and we don't end up with assets that don't match in scale. My team and students swear by these scripts so I thought I'd share it here.



    I'm a game artist who makes no claim at being a programmer so let me know if you have any problems with the script. :)

    I've struggled with scaling during the FBX import process into Unity since I started using Unity a few weeks ago but I have a system that now works for me. I'll post it here because I know some people are still having some issues with scaling between Unity and Maya:

    The FBX exporter checks to see what our settings are in Maya and changes the settings scale Factor to equal 1.0 based on what your settings are. Unity 2.5 likes to set the FBX scale factor to 0.01 (why?) and will change the transform scale to compensate (this can be bad). The goal is to set the FBX exporter/importer settings to properly scale the units as opposed to setting the transform scale which can affect performance.

    If you work in Meters in Maya and want them to equal Meters in Unity (I RECOMMEND THIS ONE):
    1. Set Maya's Linear Working units to be meters.
    2. Work in Maya as if 1 Unit = 1 Meter
    3. On export set FBX Exporter -> Units -> Scale Factor: 100.0 (Centimeters)
    4. Leave the Unity Inspector at FBX Importer -> Meshes -> Scale Factor 0.01
    5. A 1x1x1 cube should drop into a Unity scene as 1x1x1 meter with a clean 1x1x1 scale transform


    If you work in Centimeters as "generic units" in Maya and want them to equal meters in Unity:
    1. Set Maya's Linear Working units to be centimeters.
    2. Work in Maya as if 1 Unit = 1 Meter
    3. On export set FBX Exporter -> Units -> Scale Factor: 1.0 (Centimeters)
    4. In Unity Inspector set FBX Importer -> Meshes -> Scale Factor in Unity to be 1.0.
    5. A 1x1x1 cube should load into Unity as 1x1x1 meter with a clean 1x1x1 scale transform


    If you work in Centimeters in Maya and want them to equal centimeters in Unity:
    1. Set Maya's Linear Working units to be centimeters.
    2. Work in Maya as if 1 Unit = 1 Centimeter (1m = 100cm)
    3. On export set FBX Exporter -> Units -> Scale Factor: 1.0 (Centimeter)
    4. Leave the Unity Inspector at FBX Importer -> Meshes -> Scale Factor 0.01
    5. A 1x1x1 cube should load into Unity as 1x1x1 centimeters with a clean 1x1x1 scale transform


    I've been super impressed with the level of support and help available on this forum. I hope this helps someone. Please let me know of any inaccuracies in this post, thanks!

    Edit: 6/26/09. Just updated with a fix for the clipping planes in default ortho cams. Whoops! I just accidentally deleted the attachment! It had been downloaded 35 times. :oops:

    Edit: 7/13/2010.
    Updated to work in Maya 2011:
    Changed color scheme a bit for the new UI
    Fixed a few bugs with m/cm switch
    Removed the MacOS version (had been downloaded 212 times)-- this one should work for all Maya platforms.
    Please get back to me with any bugs.

    Edit: 7/14/2010
    * Fixed a bug that wouldn't allow it to work in previous versions of Maya. Now tested in Maya 2009 up to 2011.
    * Changed some of the buttons to radio buttons for better feedback.

    !! Removed the DL link from the Unity forums (had been downloaded 329 times) -- it's too hard to keep updated with my other sites.

    This script (jbUnityGrid), along with others should now be downloaded directly from my website:

    http://cgartistry.com/experimentation/melScripting.html

    FINAL EDIT: This script is no longer available. A new version can be found here: http://forum.unity3d.com/threads/116230-jbUnity-Tools-Maya-tools-script-for-Unity?p=774983#post774983
     
    Last edited: Dec 20, 2011
    pixxelbob likes this.
  2. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Thanks for sharing that :)

    The easiest way is to just save your MB or MA files directly into your Unity Project folder. The FBX process is then done automatically in the background.
     
  3. jbuck

    jbuck

    Joined:
    Jun 9, 2009
    Posts:
    169
    You're welcome! To be honest I was excited about being able to use Maya files directly in Unity but I have a couple of problems with that workflow:

    1. The background FBX conversion takes approx 20 seconds every time I jump back into Unity with a new .mb or .ma file (quad core 64-bit system with 8 gigs of RAM). In comparison, exporting a 2000 frame animated static mesh directly through FBX takes only 6 seconds or so. A 5000K poly mesh with no anim exports in less than one second and shows up in Unity instantly.

    2. By default the exported object drops down in Unity 100x larger than it should be. This means I have to edit the FBX import settings in the inspector back down from 1 to 0.01.

    3. IMO, keeping exported files separate from actual .ma or .mb source files makes for a more logical and artist friendly workflow especially when dealing with animations, multiple meshes, etc.

    I admire the source-file approach Unity has taken and I love the flexibility of being able to do either but I've seen my Unity projects explode in size because of keeping source files (PSD, Maya, etc) in the Unity project itself. This also makes for sluggish remote version/source control.
     
  4. HJPuhlmann

    HJPuhlmann

    Joined:
    Oct 18, 2007
    Posts:
    47
    Thank you. It's really useful….
     
  5. jbuck

    jbuck

    Joined:
    Jun 9, 2009
    Posts:
    169
    You're welcome! Please let me know if anything is broken or if there are any features that you'd like to see added.
     
  6. HJPuhlmann

    HJPuhlmann

    Joined:
    Oct 18, 2007
    Posts:
    47
    I changed only the GUI a little (I'm on a Mac). Would you like to have this version?

    By the way, nice Sketchbook :eek: 8)
     
  7. giyomu

    giyomu

    Joined:
    Oct 6, 2008
    Posts:
    1,094
    Hey josh , thank for taking time sharing that little handy tool ;)

    and I will also say , Nice sketchbook , your Orc is really awesome !
     
  8. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Wow, Josh, your ZBrush work is amazing!
     
  9. jbuck

    jbuck

    Joined:
    Jun 9, 2009
    Posts:
    169
    Thanks, guys, I really appreciate it! I actually teach Zbrush (among many other things) and have a lot of game industry experience but my work is a humble beginning compared to some of the work up on the Zbrush forums. :)

    Glad some of you are liking the MEL script. HJPuhlmann -- I don't work in MacOS (sometimes I DO work on a Mac), were there problems with the UI? Funny... I didn't even think to test in Mac-Maya.
     
  10. HJPuhlmann

    HJPuhlmann

    Joined:
    Oct 18, 2007
    Posts:
    47
    Nice job, enviable. I'm a professional programmer, who try to make art in the spare time :) . You could teach me/us ...
     
  11. emptythetill

    emptythetill

    Joined:
    May 29, 2009
    Posts:
    39
    I'd like that version :) You can post the code here if that's easier than posting a file. :)

    I WILL get my ... -> Unity pipe working today, I bloody well will. :)
     
  12. jbuck

    jbuck

    Joined:
    Jun 9, 2009
    Posts:
    169
    HJPuhlmann, can you pm me the file with the MacUI? I'd like to see the script too as I'm curious what changes needed to be made. I'll add it to the main post.

    emptythetill, I posted some info in your thread on getting anim into Unity. I hope it helps.
     
  13. emptythetill

    emptythetill

    Joined:
    May 29, 2009
    Posts:
    39
    Ye Josh, your post was incredibly helpful. :) Sadly though, I'm still having crazy issues which I can't work out. Random stuff occurs with no real reasons or clues as to why. But, I'm getting there, slowly. :)
     
  14. HJPuhlmann

    HJPuhlmann

    Joined:
    Oct 18, 2007
    Posts:
    47
    Josh, you got a PM.
     
  15. jbuck

    jbuck

    Joined:
    Jun 9, 2009
    Posts:
    169
    Thanks. I added the script to the original post. I can't open the file on my PC to see what changes were made. Any chance you can send me a PC friendly version? :)
     
  16. HJPuhlmann

    HJPuhlmann

    Joined:
    Oct 18, 2007
    Posts:
    47
    :D Unbelievably.:D I send you the mel script ...
     
  17. BetaRayBill

    BetaRayBill

    Joined:
    Jun 6, 2009
    Posts:
    188
    If I do meters in maya, and export as centimeters (fbx 2009 version, maya2009), my object comes in small.
    If I change the import setting to 0.1 in Unity, its correct.
    But, if I export from maya in Millimeters its correct... whats wrong with this picture?

    I'd rather not mess with the Unity import scale if I don't have to.
     
  18. jbuck

    jbuck

    Joined:
    Jun 9, 2009
    Posts:
    169
    I can't reproduce this. :(

    If I export a 1m cube from Maya (working in Meters) and set the FBX exporter scale to centimeters it comes in to Unity with an FBX importer scale factor of 0.01 which is correct as the transform scale is 1, 1, 1 and the cube is 1m in Unity.

    If I export a 1m cube from Maya (working in Meters) and set the FBX exporter scale to millimeters the cube comes in to Unity with an FBX importer scale factor of 0.01 but the transform scale for the object is 10,10,10 and the cube is 10m in Unity.

    I just tested this in Maya 2009 with both FBX 2009 and 2010. Try downloading a newer version of FBX 2009 or 2010 and see what happens?
     
  19. ookla

    ookla

    Joined:
    Oct 22, 2009
    Posts:
    12
    Just great dude, thanks!

    I made an BMP icon for your script.

    Here's a preview:



    []'s

    Mateus
     

    Attached Files:

  20. jbuck

    jbuck

    Joined:
    Jun 9, 2009
    Posts:
    169
    An icon! Awesome, thanks!
     
  21. thevossman

    thevossman

    Joined:
    Jan 25, 2010
    Posts:
    6
    This looks fantastic. Any hope for a maya 2011 version of this plugin?
     
  22. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    This is done with mel script, you should be able to use his script on all version of Maya.
     
  23. jbuck

    jbuck

    Joined:
    Jun 9, 2009
    Posts:
    169
    Just started using Maya 2011. I'll have a look and if there are any problems (that I find) I'll build a new one for 2011. If you have any specific issues that come up please let me know!
     
  24. jbuck

    jbuck

    Joined:
    Jun 9, 2009
    Posts:
    169
    Definitely some problems with Maya 2011. Update coming soon.
     
  25. jbuck

    jbuck

    Joined:
    Jun 9, 2009
    Posts:
    169
    Updated for Maya 2011. I also removed the MacOS version as this one should work fine for both Win and Mac.
     
  26. armandog

    armandog

    Joined:
    May 4, 2011
    Posts:
    1
    Hi, I must say a massive thanks for the script i thought it was the answer to my prayers and it may still be. I hate the hassle of changing grid sizes etc... between Unity and Maya. The trouble i have though is that when I bevel a polygon I get a strange exloded geometry which is very strange, any ideas?
     
  27. makan

    makan

    Joined:
    Jan 8, 2011
    Posts:
    342
    That's great thanks, i was going to start make something like that for 3ds max with MaxScript, but i have some problems with scripts... are you planning to do this for max too? :D
     
  28. i-tech

    i-tech

    Joined:
    Jan 2, 2011
    Posts:
    195
    great work man :) love your script :) keep on the good work.
     
  29. salenagills

    salenagills

    Joined:
    Aug 31, 2011
    Posts:
    1
    I have a scene i created in maya using centimeters which i want to import to unity but i've read that we need to model in meters for unity. what should i do now? will i have to model it again? :( is there any other way? please note that the scene is for a playable side scrolling level so i want all the events like collision, jump etc to work properly once the scene is set up.
     
    Last edited: Sep 1, 2011
  30. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    Set your unit to meter into the Maya's pref.

    From here you will be able to get the right scale of your object.

    You can use a Measure Tool if you want to understand more about your object scale.

    Then scale it on you own :) ...

    Well if it comes of objects skinned with animations you should export it as it is for now and change the scale value directly into Unity from the FBXImporter Scale Factor attribute...

    But with this last method you could get many bad surprise if using physic with it :(
     
  31. Mambo4

    Mambo4

    Joined:
    Jan 17, 2011
    Posts:
    14
    jbuck: this script is awsome. bye bye scale woes.