more example cleanup and polish
This commit is contained in:
parent
471639841b
commit
bb111cbafa
@ -12,7 +12,6 @@ profiler = ["bevy_ecs/profiler", "bevy_diagnostic/profiler"]
|
|||||||
members = [
|
members = [
|
||||||
"crates/*",
|
"crates/*",
|
||||||
"crates/bevy_ecs/hecs",
|
"crates/bevy_ecs/hecs",
|
||||||
"examples/app/dynamic_plugin_loading/example_plugin"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -88,10 +87,6 @@ path = "examples/3d/texture.rs"
|
|||||||
name = "z_sort_debug"
|
name = "z_sort_debug"
|
||||||
path = "examples/3d/z_sort_debug.rs"
|
path = "examples/3d/z_sort_debug.rs"
|
||||||
|
|
||||||
[[example]]
|
|
||||||
name = "dynamic_plugin_loading"
|
|
||||||
path = "examples/app/dynamic_plugin_loading/main.rs"
|
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "empty_defaults"
|
name = "empty_defaults"
|
||||||
path = "examples/app/empty_defaults.rs"
|
path = "examples/app/empty_defaults.rs"
|
||||||
|
@ -20,3 +20,21 @@ impl Default for StandardMaterial {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Color> for StandardMaterial {
|
||||||
|
fn from(color: Color) -> Self {
|
||||||
|
StandardMaterial {
|
||||||
|
albedo: color,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Handle<Texture>> for StandardMaterial {
|
||||||
|
fn from(texture: Handle<Texture>) -> Self {
|
||||||
|
StandardMaterial {
|
||||||
|
albedo_texture: Some(texture),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,6 +9,31 @@ impl Rotation {
|
|||||||
pub fn identity() -> Self {
|
pub fn identity() -> Self {
|
||||||
Self(Quat::identity())
|
Self(Quat::identity())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn from_rotation_yxz(yaw: f32, pitch: f32, roll: f32) -> Self {
|
||||||
|
Self(Quat::from_rotation_ypr(yaw, pitch, roll))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn from_rotation_xyz(x: f32, y: f32, z: f32) -> Self {
|
||||||
|
Self(Quat::from_rotation_ypr(y, x, z))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn from_rotation_x(x: f32) -> Self {
|
||||||
|
Self(Quat::from_rotation_x(x))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn from_rotation_y(y: f32) -> Self {
|
||||||
|
Self(Quat::from_rotation_y(y))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn from_rotation_z(z: f32) -> Self {
|
||||||
|
Self(Quat::from_rotation_z(z))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Rotation {
|
impl Default for Rotation {
|
||||||
|
@ -14,32 +14,18 @@ fn setup(
|
|||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
// create a cube and a plane mesh
|
|
||||||
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
|
|
||||||
let plane_handle = meshes.add(Mesh::from(shape::Plane { size: 10.0 }));
|
|
||||||
|
|
||||||
// create materials for our cube and plane
|
|
||||||
let cube_material_handle = materials.add(StandardMaterial {
|
|
||||||
albedo: Color::rgb(0.5, 0.4, 0.3),
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
let plane_material_handle = materials.add(StandardMaterial {
|
|
||||||
albedo: Color::rgb(0.1, 0.2, 0.1),
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
|
|
||||||
// add entities to the world
|
// add entities to the world
|
||||||
commands
|
commands
|
||||||
// plane
|
// plane
|
||||||
.spawn(PbrComponents {
|
.spawn(PbrComponents {
|
||||||
mesh: plane_handle,
|
mesh: meshes.add(Mesh::from(shape::Plane { size: 10.0 })),
|
||||||
material: plane_material_handle,
|
material: materials.add(Color::rgb(0.1, 0.2, 0.1).into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// cube
|
// cube
|
||||||
.spawn(PbrComponents {
|
.spawn(PbrComponents {
|
||||||
mesh: cube_handle,
|
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
||||||
material: cube_material_handle,
|
material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()),
|
||||||
translation: Translation::new(0.0, 1.0, 0.0),
|
translation: Translation::new(0.0, 1.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
@ -13,23 +13,14 @@ fn setup(
|
|||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
// load the mesh
|
|
||||||
let mesh_handle = asset_server
|
|
||||||
.load("assets/models/monkey/Monkey.gltf")
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// create a material for the mesh
|
|
||||||
let material_handle = materials.add(StandardMaterial {
|
|
||||||
albedo: Color::rgb(0.5, 0.4, 0.3),
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
|
|
||||||
// add entities to the world
|
// add entities to the world
|
||||||
commands
|
commands
|
||||||
// mesh
|
// mesh
|
||||||
.spawn(PbrComponents {
|
.spawn(PbrComponents {
|
||||||
mesh: mesh_handle,
|
// load the mesh
|
||||||
material: material_handle,
|
mesh: asset_server.load("assets/models/monkey/Monkey.gltf").unwrap(),
|
||||||
|
// create a material for the mesh
|
||||||
|
material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// light
|
// light
|
||||||
|
@ -22,10 +22,7 @@ fn setup(
|
|||||||
// cube
|
// cube
|
||||||
.spawn(PbrComponents {
|
.spawn(PbrComponents {
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()),
|
||||||
albedo: Color::rgb(0.5, 0.4, 0.3),
|
|
||||||
..Default::default()
|
|
||||||
}),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// light
|
// light
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
struct Rotator;
|
/// This example illustrates how to create parent->child relationships between entities how parent transforms
|
||||||
|
/// are propagated to their descendants
|
||||||
fn main() {
|
fn main() {
|
||||||
App::build()
|
App::build()
|
||||||
.add_resource(Msaa { samples: 4 })
|
.add_resource(Msaa { samples: 4 })
|
||||||
@ -11,6 +11,9 @@ fn main() {
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// this component indicates what entities should rotate
|
||||||
|
struct Rotator;
|
||||||
|
|
||||||
/// rotates the parent, which will result in the child also rotating
|
/// rotates the parent, which will result in the child also rotating
|
||||||
fn rotator_system(time: Res<Time>, mut query: Query<(&Rotator, &mut Rotation)>) {
|
fn rotator_system(time: Res<Time>, mut query: Query<(&Rotator, &mut Rotation)>) {
|
||||||
for (_rotator, mut rotation) in &mut query.iter() {
|
for (_rotator, mut rotation) in &mut query.iter() {
|
||||||
|
@ -36,7 +36,6 @@ fn setup(
|
|||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
|
|
||||||
commands
|
commands
|
||||||
// light
|
// light
|
||||||
.spawn(LightComponents {
|
.spawn(LightComponents {
|
||||||
@ -54,6 +53,7 @@ fn setup(
|
|||||||
});
|
});
|
||||||
|
|
||||||
let mut rng = StdRng::from_entropy();
|
let mut rng = StdRng::from_entropy();
|
||||||
|
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
|
||||||
for _ in 0..10000 {
|
for _ in 0..10000 {
|
||||||
commands.spawn(PbrComponents {
|
commands.spawn(PbrComponents {
|
||||||
mesh: cube_handle,
|
mesh: cube_handle,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
/// This example shows various ways to configure texture materials in 3D
|
||||||
fn main() {
|
fn main() {
|
||||||
App::build()
|
App::build()
|
||||||
.add_default_plugins()
|
.add_default_plugins()
|
||||||
@ -15,7 +16,7 @@ fn setup(
|
|||||||
mut textures: ResMut<Assets<Texture>>,
|
mut textures: ResMut<Assets<Texture>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
// load a texture
|
// load a texture and retrieve its aspect ratio
|
||||||
let texture_handle = asset_server
|
let texture_handle = asset_server
|
||||||
.load_sync(&mut textures, "assets/branding/bevy_logo_dark_big.png")
|
.load_sync(&mut textures, "assets/branding/bevy_logo_dark_big.png")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
/target
|
|
||||||
**/*.rs.bk
|
|
||||||
Cargo.lock
|
|
@ -1,11 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "example_plugin"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Carter Anderson <mcanders1@gmail.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
bevy = { path = "../../../../../bevy" }
|
|
@ -1,44 +0,0 @@
|
|||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
#[derive(DynamicAppPlugin)]
|
|
||||||
pub struct ExamplePlugin;
|
|
||||||
|
|
||||||
impl AppPlugin for ExamplePlugin {
|
|
||||||
fn build(&self, app: &mut AppBuilder) {
|
|
||||||
app.add_startup_system(setup.system());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn setup(
|
|
||||||
mut commands: Commands,
|
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
||||||
) {
|
|
||||||
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
|
|
||||||
let cube_material_handle = materials.add(StandardMaterial {
|
|
||||||
albedo: Color::rgb(0.5, 0.4, 0.3),
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
|
|
||||||
commands
|
|
||||||
// cube
|
|
||||||
.spawn(PbrComponents {
|
|
||||||
mesh: cube_handle,
|
|
||||||
material: cube_material_handle,
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
// light
|
|
||||||
.spawn(LightComponents {
|
|
||||||
translation: Translation::new(4.0, 5.0, 4.0),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
// camera
|
|
||||||
.spawn(Camera3dComponents {
|
|
||||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
|
||||||
Vec3::new(3.0, 5.0, 8.0),
|
|
||||||
Vec3::new(0.0, 0.0, 0.0),
|
|
||||||
Vec3::new(0.0, 1.0, 0.0),
|
|
||||||
)),
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
App::build()
|
|
||||||
.add_default_plugins()
|
|
||||||
.load_plugin("target/debug/libexample_plugin.so")
|
|
||||||
.run();
|
|
||||||
}
|
|
@ -68,7 +68,7 @@ fn setup(
|
|||||||
AssetRenderResourcesNode::<MyMaterial>::new(true),
|
AssetRenderResourcesNode::<MyMaterial>::new(true),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add a Render Graph edge connecting our new "my_material" node to the main pass node
|
// Add a Render Graph edge connecting our new "my_material" node to the main pass node. This ensures "my_material" runs before the main pass
|
||||||
render_graph
|
render_graph
|
||||||
.add_node_edge("my_material", base::node::MAIN_PASS)
|
.add_node_edge("my_material", base::node::MAIN_PASS)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -78,14 +78,11 @@ fn setup(
|
|||||||
color: Color::rgb(0.0, 0.8, 0.0),
|
color: Color::rgb(0.0, 0.8, 0.0),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a cube mesh which will use our material
|
|
||||||
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
|
|
||||||
|
|
||||||
// Setup our world
|
// Setup our world
|
||||||
commands
|
commands
|
||||||
// cube
|
// cube
|
||||||
.spawn(MeshComponents {
|
.spawn(MeshComponents {
|
||||||
mesh: cube_handle,
|
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
||||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
||||||
pipeline_handle,
|
pipeline_handle,
|
||||||
// NOTE: in the future you wont need to manually declare dynamic bindings
|
// NOTE: in the future you wont need to manually declare dynamic bindings
|
||||||
|
@ -80,7 +80,7 @@ fn setup(
|
|||||||
AssetRenderResourcesNode::<MyMaterial>::new(true),
|
AssetRenderResourcesNode::<MyMaterial>::new(true),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add a Render Graph edge connecting our new "my_material" node to the main pass node
|
// Add a Render Graph edge connecting our new "my_material" node to the main pass node. This ensures "my_material" runs before the main pass
|
||||||
render_graph
|
render_graph
|
||||||
.add_node_edge("my_material", base::node::MAIN_PASS)
|
.add_node_edge("my_material", base::node::MAIN_PASS)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user