Skip to content

Commit

Permalink
feat(Save & load): new crate bevy_gltf_save_load + lots of upgrades &…
Browse files Browse the repository at this point in the history
… improvements (#95)

* feat(bevy_gltf_save_load): saving & loading implemented
   * created new crate for save & load features, uses & filters out blueprints for efficient loading
   * saving & loading, even with dynamically spawned nested hierarchies works 
   * component filter , resource filter & save path root are configurable
   * for saving: added removal & cleanup logic for children component with children
  that have been filtered out: ie no more invalid children getting stored in the save files !
   * added sending of event once saving is done

* feat(examples/save-load): example for the new crate
   * loading level static & dynamic data as blueprints
   * added a bit of ui when entering saving & loading states & cleanup when exiting

* feat(bevy_gltf_blueprints): significant rewrite of how the crate works
     * simplified spawning process, no more spawning children containing blueprints etc
     * simplified post process : instead of copying original entity  into blueprint root
      we now copy blueprint root data (components & children) into the original entity ! fixes #96 
     * much simpler code wise
     * solves issue with needing to register components that we only use on the bevy side (not gltf)
    since we are not copying the bevy data into the blueprints data
     * added **copyComponents** helper to copy components from one entity to another, excluding existing
     components on the target entity, & some bells & whistles
     * **Name** is now optional when spawning a blueprint: closes #97 
     * **Transform** is now optional when spawning a blueprint: closes #98 
     * removed transform from bundle (BREAKING change)
     * added (optional)  **NoInBlueprint** component to have finer control over whether to inject the **InBlueprint** component inside spawned blueprint entities
     * added (optional) **Library**  component, so we can override library path when we want
     * added (optional) **AddToGameWorld** component for convenience   to automatically add entities to the game world, if there is one

* chore(bevy_gltf_components): removed verbose output, cleaned it up a bit

* feat(tools/auto_export): added option to split out "dynamic" objects in main scenes
   * ie if a collection instance (or its original collection) has a "dynamic" (aka mutable, saveable etc)
     flag it can get exported to a seperate gltf file (essentially acting like an "initial save")
   * the rest of the levels (the "static" data) is exported without the dynamic objects and
     can be reused with save files !
  • Loading branch information
kaosat-dev committed Jan 10, 2024
1 parent 42c1c71 commit 5429bf4
Show file tree
Hide file tree
Showing 109 changed files with 5,815 additions and 2,470 deletions.
65 changes: 49 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"crates/bevy_gltf_components",
"crates/bevy_gltf_blueprints",
"crates/bevy_gltf_save_load",
"examples/bevy_gltf_components/basic/",
"examples/bevy_gltf_components/basic_wasm/",
"examples/bevy_gltf_blueprints/basic/",
Expand All @@ -12,7 +13,9 @@ members = [
"examples/bevy_gltf_blueprints/animation/",
"examples/bevy_gltf_blueprints/multiple_levels/",
"examples/bevy_gltf_blueprints/multiple_levels_multiple_blendfiles",
"examples/bevy_gltf_blueprints/materials/"
"examples/bevy_gltf_blueprints/materials/",
"examples/bevy_gltf_save_load/basic/",

]
resolver = "2"

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ There is a [video tutorial/explanation](https://youtu.be/CgyNtwgYwdM) for this o
The examples for the crate are [here](./examples/bevy_gltf_blueprints/)
> Note: this is the recomended crate to use and uses ```bevy_gltf_components``` under the hood
- [bevy_gltf_save_load](./crates/bevy_gltf_save_load/) This crate adds the ability to save & load your game state in a relatively simple way, by leveraging the blueprint functionality of
bevy_gltf_blueprints to only save a minimal subset of dynamic data, seperating dynamic & static parts of levels etc.
The examples for the crate are [here](./examples/bevy_gltf_save_load/)
> Note: this uses ```bevy_gltf_blueprints``` under the hood
## Tools

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gltf_blueprints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_gltf_blueprints"
version = "0.5.1"
version = "0.6.0"
authors = ["Mark 'kaosat-dev' Moissette"]
description = "Adds the ability to define Blueprints/Prefabs for [Bevy](https://bevyengine.org/) inside gltf files and spawn them in Bevy."
homepage = "https://github.com/kaosat-dev/Blender_bevy_components_workflow"
Expand Down
78 changes: 59 additions & 19 deletions crates/bevy_gltf_blueprints/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Here's a minimal usage example:
# Cargo.toml
[dependencies]
bevy="0.12"
bevy_gltf_blueprints = { version = "0.5"}
bevy_gltf_blueprints = { version = "0.6"}

```

Expand Down Expand Up @@ -64,7 +64,7 @@ fn spawn_blueprint(
Add the following to your `[dependencies]` section in `Cargo.toml`:

```toml
bevy_gltf_blueprints = "0.5"
bevy_gltf_blueprints = "0.6"
```

Or use `cargo add`:
Expand Down Expand Up @@ -97,8 +97,7 @@ use bevy_gltf_blueprints::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(
.add_plugins((
BlueprintsPlugin{
library_folder: "advanced/models/library".into() // replace this with your blueprints library path , relative to the assets folder,
format: GltfFormat::GLB,// optional, use either format: GltfFormat::GLB, or format: GltfFormat::GLTF, or ..Default::default() if you want to keep the default .glb extension, this sets what extensions/ gltf files will be looked for by the library
Expand All @@ -107,7 +106,7 @@ fn main() {
material_library_folder: "materials".into() //defaults to "materials" the folder to look for for the material files
..Default::default()
}
)
))
.run();
}

Expand All @@ -120,7 +119,8 @@ You can spawn entities from blueprints like this:
commands.spawn((
BlueprintName("Health_Pickup".to_string()), // mandatory !!
SpawnHere, // mandatory !!
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)), // VERY important !!

TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)), // optional
// any other component you want to insert
))

Expand Down Expand Up @@ -168,11 +168,51 @@ commands.spawn((
There is also a bundle for convenience , which just has
* a ```BlueprintName``` component
* a ```SpawnHere``` component
* a ```TransformBundle``` sub-bundle (so we know where to spawn)

[```BluePrintBundle```](./src/lib.rs#22)


## Additional information

- When a blueprint is spawned, all its children entities (and nested children etc) also have an ```InBlueprint``` component that gets insert
- In cases where that is undesirable, you can add a ```NoInBlueprint``` component on the entity you spawn the blueprint with, and the components above will not be add
- if you want to overwrite the **path** where this crate looks for blueprints (gltf files) , you can add a ```Library``` component , and that will be used instead of the default path
ie :

```rust no_run
commands
.spawn((
Name::from("test"),
BluePrintBundle {
blueprint: BlueprintName("TestBlueprint".to_string()),
..Default::default()
},
Library("models".into()) // now the path to the blueprint above will be /assets/models/TestBlueprint.glb
))
```
- this crate also provides a special optional ```GameWorldTag``` component: this is useful when you want to keep all your spawned entities inside a root entity

You can use it in your queries to add your entities as children of this "world"
This way all your levels, your dynamic entities etc, are kept seperated from UI nodes & other entities that are not relevant to the game world

> Note: you should only have a SINGLE entity tagged with that component !
```rust no_run
commands.spawn((
SceneBundle {
scene: models
.get(game_assets.world.id())
.expect("main level should have been loaded")
.scenes[0]
.clone(),
..default()
},
bevy::prelude::Name::from("world"),
GameWorldTag, // here it is
));
```


## SystemSet

the ordering of systems is very important !
Expand Down Expand Up @@ -239,9 +279,9 @@ pub fn animation_change_on_proximity_foxes(
}
```

see https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/animation for how to set it up correctly
see https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/animation for how to set it up correctly

particularly from https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/animation/game/in_game.rs#86
particularly from https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/animation/game/in_game.rs#86
onward


Expand All @@ -263,27 +303,27 @@ material_library_folder: "materials".into() //defaults to "materials" the folder
```bevy_gltf_blueprints``` currently does NOT take care of loading those at runtime


see https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/materials for how to set it up correctly
see https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/materials for how to set it up correctly

Generating optimised blueprints and material libraries can be automated using the latests version of the [Blender plugin](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/tools/gltf_auto_export)

## Examples

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/basic
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/basic_xpbd_physics
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic_xpbd_physics

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/basic_scene_components
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic_scene_components

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/animation
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/animation

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/multiple_levels
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/multiple_levels

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/materials
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/materials

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/nested_blueprints
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/nested_blueprints

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/multiple_levels_multiple_blendfiles
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/multiple_levels_multiple_blendfiles


## Compatible Bevy versions
Expand All @@ -293,7 +333,7 @@ The main branch is compatible with the latest Bevy release, while the branch `be
Compatibility of `bevy_gltf_blueprints` versions:
| `bevy_gltf_blueprints` | `bevy` |
| :-- | :-- |
| `0.3 - 0.5` | `0.12` |
| `0.3 - 0.6` | `0.12` |
| `0.1 - 0.2` | `0.11` |
| branch `main` | `0.12` |
| branch `bevy_main` | `main` |
Expand Down

0 comments on commit 5429bf4

Please sign in to comment.