Building a Sync Tool for Blender to Defold

Update - 04-09-2024

Release 2.0.0 is now out. Feel free to try it out.
It is still for Blender 2.8.0 → 3.4.0 versions.
If you are using Blender 3.6.0 and above, then in the next day, there will be a new version that will support both.
Please see the release notes for all the new capabilities in the game data export.

If you have any problems or queries then feel free to ask below or raise an issue on github.


While making the f18 game, I ran into some general hassles getting 3D models into the Defold system. Its not that its hard, its just a little strict and takes more time than Id like.

Sync Tool is now Defender!

The tool is now a Blender only plugin, making it much easier to install and use. Example running here:

Supported features:

  • New GLTF and GLB Defold support
  • Animation
  • PBR Material (simple) and Defold model material
  • Global or Local single light
  • Material flat or vertex shading
  • Export all collections to Defold collections
  • Export mesh, textures, vertices, normals and uvs.
  • Base Color RGB converted to small png and mapped into PBR material
  • Hierarchy structure replicated with game objects in Defold.
  • Empty nodes are used for game information and exported to Defold as game object.

There are likely to be bugs, and I am resolving them as I use it in my f18 game. There are very few more features I need to add, so if you are looking for a feature then please ask or raise an issue and I will have a look. Some features can be very easy to add.

Possible features to be added:

  • Particle effects mapped to Defold particles
  • Multiple light support - this may happen, but I think it might be better to create a lighting system for Defold including light probes and similar.
  • More complex animation - I want to add tweening and animate export.
  • Lua Defold script testing in Blender. A little weird, but I have done some initial tests, and this could be very useful.

An application I hope to develop from this, is a Blender visualiser that allows people to view their Blender assets live on a target platform (IOS, Android, PC etc).

People interested in working on it, or want to submit PRs, please do. Happy to have input!

41 Likes

defold-blender-export

A Blender export system for the Defold game engine.

Setup Notes

There are no exhaustive documents for this tool yet. Its just not complete, so everything is very much ‘in flux’.

Note: The Sync Tool is now a Blender Only addon. This makes building Defold resource collections much simpler.

To use the tool follow the guide below.

  1. Copy the blender/addons/sync_tool folder to the blender addons folder. See blender docs for this.

  2. Or… you can copy the blender/addons/sync_tool/* files into the folder where your blender source file is, and the scripts should work from there.

  3. Open the blender file you want to work in (or open the test.blend to see an example already setup)

  4. Open the text editor in blender and loadin in the script “defoldSynUI.py”

  5. Run this file. You should see “bpy.ops.text.run_script()” in the Info Window in blender.

  6. Open the 3D layout window in blender and ensure you are in “Object Mode”.

  7. Examine the Tools menu on the right side of the Layout 3D View (see below)

  1. Enter the appropriate properties for Scene Name and Directory (project directory to save into).

  2. Select “Sync Build” for the scene mode and press the “Sync Scene” button when ready.

A folder will be created in the target project directory with all the resources needed to load the scene into Defold.

At a minimum you should see a collection file and some gameobjects (in the gameobjects folder). You can open this project and open the collection.

While the “Sync” tickbox is enabled, data will be written to the collection file - do not save new objects into it while Sync is on - they will be overwritten.

Sync can be unticked at any time and the data will stop pushing to the collection.

Once this is setup you can add/edit the blender scene as you need and any Sync’s you do, will update the meshes, textures and object positions in Defold.

Issues

There are a number of odd issues using this system. It is early days, so they will be ironed out.

Some limitations on what Blender can stream:

  • Only single texture for each object is used (this is a Defold thing).

  • Object materials only use model materials at the moment. This might change to PBR materials.

  • Lights and Camera are added in Defold, but they are not yet setup to operate correctly (TBD)

  • Many features are only partially functional. Tread carefully :slight_smile:

… Updated

8 Likes

Updated github. Win10 support was a little flakey, so I have updated it.
There are some gotchas on Win10 too:

  • Blender process doesnt close threads it owns, so the server thread started in the plugin may need to be killed in task manager.
  • Assumptions were made for pathing, but it wasnt necessary so beware of path issues within the Defold objects that are created (let me know if you find any).

I’ll add an exit event handler and see if I can manually shut the thread down before exiting blender (should be possible).

Otherwise the Win10 works pretty much the same as the Linux test.

Update:
Thread shutdown should now be happening. Pathing has been improved.

9 Likes

The sync tool is becoming a wonderful little helper :slight_smile:
I have added generic “empty” node generation and a bunch of other features. Animation is in, but I havent yet auto converted it to a dae file on sync (will probably use assimplib or similar to make sure its compatible).
Heres my f18 San Francisco map with a Threat mission added as a starting point, and a target node for a cruise missile in Blender.

The same map as a complete Defold collection that is loaded in via proxy.

And the final map in game.

Once I get the anim finished, I’ll spend some time on “game meta data”. Its a very interesting feature. I think I can even technically have lua scripts able to run in Blender and then sync across to Defold - which would be quite awesome :slight_smile:

14 Likes

Updated features:

  • Multiple objects within a scene are converted to multiple game objects in the collection.
  • Node hierarchy is respected in Blender to Defold
  • Y/Z conversion is automated. Default Blender XZY is converted to Defold XYZ. With a root transform node in Defold that can be modified if needed.
  • Cameras in Blender are now Cameras in Defold.
  • Lights are copied, but not properly activated in Defold - will add a script to apply lights to scene objects.
  • Empty objects supported (great for game events/markers etc).
  • Materials are currently minimal - this is being expanded to support specular, diffuse and other lighting properties.
  • Initial Animation is synced. To be completed.
13 Likes

Awesome work!

9 Likes

I have reworked the whole tool set :slight_smile:
Now it is a fairly simple setup only within Blender

  • no intermediate tool now - may resurrect for multi-user editing, but the server python code is a little too unstable
  • Need to have luajit installed in the OS. I used this to minimize the amount of code rewrite, and I really dont like python with its nightmarish whitespace (already had probs with that).
  • Should provide at a minimum: Project path and project name. If you dont, it will create a Sample folder where your blend file is with all the resources in it.

Here’s a little pic of the new tool:

It operates in exactly the same manner, but instead of live continuous updates, it uses the Sync Tool button to push your scene into the project folder.
You need to have access permissions to folders you want to push to.

I havent updated the documentation, will do so tomorrow. If you have any problems with it just PM me, or raise an issue on github.

Note. Animation isnt working yet (underway). Only static objects, meshes, textures and hierarchy. Empty objects are still supported and Cameras and Lights have their objects created (not fully complete yet).

12 Likes

More rework :slight_smile: I decided to try and support very large blender files. I took this demo example, and wanted it to cleanly export to Defold. After reworking the sync process a bit, I think its quite decent.
Orignal Blender scene here (its 412MB)

Looks like this in shader view:


After export to Defold:

To be honest, I expected it to be pretty bad. But its quite good.
The sync only does:

  • Base Color textures
  • No support for the particles in Blender (I think I might be able to support some with Defold particles)
  • No lighting support yet (this is coming soon).
    It turned out quite well. Im cleaning up the code, and will be checking it in within the next hour.

Yes, it takes quite some time for the collection to load :slight_smile: But it loads.
There are dozens of optimizations I can have a look at once I get a couple more core features in.

This is nearly something that can be used in production. If you do, please let me know if I can help with any issues (please report on github for problems).

16 Likes

What is the editor experience once it is loaded? Sluggish?

EDIT: And man, great job! Really impressive!

1 Like

Its pretty good. Quite surprised - I thought itd die :slight_smile: Mem usage is quite high - currently around 8.2GB.
I have two collections in this editor though so Id expect it to be around 6-7 GB.
And its all very un-optimized, I think there is quite alot of room for some general improvements in the storage of the verts etc (like indexed buffers etc). Its a fairly naive implementation atm.

Thanks btw. Its actually really nice to just work in a 3D art tool and see the results live in the editor. Kinda neat. I worked with something like this two decades ago at Ratbag games - it helps workflow alot (for the artists).

10 Likes

I decided to run the collection with the imported camera.

I will be adding a PBR shader and I think it will look very close to the shader render in Blender.

14 Likes

Added PBR shader - currently only supports BaseColor, Metallic, Emission and Normals.
Missing Alpha/Transparency, Masking and color tinting.


Will add options for enabling this in the Blender UI. The output render will depend alot on what you want to do with the scene.

8 Likes

The previous screenshot is with a single local light at 1, 1, 1
Here’s a directional lighting with same metallic and base color PBR material.


Note the normal maps and some of the metallic highlights.

< edit >
The sync tool has been tested on Win10 and Linux Debian only. Win10 has some folder issues (which should be resolved today). I dont know if I will get to OSX anytime soon, since my Mac Mini has been deprecated and probably wouldnt load this scene.

9 Likes

Finally have metallic, roughness, emissive, albedo (base color), and normals all working. I think it looks quite nice. :slight_smile:

Windows is now working fine too. Still a few things to finish off:

  • Transparency
  • Animation
  • Go scripts
  • A bunch of tests needed for regression testing.
12 Likes

Some editor notes:

  • The JVM has crashed twice. It looks like there is a leak somewhere when loading in a new collection (doesnt release some of the mem). Will have a look when I wrap some of this up.
  • When a new scene is sync’d and its big (like this one), it can sometimes take a minute or more. It appears that there might be a limit on mem use for each of the java processes - not sure though.
  • If there are lots of errors in the sync, then loading in the collection can take much longer.

Overall the editor is quite ok with this file. I’ll post some videos of it in action tomorrow.

7 Likes

I’m not working on any 3D topics, but this is amazing to follow! Thank you for sharing this! :heart_eyes:

2 Likes

I have been thinking of using it for 2D and Gui too. It would be nice to do gui animations in Blender and then just sync to Defold - I think this should be quite doable. I’ll probably look at that in early Feb. Glad you like it - if you use it and find any probs, feel free to add issues on github. I like peoples suggestions and ideas (I often have very strict personal features and often miss basic things :slight_smile: ).

6 Likes

Added in alpha setting. But now need to add a alpha predicate for ordering the objects correctly.

6 Likes

Animation, single global or local lighting and PBR or model material selection is in.
The scene exports directly to a collection with models rigged to run the animation. The below vid uses a untouched collection with key bindings to play anims and move camera.

The Blender tool panel is a little nicer now too.
sync-tool-2022-01-03_00-12

Finishing up some go script features and that will be it for a while - need to finish the F18 game :slight_smile:

13 Likes

Amazing stuff. Don’t stop, I’m sure that many have been waiting for these tools!

4 Likes