Skip to content

Commit

Permalink
more example cleanup and polish
Browse files Browse the repository at this point in the history
  • Loading branch information
cart committed Aug 1, 2020
1 parent 4716398 commit bb111cb
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 116 deletions.
5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
25 changes: 25 additions & 0 deletions crates/bevy_transform/src/components/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 4 additions & 18 deletions examples/3d/3d_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down
17 changes: 4 additions & 13 deletions examples/3d/load_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions examples/3d/msaa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions examples/3d/parenting.rs
Original file line number Diff line number Diff line change
@@ -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 })
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion examples/3d/texture.rs
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions examples/app/dynamic_plugin_loading/example_plugin/.gitignore

This file was deleted.

11 changes: 0 additions & 11 deletions examples/app/dynamic_plugin_loading/example_plugin/Cargo.toml

This file was deleted.

44 changes: 0 additions & 44 deletions examples/app/dynamic_plugin_loading/example_plugin/src/lib.rs

This file was deleted.

8 changes: 0 additions & 8 deletions examples/app/dynamic_plugin_loading/main.rs

This file was deleted.

7 changes: 2 additions & 5 deletions examples/shader/shader_custom_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/shader/shader_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit bb111cb

Please sign in to comment.