Search Unity

Simple Export Addon for Blender

Discussion in 'Asset Importing & Exporting' started by djweinbaum, Jul 15, 2014.

  1. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    I was a bit frustrated with the export pipeline for Blender, so I wrote my dream exporter. Its meant to be ultra fast for simple static mesh assets. Your model comes into unity as a single mesh (with submaterials if needed) and 0, 0, 0 on all transforms (including rotation). It uses Empties to represent props, so you can export multiple assets from a single blender scene. I find this useful for sets of related props. It also supports Dupligroups (if any one uses those, I certainly do). I wrote it for my own production, but I figured someone else might find it useful.


    Let me know if you dig it,
    Danny
     

    Attached Files:

  2. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Great! Thanks a lot for sharing :)
     
  3. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    @Izitmee Its wicked fast if you can get past the crudeness. I hope you like it.
     
  4. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    Hi. I thought this sounded interesting and might save me a bunch of time so I am trying to test it but I'm running into errors.

    Using Blender 2.71 64bit (will test latest after this post)

    Seems there is some trouble with parsing the path maybe? Leaving it blank does not thow any errors but there is no output at all. Using \\ on the end as in Path = "C:\Unity_Projects\BlenderExportTest\Assets\Models\\" or just one \ on the end throws errors.
    Top error in image is with \\
    http://imgur.com/4DCLLDY

    I am not experienced with Blender of comfortable with python so I figure maybe there is something I missed. Any ideas?
     
  5. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Nothing is jumping out at me. That path looks fine and 2.71 is the version I'm currently using. Even if you put a path that doesn't exist it will create a new one. What OS are you on? Have you installed python? I'm pretty sure python comes with the blender install but it might be something to try.
     
  6. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    win7 64bit.
    I haven't installed python anything. Can it be a dependency issue because of that?

    I completely forgot about updating Blender and ended up exporting the meshes as a group fbx. But I still want to try your way. :D I got a situation where I will use a bunch of meshes for prefabs that I then use to build up a level. the groupexport to fbx seems to work just fine but I am also so far only exporting quite simple geometric meshes.

    edit- Oh and I did see 0 of 0 exported from your plugin in the console when running with default path.
     
  7. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    It actually might be a problem with the setup inside the scene then. Perhaps make sure you're using a cube empty (empty types other than cube won't work, despite what is shown in the tutorial) and you have things properly parented. Also, make sure you have a material assigned to every child object under the empty.
     
  8. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    AHA! That is it. :D
    Not surprised at all that it was a miss on my part. It still doesn't explain why anything I put in Path don't work but you where spot on about the Empties.
    I've never used empties before so didn't know they had properties like that.

    Now if I could get the path working. What python stuff do you have installed?
     
  9. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    Solved it.
    \U is indicating a unicode key should follow. so I changed...
    Path="C:\Unity_Projects\MovesRB\Assets\Models\\"
    to
    Path="C:\\Unity_Projects\MovesRB\Assets\Models\\"
    BAAM! it works :D
     
  10. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Sweeeet! Wow, good catch. That unicode things is a very good thing for me to know. I had no idea. I should really make a GUI to define the export path. I hope the script serves you well enough to warrant all the troubleshooting you had to do to get it working!
     
  11. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    A GUI dialog that pops up on F2 where you enter/choose directory and can save a few favorites(to support multiprojects easily) would be great. Optionally have an option to let F2 be quickexport to last directory.
    Something like that would be great.
    So far it works really great. Have ~20 objects that gets exported and it is great being able to do UV mapping and material assignment work so effortless with the exporting.
     
  12. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    I have run into some problems with this one. I take it isn't supposed to be complex but as you work with visibility of objects in Blender the export plugin gets disoriented and it ends up not being able to position an empty so it moves it to world center and duplicates the child object.
    I'm guessing some check of visibility for empties and their childs should be done but I don't know anything about Blender API or Python really....

    Anyway it is a thing that can mess up your scene in blender and as such it is somewhat serious IMO.

    This was the error in Blender console.
    Traceback (most recent call last):
    File "C:\Users\CoolRidge\AppData\Roaming\Blender Foundation\Blender\2.71\scrip
    ts\addons\UnitySimpleExport_v1_2.py", line 153, in execute
    succeeded = ExportProp(prop)
    File "C:\Users\CoolRidge\AppData\Roaming\Blender Foundation\Blender\2.71\scripts\addons\UnitySimpleExport_v1_2.py", line 84, in ExportProp
    bpy.ops.object.convert(target='MESH')
    File "C:\Program Files\Blender Foundation\Blender\2.71\scripts\modules\bpy\ops.py", line 188, in __call__
    ret = op_call(self.idname_py(), None, kw)
    RuntimeError: Operator bpy.ops.object.convert.poll() failed, context is incorrect

    location: <unknown location>:-1

    location: <unknown location>:-1​

    Sorry if linebreaks where messed up with that paste
     
  13. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    You should be able to undo the damage done during export, as it stores the operations done on export as a single step in the history stack. I just uploaded v1.3 which may or may not fix your problem with hidden objects. It simply unhides everything in the scene prior to exporting. I'd version off your blender file before trying it. I always use layers so I hadn't run into the issue. I hope it hasn't messed up your stuff too badly!
     
  14. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    Nah I'm fine. I even did some test to lock it down to what was the issue. All I am doing is scenes with simple markup models so no big deal. Figured I should stop back here and say it since I figured it would be something easily fixable if you knew what to do. I assumed it slipped by cause you never yourself happen to end up triggering it. :D
     
    djweinbaum likes this.
  15. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Ah, okay good. I appreciate your looking into it and letting me know!
     
  16. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    Just tried it and it works wonders. Thanks for taking the time to fix it. Much appreciated.
     
  17. EmreB24

    EmreB24

    Joined:
    Jan 23, 2015
    Posts:
    3
    Here is the error that i am getting;


    If i can manage to solve the error i am getting you will be a life savior for the rest of my project.

    my problem is;
    Whenever i try to active your plugin i am getting the error i put in the screenshot
     
  18. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    I'm not sure this will fix it but try putting a single backslash at the start of your path string. There's only supposed to be two at the end. What version of blender are you using?
     
  19. EmreB24

    EmreB24

    Joined:
    Jan 23, 2015
    Posts:
    3
    im using the latest version
     
  20. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    "\U" indicates that the following character is Unicode in python. So your "C:\\Programming\Gaming\Unity\WeRocket\Assets\Objects\\" need to escape the "\U".
    So try changing...
    "C:\\Programming\Gaming\Unity\WeRocket\Assets\Objects\\"
    to...
    "C:\\Programming\Gaming\\Unity\WeRocket\Assets\Objects\\"

    Isn't there some way to tell python to treat the abolute path as a pure string or something? I mean it will be a problem for a lot of users since many tend to have a folder called "Unity" in their export path.
     
  21. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    I know I'm late to the party with this. But it just occurred to me we can circumvent this escape string danger by using all double backslashes. A double backslash is the escape string for backslash! I uploaded v1_4 with a new example path and a new comment. It feels like I should redo the video at this point but hopefully people will see the comment in the script.
     
  22. Mezaka

    Mezaka

    Joined:
    Jan 10, 2016
    Posts:
    2
    you just saved me a huge amount of time! Thanks for sharing this!
     
    djweinbaum likes this.
  23. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    This is a great time-saver, thanks.

    I'm having a minor problem -- it is moving some of my objects on the Blender side after the export. They are fine in the DAE that goes to Unity.

    This little blobby guy pictured below is an example. His tentacles are separate meshes parented to the body. They contain curves (parented to the tentacle meshes) and a curve modifier, which I have not Applied so that they'll remain modifiable. First picture is before export and the parenting setup, second picture is in Blender immediately after export. A simple Undo fixes it but I wondered if anyone might know what's happening.

    1.jpg 2.jpg 3.jpg
     
  24. I_Am_DreReid

    I_Am_DreReid

    Joined:
    Dec 13, 2015
    Posts:
    361
    Neat, thanx man
     
  25. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    I just figured out that the center point of the imported objects is centered on the empty-box location in Blender. Maybe it isn't a big deal on smaller models, but I was building some larger ones and they were importing in all sorts of weird locations, even though the transform showed 0,0,0.

    Probably best to center the Blender 3D cursor on the origin before creating the empty-box parent.
     
  26. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Yeah, it looks like the script is not cleaning up after itself properly, which is bad. I worried about this when I was making the script, that's why I made sure to register all the commands in the script to a single undo step. Maybe I should simply execute an undo at the end of the script itself.

    If I understand you correctly, then that is by design. I like to have a bunch of props lined up in one file (eg a bunch of tree variants) and I put their parent empties where I want their pivots to be. I don't always want the blender scene origin to be the pivot in unity. Sometimes I do and in that case I just put the empty on scene origin.
     
  27. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    It may have been something with my model. Somehow I had two copies of the faces of each tentacle in there, so the materials weren't exporting quite right. I figured it out, deleted them and re-created them, and now they export correctly and there isn't any problem after export.

    Nice job setting it all up as a single undo though, the first time through I hit Ctrl-Z with fingers crossed!
     
  28. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,435

    Attached Files:

    Last edited: Jun 25, 2022
    nikefootbag likes this.