Blender_bevy_components_wor.../tools/gltf_auto_export
kaosat.dev 0fb35d6e6a feat(blenvy):
* minor tweaks & improvements to assets handling
 * renamed a few auto export preferences for more coherence
 * "assets" folder is now mandatory again and used by the various sub asset types
 * blueprints/levels/materials paths in auto_export are not overwrite their relative values anymore,
but added their "full" variants & changed code using full paths to use those
 * added back gltf exporter post export callback, in a cleaner fashion
 * changing (wip) the way the various relative folders are auto generated in the folder selection UI
 * lots of other minor tweaks & improvements
2024-05-14 23:49:45 +02:00
..
auto_export feat(blenvy): 2024-05-14 23:49:45 +02:00
docs feat(Save & load): new crate bevy_gltf_save_load + lots of upgrades & improvements (#95) 2024-01-10 14:49:29 +01:00
helpers feat(blenvy): 2024-05-12 15:10:35 +02:00
modules feat(auto_export): 2024-04-29 00:02:50 +02:00
tests test(auto_export): overhauled & cleaned up tests 2024-04-30 11:05:24 +02:00
ui feat(tools): a ton of experiments for assets & blueprints ... wip 2024-05-12 11:05:11 +02:00
__init__.py feat(blenvy): 2024-05-14 23:49:45 +02:00
constants.py feat(auto_export): MORE experimenting, cleanup & analysis attempts 2024-04-08 23:41:17 +02:00
pytest.ini chore(testing): moved blend files into "art" folder 2024-04-26 23:01:58 +02:00
README.md refactor(): removed remains of legacy mode 2024-04-30 11:33:05 +02:00
TODO.md feat(tools): a ton of experiments for assets & blueprints ... wip 2024-05-12 11:05:11 +02:00

gltf_auto_export

This Blender addon

  • automatically exports your level/world from Blender to gltf whenever you save your Blend file.
  • in Blueprints mode (highly recommended !) :
    • supports automatic exports of used collections as Gltf blueprints
    • supports any number of main/level scenes
      • Blender scenes where you define your levels, and all collection instances are replaced with "pointers" to other gltf files (all automatic)
    • supports any number of library scenes
      • Blender scenes where you define the assets that you use in your levels, in the form of collections
    • automatic export of changed objects & collections only ! a sort of "incremental export", where only the changed collections (if in use) get exported when you save your blend file

Installation:

  • grab the latest release zip file

blender addon install

  • in Blender go to edit => preferences => install

blender addon install

  • choose the path where gltf_auto_export.zip is stored

blender addon install

Usage:

Important

if you have used a version of this add-on prior to v0.9, there was an issue that kept generating orphan (junk) data on every save ! You can easilly clean up that data

  • go to orphan data:

purge orphan data

  • click on purge

purge orphan data

  • validate

purge orphan data

This issue has been resolved in v0.9.

Basics

  • before it can automatically save to gltf, you need to configure it
  • go to file => export => gltf auto export

blender addon use

  • set the autoexport parameters in the auto export panel:

    blender addon use3

    • export folder: root folder to export models too

    • export scene settings: exports "global"/scene settings like ambient color, bloom, ao, etc

      This automatically generates additional components at the scene level

    • pick your main (level) scenes and/or library scenes (see the chapter about Blueprints and multiple Blend filles workflow below)

      • click in the scene picker & select your scene

      select scene

      • click on the "+" icon

      select scene2

      • your scene is added to the list

      select scene3

    • export blueprints: check this if you want to automatically export blueprints (default: True)

    • blueprints path: the path to export blueprints to , relative to the main export folder (default: library)

    • collection instances: select which option you want to use to deal with collection instances (aka combine mode) (both inside blueprint collections & main collections)

      • split (default, highly recomended) : the addon will 'split out' any nested collections/ blueprints & export them
      • embed: choose this option if you want to keep everything inside a gltf file (less efficient, not recomended)
      • embedExternal: this will embed ONLY collection instances whose collections have not been found inside the current blend file

      These options can also be overridden on a per collection instance basis: (if you want to split out most collection instances, but keep a few specific ones embeded inside your gltf file)

      combine override

      • simply add a custom property called _combine to the collection instance, and set it to one of the options above

      please read the dedicated section below for more information

    • Export dynamic and static objects seperatly : For MAIN scenes only (aka levels), toggle this to generate 2 files per level:

      • one with all dynamic data: collection or instances marked as dynamic (aka saveable)
      • one with all static data: anything else that is NOT marked as dynamic, the file name will have the suffix _dynamic

      Ie if you add a "Dynamic" custom property/ component to either your collection instances or your blueprint, you get a clean seperation between

      • your static level data (anything that will never change during the lifetime of your Bevy app)
      • your dynamic objects (anything that will change during the lifetime of your Bevy app, that can be saved & reloaded in save files for example)
    • export materials library: check this if you want to automatically export material libraries (default: False) please read the dedicated section below for more information

      This only works together with blueprints !

    • materials path: where to export materials to

  • and your standard gltf export parameters in the gltf panel

    blender addon use2

  • click on "apply settings"

  • now next time you save your blend file you will get an automatically exported gltf file (or more than one, depending on your settings, see below)

Blueprints

You can enable this option to automatically replace all the collection instances inside your main scene with blueprints

  • whenever you change your main scene (or your library scene , if that option is enabled), all your collection instances

    • will be replaced with empties (this will not be visible to you)
    • those empties will have additional custom properties / components : BlueprintName & SpawnHere
    • your main scene/ level will be exported to a much more trimmed down gltf file (see next point)
    • all the original collections (that you used to create the instances) will be exported as seperate gltf files into the "library" folder
  • this means you will have

    • one small main gltf file (your level/world)
    • as many gltf files as you have used collections in the main scene , in the library path you specified : for the included basic example's assets, it looks something like this:

    library

    the .blend file that they are generated from can be found here

  • the above only applies to collections that have instances in your main scene! if you want a specific collection in your library to always get exported regardless of its use, you need to add a COLLECTION (boolean) custom property called AutoExport set to true

    not at the object level ! the collection level !

    force-export

    It will get automatically exported like any of the "in-use" collections.

  • you can also get an overview of all the exported collections in the export menu

    exported collections

  • there are some workflow specificities for multi blend file workflows

Collection instances & Nested blueprints

To maximise reuse of meshes/components etc, you can also nest collections instances inside collections (as normally in Blender), but also export each nested Blueprint as a seperate blueprints.

Don't forget to choose the relevant option in the exporter settings (aka "split")

This replaces the previous "export nested blueprints" checkbox/ option

instance combine mode

  • To make things clearer:

    nested-blueprints

    • Player2 & Enemy both use the Humanoid_cactus nested collection/blueprint, so Humanoid_cactus gets exported as a Blueprint for re-use ...but
    • Humanoid_cactus is also made up of a main mesh & two instances of Hand , so Hand gets exported as a Blueprint for re-use ...but
    • Hand is also made up of a main mesh & three instances of Finger, so Finger gets exported as a Blueprint for re-use
  • The exported models in this case end up being:

    nested_blueprints2

    • Note how Player2.glb is tiny, because most of its data is actually sotred in Humanoid_cactus.glb
    • Enemy.glb is slightly bigger because that blueprints contains additional meshes
    • All the intermediary blueprints got exported automatically, and all instances have been replaced with "empties" (see explanation in the Process section ) to minimize file size
  • Compare this to the output WITHOUT the nested export option:

    nested_blueprints3

    • less blueprints as the sub collections that are not in use somewhere directly are not exported
    • Player2.glb & Enemy.glb are significantly larger

TLDR: smaller, more reuseable blueprints which can share sub-parts with other entities !

Materials

You can enable this option to automatically generate a material library file that combines all the materials in use in your blueprints.

material_library

Since each blueprint is normally a completely independant gltf file, without this option, if you have a material with a large texture for example, ALL of your blueprints using that material will embed that large texture, leading to significant bloat & memory use.

  • When this option is enabled, you get a single material library per Blender project, and a MaterialInfo component is inserted into each object using a material.
  • The correct material will then be inserted on the Bevy side (that loads any number of material libraries that you need) into the correct mesh (see the configuration options in bevy_gltf_blueprints for more information on that)
  • Only one material per object is supported at this stage, ie the last material slot's material is the one that is going to be used

material_library

TLDR: Use this option to make sure that each blueprint file does not contain a copy of the same materials

Multiple blend file workflow

If you want to use multiple blend files, use Blender's asset library etc, we got you coverred too ! There are only a few things to keep in mind

Assets/library/blueprints files

  • mark your library scenes as specified above, but do NOT specify a main scene
  • mark any collection in your scenes as "assets" (more convenient) or add the "AutoExport" custom property to the collection
  • choose "split" for the combine mode (as you want your gltf blueprints to be saved for external use)
  • do your Blender things as normal
  • anytime you save your file, it will automatically export any relevant collections/blueprints
  • (optional) activate the material library option, so you only have one set of material per asset library (recomended)

Level/world files

  • mark your main scenes as specified above, but do NOT specify a library scene
  • configure your asset libraries as you would usually do , I recomend using the "link" mode so that any changes to asset files are reflected correctly
  • drag & drop any assets from the blueprints library (as you would normally do in Blender as well)
  • choose "split" for the combine mode (as you want your gltf blueprints to be external usually & use the gltf files generated from your assets library)
  • do your Blender things as normal
  • anytime you save your file, it will automatically export your level(s)

Take a look at the relevant example for more details

Internal Process overview

This is the internal logic of the export process with blueprints (simplified)

process

ie this is an example scene...

and what actually gets exported for the main scene/world/level

all collections instances replaced with empties, and all those collections exported to gltf files as seen above

Development

  • since the code has now been split up into multiple modules, to make your life easier, I highly recomend (if you are using vscode like me) to use this excellent extension , works easilly and fast , even for the latest versions of Blender (v4.0 as of this writing)
  • this article might also help out (easy enough to get it working on linux too)

License

This tool, all its code, contents & assets is Dual-licensed under either of