Search Unity

modo to Unity Script

Discussion in 'Formats & External Tools' started by wesrm, Feb 19, 2010.

  1. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    Fellow modonauts,

    I just finished creating a script for exporting FBX files from modo to Unity! I've seen a couple of these type scripts on LUX and Unity forums and I didn't find them until I was already 90% finished creating my own, so I went ahead and finished my version and wanted to offer it to the community as well.

    This script will export only mesh items from modo. The mesh items can be parented to each other or placed in a groupLocator. Also, if you've used IK or constraints to create animation, the script will automatically bake the animation for you!

    You can see a demo video of the script and install instructions on my blog. I hope you find this useful!

    -Wes

    http://the3dninja.com/blog/?p=627
     
  2. wright.tom85

    wright.tom85

    Joined:
    Feb 21, 2010
    Posts:
    27
    Question, will this script get FBX files from Modo to Unity without bringing extra cameras and lights along? We've been having troubles with clutter on import, and we're looking for a way to import just the mesh and textures.

    Thanks!
    -Tom
     
  3. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    Yes, this script will remove all items except mesh items i.e. cameras, lights, locators, materials etc. In case you use groupLocators for organization, it won't remove groupLocators if they contain mesh items. Also, all hierarchy is retained by the script when exported. If you have used constraints or IK for animation, the script will bake this animation.

    Hope you find it useful!

    Wes
     
  4. myunity

    myunity

    Joined:
    Nov 7, 2009
    Posts:
    117
    thanks for your help dear friend.

    i want creat my level and texture it in modo.

    does it have any problem for export to unity?which exporter i us is better?your's or modo?

    so thanks.
     
  5. wright.tom85

    wright.tom85

    Joined:
    Feb 21, 2010
    Posts:
    27
    Thank you very much, I'll get started on figuring these scripts out. =)
     
  6. wright.tom85

    wright.tom85

    Joined:
    Feb 21, 2010
    Posts:
    27
    So I've installed the script and given it a spin. It works quite well, but it crashes Modo 401 after it exports the file. has anyone else reported that problem?
     
  7. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    I'm sorry to hear that it crashed. I haven't had any issues and no one else has reported any crashes. Are you on OS X or PC? I developed the scripts under OS X and tested them on Windows 7.

    Please let me know what's in your scene when you export.

    Thanks!

    -Wes
     
  8. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    This script still exports an FBX just as modo does. However, this script will remove all of the unnecessary items such as cameras, locators and lights before exporting the FBX. It will also bake any animations you have that have constraints applied such as Directional or IK.

    -Wes
     
  9. wright.tom85

    wright.tom85

    Joined:
    Feb 21, 2010
    Posts:
    27
    I'm using laptop PC, but running on Windows XP. It may simply be this computer, if there are no other complaints.
    I've already checked to make sure the script includes the changes outlined on your blog, and it does.
    So far I've just been dealing with the crashes after export.
     
  10. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    Nice work Wes!
    I got problem with the Windows version of the script.
    Everytime I export a simple scene (just a default scene and a cube), I get the message:
    'The FBX file exported and is in your Unity Project's Asset folder!'.
    But it's not.
    And when I export my less-simple-scenes, modo stops responding and the file is still not exported.
    Anyone got the same problem, or found a solution?

    Windows 7
    Core i7 (OC)
    24GB RAM
    Modo 401 SP3
     
  11. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    Sorry, my bad.

    After reading the script I found the problem.
    Problem was that I tested the script on a non-Unityproject folder. The User NEED to select a folder that contains a '\Assets' folder.
    Still got problem with more complex scenes, thou.
     
  12. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    I'm sorry you're having issues with the PC version. I will take a look at the script when I get in front of my windows machine. I created the script under OS X. I tested it under windows 7 and it worked, but I'll definitely continue to look into the issues.

    When prompted to select unity project, did you select just the project folder? The script hardcodes the "Assets" folder into the save path, so if you didn't select the project folder, the file wouldn't be saved. I tried it on OS X build and if you don't select the right path i.e. the project folder, the file doesn't get saved. Although, the OS X build doesn't crash modo.

    I should look to build in a fail safe if the Assets folder isn't there the script won't execute and tells the user the file couldn't be saved.

    Best Regards,

    Wes
     
  13. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    That's right. The simple scene gets exported when a '/Asset' folder is selected.
    I'm still trying to get 'less-simple' scene to stop crashing Modo and start doing some exports.
     
  14. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    Glad the exports working with the project folder selected.

    Can you send me the scene or give me an idea of the 'less-simple' scenes that are crashing modo i.e. what items to you have in the scenes? I'd love to get this worked out for you and make sure the script is working 100%

    Thanks!

    Wes
     
  15. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    Coming up!
    I stripped the scene on almost everything. Still crashing.
    Try it out.
     

    Attached Files:

  16. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    Update:
    The export works fine when I:
    Move all the object to a new modoscene.
    I moved the objects with Children and Shaders checkboxes turned on.


    I removed every material, lights, cameras, environments, group hierarchies, images and vertexmaps but the old scene is still crashing.
    No problem exporting with the build-in FBX exporter!
    I removed the config file (modo401.cfg) to reset modo without success.

    I have no idea why it's crashing. What else information is stored 'per scene'?'
     
  17. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    Thanks for sending the file. Well, I was getting a crash on OS X as well. There's nothing in the scene that would cause this. I removed everything from the scene and created a new box mesh. Upon export, I was still getting a crash in the scene. So with completely new simple geometry the scene was still crashing.

    I then created a new scene and just moved all of the items in your scene to the new scene and no more crashes. Perhaps something could have gotten corrupted in that scene file. There's nothing wrong with your geometry or grouping. I've uploaded the new scene, please give this a try.

    Best Regards,

    Wes
     

    Attached Files:

  18. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    The scene you sent works perfectly.
    I have really no idea what's wrong with the old scene.

    Thanks for the support.





    Your script would reach a new level of awesomeness if you could implement an option for modo to remember the projectfolder.
    Why:
    Because I (most users?) is exporting the same file most of the time. The time lost in foldernavigation with mouse per export is probably WAY more than if user has to select the folder when user changes project.

    You could store the path with 'user.defNew' and a 'life' of 'temporary' to store the AssetPath:
    user.defNew name:string <type:string> <life:{config | temporary | momentary}> // page 62 in scriptmanual

    The momentay flag stores the variable until modo is restarted.
    Which means: that for the user to change Assetpath, he/she has to restart modo. A simple solution and I think it's a step up.
     
  19. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    No problem! Not sure what could be causing the old scene to crash. I emptied the old scene completely and created a new mesh item and still it crashes. Perhaps it's just a quirky thing with the old scene file. I completely picked it apart as well and can't find anything that sticks out either.

    I really like your ideas on remembering the asset path! I will implement this into the script. This is a great idea and would be a good time saver. I'll get it working soon and post the update here.

    Thanks!

    Wes
     
  20. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    While you're at it:
    I don't see a good reason to hardcode in the '\Assets'!
    The downside is that the user don't have control over their Asset hierarchy anymore. I, for instance, store my FBX files in a subfolder named Graphics\Source. When I export with the script the file is stored in the root Assetfolder. Of course I could move it, but that gets problematic next time i do an export.
    Solution:
    Let the user choose where to store the FBX file, instead of letting the user to specify a Unity project folder.
     
  21. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    Yes, this is probably the best choice. I pondered over this before hardcoding the Assets folder. I'll change this as well.

    Thanks much for the suggestions!

    Wes
     
  22. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    I just realized that in the 'less-simple' scene, one of the models was imported in COLLADA format.
    I guess that could be the problem. I've seen what COLLADA importers can do to Maya and XSI scenes. There's often a lot of unused/empty/unknown nodes imported in the scene. Some scene cleanup is always necessary to avoid instability in Maya and XSI. But I don't know how to do it i modo.
     
  23. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    That's the only thing that makes sense. It might have been the Collada files that were imported in modo that caused the problem.

    I updated the script to retain the save path during a modo session and it works much better : ) It's a real time-saver and increases workflow. I also got rid of the hardcoded assets folder so the user can save the file any place they'd like. I'll upload the script on my blog and post a link here later this evening.

    Thanks for your suggestions!

    Wes
     
  24. NERVAGON

    NERVAGON

    Joined:
    Oct 27, 2009
    Posts:
    73
    I really liked how some of the other scripts here would just use your LXO save path and drop the FBX there without presenting any dialogs. It might be cool to have a version of your script that works that way. Some people like to work from the project directory.

    I use maya, but who knows, 501, or 601 might be worth buying, so it's nice to see modo getting some unity scripts...
     
  25. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    I use Maya as well, mainly for all of my animation work. Perhaps I could port a version of the script to MEL.

    I made a change in the script that allows the user to select the directory themselves instead of hardcoding the Unity Project Assets folder. Also, the script will now retain the user save path for the entire modo session. This will hopefully improve the workflow a lot.

    -Wes
     
  26. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    I've updated the script to the suggestions by erix (thanks!). The script will will now allow the user to select their own save path. Also, the user will only have to select a save path once per modo session. The save path is retained while modo is running and hopefully this will improve workflow as now you can just export the FBX changes to Unity without a save dialog each time.

    The update can be downloaded here. I've also created a new video that shows the updates in action! Check it out.
    http://the3dninja.com/blog/?page_id=632

    Thanks everyone for the suggestions and feedback!

    -Wes
     
  27. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    Works like a charm. Thanks!
     
  28. archimi

    archimi

    Joined:
    Mar 21, 2010
    Posts:
    8
    would it be possible to export the uv coordinates. If i bake a texture on uv and export it with your script, i can't attach the backed texture on the model, because the uv isn't exported. Or i do something wrong, and i don't understand your workflow.

    I just want to bring a building with sunlight backed textures to unity.
    At the moment, for me it works with the standard FBX export, but it needs to long time for the save ritual. One button click like your script is great...but the UV is gone.

    An other question. To you now the difference of modos fbx and fbx 2006.11?

    thank's for answer
     
  29. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    You got it all wrong, archimi.
    The FBX file does not contain the textures, only geometri(es) and the uv(s).
    The correct workflow would be:
    1. Bake textures in modo, and save the texture file to the Unity Assetfolder.
    2. Export the modoscene into a FBX file, and place it in the Unity Assetfolder. I recommend this script.
    3. Assign the texture to the imported asset's material in Unity.

    Good luck
     
  30. archimi

    archimi

    Joined:
    Mar 21, 2010
    Posts:
    8
    thank's for answer erix

    i will check it out.
    Here som other questions, if you can help me (I'm new in unity):

    Ok, just for understanding correct: The FBX export with the script also includes UV's? Nut just the standard FBX export from the file menu in modo?

    Witch settings are you use for rendering the lightmaps in modo, that the result is nice, but the calculating dosn't need to long time? I think i also have here not very well settings in modo.

    Do you also use two uv-maps per geometry item?
    I use the uv1 (box) for texture placing and uv2 (atlas) for lightmap. Then in unity i choose "Lightmapped / Bumped Diffuse" and place the three maps. It works quite good but i have some dark areas on my geometry and i think that my lightmap is not correct calculated in modo for my building walls. On the ground for the grass it did work well. Maybe you can help me

    Thanks
     

    Attached Files:

  31. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    I'm sorry for the late reply. Thanks @erix for answering this!

    The UVs are exported in the FBX file generated from the script. Please let me know if you are still having issues with this. I'd be happy to help!

    An other question. To you now the difference of modos fbx and fbx 2006.11?

    fbx 2006 export is a legacy version of fbx. The fbx option from modo is actually based on FBX 2009.3 and the script exports to this version.

    Best Regards,

    Wes
     
  32. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    -'The FBX export with the script also includes UV's?'
    Yes, it's actually the same exporter as your version of modo uses. And therefore supports the same options as the regular export, but it's far more effecient workflow-wise.

    -'Witch settings are you use for rendering the lightmaps in modo?'
    It's depending on the object. You have to experiment and find a good solution by yourself.
    Make low quality/resolution bakes at first, because iterationspeed on assetcreation is very important, and make the high quality render later.
    Some materials is much better/faster to bake with Monte Carlo algoritm instead of Irradiance Cache. You can override the setting in the shader.
    Turn off reflections on the materials ( specially blurred reflections ), or use Monte Carlo.

    It's hard to troubleshoot the image you posted.
    Have you checked the uvs? Never use overlapped uvs when you bake, unless you know what you're doing.
    Could it be that you're baking on uvmap1 and not uvmap2? Always select the active uvmap in modo before baking.
     
  33. archimi

    archimi

    Joined:
    Mar 21, 2010
    Posts:
    8
    Ok, if i export with the script. Then i have just one Material over all. See the screenshot. If i export with the standard fbx from modo i can drag and drop each material. See my screenshot from my prevue message.

    I think i make a wrong workflow. Im new at unity. What's the correct workflow?
    Step by Step form Modo to Unity?

    Thank's
     

    Attached Files:

  34. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    You got a good point there. Just tested and verified.
    The builtin FBX exporter in modo, creates new materials in Unity on import. The name of the materials is '[ASSETNAME]-[MaterialName]'.
    Wes script only creates one material, with the name '[ASSETNAME]-no name'.


    I always turn the import material feature off in Unity and manually make my own materials.
    This is because I often have a complex shadertrree in modo and the exporter never gets it right.
     
  35. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    You obviously have problem with the different uvsets.
    The shader you applied is not using uvmap2, only uvmap1 for diffuse and illumination channels.
    You have to use a shader that uses uvmap2.
    I think the builtin Lightmapped shaders, should have support for uvmap2.
    There is not possible to change witch uvmap the shader is using without changing the code in the shader.

    Use the lightmapped materials.
     
  36. wesrm

    wesrm

    Joined:
    May 20, 2009
    Posts:
    193
    Hi erix and archimi,

    I created the script with Unity iPhone in mind. As erix mentions I always make my own materials especially if using Unity iPhone as I want to make sure that I am using the optimized Unity shaders. The script will strip all of the materials from the the scene before export. Unity by default adds a blank material so to speak ([ASSETNAME]-no name). I then rename this material and add one of Unity's optimized iPhone shaders such as one of the LightMapped shaders. However, I also use the same workflow when using Unity desktop.

    Just as erix mentions, using a complex modo shader tree will usually cause more headaches in Unity so it's best to rebuild the material in Unity with optimized shaders/materials that ship with Unity.

    I'm with erix, I think this is where the issue is happening. If you import an object and let's say you have 2 UV, with the first UV set being the UV's for applying color textures and the second UV set for applying a lightmap, you may be having an issue where the textures aren't targeting the correct UV set. For example, if you're using the LightMapping Shader and it seems that once you've applied the texture to the RGB and the lightmap to the lightmap slot in the LightMapping shader the textures aren't lining up correctly, you can swap the UVs using the import options( see the attached image). This will then change which UV set is applied to which texture and will correct the issue of the texture being targeted to the wrong UV set.

    I hope this helps!

    Wes
     

    Attached Files:

  37. archimi

    archimi

    Joined:
    Mar 21, 2010
    Posts:
    8
    Thank's for help. Now I'm a step closer to my Target. I did also create new materials in Units and did drag.them on the geometry. I'd works at one item and by the oters not. So i have it to check in modo.
    How do you set up a Light Map in modo? And what kind of right render settings do you use. Have you done some good experiance? Some rules?

    Thank's for help
     
  38. BenH

    BenH

    Joined:
    May 11, 2007
    Posts:
    175
    @archimi
    why are you using a self illum shader? Don't you want to display a lightmap? In Unity use a "Lightmapped>Diffuse" shader.
     
  39. archimi

    archimi

    Joined:
    Mar 21, 2010
    Posts:
    8
    Yes, i have see that. I allready use now a lightmap. Thank's anyway ;-)
     
  40. archimi

    archimi

    Joined:
    Mar 21, 2010
    Posts:
    8
    - Where can i set the Monte Carlo algoritm. I can't find it. Is it active if i deselect the Irradiance Caching?

    - No i don't habe overlapping uvs, they would be red marked, right?
    (see my screenshots.

    - I use the standard settings for global illumination. Ore what settings are you use normally? Indirect Rays higher or lower. Indirect Bounces more the one?
     

    Attached Files:

  41. erix

    erix

    Joined:
    May 25, 2009
    Posts:
    36
    If you disable the Irradiance Cache and have 'Indirect Illumination' enabled in the render settings you enable Monte Carlo algoritm globally. That is not recommended as MC usually take a lot longer time to bake cleanly.
    Enable only Monte Carlo on objects that returns the wrong result with Irradiance Cache or takes way to long to bake. You can enable MC on specific objects by assigning them a new shader, and set the 'Indirect Illum Type' to Monte Carlo instead.

    'Indirect Rays' only affect the Monte Carlo render. Use 'Irradiance Rays' to control the quality of the bake. If it gets splotchy, raise it.
    I suggest that you don't use automatic unwraping because of all the borderedges in uv's.
    I also suggest you search the excellent modo forum, or make a new thread here, as this this thread should be about information regarding Wes'(s?) export script.

    There's a lot of good information about rendering and baking here:
    http://forums.luxology.com/discussion/
    http://www.luxology.com/training/training.aspx?mode=Category&id=5
    or buy any of the training materials on luxology's website:
    http://www.luxology.com/store/training_materials/


    Good luck
     
  42. archimi

    archimi

    Joined:
    Mar 21, 2010
    Posts:
    8
    Thank's a lot for the help. Now i have got the turn around.