more example cleanup and polish

This commit is contained in:
Carter Anderson 2020-07-31 17:10:29 -07:00
parent 471639841b
commit bb111cbafa
15 changed files with 63 additions and 116 deletions

View file

@ -12,7 +12,6 @@ profiler = ["bevy_ecs/profiler", "bevy_diagnostic/profiler"]
members = [
"crates/*",
"crates/bevy_ecs/hecs",
"examples/app/dynamic_plugin_loading/example_plugin"
]
[dependencies]
@ -88,10 +87,6 @@ path = "examples/3d/texture.rs"
name = "z_sort_debug"
path = "examples/3d/z_sort_debug.rs"
[[example]]
name = "dynamic_plugin_loading"
path = "examples/app/dynamic_plugin_loading/main.rs"
[[example]]
name = "empty_defaults"
path = "examples/app/empty_defaults.rs"

View file

@ -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()
}
}
}

View file

@ -9,6 +9,31 @@ impl Rotation {
pub fn identity() -> Self {
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 {

View file

@ -14,32 +14,18 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
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
commands
// plane
.spawn(PbrComponents {
mesh: plane_handle,
material: plane_material_handle,
mesh: meshes.add(Mesh::from(shape::Plane { size: 10.0 })),
material: materials.add(Color::rgb(0.1, 0.2, 0.1).into()),
..Default::default()
})
// cube
.spawn(PbrComponents {
mesh: cube_handle,
material: cube_material_handle,
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()),
translation: Translation::new(0.0, 1.0, 0.0),
..Default::default()
})

View file

@ -13,23 +13,14 @@ fn setup(
asset_server: Res<AssetServer>,
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
commands
// mesh
.spawn(PbrComponents {
mesh: mesh_handle,
material: material_handle,
// load the mesh
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()
})
// light

View file

@ -22,10 +22,7 @@ fn setup(
// cube
.spawn(PbrComponents {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(StandardMaterial {
albedo: Color::rgb(0.5, 0.4, 0.3),
..Default::default()
}),
material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()),
..Default::default()
})
// light

View file

@ -1,7 +1,7 @@
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() {
App::build()
.add_resource(Msaa { samples: 4 })
@ -11,6 +11,9 @@ fn main() {
.run();
}
/// this component indicates what entities should rotate
struct Rotator;
/// rotates the parent, which will result in the child also rotating
fn rotator_system(time: Res<Time>, mut query: Query<(&Rotator, &mut Rotation)>) {
for (_rotator, mut rotation) in &mut query.iter() {

View file

@ -36,7 +36,6 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
commands
// light
.spawn(LightComponents {
@ -54,6 +53,7 @@ fn setup(
});
let mut rng = StdRng::from_entropy();
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
for _ in 0..10000 {
commands.spawn(PbrComponents {
mesh: cube_handle,

View file

@ -1,5 +1,6 @@
use bevy::prelude::*;
/// This example shows various ways to configure texture materials in 3D
fn main() {
App::build()
.add_default_plugins()
@ -15,7 +16,7 @@ fn setup(
mut textures: ResMut<Assets<Texture>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// load a texture
// load a texture and retrieve its aspect ratio
let texture_handle = asset_server
.load_sync(&mut textures, "assets/branding/bevy_logo_dark_big.png")
.unwrap();

View file

@ -1,3 +0,0 @@
/target
**/*.rs.bk
Cargo.lock

View file

@ -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" }

View file

@ -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()
});
}

View file

@ -1,8 +0,0 @@
use bevy::prelude::*;
fn main() {
App::build()
.add_default_plugins()
.load_plugin("target/debug/libexample_plugin.so")
.run();
}

View file

@ -68,7 +68,7 @@ fn setup(
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
.add_node_edge("my_material", base::node::MAIN_PASS)
.unwrap();
@ -78,14 +78,11 @@ fn setup(
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
commands
// cube
.spawn(MeshComponents {
mesh: cube_handle,
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
pipeline_handle,
// NOTE: in the future you wont need to manually declare dynamic bindings

View file

@ -80,7 +80,7 @@ fn setup(
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
.add_node_edge("my_material", base::node::MAIN_PASS)
.unwrap();