Skip to content

Commit 1ba7429

Browse files
committed
Doc/module style doc blocks for examples (bevyengine#4438)
# Objective Provide a starting point for bevyengine#3951, or a partial solution. Providing a few comment blocks to discuss, and hopefully find better one in the process. ## Solution Since I am pretty new to pretty much anything in this context, I figured I'd just start with a draft for some file level doc blocks. For some of them I found more relevant details (or at least things I considered interessting), for some others there is less. ## Changelog - Moved some existing comments from main() functions in the 2d examples to the file header level - Wrote some more comment blocks for most other 2d examples TODO: - [x] 2d/sprite_sheet, wasnt able to come up with something good yet - [x] all other example groups... Also: Please let me know if the commit style is okay, or to verbose. I could certainly squash these things, or add more details if needed. I also hope its okay to raise this PR this early, with just a few files changed. Took me long enough and I dont wanted to let it go to waste because I lost motivation to do the whole thing. Additionally I am somewhat uncertain over the style and contents of the commets. So let me know what you thing please.
1 parent 7462f21 commit 1ba7429

File tree

120 files changed

+425
-177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+425
-177
lines changed

examples/2d/mesh2d.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Shows how to render a polygonal [`Mesh`], generated from a [`Quad`] primitive, in a 2D scene.
2+
13
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
24

35
fn main() {

examples/2d/mesh2d_manual.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//! This example shows how to manually render 2d items using "mid level render apis" with a custom
2+
//! pipeline for 2d meshes.
3+
//! It doesn't use the [`Material2d`] abstraction, but changes the vertex buffer to include vertex color.
4+
//! Check out the "mesh2d" example for simpler / higher level 2d meshes.
5+
16
use bevy::{
27
core_pipeline::Transparent2d,
38
prelude::*,
@@ -23,9 +28,6 @@ use bevy::{
2328
utils::FloatOrd,
2429
};
2530

26-
/// This example shows how to manually render 2d items using "mid level render apis" with a custom pipeline for 2d meshes
27-
/// It doesn't use the [`Material2d`] abstraction, but changes the vertex buffer to include vertex color
28-
/// Check out the "mesh2d" example for simpler / higher level 2d meshes
2931
fn main() {
3032
App::new()
3133
.add_plugins(DefaultPlugins)

examples/2d/move_sprite.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Renders a 2D scene containing a single, moving sprite.
2+
13
use bevy::prelude::*;
24

35
fn main() {
@@ -25,6 +27,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
2527
.insert(Direction::Up);
2628
}
2729

30+
/// The sprite is animated by changing its translation depending on the time that has passed since
31+
/// the last frame.
2832
fn sprite_movement(time: Res<Time>, mut sprite_position: Query<(&mut Direction, &mut Transform)>) {
2933
for (mut logo, mut transform) in sprite_position.iter_mut() {
3034
match *logo {

examples/2d/rotation.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Demonstrates rotating entities in 2D using quaternions.
2+
13
use bevy::{
24
core::FixedTimestep,
35
math::{const_vec2, Vec3Swizzles},

examples/2d/shapes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Shows how to render simple primitive shapes with a single color.
2+
13
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
24

35
fn main() {

examples/2d/sprite.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Displays a single [`Sprite`], created from an image.
2+
13
use bevy::prelude::*;
24

35
fn main() {

examples/2d/sprite_flipping.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Displays a single [`Sprite`], created from an image, but flipped on one axis.
2+
13
use bevy::prelude::*;
24

35
fn main() {

examples/2d/sprite_sheet.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Renders an animated sprite by loading all animation frames from a single image (a sprite sheet)
2+
//! into a texture atlas, and changing the displayed image periodically.
3+
14
use bevy::prelude::*;
25

36
fn main() {

examples/2d/text2d.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//! Shows text rendering with moving, rotating and scaling text.
2+
//!
3+
//! Note that this uses [`Text2dBundle`] to display text alongside your other entities in a 2D scene.
4+
//!
5+
//! For an example on how to render text as part of a user interface, independent from the world
6+
//! viewport, you may want to look at `2d/contributors.rs` or `ui/text.rs`.
7+
18
use bevy::{prelude::*, text::Text2dBounds};
29

310
fn main() {

examples/2d/texture_atlas.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
//! In this example we generate a new texture atlas (sprite sheet) from a folder containing
2+
//! individual sprites.
3+
14
use bevy::{asset::LoadState, prelude::*};
25

3-
/// In this example we generate a new texture atlas (sprite sheet) from a folder containing
4-
/// individual sprites
56
fn main() {
67
App::new()
78
.init_resource::<RpgSpriteHandles>()

examples/3d/3d_scene.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! A simple 3D scene with light shining over a cube sitting on a plane.
2+
13
use bevy::prelude::*;
24

35
fn main() {

examples/3d/lighting.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Illustrates different lights of various types and colors, some static, some moving over
2+
//! a simple scene.
3+
14
use bevy::prelude::*;
25

36
fn main() {

examples/3d/load_gltf.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Loads and renders a glTF file as a scene.
2+
13
use bevy::prelude::*;
24

35
fn main() {

examples/3d/msaa.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
//! This example shows how to configure Multi-Sample Anti-Aliasing. Setting the sample count higher
2+
//! will result in smoother edges, but it will also increase the cost to render those edges. The
3+
//! range should generally be somewhere between 1 (no multi sampling, but cheap) to 8 (crisp but
4+
//! expensive).
5+
//! Note that WGPU currently only supports 1 or 4 samples.
6+
//! Ultimately we plan on supporting whatever is natively supported on a given device.
7+
//! Check out [this issue](https://github.com/gfx-rs/wgpu/issues/1832) for more info.
8+
19
use bevy::prelude::*;
210

3-
/// This example shows how to configure Multi-Sample Anti-Aliasing. Setting the sample count higher
4-
/// will result in smoother edges, but it will also increase the cost to render those edges. The
5-
/// range should generally be somewhere between 1 (no multi sampling, but cheap) to 8 (crisp but
6-
/// expensive).
7-
/// Note that WGPU currently only supports 1 or 4 samples.
8-
/// Ultimately we plan on supporting whatever is natively supported on a given device.
9-
/// Check out [this issue](https://github.com/gfx-rs/wgpu/issues/1832) for more info.
1011
fn main() {
1112
App::new()
1213
.insert_resource(Msaa { samples: 4 })

examples/3d/orthographic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Shows how to create a 3D orthographic view (for isometric-look games or CAD applications).
2+
13
use bevy::prelude::*;
24

35
fn main() {

examples/3d/parenting.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
//! Illustrates how to create parent-child relationships between entities and how parent transforms
2+
//! are propagated to their descendants.
3+
14
use bevy::prelude::*;
25

3-
/// This example illustrates how to create parent->child relationships between entities how parent
4-
/// transforms are propagated to their descendants
56
fn main() {
67
App::new()
78
.insert_resource(Msaa { samples: 4 })

examples/3d/pbr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
//! This example shows how to configure Physically Based Rendering (PBR) parameters.
2+
13
use bevy::prelude::*;
24

3-
/// This example shows how to configure Physically Based Rendering (PBR) parameters.
45
fn main() {
56
App::new()
67
.add_plugins(DefaultPlugins)

examples/3d/render_to_texture.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Shows how to render to a texture. Useful for mirrors, UI, or exporting images.
2+
13
use bevy::{
24
core_pipeline::{
35
draw_3d_graph, node, AlphaMask3d, Opaque3d, RenderTargetClearColors, Transparent3d,

examples/3d/shadow_biases.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Demonstrates how shadow biases affect shadows in a 3d scene.
2+
13
use bevy::{input::mouse::MouseMotion, prelude::*};
24

35
fn main() {

examples/3d/shadow_caster_receiver.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Demonstrates how to prevent meshes from casting/receiving shadows in a 3d scene.
2+
13
use bevy::{
24
pbr::{NotShadowCaster, NotShadowReceiver},
35
prelude::*,

examples/3d/spherical_area_lights.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Demonstrates how lighting is affected by different radius of point lights.
2+
13
use bevy::prelude::*;
24

35
fn main() {

examples/3d/texture.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
//! This example shows various ways to configure texture materials in 3D.
2+
13
use bevy::prelude::*;
24

3-
/// This example shows various ways to configure texture materials in 3D
45
fn main() {
56
App::new()
67
.add_plugins(DefaultPlugins)

examples/3d/two_passes.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Shows how to render multiple passes to the same window, useful for rendering different views
2+
//! or drawing an object on top regardless of depth.
3+
14
use bevy::{
25
core_pipeline::{draw_3d_graph, node, AlphaMask3d, Opaque3d, Transparent3d},
36
prelude::*,
@@ -68,6 +71,7 @@ fn extract_first_pass_camera_phases(
6871
));
6972
}
7073
}
74+
7175
// A node for the first pass camera that runs draw_3d_graph with this camera.
7276
struct FirstPassCameraDriver {
7377
query: QueryState<Entity, With<FirstPassCamera>>,

examples/3d/update_gltf_scene.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Update a scene from a glTF file, either by spawning the scene as a child of another entity,
2+
//! or by accessing the entities of the scene.
3+
14
use bevy::{prelude::*, scene::InstanceId};
25

36
fn main() {

examples/3d/vertex_colors.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Illustrates the use of vertex colors.
2+
13
use bevy::{prelude::*, render::mesh::VertexAttributeValues};
24

35
fn main() {

examples/3d/wireframe.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Showcases wireframe rendering.
2+
13
use bevy::{
24
pbr::wireframe::{Wireframe, WireframeConfig, WireframePlugin},
35
prelude::*,

examples/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@ Example | File | Description
241241

242242
Example | File | Description
243243
--- | --- | ---
244-
`custom_vertex_attribute` | [`shader/custom_vertex_attribute.rs`](./shader/custom_vertex_attribute.rs) | Illustrates creating a custom shader material that reads a mesh's custom vertex attribute.
245-
`shader_material` | [`shader/shader_material.rs`](./shader/shader_material.rs) | Illustrates creating a custom material and a shader that uses it
246-
`shader_material_screenspace_texture` | [`shader/shader_material_screenspace_texture.rs`](./shader/shader_material_screenspace_texture.rs) | A custom shader sampling a texture with view-independent UV coordinates
247-
`shader_material_glsl` | [`shader/shader_material_glsl.rs`](./shader/shader_material_glsl.rs) | A custom shader using the GLSL shading language.
248-
`shader_instancing` | [`shader/shader_instancing.rs`](./shader/shader_instancing.rs) | A custom shader showing off rendering a mesh multiple times in one draw call.
249244
`animate_shader` | [`shader/animate_shader.rs`](./shader/animate_shader.rs) | Shows how to pass changing data like the time since startup into a shader.
250245
`compute_shader_game_of_life` | [`shader/compute_shader_game_of_life.rs`](./shader/compute_shader_game_of_life.rs) | A compute shader simulating Conway's Game of Life
246+
`custom_vertex_attribute` | [`shader/custom_vertex_attribute.rs`](./shader/custom_vertex_attribute.rs) | Illustrates creating a custom shader material that reads a mesh's custom vertex attribute.
251247
`shader_defs` | [`shader/shader_defs.rs`](./shader/shader_defs.rs) | Demonstrates creating a custom material that uses "shaders defs" (a tool to selectively toggle parts of a shader)
248+
`shader_instancing` | [`shader/shader_instancing.rs`](./shader/shader_instancing.rs) | A custom shader showing off rendering a mesh multiple times in one draw call.
249+
`shader_material` | [`shader/shader_material.rs`](./shader/shader_material.rs) | Illustrates creating a custom material and a shader that uses it
250+
`shader_material_glsl` | [`shader/shader_material_glsl.rs`](./shader/shader_material_glsl.rs) | A custom shader using the GLSL shading language.
251+
`shader_material_screenspace_texture` | [`shader/shader_material_screenspace_texture.rs`](./shader/shader_material_screenspace_texture.rs) | A custom shader sampling a texture with view-independent UV coordinates.
252252

253253
## Stress Tests
254254

@@ -279,14 +279,14 @@ Example | File | Description
279279

280280
Example | File | Description
281281
--- | --- | ---
282-
`scene_viewer` | [`tools/scene_viewer.rs`](./tools/scene_viewer.rs) | A simple way to view glTF models with Bevy. Just run `cargo run --release --example scene_viewer -- /path/to/model.gltf#Scene0`, replacing the path as appropriate. With no arguments it will load the FieldHelmet glTF model from the repository assets subdirectory.
282+
`scene_viewer` | [`tools/scene_viewer.rs`](./tools/scene_viewer.rs) | A simple way to view glTF models with Bevy. Just run `cargo run --release --example scene_viewer /path/to/model.gltf#Scene0`, replacing the path as appropriate. With no arguments it will load the FieldHelmet glTF model from the repository assets subdirectory.
283283

284284
## Transforms
285285

286286
Example | File | Description
287287
--- | --- | ---
288-
`global_vs_local_translation` | [`transforms/global_vs_local_translation.rs`](./transforms/global_vs_local_translation.rs) | Illustrates the difference between direction of a translation in respect to local object or global object Transform
289288
`3d_rotation` | [`transforms/3d_rotation.rs`](./transforms/3d_rotation.rs) | Illustrates how to (constantly) rotate an object around an axis
289+
`global_vs_local_translation` | [`transforms/global_vs_local_translation.rs`](./transforms/global_vs_local_translation.rs) | Illustrates the difference between direction of a translation in respect to local object or global object Transform.
290290
`scale` | [`transforms/scale.rs`](./transforms/scale.rs) | Illustrates how to scale an object in each direction
291291
`transform` | [`transforms/transfrom.rs`](./transforms/transform.rs) | Shows multiple transformations of objects
292292
`translation` | [`transforms/translation.rs`](./transforms/translation.rs) | Illustrates how to move an object along an axis

examples/animation/animated_fox.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Plays animations from a skinned glTF.
2+
13
use bevy::prelude::*;
24

35
fn main() {

examples/animation/animated_transform.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Create and play an animation defined by code that operates on the `Transform` component.
2+
13
use std::f32::consts::{FRAC_PI_2, PI};
24

35
use bevy::prelude::*;

examples/animation/custom_skinned_mesh.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Skinned mesh example with mesh and joints data defined in code.
2+
//! Example taken from <https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_019_SimpleSkin.md>
3+
14
use std::f32::consts::PI;
25

36
use bevy::{
@@ -10,8 +13,6 @@ use bevy::{
1013
};
1114
use rand::Rng;
1215

13-
/// Skinned mesh example with mesh and joints data defined in code.
14-
/// Example taken from <https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_019_SimpleSkin.md>
1516
fn main() {
1617
App::new()
1718
.add_plugins(DefaultPlugins)

examples/animation/gltf_skinned_mesh.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
//! Skinned mesh example with mesh and joints data loaded from a glTF file.
2+
//! Example taken from <https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_019_SimpleSkin.md>
3+
14
use std::f32::consts::PI;
25

36
use bevy::{pbr::AmbientLight, prelude::*, render::mesh::skinning::SkinnedMesh};
47

5-
/// Skinned mesh example with mesh and joints data loaded from a glTF file.
6-
/// Example taken from <https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_019_SimpleSkin.md>
78
fn main() {
89
App::new()
910
.add_plugins(DefaultPlugins)
@@ -27,7 +28,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
2728
commands.spawn_scene(asset_server.load::<Scene, _>("models/SimpleSkin/SimpleSkin.gltf#Scene0"));
2829
}
2930

30-
/// The scene hierachy currently looks somewhat like this:
31+
/// The scene hierarchy currently looks somewhat like this:
3132
///
3233
/// ```ignore
3334
/// <Parent entity>

examples/app/custom_loop.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
//! This example demonstrates you can create a custom runner (to update an app manually). It reads
2+
//! lines from stdin and prints them from within the ecs.
3+
14
use bevy::prelude::*;
25
use std::{io, io::BufRead};
36

47
struct Input(String);
58

6-
/// This example demonstrates you can create a custom runner (to update an app manually). It reads
7-
/// lines from stdin and prints them from within the ecs.
89
fn my_runner(mut app: App) {
910
println!("Type stuff into the console");
1011
for line in io::stdin().lock().lines() {

examples/app/drag_and_drop.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! An example that shows how to handle drag and drop of files in an app.
2+
13
use bevy::prelude::*;
24

35
fn main() {

examples/app/empty.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! An empty application (does nothing)
2+
13
use bevy::prelude::*;
24

35
fn main() {

examples/app/empty_defaults.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! An empty application with default plugins.
2+
13
use bevy::prelude::*;
24

35
fn main() {

examples/app/headless.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use bevy::{app::ScheduleRunnerSettings, prelude::*, utils::Duration};
1+
//! This example only enables a minimal set of plugins required for bevy to run.
2+
//! You can also completely remove rendering / windowing Plugin code from bevy
3+
//! by making your import look like this in your Cargo.toml.
4+
//!
5+
//! [dependencies]
6+
//! bevy = { version = "*", default-features = false }
7+
//! # replace "*" with the most recent version of bevy
28
3-
// This example only enables a minimal set of plugins required for bevy to run.
4-
// You can also completely remove rendering / windowing Plugin code from bevy
5-
// by making your import look like this in your Cargo.toml
6-
//
7-
// [dependencies]
8-
// bevy = { version = "*", default-features = false }
9-
// # replace "*" with the most recent version of bevy
9+
use bevy::{app::ScheduleRunnerSettings, prelude::*, utils::Duration};
1010

1111
fn main() {
1212
// this app runs once

examples/app/headless_defaults.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! An application that runs with default plugins, but without an actual renderer.
2+
//! This can be very useful for integration tests or CI.
3+
14
use bevy::{prelude::*, render::settings::WgpuSettings};
25

36
fn main() {

examples/app/logs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
//! This example illustrates how to use logs in bevy.
2+
13
use bevy::prelude::*;
24

3-
/// This example illustrates how to use logs in bevy
45
fn main() {
56
App::new()
67
// Uncomment this to override the default log settings:

examples/app/plugin.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
//! Demonstrates the creation and registration of a custom plugin.
2+
//!
3+
//! Plugins are the foundation of Bevy. They are scoped sets of components, resources, and systems
4+
//! that provide a specific piece of functionality (generally the smaller the scope, the better).
5+
//! This example illustrates how to create a simple plugin that prints out a message.
6+
17
use bevy::{prelude::*, utils::Duration};
28

3-
/// Plugins are the foundation of Bevy. They are scoped sets of components, resources, and systems
4-
/// that provide a specific piece of functionality (generally the smaller the scope, the better).
5-
/// This example illustrates how to create a simple plugin that prints out a message.
69
fn main() {
710
App::new()
811
.add_plugins(DefaultPlugins)

0 commit comments

Comments
 (0)