Search Unity

Blender 2.57

Discussion in 'External Tools' started by KnifeFightBob, Apr 14, 2011.

  1. KnifeFightBob

    KnifeFightBob

    Joined:
    Jan 22, 2009
    Posts:
    196
    So, I guess most of you other Blender users out there are excited that 2.57 is finally and officially out now. It seems the automatic conversion is not working at this point in time.

    What happens now? Do we have to wait for Unity Tech to create a new version with support? When can we expect 2.57 integration?
     
  2. vortex69

    vortex69

    Joined:
    Feb 4, 2010
    Posts:
    92
    You start using FBX, sit comfortably and wait :)

    blender import probably will only be updated in the next version of Unity, so I guess it will be for blender 2.58 (but the guys at UT could surprise us, 3.x is having a pretty fast update cycle)
     
  3. Bampf

    Bampf

    Joined:
    Oct 21, 2005
    Posts:
    369
    Last edited: Apr 15, 2011
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I can confirm that 2.56 worked, but it was necesarry to do it exactly as woodn described it. Don't know about 2.57 yet.
     
  5. Veles

    Veles

    Joined:
    Feb 23, 2010
    Posts:
    21
    It doesnt work....2.57 stable version...I was really hoping that it would...

    Well, this is really stupid...
    How long 2.5x version exist and i cant use it for so long because the direct import cant be fixed and resolved...Not even when i export fbx file from 2.57 Unity doesnt recognize.. not that i would use fbx files anyway, because i dont want to non stop export fbx files when im updating models...So im still using 2.49b...I mean wtf ?!!? Does nobody cares or what!?!? This is long time now and this doesnt work.....I really dont understand....
     
    Last edited: Apr 17, 2011
  6. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    It's because the 2.5 series was still a moving target, APIs getting changed constantly. Now that a stable version has finally been released, hopefully the next release of Unity will have direct support.
     
  7. the_Simian

    the_Simian

    Joined:
    Mar 13, 2011
    Posts:
    33
    possibly dumb, albeit sincere, question: im using fbx with no issues. aside from the seemingly minor convenience of dropping the blend file into the assets folder, what is the main advantage? whats fbx lacking?
     
  8. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Nothing. The big advantage of using blend files directly is when you need to make small adjustments. Just double click the file in the project list, make the change, save. So it's really just a workflow enhancement.
     
  9. jorrit5477

    jorrit5477

    Joined:
    Aug 7, 2009
    Posts:
    50
    The Python API for exporting .blend files seems to have changed from 2.56 to 2.57. It should be stable with version 2.57 (I am not an Blender expert though, so you never know when the final release comes out of 2.5x). I have successfully updated Unity-BlenderToFBX.py.

    I have only tested this with meshes (no animations, texturing, lights).

    From line 53:
    Code (csharp):
    1.  
    2.     io_scene_fbx.export_fbx.save(FakeOp(), bpy.context, filepath=outfile,
    3.     GLOBAL_MATRIX=mtx4_x90n,
    4.     use_selection=False,
    5.     #EXP_OBS_SELECTED=False,
    6.     EXP_MESH=True,
    7.     EXP_MESH_APPLY_MOD=True,
    8.     EXP_ARMATURE=True,
    9.     EXP_LAMP=False,
    10.     EXP_CAMERA=False,
    11.     EXP_EMPTY=True,
    12.     EXP_IMAGE_COPY=False,
    13.     ANIM_ENABLE=True,
    14.     ANIM_OPTIMIZE=False,
    15.     ANIM_OPTIMIZE_PRECISSION=6,
    16.     ANIM_ACTION_ALL=True,
    17.     batch_mode='OFF',
    18.     #BATCH_ENABLE=False,
    19.     #BATCH_GROUP=True,
    20.     #BATCH_FILE_PREFIX='',
    21.     BATCH_OWN_DIR=False,
    22.     use_metadata=True)
    23.     # I don't think HQ normals are supported in the current exporter
     
    Last edited: Apr 21, 2011
  10. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    jorrit! thank you :)

    works like a charm on os x, even with skinned animations!
    trying it out on windows now. there are some cool new builds on graphicall ;-)
     
  11. KnifeFightBob

    KnifeFightBob

    Joined:
    Jan 22, 2009
    Posts:
    196
    Thanks! Just tried it with a simple mesh with baked texture just to see. And since someone asked before, the direct importing from Blender really is a time (and effort) saver. I'm also having weird stuff happening with my FBX files so I'd rather stay far away from them.
     
  12. G_E

    G_E

    Joined:
    Feb 27, 2011
    Posts:
    2
    I can't find the Unity-BlenderToFBX.py on my Mac, can you please tell me how you made it work?
     
  13. IcyPeak_S

    IcyPeak_S

    Joined:
    Dec 1, 2009
    Posts:
    377
    Please do let us know.... and thanks jorrit!
     
  14. KnifeFightBob

    KnifeFightBob

    Joined:
    Jan 22, 2009
    Posts:
    196
    @G_E: You need to right-click on the Unity.app in your Unity folder and choose "Show Package Contents" (or something similar to that). Inside, you should find the file within Contents -> Tools.
     
  15. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    what knifefightbob said!

    EDIT: Removed the how-to for blender 2.57 because of obsoleteness. See alewinns post below.
     
    Last edited: Apr 22, 2011
  16. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    And the new fbx-exporter shipping with the just released blender 2.57a broke the blend-workflow again :p
    Still, you can use the old exporter scripts...
     
  17. alewinn

    alewinn

    Joined:
    Nov 8, 2009
    Posts:
    185
    Seems to work fine with the following config :


    io_scene_fbx.export_fbx.save(
    FakeOp(),
    bpy.context,
    filepath=outfile,
    use_selection=False,
    batch_mode='OFF',
    BATCH_OWN_DIR=False,
    GLOBAL_MATRIX=mtx4_x90n,
    context_objects=None,
    object_types={'EMPTY', 'ARMATURE', 'MESH'},
    mesh_apply_modifiers=True,
    mesh_smooth_type='FACE',
    ANIM_ENABLE=True,
    ANIM_OPTIMIZE=False,
    ANIM_OPTIMIZE_PRECISSION=6,
    ANIM_ACTION_ALL=True,
    use_metadata=True,
    path_mode='AUTO'
    )
     
    Last edited: Apr 23, 2011
  18. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    thanks alewinn. that is the much better solution and it works of course ;-)
    the only two values i changed was mesh_apply_modifiers = True, because i use the edge split modifier quite a lot and ANIM_ACTION_ALL= True, because i use more than one action most of the time.
     
  19. alewinn

    alewinn

    Joined:
    Nov 8, 2009
    Posts:
    185
    Exact !
    Code Updated Woodn :)
     
  20. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    Ok, collecting all infos until unity is updated officially:
    Credits go to jorrit and Alewinn!

    Mac:
    - Get Blender 2.57a from blender.org or a recent build from graphicall.org and unzip it somewhere. Assign blend files to open with the just downloaded blender.app.
    - Browse to the Unity folder and right-click "Unity.app" and select " Show Package content". Then browse to the folder Contents/Tools/ and backup "Unity-BlenderToFBX.py". Then replace it with the one in the attached zip file or change the lines described by alewinn a few posts above yourself.
    - Done.

    Win:
    - Get Blender 2.57a from blender.org or a recent build from graphicall.org and unzip it somewhere. If you use a zip package, make sure you register the blender.exe by executing "blender.exe -r" in a cmd prompt or with a shortcut. If you use the installer, you don't need to do this.
    - Browse to the C:\Program Files (x86)\Unity\Editor\Data\Tools folder and backup "Unity-BlenderToFBX.py". Then Replace it with the one in the attached zip file or change the lines described by alewinn a few posts above yourself.
    - Done.
     

    Attached Files:

    Last edited: Apr 23, 2011
  21. LordMoggy

    LordMoggy

    Joined:
    Aug 28, 2010
    Posts:
    72
  22. pjezek

    pjezek

    Joined:
    Jun 10, 2009
    Posts:
    18
    thanks a lot @jorrit, Alewinn and woodn!
     
  23. temp_account

    temp_account

    Joined:
    Apr 24, 2011
    Posts:
    6
    Hey guys, thanks for the udpated script. It's working great and I'm glad to be using 2.57 finally with Unity!

    By the way, Is there any way to have models imported in the same orientation to Unity as they are in Blender? I'd like to have all my models in 0-rotation in both Blender and Unity, but I'm finding I need to rotate the models -90 degrees on the X-axis and 180 on the Z-axis to orient them properly in Unity, and this leads to some kludgery on Blender's side of things (basically I need to bake a 'correct' rotation to each and every mesh I have).
     
    Last edited: Apr 24, 2011
  24. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    @temp_account : I don't know if it is possible, but the problem is based on the different axis systems Unity and Blender use. A complete recalculation of the axis in a script would be quite the math challenge i guess. Especially when it comes to complex armatures and the rotations of bones. But it would be very helpful of course...

    From the Blender side I remember a dev saying that their axis system is to much wrangled into and spread across their code to make the axis system a changeable user option, so i guess no relieve from that side anytime soon.
     
  25. temp_account

    temp_account

    Joined:
    Apr 24, 2011
    Posts:
    6
    @woodn

    Yeah, I'm not sure. In order to achieve this currently I have to do the following in Blender:
    1. Rotate the mesh 90 degrees on the X-axis and 180 degrees on the Z-axis
    2. Bake the rotation (Ctrl-A)
    3. Rotate the mesh again 90 and 180 on the X and Z

    Now that I have baked the correct import orientation to the mesh (since it doesn't seem that I can modify it from Unity's side of things), I can rotate it freely to the original orientation in Blender, since the rotation doesn't actually affect anything if it's not baked. It's the same with scale and position, obviously.

    Now, if I use just the mesh object in Unity and not the GameObject it creates, the mesh can exist in 0-rotation in Unity. Yay.

    I tried modifying the import script - there's the GLOBAL_MATRIX parameter, but it only affects the GameObject's Transform object that Unity creates in import, and doesn't actually modify the mesh's import rotation in any way. This isn't a problem if you only have a single mesh per single Blender file, since Unity also combines all the meshes in a file to the GameObject it creates..

    I guess I'll just have to fashion a script on Blender's side of things that does the 3 steps mentioned above, to save me a few clicks.
     
  26. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    @temp_account
    maybe the copy rotation constraint targeted at a rotated empty could be useful to you. it would be the same approach, but you'd only have to slide the influence-slider before export.

    unfortunately, this is only a solution to non-rigged models :-(
     
    Last edited: Apr 24, 2011
  27. temp_account

    temp_account

    Joined:
    Apr 24, 2011
    Posts:
    6
    I tried fooling a bit around with this today - basically it seems like you could call the Blender API from the Unity's import script, and I managed to create a script on Blender's side of things that does the operations required for the correct import orientation.. I got the impression that it could be automated through the import script, but alas, my skills didn't really carry all the way to the end.

    I think it'll be safer to use the GameObject Unity creates in import anyway, especially if you're importing with animations. I managed to modify the import script in a way that it imports the GameObject in the correct orientation (essentially applying the correct rotation to the Transform of the Mesh object), while the GameObject stays in 0-rotation.

    Again, the main thing is that 2.57 import works, I'm happy with that. The rotation kludgery is a minor inconvenience.
     
  28. G_E

    G_E

    Joined:
    Feb 27, 2011
    Posts:
    2
    Thanks. :)
     
  29. deps

    deps

    Joined:
    Nov 19, 2009
    Posts:
    78
    Used to work great with Unity and latest blender just as it was, then suddenly it stopped working. Thanks to this it's working like a charm again. :)

    Thanks!
     
  30. relational

    relational

    Joined:
    Sep 28, 2010
    Posts:
    15
    Is anyone able to use fully animated armatures with unity and blender 2.57? I'm still getting inconsistent results. Sometimes the mesh gets imported from the fbx, sometimes it doesn't. I've checked the vertex groups and have made sure that all the verts are assigned.
     
  31. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    @relational
    i haven't had any troubles with my characters and their animations. but i'm only using the direct .blend import. just an idea: you are aware of the "export only selected objects" checkbox in the export settings, right?
     
  32. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    You have not only to select the armature, you need to select the meshes of the character in the armature too. Means in the Outliner you click at the armature, then you expand the hierarchy, and click at your attached mesh(es) too until everything is selected. When the mesh is not selected, then it doesn`t export.

    For me a bug, because i have already selected the top hierarchical object: my armature. And then the whole stuff should export, including attached meshes. For the Blender Devs it is the normal export workflow though that you explicitely need to select all the attached and skinned meshes too. Maybe somebody else could make a bug report about it. I already tried ...
     
  33. Veles

    Veles

    Joined:
    Feb 23, 2010
    Posts:
    21

    Ok. I installed 2.57b and this doesnt work for me. Back to 2.49 version again. This is so sad and frustrating....
     
  34. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    @veles : just tried it with 2.57b and it works for me. (with the modified unity-blender script)
     
  35. KnifeFightBob

    KnifeFightBob

    Joined:
    Jan 22, 2009
    Posts:
    196
    Works for me as well.
     
  36. Veles

    Veles

    Joined:
    Feb 23, 2010
    Posts:
    21
    So, I completely uninstall everything including 2.49 version, clean the registry for errors and perfromed clean new install with default settings...

    It works now with that modified script. Finally. I hope everything else would work too :)..So thanks for this. I will finally work everything in Blender 2.5. Yay
     
  37. chs200123

    chs200123

    Joined:
    Oct 14, 2010
    Posts:
    7
    IM trying to understand FBX a little bit more. It seems to me the the FBX format destroys blender topology. Why does it convert everything into tris? Is there an advantage to this? Also, when people keep saying that you can make adjustments after converting to FBX, I'm assuming that these adjustments are being made with unity and not Blender. Is that correct?
     
  38. cacysunlee

    cacysunlee

    Joined:
    Jan 25, 2011
    Posts:
    24
    Blender 2.5 works for me well...

    my last test was this : http://www.sunlee.t15.org/egypt.html
    level build with blender, textures with gimp

    i have no problems to export from blender to fbx and no problems to import in unty, same with simple animations...
     
  39. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    @chs200123 : If you export a model to FBX, it gets triangulated for usage in unity. unity doesn't know quads or ngons or similar, so thats why the model is exported as a triangulated mesh.

    A typical base workflow:
    1. When working with FBX files, you keep the original .blend file somewhere save and if you need to change something on the model or add to the model, you change it in the .blend file and export the FBX again. Never import a FBX to Blender if you don't really have to. Always work with the original .blend file and export from it again. Almost everything related to physics or shaders is best done in unity after you imported the FBX. You have to play around with it a little until you find a good workflow.

    Another base workflow (i prefere):
    2. You only work with one original .blend file and place it directly in the Asset folder of your project. This way, Unity automatically opens the blend file in the background, exports an FBX file and updates the model in Unity. If you need to make changes to the model, doubleclick the .blend file directly in Unity, change what you have to in Blender and save the file. Done. The .blend file isn't altered and doesn't get triangulated, it's modifier stack or helper bones or constraints are left intact.
     
  40. cacysunlee

    cacysunlee

    Joined:
    Jan 25, 2011
    Posts:
    24
    thank you for this advice !
     
  41. relational

    relational

    Joined:
    Sep 28, 2010
    Posts:
    15
    Thanks Tiles and woodn. With the python script edits and selecting just the armature and mesh I was able to export the fbx file to Unity on OSX 10.6 with Blender 2.57a and the animation and mesh stays intact. BTW I also used automatic weights with weight painting and it seems to be working.

    With all the information in this thread it would be great to create a sticky at the top that shows these two pieces of information:

    1) Make changes to python script.

    2) Select just the Armature and mesh for export.

    I think this would save a lot of people a lot of headaches.
     
  42. relational

    relational

    Joined:
    Sep 28, 2010
    Posts:
    15
    @woodn
    Are you using the .blend file with 2.57a and Unity 3.2 with just the edits to the python file, and you are still able to get imported animation? This still isn't working or me. I can do it via fbx but when I use a straight .blend file I still get:

    line 2841, in save
    return save_single(operator, context.scene, filepath, **kwargs_mod)
    TypeError: save_single() got an unexpected keyword argument 'object_types'
    Blender could not convert the .blend file to FBX file.
    You need to use Blender 2.45 or higher for direct Blender import to work.

    in the Unity editor log.
     
  43. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    jep, 2.57a with the latest unity and the posted python file from the zip.
    the error you're getting doesn't ring any bells with me, sorry...
     
  44. prophet

    prophet

    Joined:
    Sep 8, 2009
    Posts:
    205
    So, I tried the python replace and unity is telling me that I need blender 2.45 or better still. Would did I miss?
     
  45. relational

    relational

    Joined:
    Sep 28, 2010
    Posts:
    15
    @prohpet

    Are you exporting to fbx or using the .blend file method?
     
  46. Muzzn

    Muzzn

    Joined:
    Jan 23, 2011
    Posts:
    406
    Here's a problem I've had - not all faces of a plane are imported. I model everything from planes, and when I import them into unity, only one face is imported ( the one before extrusions etc.). How do you solve this error?
     
    Last edited: May 1, 2011
  47. chs200123

    chs200123

    Joined:
    Oct 14, 2010
    Posts:
    7
    This sounds like a much more manageable workflow. So I tried to create a new folder in the bootcamp asset folder and called it "Test_Asset". I then placed a .blend file in there with its textures to see what would happen. I closed Unity and reopened. Unity said it was importing the assets. When I click the asset under Unity's project pane, I cannot drag it in to the screen. Is there something else that has to be done?

     
  48. chs200123

    chs200123

    Joined:
    Oct 14, 2010
    Posts:
    7
  49. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    bottom left corner of your image: "blender could not be found" in red. that means that your blender installation is messed up. my advice would be to uninstall all previous blender versions and follow the instructions in this post.
     
  50. chs200123

    chs200123

    Joined:
    Oct 14, 2010
    Posts:
    7
    Hello Woodn,

    That was amazingly simple. I managed to import some very complex architecture I had worked on about a year ago just by openeing Unity. You're right. To modify the .blend, I kept unity open, modified the .blend with blender and closed. Unity updated the scene almost immediatley preserving everything. I'm blown away at the ease of it.

    There are some texture problems however and I cant seem to get collision detected. Do collisions need to be setup in blender? Do I just need to "Generate Colliders"? Also, it seems that Unity does not take advantage of Blender's spliting of mesh (using Y in blender). This along with library linking and memory instancing (instances of groups) are very important parts of Blender-workflow. With your experiance so far, do you think Unity devlopers will try and include support for them or is the blender community sort of left on their own to devlop their own tools (primary reason why I have abondoned Cryengine).

    I'm curious as far as what you think of Unity's support for blender. Do they take recommendations and actually implement them or no? I'm trying to decide wether to use Unity for some upcoming major projects. Thank you Woodn for your help so far.
     
    Last edited: May 3, 2011