Add relations example

This commit is contained in:
DasLixou 2024-08-20 18:14:35 +02:00
parent 7f4c8d34f3
commit 2bc47ad624
9 changed files with 14147 additions and 0 deletions

View File

@ -0,0 +1,9 @@
[package]
name = "blenvy_relations_example"
version = "0.0.1"
edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy = { version = "0.14", features = ["dynamic_linking"] }
blenvy = { path = "../../crates/blenvy" }

View File

@ -0,0 +1,41 @@
# Basic relations example/demo
This example showcases how to refer to another `Entity` inside Bevy components added to objects/ blueprints/ meshes and materials extracted from the gltf files
## Running this example
```
cargo run --features bevy/dynamic_linking
```
## Wasm instructions
### 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_blueprints_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.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,5 @@
(
assets:
[
]
)

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
use bevy::prelude::*;
use blenvy::{BlenvyPlugin, BlueprintInfo, GameWorldTag, HideUntilReady, SpawnBlueprint};
#[derive(Component, Reflect)]
#[reflect(Component)]
pub struct TupleRelations(Entity);
#[derive(Component, Reflect)]
#[reflect(Component)]
pub struct BigRelations {
main: Entity,
other: Vec<Entity>,
}
fn main() {
App::new()
.add_plugins((
DefaultPlugins.set(AssetPlugin::default()),
BlenvyPlugin::default(),
))
.register_type::<TupleRelations>()
.register_type::<BigRelations>()
.add_systems(Startup, setup_game)
.run();
}
fn setup_game(mut commands: Commands) {
// here we actually spawn our game world/level
commands.spawn((
BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info...
SpawnBlueprint, // and spawnblueprint to tell blenvy to spawn the blueprint now
HideUntilReady, // only reveal the level once it is ready
GameWorldTag,
));
}