chore(): updated docs, moved examples around etc

* started docs for Blender Blenvy add-on
 * started migration guide
 * got rid of a few examples
 * moved (for now, wip) all remaining examples under the Blenvy umbrella
 * updated main README
 * fixed issue with undeleted bin file when setting gltf export options for gltf/bin mode
 * updated release tools (internal_generate_release_zips)
 * moved main TODO to root of repo
 * a lot of related prep work & cleanup
This commit is contained in:
kaosat.dev 2024-07-16 01:14:41 +02:00
parent 9d30d18416
commit 3380f4c71d
150 changed files with 613 additions and 14213 deletions

View File

@ -2,10 +2,7 @@
members = [ members = [
"crates/*", "crates/*",
"examples/common*", "examples/common*",
"examples/bevy_gltf_components/*", "examples/blenvy/*",
"examples/bevy_gltf_blueprints/*",
"examples/bevy_gltf_save_load/*",
"examples/bevy_registry_export/*",
"testing/bevy_example/", "testing/bevy_example/",
] ]
resolver = "2" resolver = "2"

143
Migration_guide.md Normal file
View File

@ -0,0 +1,143 @@
# Blender add-ons
- gltf_auto_export and bevy_components have been replaced with a single add-on for simplicity
## Components:
- no more need to add your components to an empty called xxx_components, you can now directly add your components to the blueprint's collection itself
- you will need to "upgrade" your components from the previous add-on, as they are stored in a completely different way
- bonus: you can also visualize & edit your blueprint's component directly on each instance
## Multiple components with the same short name
Up until now , it was not possible to have multiple components with the same name (ie foo::bar::componentA & some::other::componentA) as all the logic was based on short names,
this is not an issue anymore
## Auto export:
- the previous stripped down gltf export settings are not part of the add-on anymore, please configure them like this:
- you need to reconfigure your auto export settings , as they have changed significantly as has their storage
## All the Bevy crates have been replaced with a single one
- the new crate doesn't even really need configuring, so
- in your cargo.toml file, replace any references to the old crates (bevy_gltf_components, bevy_gltf_blueprints, bevy_registry_export, bevy_gltf_save_load etc)
with:
```toml
# Cargo.toml
[dependencies]
bevy="0.14"
blenvy = { version = "0.1.0"}
```
and set things up in your code:
```rust no_run
use bevy::prelude::*;
use blenvy::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(BlenvyPlugin)
.run();
}
```
## Removed almost all setting for the crate
- the ONLY setting is **aabbs** // defaults to true
## Legacy mode has been removed
- less headaches when using the tools!
If you still want to manually specify components using Blender's custom properties you need to
## BlueprintName replaced with BlueprintInfo
- this is a very important change ! to avoid possible path clashes , the ```BlueprintInfo``` component contains
the actual path (with your **assets** folder) to the Blueprint, and a name (for convenience)
## SpawnHere renamed to SpawnBlueprint
changed the naming for more clarity & specificity
## Automatic assets loading
- no more need to preload gltf files, you can spawn a level & all its blueprint like this:
```rust no_run
commands.spawn((
BlueprintInfo::from_path("levels/World.gltf"),
HideUntilReady, // Only if you want to keep the level hidden until it is finished spawning
SpawnBlueprint, // See note above
GameWorldTag,
InAppRunning,
));
```
Blenvy will take care of loading all needed blueprints & other assets for you
## Blueprint instance events
- you can now use the ```BlueprintEvent``` to get notified of crucial blueprint instance events
* ```AssetsLoaded```
```rust no run
/// event fired when a blueprint instance has finished loading all of its assets & before it attempts spawning
AssetsLoaded {
entity: Entity,
blueprint_name: String,
blueprint_path: String,
// TODO: add assets list ?
}
```
* ```InstanceReady```
```rust no run
/// event fired when a blueprint instance has completely finished spawning, ie
/// - all its assests have been loaded
/// - all of its child blueprint instances are ready
/// - all the post processing is finished (aabb calculation, material replacements etc)
InstanceReady {
entity: Entity,
blueprint_name: String,
blueprint_path: String,
},
```
## BlueprintDisabled
you can now query for this component
## Track loading blueprint instances with the BlueprintSpawning component
- other than with events, you can also query for the ```BlueprintSpawning``` component to be sure an entity you are manipulating is finished with its blueprint instance spawning process
## Keep your currently spawning blueprint instances hidden until they are ready with the HideUntilReady component
If you want your blueprint instance to be hidden until it is ready, just add this component to the entity.
This can be particularly usefull in at least two use cases:
- when spawning levels
- when spawning bluprint instances that contain **lights** at runtime: in previous versions I have noticed some very unpleasant "flashing" effect when spawning blueprints with lights,
this component avoids that issue
## Hot reload
if you have configured your Bevy project to use hot reload you will automatically get hot reloading of levels & blueprints
## Improved animation handling
- sceneAnimations
- animationTriggers
## Completely restructured blueprint spawning process
Additionally
- you do not really need to worry about SystemSets anymore

View File

@ -4,11 +4,11 @@ The workflow goes as follows (once you got your Bevy code setup)
## Bevy side ## Bevy side
- create & register all your components you want to be able to set from the Blender side (this is basic Bevy, no specific work needed) - create & register all your components you want to be able to set from the Blender side (this is basic Bevy, no specific work needed)
- follow the instructions in the [bevy_registry_export](./crates/bevy_registry_export/) to generate a registry export - follow the instructions in the [blenvy](./crates/blenvy/) to generate a registry export
## Component creation ## Component creation
Setup the Blender [bevy_components](./tools/blenvy/README.md) add-on Setup the Blender [Blenvy](./tools/blenvy/README.md) blender add-on
to add & edit your components visually & reliably to add & edit your components visually & reliably
![bevy_components](./docs/bevy_components.png) ![bevy_components](./docs/bevy_components.png)

View File

@ -8,44 +8,41 @@
Crates & tools for adding components from gltf files in the [Bevy](https://bevyengine.org/) game engine. Crates & tools for adding components from gltf files in the [Bevy](https://bevyengine.org/) game engine.
It enables minimalistic [Blender](https://www.blender.org/) (gltf) centric workflow for Bevy, ie defining entites & their components It enables a [Blender](https://www.blender.org/) (gltf) centric workflow for Bevy, ie defining entites & their components
inside Blender using Blender's objects **custom properties**. inside Blender. Aka "Blender as editor for Bevy"
Aka "Blender as editor for Bevy"
It also allows you to setup 'blueprints' in Blender by using collections (the recomended way to go most of the time), or directly on single use objects . It also allows you to setup 'blueprints' in Blender by using collections (the recomended way to go most of the time), or directly on single use objects .
## Features ## Features
* Useful if you want to use Blender (or any editor allowing to export gltf with configurable gltf_extras) as your Editor * Useful if you want to use Blender as your Editor
* define Bevy components as custom properties in Blender (some visually , some using RON, though an older JSON version is also available) * define Bevy components as custom properties in Blender with an UI tool to add & edit Bevy components, automatically export gltf blueprints & more in [Blender](./tools/blenvy/README.md)
* now also with an UI tool to add & edit Bevy components, automatically export gltf blueprints & more in [Blender](./tools/blenvy/README.md) * blueprints & levels system : turn your Blender collections into [gltf Blueprints](./crates/blenvy/README.md) for reuse inside levels that are just Blender scenes
* define components in Blender Collections & override any of them in your collection instances if you want * setup & tweak components in Blender Collections & override any of them in your collection instances if you want
* ability to automatically turn your Blender collections into [gltf Blueprints](./crates/bevy_gltf_blueprints/README.md) for reuse * setup & tweak components for objects, meshes and materials as well !
* minimal setup & code, you can have something basic running fast * automatically load all assets for each blueprint (gltf files, manually added assets), with no setup required
* hot reload of your levels & blueprints
* minimal setup & code, you can have something basic running fast
* minimal dependencies: Bevy, Serde & Ron only ! * minimal dependencies: Bevy, Serde & Ron only !
* opensource * opensource
> If you were previously using the individual bevy_gltf_xxx crates & Blender add-ons please see the [migration guide](./Migration_guide.md)
## Crates ## Crates
- [bevy_gltf_components](./crates/bevy_gltf_components/) This crate allows you to define components direclty inside gltf files and instanciate/inject the components on the Bevy side. One crate to rule them all !
- [blenvy](./crates/blenvu/) This crate allows you to
* define components direclty inside gltf files and instanciate/inject the components on the Bevy side.
* export your project's Bevy registry to json, in order to be able to generate custom component UIs on the Blender side in the Blender [blenvy](./tools/blenvy/README.md) add-on
* define Blueprints/Prefabs for Bevy inside gltf files and spawn them in Bevy. With the ability to override and add components when spawning, efficient "level" loading etc
* the ability to save & load your game state in a relatively simple way, by leveraging the blueprint functionality to only save a minimal subset of dynamic data, seperating dynamic & static parts of levels etc.
OLD videos:
There is a [video tutorial/explanation](https://youtu.be/-lcScjQCA3c) if you want, or you can read the crate docs. There is a [video tutorial/explanation](https://youtu.be/-lcScjQCA3c) if you want, or you can read the crate docs.
The examples for the crate are [here](./examples/bevy_gltf_components/)
- [bevy_gltf_blueprints](./crates/bevy_gltf_blueprints/) This crate adds the ability to define Blueprints/Prefabs for Bevy inside gltf files and spawn them in Bevy. With the ability to override and add components when spawning, efficient "level" loading etc
There is a [video tutorial/explanation](https://youtu.be/CgyNtwgYwdM) for this one too, or you can read the crate docs There is a [video tutorial/explanation](https://youtu.be/CgyNtwgYwdM) for this one too, or you can read the crate docs
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 The examples for the crate are [here](./examples/blenvy/)
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
- [bevy_registry_export](./crates/bevy_registry_export/) This crate adds the ability to export your project's Bevy registry to json, in order to be able to generate custom component UIs on the Blender side in the Blender [blenvy](./tools/blenvy/README.md) add-on
## Tools ## Tools
@ -54,50 +51,37 @@ The examples for the crate are [here](./examples/bevy_gltf_save_load/)
- an all in one [Blender addon](./tools/blenvy/README.md) for the Blender side of the workflow: - an all in one [Blender addon](./tools/blenvy/README.md) for the Blender side of the workflow:
- allow easilly adding & editing Bevy components , using automatically generated UIs for each component - allow easilly adding & editing Bevy components , using automatically generated UIs for each component
- automatically exports your level/world from Blender to gltf whenever you save your Blend file - automatically exports your level/world from Blender to gltf whenever you save your Blend file
- it also supports automatical exports of collections as [Gltf blueprints](./crates/bevy_gltf_blueprints/README.md) & - automatically export your [Gltf blueprints](./crates/blenvy/README.md) & assets
Please read the [README]((./tools/blenvy/README.md)) of the add-on for installation & use instructions
## Examples ## Examples
you can find all examples, by crate as seperate crates for clearer dependencies in [here](./examples/) you can find all examples, [here](./examples/blenvy)
- [bevy_gltf_components](./examples/bevy_gltf_components/)
* [basic](./examples/bevy_gltf_components/basic/) use of ```bevy_gltf_components``` only, to spawn entities with components defined inside gltf files
- [bevy_gltf_blueprints](./examples/bevy_gltf_blueprints/)
* [basic](./examples/bevy_gltf_blueprints/basic/) more advanced example : use of ```bevy_gltf_blueprints``` to spawn a level and then populate it with entities coming from different gltf files, live (at runtime) spawning of entities etc
* [animation](./examples/bevy_gltf_blueprints/animation/) how to use and trigger animations from gltf files (a feature of ```bevy_gltf_blueprints```)
* & lots more
- [bevy_gltf_save_load](./examples/bevy_gltf_save_load/)
- [bevy_registry_export](./examples/bevy_registry_export/)
* [components](./examples/blenvy/components/) use of ```components``` only, to spawn entities with components defined inside gltf files
* [blueprints](./examples/blenvy/blueprints/) use of ```blueprints``` and ```levels``` to spawn a level and then populate it with entities coming from different gltf files, live (at runtime) spawning of entities etc
* [animation](./examples/blenvy/animation/) how to use and trigger animations from gltf files
* [save_load](./examples/blenvy/save_load/) how to save & load levels
* [demo](./examples/demo/) a full demo showcasing all features , including physics, animation
## Workflow ## Workflow
The workflow goes as follows (once you got your Bevy code setup) The workflow goes as follows (once you got your Bevy code setup)
- create & register all your components you want to be able to set from the Blender side (this is basic Bevy, no specific work needed) - create & register all your components you want to be able to set from the Blender side (this is basic Bevy, no specific work needed)
![component registration](./docs/component_registration.png) ![component registration](./docs/component_registration.png)
- then you have two options - setup & then use the Blenvy [Bevy crate](./crates/blenvy/README.md)
- add your components to objects in Blender **manually** as **custom properties** : see [here](./README-workflow-classic.md) for more details - setup & then use the Blenvy [Blender add-on](./tools/blenvy/README.md)
- add your components to objects in Blender **with a nice UI** see [here](./README-workflow-ui.md) for more details - iterate
- have fun !
- then add your components to objects in Blender **with a nice UI** see [here](./README-workflow-ui.md) for more details
## Limitations / issues ## Limitations / issues
- Some of `bevy_rapier`/physics code / ways to define colliders could perhaps be done better/visually within Blender (currently it also goes via RON)
## Future work - Some of `avian` or `bevy_rapier` /physics code / ways to define colliders could perhaps be done better/visually within Blender
- I have a number of other tools/ code helpers that I have not yet included here, because they need cleanup/ might make this example too complex
## Credits
- somebody I cannot recall helped me originally with the gltf loading tracker in the Bevy Discord, so thanks ! And if it was you, please let me know so I can give credit where credit is due :)
## Contributors ## Contributors

View File

@ -31,13 +31,13 @@ Assets:
- [x] store assets - [x] store assets
- [x] per main scene for level/world assets - [x] per main scene for level/world assets
- [x] per blueprint for blueprint in lib scene - [x] per blueprint for blueprint in lib scene
- [ ] UI: - [x] UI:
- [x] we need to display all direct assets (stored in the scene) - [x] we need to display all direct assets (stored in the scene)
- [ ] indirect assets: - [ ] indirect assets:
- QUESTION : do we want to include them in the list of assets per level ? - QUESTION : do we want to include them in the list of assets per level ?
- this would enable pre-loading ALL the assets, but is not ideal in most other cases - this would enable pre-loading ALL the assets, but is not ideal in most other cases
- so add an option ? - so add an option ?
- [ ] the assets of local blueprints - [x] the assets of local blueprints
Blueprints: Blueprints:
- [x] on save: write IN THE COLLECTION PROPERTIES - [x] on save: write IN THE COLLECTION PROPERTIES
@ -119,7 +119,7 @@ General issues:
- [x] load settings on file load - [x] load settings on file load
- [x] auto_export - [x] auto_export
- [x] components - [x] components
- [ ] add handling of errors when trying to load settings - [x] add handling of errors when trying to load settings
- [x] fix auto export workflow - [x] fix auto export workflow
@ -161,7 +161,7 @@ Blender side:
- [ ] move the rename detection to AFTER scene serialization, otherwise we could have a naming mistmatch - [ ] move the rename detection to AFTER scene serialization, otherwise we could have a naming mistmatch
- weird behaviour, perhaps find another way , ie for example replace scene name in saved previous data - weird behaviour, perhaps find another way , ie for example replace scene name in saved previous data
- is post save causing the issue ? review - is post save causing the issue ? review
- [ ] investigate weird issue of changes detected to all after a reload - [x] investigate weird issue of changes detected to all after a reload
- [x] should we write the previous _xxx data only AFTER a sucessfull export only ? - [x] should we write the previous _xxx data only AFTER a sucessfull export only ?
- [x] finer grained control of setting changes to trigger a re-export: - [x] finer grained control of setting changes to trigger a re-export:
@ -201,7 +201,7 @@ Blender side:
- [x] change scene serialization to account for collections ...sigh - [x] change scene serialization to account for collections ...sigh
- [x] also add one NOT PER scene for materials, to fix the above issue with materials - [x] also add one NOT PER scene for materials, to fix the above issue with materials
- [x] move material caching into hash material - [x] move material caching into hash material
- [ ] also remove ____dummy____.bin when export format is gltf - [x] also remove ____dummy____.bin when export format is gltf
- [ ] fix/cleanup asset information injection (also needed for hot reload) - [ ] fix/cleanup asset information injection (also needed for hot reload)
- [ ] add back per blueprint assets - [ ] add back per blueprint assets
@ -260,12 +260,12 @@ Bevy Side:
- [x] fix/upgrade blueprint level animations - [x] fix/upgrade blueprint level animations
- [x] fix/upgrade scene level animations - [x] fix/upgrade scene level animations
- [ ] rename SceneAnimations to LevelAnimations (more coherent with the rest) - [ ] rename SceneAnimations to LevelAnimations (more coherent with the rest)
- [ ] add back & cleanup animation frame triggers
- [x] move sub blueprint handling to blueprints_finalize_instances - [x] move sub blueprint handling to blueprints_finalize_instances
- [x] look into component overriding , it seems broken: - [x] look into component overriding , it seems broken:
- [x] blueprint level/ collection level components are now visible in instances in Blender - [x] blueprint level/ collection level components are now visible in instances in Blender
- [x] they do not seem to be transfered to the (instance) entity above: - [x] they do not seem to be transfered to the (instance) entity above:
could they be on the "empty node" ? could they be on the "empty node" ?
- [ ] add back & cleanup animation frame triggers
- [ ] simplify testing example: - [ ] simplify testing example:
- [x] remove use of rapier physics (or even the whole common boilerplate ?) - [x] remove use of rapier physics (or even the whole common boilerplate ?)
@ -298,6 +298,10 @@ Bevy Side:
- [x] fix animation handling - [x] fix animation handling
- [x] how to deal with animation graphs ? - [x] how to deal with animation graphs ?
- [ ] remove "Library" component & co
- [ ] BlueprintDisabled => BlueprintInstanceDisabled
- [ ] update main docs - [ ] update main docs
- [ ] rename project to Blenvy - [ ] rename project to Blenvy
- [ ] replace all references to the old 2 add-ons with those to Blenvy - [ ] replace all references to the old 2 add-ons with those to Blenvy

View File

@ -76,7 +76,7 @@ pub struct BlueprintDisabled;
#[derive(Event, Debug)] #[derive(Event, Debug)]
pub enum BlueprintEvent { pub enum BlueprintEvent {
/// event fired when a blueprint has finished loading all of its assets & before it attempts spawning /// event fired when a blueprint instance has finished loading all of its assets & before it attempts spawning
AssetsLoaded { AssetsLoaded {
entity: Entity, entity: Entity,
blueprint_name: String, blueprint_name: String,
@ -84,7 +84,10 @@ pub enum BlueprintEvent {
// TODO: add assets list ? // TODO: add assets list ?
}, },
/// /// event fired when a blueprint instance has completely finished spawning, ie
/// - all its assests have been loaded
/// - all of its child blueprint instances are ready
/// - all the post processing is finished (aabb calculation, material replacements etc)
InstanceReady { InstanceReady {
entity: Entity, entity: Entity,
blueprint_name: String, blueprint_name: String,

View File

@ -1,10 +0,0 @@
[package]
name = "bevy_gltf_components_basic_example"
version = "0.3.0"
edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_components = { path = "../../../crates/bevy_gltf_components" }
bevy_gltf_worlflow_examples_common_rapier = { path = "../../common_rapier" }

View File

@ -1,64 +0,0 @@
# Basic bevy_gltf_components + wasm demo
## Running this example (non-wasm)
```
cargo run --features bevy/dynamic_linking
```
## Wasm
### Setup
as per the bevy documentation:
```shell
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli
```
### Building this example
navigate to the current folder , and then
```shell
cargo build --release --target wasm32-unknown-unknown --target-dir ./target
wasm-bindgen --out-name wasm_example \
--out-dir ./target/wasm \
--target web target/wasm32-unknown-unknown/release/bevy_gltf_components_basic_wasm_example.wasm
```
### Running this example
run a web server in the current folder, and navigate to the page, you should see the example in your browser
## Additional notes
* You usually define either the Components directly or use ```Proxy components``` that get replaced in Bevy systems with the actual Components that you want (usually when for some reason, ie external crates with unregistered components etc) you cannot use the components directly.
Included are the following modules / tools
* [```process_gltf```](./src/process_gltfs.rs) the most important module: this is the one extracting ```component``` information from the gltf files
* [```insert_dependant_component```](./src/core/relationships/relationships_insert_dependant_components.rs) a small utility to automatically inject
components that are dependant on an other component
for example an Entity with a Player component should also always have a ShouldBeWithPlayer component
you get a warning if you use this though, as I consider this to be stop-gap solution (usually you should have either a bundle, or directly define all needed components)
* [```camera```](./src/core/camera/) an example post process/replace proxies plugin, for Camera that also adds CameraTracking functions (to enable a camera to follow an object, ie the player)
* [```lighting```](./src/core/lighting/) an other example post process/replace proxies plugin for lighting, that toggles shadows, lighting config, etc so that things look closer to the original Blender data
* [```physics```](./src/core/physics/) an other example post process/replace proxies plugin for physics, that add [Rapier](https://rapier.rs/docs/user_guides/bevy_plugin/getting_started_bevy) Colliders, Rigidbodies etc . Most of these do not need proxies these days, as the most Rapier components are in the Registry & can be used directly
Feel free to use as you want, rip it appart, use any/all parts that you need !
This tooling and workflow has enabled me to go from a blank Bevy + Blender setup to a working barebones level in very little time (30 minutes or so ?) !
You can then add your own components & systems for your own gameplay very easilly
## Information
- the Bevy/ Rust code is [here](./src/main.rs)
- the Blender file is [here](./assets/basic.blend)
- I added [bevy_editor_pls](https://github.com/jakobhellermann/bevy_editor_pls) as a dependency for convenience so you can inspect your level/components

View File

@ -1,27 +0,0 @@
<html>
<head>
<meta charset="UTF-8" />
<style>
body {
background: linear-gradient(
135deg,
white 0%,
white 49%,
black 49%,
black 51%,
white 51%,
white 100%
);
background-repeat: repeat;
background-size: 20px 20px;
}
canvas {
background-color: white;
}
</style>
</head>
<script type="module">
import init from './target/wasm/wasm_example.js'
init()
</script>
</html>

View File

@ -1,74 +0,0 @@
use bevy::{gltf::Gltf, prelude::*};
use bevy_gltf_components::ComponentsFromGltfPlugin;
use bevy_gltf_worlflow_examples_common_rapier::CorePlugin;
mod test_components;
use test_components::*;
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
/// helper marker component
pub struct LoadedMarker;
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
enum AppState {
#[default]
Loading,
Running,
}
#[derive(Resource)]
pub struct MyGltf(pub Handle<Gltf>);
// we preload the data here, but this is for DEMO PURPOSES ONLY !! Please use https://github.com/NiklasEi/bevy_asset_loader or a similar logic to seperate loading / pre processing
// of assets from the spawning
// MyGltf is also just for the same purpose, you do not need it in a real scenario
// the states here are also for demo purposes only,
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.insert_resource(MyGltf(asset_server.load("models/Level1.glb")));
}
fn spawn_level(
mut commands: Commands,
scene_markers: Query<&LoadedMarker>,
mut asset_event_reader: EventReader<AssetEvent<Gltf>>,
mut next_state: ResMut<NextState<AppState>>,
models: Res<Assets<bevy::gltf::Gltf>>,
) {
if let Some(asset_event) = asset_event_reader.read().next() {
if let AssetEvent::Added { id } = asset_event {
info!("GLTF loaded/ added {:?}", asset_event);
let my_gltf = models.get(*id).unwrap();
if scene_markers.is_empty() {
info!("spawning scene");
commands.spawn((
SceneBundle {
scene: my_gltf.scenes[0].clone(),
..default()
},
LoadedMarker,
Name::new("Level1"),
));
next_state.set(AppState::Running);
}
}
}
}
fn main() {
App::new()
.add_plugins((
DefaultPlugins.set(AssetPlugin::default()),
// editor
// EditorPlugin::default(),
// physics
// our custom plugins
ComponentsFromGltfPlugin::default(),
CorePlugin, // reusable plugins
ComponentsTestPlugin, // Showcases different type of components /structs
))
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, (spawn_level.run_if(in_state(AppState::Loading)),))
.run();
}

View File

@ -1,80 +0,0 @@
use bevy::prelude::*;
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct UnitTest;
#[derive(Component, Reflect, Default, Debug, Deref, DerefMut)]
#[reflect(Component)]
struct TupleTestF32(f32);
#[derive(Component, Reflect, Default, Debug, Deref, DerefMut)]
#[reflect(Component)]
struct TupleTestU64(u64);
#[derive(Component, Reflect, Default, Debug, Deref, DerefMut)]
#[reflect(Component)]
pub struct TupleTestStr(String);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleTest2(f32, u64, String);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleTestBool(bool);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleVec2(Vec2);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleVec3(Vec3);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleVec(Vec<String>);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleTestColor(Color);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct BasicTest {
a: f32,
b: u64,
c: String,
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub enum EnumTest {
Metal,
Wood,
Rock,
Cloth,
Squishy,
#[default]
None,
}
pub struct ComponentsTestPlugin;
impl Plugin for ComponentsTestPlugin {
fn build(&self, app: &mut App) {
app.register_type::<BasicTest>()
.register_type::<UnitTest>()
.register_type::<TupleTestF32>()
.register_type::<TupleTestU64>()
.register_type::<TupleTestStr>()
.register_type::<TupleTestBool>()
.register_type::<TupleTest2>()
.register_type::<TupleVec2>()
.register_type::<TupleVec3>()
.register_type::<EnumTest>()
.register_type::<TupleTestColor>()
.register_type::<TupleVec>()
.register_type::<Vec<String>>();
}
}

View File

@ -1,13 +0,0 @@
[package]
name = "bevy_bevy_registry_export_basic_example"
version = "0.3.0"
edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_blueprints = { path = "../../../crates/bevy_gltf_blueprints" }
bevy_registry_export = { path = "../../../crates/bevy_registry_export" }
bevy_gltf_worlflow_examples_common_rapier = { path = "../../common_rapier" }
bevy_rapier3d = { version = "0.25.0", features = ["serde-serialize", "debug-render-3d", "enhanced-determinism"] }
rand = "0.8.5"

View File

@ -1,15 +0,0 @@
# Bevy registry export example/demo
This example showcases
* the use of the bevy_registry_export crate to extract all components & types information into a json file.
* That file is then used by the [Blender addon](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/tools/blenvy) to create Uis for each component,
to be able to add & edit Bevy components easilly in Blender !
## Running this example
```
cargo run --features bevy/dynamic_linking
```
Running the example also regenerates the registry.json file.

View File

@ -1,6 +0,0 @@
({
"world":File (path: "models/World.glb"),
"models": Folder (
path: "models/library",
),
})

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +0,0 @@
use bevy::prelude::*;
use bevy_gltf_blueprints::*;
use bevy_registry_export::*;
pub struct CorePlugin;
impl Plugin for CorePlugin {
fn build(&self, app: &mut App) {
app.add_plugins((
ExportRegistryPlugin {
save_path: "registry.json".into(),
..Default::default()
},
BlueprintsPlugin {
aabbs: true,
..Default::default()
},
));
}
}

View File

@ -1,83 +0,0 @@
use bevy::prelude::*;
use bevy_gltf_blueprints::{BluePrintBundle, BlueprintName, GameWorldTag};
use bevy_gltf_worlflow_examples_common_rapier::{assets::GameAssets, GameState, InAppRunning};
use bevy_rapier3d::prelude::Velocity;
use rand::Rng;
pub fn setup_game(
mut commands: Commands,
game_assets: Res<GameAssets>,
models: Res<Assets<bevy::gltf::Gltf>>,
mut next_game_state: ResMut<NextState<GameState>>,
) {
commands.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 0.2,
});
// here we actually spawn our game world/level
commands.spawn((
SceneBundle {
// note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene
scene: models
.get(game_assets.world.clone().unwrap().id())
.expect("main level should have been loaded")
.scenes[0]
.clone(),
..default()
},
bevy::prelude::Name::from("world"),
GameWorldTag,
InAppRunning,
));
next_game_state.set(GameState::InGame)
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct UnregisteredComponent;
pub fn spawn_test(
keycode: Res<ButtonInput<KeyCode>>,
mut commands: Commands,
mut game_world: Query<(Entity, &Children), With<GameWorldTag>>,
) {
if keycode.just_pressed(KeyCode::KeyT) {
let world = game_world.single_mut();
let world = world.1[0];
let mut rng = rand::thread_rng();
let range = 5.5;
let x: f32 = rng.gen_range(-range..range);
let y: f32 = rng.gen_range(-range..range);
let mut rng = rand::thread_rng();
let range = 0.8;
let vel_x: f32 = rng.gen_range(-range..range);
let vel_y: f32 = rng.gen_range(2.0..2.5);
let vel_z: f32 = rng.gen_range(-range..range);
let name_index: u64 = rng.gen();
let new_entity = commands
.spawn((
BluePrintBundle {
blueprint: BlueprintName("Health_Pickup".to_string()),
..Default::default()
},
bevy::prelude::Name::from(format!("test{}", name_index)),
// BlueprintName("Health_Pickup".to_string()),
// SpawnHere,
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
Velocity {
linvel: Vec3::new(vel_x, vel_y, vel_z),
angvel: Vec3::new(0.0, 0.0, 0.0),
},
))
.id();
commands.entity(world).add_child(new_entity);
}
}

View File

@ -1,107 +0,0 @@
use bevy::prelude::*;
use bevy_gltf_worlflow_examples_common_rapier::{AppState, InMainMenu};
pub fn setup_main_menu(mut commands: Commands) {
commands.spawn((
Camera2dBundle {
camera: Camera {
order: 102, // needed because of this: https://github.com/jakobhellermann/bevy_editor_pls/blob/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs#L213C9-L213C28
..default()
},
..Default::default()
},
InMainMenu,
));
commands.spawn((
TextBundle::from_section(
"SOME GAME TITLE !!",
TextStyle {
//font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 18.0,
color: Color::WHITE,
..Default::default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(100.0),
left: Val::Px(200.0),
..default()
}),
InMainMenu,
));
commands.spawn((
TextBundle::from_section(
"New Game (press Enter to start, press T once the game is started for demo spawning)",
TextStyle {
//font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 18.0,
color: Color::WHITE,
..Default::default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(200.0),
left: Val::Px(200.0),
..default()
}),
InMainMenu,
));
/*
commands.spawn((
TextBundle::from_section(
"Load Game",
TextStyle {
//font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 18.0,
color: Color::WHITE,
..Default::default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(250.0),
left: Val::Px(200.0),
..default()
}),
InMainMenu
));
commands.spawn((
TextBundle::from_section(
"Exit Game",
TextStyle {
//font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 18.0,
color: Color::WHITE,
..Default::default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(300.0),
left: Val::Px(200.0),
..default()
}),
InMainMenu
));*/
}
pub fn teardown_main_menu(bla: Query<Entity, With<InMainMenu>>, mut commands: Commands) {
for bli in bla.iter() {
commands.entity(bli).despawn_recursive();
}
}
pub fn main_menu(
keycode: Res<ButtonInput<KeyCode>>,
mut next_app_state: ResMut<NextState<AppState>>,
) {
if keycode.just_pressed(KeyCode::Enter) {
next_app_state.set(AppState::AppLoading);
}
}

View File

@ -1,19 +0,0 @@
pub mod in_game;
pub use in_game::*;
pub mod in_main_menu;
pub use in_main_menu::*;
use bevy::prelude::*;
use bevy_gltf_worlflow_examples_common_rapier::{AppState, GameState};
pub struct GamePlugin;
impl Plugin for GamePlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, (spawn_test).run_if(in_state(GameState::InGame)))
.add_systems(OnEnter(AppState::MenuRunning), setup_main_menu)
.add_systems(OnExit(AppState::MenuRunning), teardown_main_menu)
.add_systems(Update, main_menu.run_if(in_state(AppState::MenuRunning)))
.add_systems(OnEnter(AppState::AppRunning), setup_game);
}
}

View File

@ -1,24 +0,0 @@
use bevy::prelude::*;
use bevy_gltf_worlflow_examples_common_rapier::CommonPlugin;
mod core;
use crate::core::*;
mod game;
use game::*;
mod test_components;
use test_components::*;
fn main() {
App::new()
.add_plugins((
DefaultPlugins.set(AssetPlugin::default()),
// our custom plugins
CommonPlugin,
CorePlugin, // reusable plugins
GamePlugin, // specific to our game
ComponentsTestPlugin, // Showcases different type of components /structs
))
.run();
}

View File

@ -1,136 +0,0 @@
use bevy::prelude::*;
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct UnitTest;
#[derive(Component, Reflect, Default, Debug, Deref, DerefMut)]
#[reflect(Component)]
struct TupleTestF32(f32);
#[derive(Component, Reflect, Default, Debug, Deref, DerefMut)]
#[reflect(Component)]
struct TupleTestU64(u64);
#[derive(Component, Reflect, Default, Debug, Deref, DerefMut)]
#[reflect(Component)]
pub struct TupleTestStr(String);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleTest2(f32, u64, String);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleTestBool(bool);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleVec2(Vec2);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleVec3(Vec3);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleVec(Vec<String>);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleVecF32F32(Vec<(f32, f32)>);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct TupleTestColor(Color);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct BasicTest {
a: f32,
b: u64,
c: String,
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub enum EnumTest {
Metal,
Wood,
Rock,
Cloth,
Squishy,
#[default]
None,
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct NestingTestLevel2 {
text: String,
enable: bool,
enum_inner: EnumTest,
color: TupleTestColor,
toggle: TupleTestBool,
basic: BasicTest,
pub nested: NestingTestLevel3,
colors_list: VecOfColors,
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct NestingTestLevel3 {
vec: TupleVec3,
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct NestedTupleStuff(f32, u64, NestingTestLevel2);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub enum EnumComplex {
Float(f32),
Wood(String),
Vec(BasicTest),
SomeThing,
#[default]
None,
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct VecOfVec3s2(Vec<TupleVec3>);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct VecOfColors(Vec<Color>);
pub struct ComponentsTestPlugin;
impl Plugin for ComponentsTestPlugin {
fn build(&self, app: &mut App) {
app.register_type::<BasicTest>()
.register_type::<UnitTest>()
.register_type::<TupleTestF32>()
.register_type::<TupleTestU64>()
.register_type::<TupleTestStr>()
.register_type::<TupleTestBool>()
.register_type::<TupleTest2>()
.register_type::<TupleVec2>()
.register_type::<TupleVec3>()
.register_type::<EnumTest>()
.register_type::<TupleTestColor>()
.register_type::<TupleVec>()
.register_type::<Vec<String>>()
.register_type::<NestingTestLevel2>()
.register_type::<NestingTestLevel3>()
.register_type::<NestedTupleStuff>()
.register_type::<EnumComplex>()
.register_type::<VecOfVec3s2>()
.register_type::<TupleVecF32F32>()
.register_type::<(f32, f32)>()
.register_type::<Vec<(f32, f32)>>()
.register_type::<Vec<TupleVec3>>()
.register_type::<Vec<Color>>()
.register_type::<VecOfColors>();
}
}

Some files were not shown because too many files have changed in this diff Show More