docs/bevy/examples/README.md 62.1 K · 937 lines · raw · history

1 <!-- MD024 - The Headers from the Platform-Specific Examples should be identical -->
2 <!-- Use 'cargo run -p build-templated-pages -- build-example-page' to generate the final example README.md -->
3 <!-- markdownlint-disable-file MD024 -->
4
5 # Examples
6
7 These examples demonstrate the main features of Bevy and how to use them.
8 To run an example, use the command `cargo run --example <Example>`, and add the option `--features x11` or `--features wayland` to force the example to run on a specific window compositor, e.g.
9
10 ```sh
11 cargo run --features wayland --example hello_world
12 ```
13
14 **⚠️ Note: for users of releases on crates.io!**
15
16 There are often large differences and incompatible API changes between the latest [crates.io](https://crates.io/crates/bevy) release and the development version of Bevy in the git main branch!
17
18 If you are using a released version of Bevy, you need to make sure you are viewing the correct version of the examples!
19
20 - Latest release: [https://github.com/bevyengine/bevy/tree/latest/examples](https://github.com/bevyengine/bevy/tree/latest/examples)
21 - Specific version, such as `0.4`: [https://github.com/bevyengine/bevy/tree/v0.4.0/examples](https://github.com/bevyengine/bevy/tree/v0.4.0/examples)
22
23 When you clone the repo locally to run the examples, use `git checkout` to get the correct version:
24
25 ```bash
26 # `latest` always points to the newest release
27 git checkout latest
28 # or use a specific version
29 git checkout v0.4.0
30 ```
31
32 ---
33
34 ## Table of Contents
35
36 - [Examples](#examples)
37 - [Table of Contents](#table-of-contents)
38 - [The Bare Minimum](#the-bare-minimum)
39 - [Hello, World!](#hello-world)
40 - [Cross-Platform Examples](#cross-platform-examples)
41 - [2D Rendering](#2d-rendering)
42 - [3D Rendering](#3d-rendering)
43 - [Animation](#animation)
44 - [Application](#application)
45 - [Assets](#assets)
46 - [Async Tasks](#async-tasks)
47 - [Audio](#audio)
48 - [Camera](#camera)
49 - [Dev tools](#dev-tools)
50 - [Diagnostics](#diagnostics)
51 - [ECS (Entity Component System)](#ecs-entity-component-system)
52 - [Embedded](#embedded)
53 - [Games](#games)
54 - [Gizmos](#gizmos)
55 - [Input](#input)
56 - [Math](#math)
57 - [Movement](#movement)
58 - [Picking](#picking)
59 - [Reflection](#reflection)
60 - [Remote Protocol](#remote-protocol)
61 - [Scene](#scene)
62 - [Shaders](#shaders)
63 - [Shaders Advanced](#shaders-advanced)
64 - [State](#state)
65 - [Stress Tests](#stress-tests)
66 - [Time](#time)
67 - [Tools](#tools)
68 - [Transforms](#transforms)
69 - [UI (User Interface)](#ui-user-interface)
70 - [Usage](#usage)
71 - [Window](#window)
72 - [glTF](#gltf)
73
74 - [Tests](#tests)
75 - [Platform-Specific Examples](#platform-specific-examples)
76 - [Android](#android)
77 - [Setup](#setup)
78 - [Build & Run](#build--run)
79 - [Old phones](#old-phones)
80 - [About `cargo-apk`](#about-cargo-apk)
81 - [iOS](#ios)
82 - [Setup](#setup-1)
83 - [Build & Run](#build--run-1)
84 - [Wasm](#wasm)
85 - [Setup](#setup-2)
86 - [Build & Run](#build--run-2)
87 - [WebGL2 and WebGPU](#webgl2-and-webgpu)
88 - [Audio in the browsers](#audio-in-the-browsers)
89 - [Optimizing](#optimizing)
90 - [Loading Assets](#loading-assets)
91
92 ## The Bare Minimum
93
94 <!-- MD026 - Hello, World! looks better with the ! -->
95 <!-- markdownlint-disable-next-line MD026 -->
96 ### Hello, World!
97
98 Example | Description
99 --- | ---
100 [`hello_world.rs`](./hello_world.rs) | Runs a minimal example that outputs "hello world"
101
102 ## Cross-Platform Examples
103
104 ### 2D Rendering
105
106 Example | Description
107 --- | ---
108 [2D Bloom](../examples/2d/bloom_2d.rs) | Illustrates bloom post-processing in 2d
109 [2D Rotation to Cursor](../examples/2d/rotate_to_cursor.rs) | Demonstrates rotating entities in 2D to follow the cursor
110 [2D Shapes](../examples/2d/2d_shapes.rs) | Renders simple 2D primitive shapes like circles and polygons
111 [2D Viewport To World](../examples/2d/2d_viewport_to_world.rs) | Demonstrates how to use the `Camera::viewport_to_world_2d` method with a dynamic viewport and camera.
112 [2D Wireframe](../examples/2d/wireframe_2d.rs) | Showcases wireframes for 2d meshes
113 [Arc 2D Meshes](../examples/2d/mesh2d_arcs.rs) | Demonstrates UV-mapping of the circular segment and sector primitives
114 [CPU Drawing](../examples/2d/cpu_draw.rs) | Manually read/write the pixels of a texture
115 [Dynamic Mipmap Generation](../examples/2d/dynamic_mip_generation.rs) | Demonstrates use of the mipmap generation plugin to generate mipmaps for a texture
116 [Generic 2D Rotation](../examples/2d/rotation.rs) | Demonstrates rotating entities in 2D with quaternions
117 [Manual Mesh 2D](../examples/2d/mesh2d_manual.rs) | Renders a custom mesh "manually" with "mid-level" renderer apis
118 [Mesh 2D](../examples/2d/mesh2d.rs) | Renders a 2d mesh
119 [Mesh 2D With Vertex Colors](../examples/2d/mesh2d_vertex_color_texture.rs) | Renders a 2d mesh with vertex color attributes
120 [Mesh2d Alpha Mode](../examples/2d/mesh2d_alpha_mode.rs) | Used to test alpha modes with mesh2d
121 [Mesh2d Repeated Texture](../examples/2d/mesh2d_repeated_texture.rs) | Showcase of using `uv_transform` on the `ColorMaterial` of a `Mesh2d`
122 [Move Sprite](../examples/2d/move_sprite.rs) | Changes the transform of a sprite
123 [Multi-Window Text](../examples/window/multi_window_text.rs) | Renders text to multiple windows with different scale factors using both Text and Text2d
124 [Pixel Grid Snapping](../examples/2d/pixel_grid_snap.rs) | Shows how to create graphics that snap to the pixel grid by rendering to a texture in 2D
125 [Sprite](../examples/2d/sprite.rs) | Renders a sprite
126 [Sprite Animation](../examples/2d/sprite_animation.rs) | Animates a sprite in response to an event
127 [Sprite Flipping](../examples/2d/sprite_flipping.rs) | Renders a sprite flipped along an axis
128 [Sprite Scale](../examples/2d/sprite_scale.rs) | Shows how a sprite can be scaled into a rectangle while keeping the aspect ratio
129 [Sprite Sheet](../examples/2d/sprite_sheet.rs) | Renders an animated sprite
130 [Sprite Slice](../examples/2d/sprite_slice.rs) | Showcases slicing sprites into sections that can be scaled independently via the 9-patch technique
131 [Sprite Tile](../examples/2d/sprite_tile.rs) | Renders a sprite tiled in a grid
132 [Text 2D](../examples/2d/text2d.rs) | Generates text in 2D
133 [Texture Atlas](../examples/2d/texture_atlas.rs) | Generates a texture atlas (sprite sheet) from individual sprites
134 [Tilemap Chunk](../examples/2d/tilemap_chunk.rs) | Renders a tilemap chunk
135 [Tilemap Chunk with Orientations](../examples/2d/tilemap_chunk_orientation.rs) | Renders a tilemap chunk using tile orientations (mirrored, rotated)
136 [Transparency in 2D](../examples/2d/transparency_2d.rs) | Demonstrates transparency in 2d
137
138 ### 3D Rendering
139
140 Example | Description
141 --- | ---
142 [3D Bloom](../examples/3d/bloom_3d.rs) | Illustrates bloom configuration using HDR and emissive materials
143 [3D Scene](../examples/3d/3d_scene.rs) | Simple 3D scene with basic shapes and lighting
144 [3D Shapes](../examples/3d/3d_shapes.rs) | A scene showcasing the built-in 3D shapes
145 [3D Viewport To World](../examples/3d/3d_viewport_to_world.rs) | Demonstrates how to use the `Camera::viewport_to_world` method
146 [Animated Material](../examples/3d/animated_material.rs) | Shows how to animate material properties
147 [Anisotropy](../examples/3d/anisotropy.rs) | Displays an example model with anisotropy
148 [Anti-aliasing](../examples/3d/anti_aliasing.rs) | Compares different anti-aliasing techniques supported by Bevy
149 [Atmosphere](../examples/3d/atmosphere.rs) | A scene showcasing pbr atmospheric scattering
150 [Atmospheric Fog](../examples/3d/atmospheric_fog.rs) | A scene showcasing the atmospheric fog effect
151 [Auto Exposure](../examples/3d/auto_exposure.rs) | A scene showcasing auto exposure
152 [Blend Modes](../examples/3d/blend_modes.rs) | Showcases different blend modes
153 [Built-in postprocessing](../examples/3d/post_processing.rs) | Demonstrates the built-in postprocessing features
154 [Camera sub view](../examples/3d/camera_sub_view.rs) | Demonstrates using different sub view effects on a camera
155 [Clearcoat](../examples/3d/clearcoat.rs) | Demonstrates the clearcoat PBR feature
156 [Clustered Decal Maps](../examples/3d/clustered_decal_maps.rs) | Demonstrates normal and metallic-roughness maps of decals
157 [Clustered Decals](../examples/3d/clustered_decals.rs) | Demonstrates clustered decals
158 [Color grading](../examples/3d/color_grading.rs) | Demonstrates color grading
159 [Contact Shadows](../examples/3d/contact_shadows.rs) | Showcases how contact shadows add shadow detail
160 [Decal](../examples/3d/decal.rs) | Decal rendering
161 [Deferred Rendering](../examples/3d/deferred_rendering.rs) | Renders meshes with both forward and deferred pipelines
162 [Depth of field](../examples/3d/depth_of_field.rs) | Demonstrates depth of field
163 [Fog](../examples/3d/fog.rs) | A scene showcasing the distance fog effect
164 [Fog volumes](../examples/3d/fog_volumes.rs) | Demonstrates fog volumes
165 [Generate Custom Mesh](../examples/3d/generate_custom_mesh.rs) | Simple showcase of how to generate a custom mesh with a custom texture
166 [Irradiance Volumes](../examples/3d/irradiance_volumes.rs) | Demonstrates irradiance volumes
167 [Light Probe Blending](../examples/3d/light_probe_blending.rs) | Demonstrates blending between multiple reflection probes
168 [Light Textures](../examples/3d/light_textures.rs) | Demonstrates light textures
169 [Lighting](../examples/3d/lighting.rs) | Illustrates various lighting options in a simple scene
170 [Lightmaps](../examples/3d/lightmaps.rs) | Rendering a scene with baked lightmaps
171 [Lines](../examples/3d/lines.rs) | Create a custom material to draw 3d lines
172 [Mesh Ray Cast](../examples/3d/mesh_ray_cast.rs) | Demonstrates ray casting with the `MeshRayCast` system parameter
173 [Meshlet](../examples/3d/meshlet.rs) | Meshlet rendering for dense high-poly scenes (experimental)
174 [Mirror](../examples/3d/mirror.rs) | Demonstrates how to create a mirror with a second camera
175 [Mixed lighting](../examples/3d/mixed_lighting.rs) | Demonstrates how to combine baked and dynamic lighting
176 [Motion Blur](../examples/3d/motion_blur.rs) | Demonstrates per-pixel motion blur
177 [Occlusion Culling](../examples/3d/occlusion_culling.rs) | Demonstration of Occlusion Culling
178 [Order Independent Transparency](../examples/3d/order_independent_transparency.rs) | Demonstrates how to use OIT
179 [Orthographic View](../examples/3d/orthographic.rs) | Shows how to create a 3D orthographic view (for isometric-look in games or CAD applications)
180 [Parallax Mapping](../examples/3d/parallax_mapping.rs) | Demonstrates use of a normal map and depth map for parallax mapping
181 [Parallax-Corrected Cubemaps](../examples/3d/pccm.rs) | Demonstrates parallax-corrected cubemap reflections
182 [Parenting](../examples/3d/parenting.rs) | Demonstrates parent->child relationships and relative transformations
183 [Percentage-closer soft shadows](../examples/3d/pcss.rs) | Demonstrates percentage-closer soft shadows (PCSS)
184 [Physically Based Rendering](../examples/3d/pbr.rs) | Demonstrates use of Physically Based Rendering (PBR) properties
185 [Rectangular Area Light](../examples/3d/rect_light.rs) | Simple 3D scene demonstrating rectangular area lights.
186 [Reflection Probes](../examples/3d/reflection_probes.rs) | Demonstrates reflection probes
187 [Render to Texture](../examples/3d/render_to_texture.rs) | Shows how to render to a texture, useful for mirrors, UI, or exporting images
188 [Rotate Environment Map](../examples/3d/rotate_environment_map.rs) | Demonstrates how to rotate the skybox and the environment map simultaneously
189 [Screen Space Ambient Occlusion](../examples/3d/ssao.rs) | A scene showcasing screen space ambient occlusion
190 [Screen Space Reflections](../examples/3d/ssr.rs) | Demonstrates screen space reflections with water ripples
191 [Scrolling fog](../examples/3d/scrolling_fog.rs) | Demonstrates how to create the effect of fog moving in the wind
192 [Shadow Biases](../examples/3d/shadow_biases.rs) | Demonstrates how shadow biases affect shadows in a 3d scene
193 [Shadow Caster and Receiver](../examples/3d/shadow_caster_receiver.rs) | Demonstrates how to prevent meshes from casting/receiving shadows in a 3d scene
194 [Skybox](../examples/3d/skybox.rs) | Load a cubemap texture onto a cube like a skybox and cycle through different compressed texture formats.
195 [Solari](../examples/3d/solari.rs) | Demonstrates realtime dynamic raytraced lighting using Bevy Solari.
196 [Specular Tint](../examples/3d/specular_tint.rs) | Demonstrates specular tints and maps
197 [Spherical Area Lights](../examples/3d/spherical_area_lights.rs) | Demonstrates how point light radius values affect light behavior
198 [Split Screen](../examples/3d/split_screen.rs) | Demonstrates how to render two cameras to the same window to accomplish "split screen"
199 [Spotlight](../examples/3d/spotlight.rs) | Illustrates spot lights
200 [Texture](../examples/3d/texture.rs) | Shows configuration of texture materials
201 [Tonemapping](../examples/3d/tonemapping.rs) | Compares tonemapping options
202 [Transmission](../examples/3d/transmission.rs) | Showcases light transmission in the PBR material
203 [Transparency in 3D](../examples/3d/transparency_3d.rs) | Demonstrates transparency in 3d
204 [Two Passes](../examples/3d/two_passes.rs) | Renders two 3d passes to the same window from different perspectives
205 [Vertex Colors](../examples/3d/vertex_colors.rs) | Shows the use of vertex colors
206 [Visibility range](../examples/3d/visibility_range.rs) | Demonstrates visibility ranges
207 [Volumetric fog](../examples/3d/volumetric_fog.rs) | Demonstrates volumetric fog and lighting
208 [Wireframe](../examples/3d/wireframe.rs) | Showcases wireframe rendering
209
210 ### Animation
211
212 Example | Description
213 --- | ---
214 [Animated Mesh](../examples/animation/animated_mesh.rs) | Plays an animation on a skinned glTF model of a fox
215 [Animated Mesh Control](../examples/animation/animated_mesh_control.rs) | Plays an animation from a skinned glTF with keyboard controls
216 [Animated Mesh Events](../examples/animation/animated_mesh_events.rs) | Plays an animation from a skinned glTF with events
217 [Animated Transform](../examples/animation/animated_transform.rs) | Create and play an animation defined by code that operates on the `Transform` component
218 [Animated UI](../examples/animation/animated_ui.rs) | Shows how to use animation clips to animate UI properties
219 [Animation Events](../examples/animation/animation_events.rs) | Demonstrate how to use animation events
220 [Animation Graph](../examples/animation/animation_graph.rs) | Blends multiple animations together with a graph
221 [Animation Masks](../examples/animation/animation_masks.rs) | Demonstrates animation masks
222 [Color animation](../examples/animation/color_animation.rs) | Demonstrates how to animate colors using mixing and splines in different color spaces
223 [Custom Skinned Mesh](../examples/animation/custom_skinned_mesh.rs) | Skinned mesh example with mesh and joints data defined in code
224 [Eased Motion](../examples/animation/eased_motion.rs) | Demonstrates the application of easing curves to animate an object
225 [Easing Functions](../examples/animation/easing_functions.rs) | Showcases the built-in easing functions
226 [Morph Targets](../examples/animation/morph_targets.rs) | Plays an animation from a glTF file with meshes with morph targets
227
228 ### Application
229
230 Example | Description
231 --- | ---
232 [Advanced log layers](../examples/app/log_layers_ecs.rs) | Illustrate how to transfer data between log layers and Bevy's ECS
233 [Custom Loop](../examples/app/custom_loop.rs) | Demonstrates how to create a custom runner (to update an app manually)
234 [Drag and Drop](../examples/app/drag_and_drop.rs) | An example that shows how to handle drag and drop in an app
235 [Empty](../examples/app/empty.rs) | An empty application (does nothing)
236 [Empty with Defaults](../examples/app/empty_defaults.rs) | An empty application with default plugins
237 [Externally Driven Headless Renderer](../examples/app/externally_driven_headless_renderer.rs) | Using bevy with manually driven update to render images
238 [Headless](../examples/app/headless.rs) | An application that runs without default plugins
239 [Headless Renderer](../examples/app/headless_renderer.rs) | An application that runs with no window, but renders into image file
240 [Log layers](../examples/app/log_layers.rs) | Illustrate how to add custom log layers
241 [Logs](../examples/app/logs.rs) | Illustrate how to use generate log output
242 [No Renderer](../examples/app/no_renderer.rs) | An application that runs with default plugins and displays an empty window, but without an actual renderer
243 [Plugin](../examples/app/plugin.rs) | Demonstrates the creation and registration of a custom plugin
244 [Plugin Group](../examples/app/plugin_group.rs) | Demonstrates the creation and registration of a custom plugin group
245 [Render Recovery](../examples/app/render_recovery.rs) | Demonstrates how bevy can recover from rendering failures.
246 [Return after Run](../examples/app/return_after_run.rs) | Show how to return to main after the Bevy app has exited
247 [Save Window Position](../examples/window/persisting_window_settings.rs) | Demonstrates saving window position settings
248 [Settings](../examples/app/settings.rs) | Demonstrates persistence of settings
249 [Thread Pool Resources](../examples/app/thread_pool_resources.rs) | Creates and customizes the internal thread pool
250 [Without Winit](../examples/app/without_winit.rs) | Create an application without winit (runs single time, no event loop)
251
252 ### Assets
253
254 Example | Description
255 --- | ---
256 [Alter Mesh](../examples/asset/alter_mesh.rs) | Shows how to modify the underlying asset of a Mesh after spawning.
257 [Alter Sprite](../examples/asset/alter_sprite.rs) | Shows how to modify texture assets after spawning.
258 [Asset Decompression](../examples/asset/asset_decompression.rs) | Demonstrates loading a compressed asset
259 [Asset Loading](../examples/asset/asset_loading.rs) | Demonstrates various methods to load assets
260 [Asset Processing](../examples/asset/processing/asset_processing.rs) | Demonstrates how to process and load custom assets
261 [Asset Saving](../examples/asset/asset_saving.rs) | Demonstrates how to save an asset
262 [Asset Saving with Subassets](../examples/asset/asset_saving_with_subassets.rs) | Demonstrates how to save an asset with subassets
263 [Asset Settings](../examples/asset/asset_settings.rs) | Demonstrates various methods of applying settings when loading an asset
264 [Compressed Image Saver](../examples/asset/compressed_image_saver.rs) | Demonstrates compressing textures and generating mipmaps using CompressedImageSaver
265 [Custom Asset](../examples/asset/custom_asset.rs) | Implements a custom asset loader
266 [Custom Asset IO](../examples/asset/custom_asset_reader.rs) | Implements a custom AssetReader
267 [Embedded Asset](../examples/asset/embedded_asset.rs) | Embed an asset in the application binary and load it
268 [Extra Asset Source](../examples/asset/extra_source.rs) | Load an asset from a non-standard asset source
269 [Generated Assets](../examples/asset/generated_assets.rs) | Shows how to generate and store assets at runtime
270 [Hot Reloading of Assets](../examples/asset/hot_asset_reloading.rs) | Demonstrates automatic reloading of assets when modified on disk
271 [Multi-asset synchronization](../examples/asset/multi_asset_sync.rs) | Demonstrates how to wait for multiple assets to be loaded.
272 [Repeated texture configuration](../examples/asset/repeated_texture.rs) | How to configure the texture to repeat instead of the default clamp to edges
273 [Web Asset](../examples/asset/web_asset.rs) | Load an asset from the web
274
275 ### Async Tasks
276
277 Example | Description
278 --- | ---
279 [Async Channel Pattern](../examples/async_tasks/async_channel_pattern.rs) | An example showing how to offload work to background async tasks using channels for communication.
280 [Async Compute](../examples/async_tasks/async_compute.rs) | How to use `AsyncComputeTaskPool` to complete longer running tasks
281 [External Source of Data on an External Thread](../examples/async_tasks/external_source_external_thread.rs) | How to use an external thread to run an infinite task and communicate with a channel
282
283 ### Audio
284
285 Example | Description
286 --- | ---
287 [Audio](../examples/audio/audio.rs) | Shows how to load and play an audio file
288 [Audio Control](../examples/audio/audio_control.rs) | Shows how to load and play an audio file, and control how it's played
289 [Decodable](../examples/audio/decodable.rs) | Shows how to create and register a custom audio source by implementing the `Decodable` type.
290 [Pitch](../examples/audio/pitch.rs) | Shows how to directly play a simple pitch
291 [Play Sound Effect](../examples/audio/play_sound_effect.rs) | Shows how to play a sound effect in response to an event
292 [Soundtrack](../examples/audio/soundtrack.rs) | Shows how to play different soundtracks based on game state
293 [Spatial Audio 2D](../examples/audio/spatial_audio_2d.rs) | Shows how to play spatial audio, and moving the emitter in 2D
294 [Spatial Audio 3D](../examples/audio/spatial_audio_3d.rs) | Shows how to play spatial audio, and moving the emitter in 3D
295
296 ### Camera
297
298 Example | Description
299 --- | ---
300 [2D on Bevy UI](../examples/camera/2d_on_ui.rs) | Shows how to render 2D objects on top of Bevy UI
301 [2D top-down camera](../examples/camera/2d_top_down_camera.rs) | A 2D top-down camera smoothly following player movements
302 [Camera Orbit](../examples/camera/camera_orbit.rs) | Shows how to orbit a static scene using pitch, yaw, and roll.
303 [Custom Projection](../examples/camera/custom_projection.rs) | Shows how to create custom camera projections.
304 [First person view model](../examples/camera/first_person_view_model.rs) | A first-person camera that uses a world model and a view model with different field of views (FOV)
305 [Free Camera controller](../examples/camera/free_camera_controller.rs) | Demonstrates the FreeCamera controller for 3D scenes.
306 [Minimal Pan Orbit Camera](../examples/camera/pan_orbit_camera_minimal.rs) | Minimum setup for working PanOrbitCamera
307 [Orthographic Pan Orbit Camera](../examples/camera/pan_orbit_camera_ortho.rs) | Using Pan Orbit Camera in orthographic-only projection
308 [Pan Camera](../examples/camera/pan_camera_controller.rs) | Example Pan-Camera Styled Camera Controller for 2D scenes
309 [Pan Orbit Camera](../examples/camera/pan_orbit_camera_cad.rs) | CAD-like controls and setup for PanOrbitCamera
310 [Projection Zoom](../examples/camera/projection_zoom.rs) | Shows how to zoom orthographic and perspective projection cameras.
311 [Screen Shake](../examples/camera/2d_screen_shake.rs) | A simple 2D screen shake effect
312
313 ### Dev tools
314
315 Example | Description
316 --- | ---
317 [Extract Schedule Data](../examples/dev_tools/schedule_data.rs) | Extracts the schedule data from a default app and writes it to a file
318 [FPS overlay](../examples/dev_tools/fps_overlay.rs) | Demonstrates FPS overlay
319 [Infinite grid](../examples/dev_tools/infinite_grid.rs) | Demonstrates Bevy's infinite grid, suitable as a ground plane for editors
320
321 ### Diagnostics
322
323 Example | Description
324 --- | ---
325 [Custom Diagnostic](../examples/diagnostics/custom_diagnostic.rs) | Shows how to create a custom diagnostic
326 [Enabling/disabling diagnostic](../examples/diagnostics/enabling_disabling_diagnostic.rs) | Shows how to disable/re-enable a Diagnostic during runtime
327 [Log Diagnostics](../examples/diagnostics/log_diagnostics.rs) | Add a plugin that logs diagnostics, like frames per second (FPS), to the console
328
329 ### ECS (Entity Component System)
330
331 Example | Description
332 --- | ---
333 [Callbacks](../examples/ecs/callbacks.rs) | Store arbitrary systems in components and run them on demand
334 [Change Detection](../examples/ecs/change_detection.rs) | Change detection on components and resources
335 [Component Hooks](../examples/ecs/component_hooks.rs) | Define component hooks to manage component lifecycle events
336 [Contiguous Query](../examples/ecs/contiguous_query.rs) | Demonstrates contiguous queries
337 [Custom Executor](../examples/ecs/custom_executor.rs) | Demonstrates how to make a custom SystemExecutor
338 [Custom Query Parameters](../examples/ecs/custom_query_param.rs) | Groups commonly used compound queries and query filters into a single type
339 [Custom Schedule](../examples/ecs/custom_schedule.rs) | Demonstrates how to add custom schedules
340 [Delayed Commands](../examples/ecs/delayed_commands.rs) | Demonstrates how to schedule ECS commands with a delay
341 [Dynamic ECS](../examples/ecs/dynamic.rs) | Dynamically create components, spawn entities with those components and query those components
342 [ECS Guide](../examples/ecs/ecs_guide.rs) | Full guide to Bevy's ECS
343 [Entity disabling](../examples/ecs/entity_disabling.rs) | Demonstrates how to hide entities from the ECS without deleting them
344 [Error handling](../examples/ecs/error_handling.rs) | How to return and handle errors across the ECS
345 [Extraction](../examples/ecs/extraction.rs) | Demonstrates different ways of extracting components, copying them from the main world to the render world
346 [Fallible System Parameters](../examples/ecs/fallible_params.rs) | Systems are skipped if their parameters cannot be acquired
347 [Fixed Timestep](../examples/ecs/fixed_timestep.rs) | Shows how to create systems that run every fixed timestep, rather than every tick
348 [Generic System](../examples/ecs/generic_system.rs) | Shows how to create systems that can be reused with different types
349 [Hierarchy](../examples/ecs/hierarchy.rs) | Creates a hierarchy of parents and children entities
350 [Hotpatching Systems](../examples/ecs/hotpatching_systems.rs) | Demonstrates how to hotpatch systems
351 [Immutable Components](../examples/ecs/immutable_components.rs) | Demonstrates the creation and utility of immutable components
352 [Iter Combinations](../examples/ecs/iter_combinations.rs) | Shows how to iterate over combinations of query results
353 [Message](../examples/ecs/message.rs) | Illustrates message creation, activation, and reception
354 [Nondeterministic System Order](../examples/ecs/nondeterministic_system_order.rs) | Systems run in parallel, but their order isn't always deterministic. Here's how to detect and fix this.
355 [Observer Propagation](../examples/ecs/observer_propagation.rs) | Demonstrates event propagation with observers
356 [Observers](../examples/ecs/observers.rs) | Demonstrates observers that react to events (both built-in life-cycle events and custom events)
357 [One Shot Systems](../examples/ecs/one_shot_systems.rs) | Shows how to flexibly run systems without scheduling them
358 [Parallel Query](../examples/ecs/parallel_query.rs) | Illustrates parallel queries with `ParallelIterator`
359 [Relationships](../examples/ecs/relationships.rs) | Define and work with custom relationships between entities
360 [Removal Detection](../examples/ecs/removal_detection.rs) | Query for entities that had a specific component removed earlier in the current frame
361 [Run Conditions](../examples/ecs/run_conditions.rs) | Run systems only when one or multiple conditions are met
362 [Startup System](../examples/ecs/startup_system.rs) | Demonstrates a startup system (one that runs once when the app starts up)
363 [State Scoped](../examples/ecs/state_scoped.rs) | Shows how to spawn entities that are automatically despawned either when entering or exiting specific game states.
364 [System Closure](../examples/ecs/system_closure.rs) | Show how to use closures as systems, and how to configure `Local` variables by capturing external state
365 [System Parameter](../examples/ecs/system_param.rs) | Illustrates creating custom system parameters with `SystemParam`
366 [System Piping](../examples/ecs/system_piping.rs) | Pipe the output of one system into a second, allowing you to handle any errors gracefully
367 [System Stepping](../examples/ecs/system_stepping.rs) | Demonstrate stepping through systems in order of execution.
368
369 ### Embedded
370
371 Example | Description
372 --- | ---
373 [`no_std` Compatible Library](../examples/no_std/library/src/lib.rs) | Example library compatible with `std` and `no_std` targets
374
375 ### Games
376
377 Example | Description
378 --- | ---
379 [Alien Cake Addict](../examples/showcase/alien_cake_addict.rs) | Eat the cakes. Eat them all. An example 3D game
380 [Breakout](../examples/showcase/breakout.rs) | An implementation of the classic game "Breakout".
381 [Contributors](../examples/showcase/contributors.rs) | Displays each contributor as a bouncy bevy-ball!
382 [Desk Toy](../examples/showcase/desk_toy.rs) | Bevy logo as a desk toy using transparent windows! Now with Googly Eyes!
383 [Game Menu](../examples/showcase/game_menu.rs) | A simple game menu
384 [Loading Screen](../examples/showcase/loading_screen.rs) | Demonstrates how to create a loading screen that waits for all assets to be loaded and render pipelines to be compiled.
385 [Mines](../examples/showcase/mines.rs) | A simple minesweeper-style game in Bevy UI
386
387 ### Gizmos
388
389 Example | Description
390 --- | ---
391 [2D Gizmos](../examples/gizmos/2d_gizmos.rs) | A scene showcasing 2D gizmos
392 [3D Gizmos](../examples/gizmos/3d_gizmos.rs) | A scene showcasing 3D gizmos
393 [Anchored Text Gizmos](../examples/gizmos/anchored_text_gizmos.rs) | Demonstrates anchored text gizmos
394 [Axes](../examples/gizmos/axes.rs) | Demonstrates the function of axes gizmos
395 [Light Gizmos](../examples/gizmos/light_gizmos.rs) | A scene showcasing light gizmos
396 [Text Gizmos 2d](../examples/gizmos/2d_text_gizmos.rs) | A scene showcasing 2d text gizmos
397 [Text Gizmos 3d](../examples/gizmos/3d_text_gizmos.rs) | A scene showcasing 3d text gizmos
398 [Text Gizmos Font](../examples/gizmos/text_gizmos_font.rs) | Example displaying the font used by text gizmos
399 [Transform Gizmo](../examples/gizmos/transform_gizmo.rs) | Interactive transform gizmo for translating, rotating, and scaling entities
400
401 ### Input
402
403 Example | Description
404 --- | ---
405 [Char Input Events](../examples/input/char_input_events.rs) | Prints out all chars as they are inputted
406 [Gamepad Input](../examples/input/gamepad_input.rs) | Shows handling of gamepad input, connections, and disconnections
407 [Gamepad Input Events](../examples/input/gamepad_input_events.rs) | Iterates and prints gamepad input and connection events
408 [Gamepad Rumble](../examples/input/gamepad_rumble.rs) | Shows how to rumble a gamepad using force feedback
409 [Keyboard Input](../examples/input/keyboard_input.rs) | Demonstrates handling a key press/release
410 [Keyboard Input Events](../examples/input/keyboard_input_events.rs) | Prints out all keyboard events
411 [Keyboard Modifiers](../examples/input/keyboard_modifiers.rs) | Demonstrates using key modifiers (ctrl, shift)
412 [Mouse Grab](../examples/input/mouse_grab.rs) | Demonstrates how to grab the mouse, locking the cursor to the app's screen
413 [Mouse Input](../examples/input/mouse_input.rs) | Demonstrates handling a mouse button press/release
414 [Mouse Input Events](../examples/input/mouse_input_events.rs) | Prints out all mouse events (buttons, movement, etc.)
415 [Touch Input](../examples/input/touch_input.rs) | Displays touch presses, releases, and cancels
416 [Touch Input Events](../examples/input/touch_input_events.rs) | Prints out all touch inputs
417
418 ### Math
419
420 Example | Description
421 --- | ---
422 [Bounding Volume Intersections (2D)](../examples/math/bounding_2d.rs) | Showcases bounding volumes and intersection tests
423 [Cubic Splines](../examples/math/cubic_splines.rs) | Exhibits different modes of constructing cubic curves using splines
424 [Custom Primitives](../examples/math/custom_primitives.rs) | Demonstrates how to add custom primitives and useful traits for them.
425 [Random Sampling](../examples/math/random_sampling.rs) | Demonstrates how to sample random points from mathematical primitives
426 [Rendering Primitives](../examples/math/render_primitives.rs) | Shows off rendering for all math primitives as both Meshes and Gizmos
427 [Smooth Follow](../examples/movement/smooth_follow.rs) | Demonstrates how to make an entity smoothly follow another using interpolation
428
429 ### Movement
430
431 Example | Description
432 --- | ---
433 [Run physics in a fixed timestep](../examples/movement/physics_in_fixed_timestep.rs) | Handles input, physics, and rendering in an industry-standard way by using a fixed timestep
434
435 ### Picking
436
437 Example | Description
438 --- | ---
439 [Custom Hit Data](../examples/picking/custom_hit_data.rs) | Demonstrates a custom picking backend with custom hit data.
440 [Drag and Drop](../examples/picking/dragdrop_picking.rs) | Demonstrates drag and drop using picking events
441 [Draggable Slider](../examples/picking/draggable_slider.rs) | Demonstrates pointer capture using a draggable slider
442 [Mesh Picking](../examples/picking/mesh_picking.rs) | Demonstrates picking meshes
443 [Picking Debug Tools](../examples/picking/debug_picking.rs) | Demonstrates picking debug overlay
444 [Showcases simple picking events and usage](../examples/picking/simple_picking.rs) | Demonstrates how to use picking events to spawn simple objects
445 [Sprite Picking](../examples/picking/sprite_picking.rs) | Demonstrates picking sprites and sprite atlases
446
447 ### Reflection
448
449 Example | Description
450 --- | ---
451 [Automatic types registration](../examples/reflection/auto_register_static/src/lib.rs) | Demonstrates how to set up automatic reflect types registration for platforms without `inventory` support
452 [Custom Attributes](../examples/reflection/custom_attributes.rs) | Registering and accessing custom attributes on reflected types
453 [Dynamic Types](../examples/reflection/dynamic_types.rs) | How dynamic types are used with reflection
454 [Function Reflection](../examples/reflection/function_reflection.rs) | Demonstrates how functions can be called dynamically using reflection
455 [Generic Reflection](../examples/reflection/generic_reflection.rs) | Registers concrete instances of generic types that may be used with reflection
456 [Mutation by Reflection](../examples/reflection/mutation_by_reflection.rs) | Demonstrates how to mutate abstract or non-Rust data at runtime using reflection
457 [Reflection](../examples/reflection/reflection.rs) | Demonstrates how reflection in Bevy provides a way to dynamically interact with Rust types
458 [Reflection Types](../examples/reflection/reflection_types.rs) | Illustrates the various reflection types available
459 [Serialization](../examples/reflection/serialization.rs) | Demonstrates serialization and deserialization using reflection without serde's Serialize/Deserialize traits
460 [Type Data](../examples/reflection/type_data.rs) | Demonstrates how to create and use type data
461
462 ### Remote Protocol
463
464 Example | Description
465 --- | ---
466 [App Under Test](../examples/remote/app_under_test.rs) | A Bevy app that you can connect to with the BRP and control
467 [Integration Test](../examples/remote/integration_test.rs) | Connects to a running Bevy app via BRP, finds a button, and clicks it
468 [client](../examples/remote/client.rs) | A simple command line client that can control Bevy apps via the BRP
469 [server](../examples/remote/server.rs) | A Bevy app that you can connect to with the BRP and edit
470
471 ### Scene
472
473 Example | Description
474 --- | ---
475 [BSN example](../examples/scene/bsn.rs) | Demonstrates how to use BSN to compose scenes
476 [World Serialization](../examples/scene/world_serialization.rs) | Demonstrates loading from and saving world to files
477
478 ### Shaders
479
480 These examples demonstrate how to implement different shaders in user code.
481
482 A shader in its most common usage is a small program that is run by the GPU per-vertex in a mesh (a vertex shader) or per-affected-screen-fragment (a fragment shader.) The GPU executes these programs in a highly parallel way.
483
484 There are also compute shaders which are used for more general processing leveraging the GPU's parallelism.
485
486 Example | Description
487 --- | ---
488 [Animated](../examples/shader/animate_shader.rs) | A shader that uses dynamic data like the time since startup
489 [Array Texture](../examples/shader/array_texture.rs) | A shader that shows how to reuse the core bevy PBR shading functionality in a custom material that obtains the base color from an array texture.
490 [Compute - Game of Life](../examples/shader/compute_shader_game_of_life.rs) | A compute shader that simulates Conway's Game of Life
491 [Compute Shader Mesh](../examples/shader_advanced/compute_mesh.rs) | A compute shader that generates a mesh that is controlled by a Handle
492 [Custom Render Phase](../examples/shader_advanced/custom_render_phase.rs) | Shows how to make a complete render phase
493 [Custom Vertex Attribute](../examples/shader_advanced/custom_vertex_attribute.rs) | A shader that reads a mesh's custom vertex attribute
494 [Custom phase item](../examples/shader_advanced/custom_phase_item.rs) | Demonstrates how to enqueue custom draw commands in a render phase
495 [Extended Bindless Material](../examples/shader/extended_material_bindless.rs) | Demonstrates bindless `ExtendedMaterial`
496 [Extended Material](../examples/shader/extended_material.rs) | A custom shader that builds on the standard material
497 [GPU Component Array Buffer](../examples/shader/gpu_component_array_buffer.rs) | Shows how to expose per-mesh-instance data to the GPU
498 [GPU readback](../examples/shader/gpu_readback.rs) | A very simple compute shader that writes to a buffer that is read by the cpu
499 [Instancing](../examples/shader/automatic_instancing.rs) | Shows that multiple instances of a cube are automatically instanced in one draw call
500 [Instancing](../examples/shader_advanced/custom_shader_instancing.rs) | A shader that renders a mesh multiple times in one draw call using low level rendering api
501 [Material](../examples/shader/shader_material.rs) | A shader and a material that uses it
502 [Material](../examples/shader/shader_material_2d.rs) | A shader and a material that uses it on a 2d mesh
503 [Material - 2D Bindless](../examples/shader/shader_material_2d_bindless.rs) | Demonstrates bindless materials in 2D
504 [Material - Bindless](../examples/shader/shader_material_bindless.rs) | Demonstrates how to make materials that use bindless textures
505 [Material - Screenspace Texture](../examples/shader/shader_material_screenspace_texture.rs) | A shader that samples a texture with view-independent UV coordinates
506 [Material Prepass](../examples/shader/shader_prepass.rs) | A shader that uses the various textures generated by the prepass
507 [Pipeline Constants](../examples/shader/pipeline_constants.rs) | Demonstrates pipeline-overridable constants (WGSL `override`) by compiling the same shader into multiple variants with different posterization levels
508 [Post Processing - Custom Render Pass](../examples/shader_advanced/custom_post_processing.rs) | A custom post processing effect, using a custom render pass that runs after the main pass
509 [Render Depth to Texture](../examples/shader_advanced/render_depth_to_texture.rs) | Demonstrates how to use depth-only cameras
510 [Shader Defs](../examples/shader/shader_defs.rs) | A shader that uses "shaders defs" (a bevy tool to selectively toggle parts of a shader)
511 [Specialized Mesh Pipeline](../examples/shader_advanced/specialized_mesh_pipeline.rs) | Demonstrates how to write a specialized mesh pipeline
512 [Sprite Material](../examples/shader/sprite_material.rs) | A custom shader for sprites
513 [Storage Buffer](../examples/shader/storage_buffer.rs) | A shader that shows how to bind a storage buffer using a custom material.
514 [Texture Binding Array (Bindless Textures)](../examples/shader_advanced/texture_binding_array.rs) | A shader that shows how to bind and sample multiple textures as a binding array (a.k.a. bindless textures).
515
516 ### Shaders Advanced
517
518 Example | Description
519 --- | ---
520 [Deferred Gbuffer Raymarching](../examples/shader_advanced/deferred_raymarch.rs) | Writes a raymarched SDF into the deferred gbuffer so it is lit by the standard PBR deferred lighting pass
521 [Fullscreen Material](../examples/shader_advanced/fullscreen_material.rs) | Demonstrates how to write a fullscreen material
522 [Manual Material Implementation](../examples/shader_advanced/manual_material.rs) | Demonstrates how to implement a material manually using the mid-level render APIs
523 [Mesh Shader Introduction](../examples/shader_advanced/mesh_shader_intro.rs) | Demonstrates how to use Task/Amplification/Mesh Shaders
524
525 ### State
526
527 Example | Description
528 --- | ---
529 [Computed States](../examples/state/computed_states.rs) | Advanced state patterns using Computed States.
530 [Custom State Transition Behavior](../examples/state/custom_transitions.rs) | Creating and working with custom state transition schedules.
531 [States](../examples/state/states.rs) | Illustrates how to use States to control transitioning from a Menu state to an InGame state.
532 [Sub States](../examples/state/sub_states.rs) | Using Sub States for hierarchical state handling.
533
534 ### Stress Tests
535
536 These examples are used to test the performance and stability of various parts of the engine in an isolated way.
537
538 Due to the focus on performance it's recommended to run the stress tests in release mode:
539
540 ```sh
541 cargo run --release --example <example name>
542 ```
543
544 Example | Description
545 --- | ---
546 [Bevymark](../examples/stress_tests/bevymark.rs) | A heavy sprite rendering workload to benchmark your system with Bevy
547 [Bevymark 3D](../examples/stress_tests/bevymark_3d.rs) | A heavy 3D cube rendering workload to benchmark your system with Bevy
548 [Many Animated Materials](../examples/stress_tests/many_materials.rs) | Benchmark to test rendering many animated materials
549 [Many Animated Sprites](../examples/stress_tests/many_animated_sprites.rs) | Displays many animated sprites in a grid arrangement with slight offsets to their animation timers. Used for performance testing.
550 [Many Buttons](../examples/stress_tests/many_buttons.rs) | Test rendering of many UI elements
551 [Many Cameras & Lights](../examples/stress_tests/many_cameras_lights.rs) | Test rendering of many cameras and lights
552 [Many Components (and Entities and Systems)](../examples/stress_tests/many_components.rs) | Test large ECS systems
553 [Many Cubes](../examples/stress_tests/many_cubes.rs) | Simple benchmark to test per-entity draw overhead. Run with the `sphere` argument to test frustum culling
554 [Many Foxes](../examples/stress_tests/many_foxes.rs) | Loads an animated fox model and spawns lots of them. Good for testing skinned mesh performance. Takes an unsigned integer argument for the number of foxes to spawn. Defaults to 1000
555 [Many Gizmos](../examples/stress_tests/many_gizmos.rs) | Test rendering of many gizmos
556 [Many Glyphs](../examples/stress_tests/many_glyphs.rs) | Simple benchmark to test text rendering.
557 [Many Gradients](../examples/stress_tests/many_gradients.rs) | Stress test for gradient rendering performance
558 [Many Lights](../examples/stress_tests/many_lights.rs) | Simple benchmark to test rendering many point lights. Run with `WGPU_SETTINGS_PRIO=webgl2` to restrict to uniform buffers and max 256 lights
559 [Many Meshlet Materials](../examples/stress_tests/many_meshlet_materials.rs) | Benchmark to test rendering many meshlet materials (experimental)
560 [Many Morph Targets](../examples/stress_tests/many_morph_targets.rs) | Simple benchmark to test rendering many meshes with animated morph targets.
561 [Many Sprites](../examples/stress_tests/many_sprites.rs) | Displays many sprites in a grid arrangement! Used for performance testing. Use `--colored` to enable color tinted sprites.
562 [Many Text](../examples/stress_tests/many_text.rs) | Displays many UI Text nodes. Used for performance testing.
563 [Many Text2d](../examples/stress_tests/many_text2d.rs) | Displays many Text2d! Used for performance testing.
564 [Text Pipeline](../examples/stress_tests/text_pipeline.rs) | Text Pipeline benchmark
565 [Transform Hierarchy](../examples/stress_tests/transform_hierarchy.rs) | Various test cases for hierarchy and transform propagation performance
566
567 ### Time
568
569 Example | Description
570 --- | ---
571 [Time handling](../examples/time/time.rs) | Explains how Time is handled in ECS
572 [Timers](../examples/time/timers.rs) | Illustrates ticking `Timer` resources inside systems and handling their state
573 [Virtual time](../examples/time/virtual_time.rs) | Shows how `Time<Virtual>` can be used to pause, resume, slow down and speed up a game.
574
575 ### Tools
576
577 Example | Description
578 --- | ---
579 [Gamepad Viewer](../examples/tools/gamepad_viewer.rs) | Shows a visualization of gamepad buttons, sticks, and triggers
580 [Scene Viewer](../examples/tools/scene_viewer/main.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
581
582 ### Transforms
583
584 Example | Description
585 --- | ---
586 [3D Rotation](../examples/transforms/3d_rotation.rs) | Illustrates how to (constantly) rotate an object around an axis
587 [Alignment](../examples/transforms/align.rs) | A demonstration of Transform's axis-alignment feature
588 [Scale](../examples/transforms/scale.rs) | Illustrates how to scale an object in each direction
589 [Transform](../examples/transforms/transform.rs) | Shows multiple transformations of objects
590 [Translation](../examples/transforms/translation.rs) | Illustrates how to move an object along an axis
591
592 ### UI (User Interface)
593
594 Example | Description
595 --- | ---
596 [Anchor Layout](../examples/ui/layout/anchor_layout.rs) | Shows an 'anchor layout' style of ui layout
597 [Borders](../examples/ui/styling/borders.rs) | Demonstrates how to create a node with a border
598 [Box Shadow](../examples/ui/styling/box_shadow.rs) | Demonstrates how to create a node with a shadow
599 [Button](../examples/ui/widgets/button.rs) | Illustrates creating and updating a button
600 [CSS Grid](../examples/ui/layout/grid.rs) | An example for CSS Grid layout
601 [Directional Navigation](../examples/ui/navigation/directional_navigation.rs) | Demonstration of automatic directional navigation based on UI element positions
602 [Directional Navigation Overrides](../examples/ui/navigation/directional_navigation_overrides.rs) | Demonstration of automatic directional navigation between UI elements with manual overrides
603 [Display and Visibility](../examples/ui/layout/display_and_visibility.rs) | Demonstrates how Display and Visibility work in the UI.
604 [Drag to Scroll](../examples/ui/scroll_and_overflow/drag_to_scroll.rs) | This example tests scale factor, dragging and scrolling
605 [Editable Text Filter](../examples/ui/text/editable_text_filter.rs) | Demonstrates an 8-character hex input using EditableTextFilter
606 [Feathers Counter](../examples/ui/widgets/feathers_counter.rs) | Simple counter using feathers
607 [Feathers Number Input](../examples/ui/widgets/feathers_number_input.rs) | Feathers Number Input Options
608 [Feathers Widgets](../examples/ui/widgets/feathers_gallery.rs) | Gallery of Feathers Widgets
609 [Fixed Node](../examples/ui/layout/fixed_node.rs) | Demonstrates how to use FixedNode to lay out a UI node as a root node
610 [Flex Layout](../examples/ui/layout/flex_layout.rs) | Demonstrates how the AlignItems and JustifyContent properties can be composed to layout nodes and position text
611 [Font Atlas Debug](../examples/ui/text/font_atlas_debug.rs) | Illustrates how FontAtlases are populated (used to optimize text rendering internally)
612 [Font Queries](../examples/ui/text/font_query.rs) | Demonstrates font querying
613 [Font Variations](../examples/ui/text/font_variations.rs) | Demonstrates how to use OpenType font variations.
614 [Font Weights](../examples/ui/text/font_weights.rs) | Demonstrates how to use font weights.
615 [Generic Font Families](../examples/ui/text/generic_font_families.rs) | Demonstrates how to use generic font families
616 [Ghost Nodes](../examples/ui/layout/ghost_nodes.rs) | Demonstrates the use of Ghost Nodes to skip entities in the UI layout hierarchy
617 [Gradients](../examples/ui/styling/gradients.rs) | An example demonstrating gradients
618 [Headless Tabs](../examples/ui/widgets/headless_tabs.rs) | Demonstrates controlled and self-updating headless tab lists
619 [IME Support](../examples/ui/text/ime_support.rs) | Demonstrates IME (Input Method Editor) support for text input
620 [Image Node](../examples/ui/images/image_node.rs) | Demonstrates how to create an image node
621 [Image Node Resizing](../examples/ui/images/image_node_resizing.rs) | Demonstrates how to resize an image node
622 [Inline Images](../examples/ui/text/inline_image.rs) | Demonstrates how to display images inline with text
623 [Letter Spacing](../examples/ui/text/letter_spacing.rs) | Demonstrates the letter spacing feature
624 [Multiline Text Input](../examples/ui/text/multiline_text_input.rs) | Demonstrates a single multiline EditableText widget
625 [Multiple Text Inputs](../examples/ui/text/multiple_text_inputs.rs) | Demonstrates multiple text inputs
626 [Overflow](../examples/ui/scroll_and_overflow/overflow.rs) | Simple example demonstrating overflow behavior
627 [Overflow Clip Margin](../examples/ui/scroll_and_overflow/overflow_clip_margin.rs) | Simple example demonstrating the OverflowClipMargin style property
628 [Overflow Transform](../examples/ui/scroll_and_overflow/overflow_transform.rs) | Demonstrates nested transformed UI clipping
629 [Overflow and Clipping Debug](../examples/ui/scroll_and_overflow/overflow_debug.rs) | An example to debug overflow and clipping behavior
630 [Relative Cursor Position](../examples/ui/relative_cursor_position.rs) | Showcases the RelativeCursorPosition component
631 [Render UI to Texture](../examples/ui/render_ui_to_texture.rs) | An example of rendering UI as a part of a 3D world
632 [Scroll](../examples/ui/scroll_and_overflow/scroll.rs) | Demonstrates scrolling UI containers
633 [Scrollbars](../examples/ui/scroll_and_overflow/scrollbars.rs) | Demonstrates use of core scrollbar in Bevy UI
634 [Size Constraints](../examples/ui/layout/size_constraints.rs) | Demonstrates how the to use the size constraints to control the size of a UI node.
635 [Stacked Gradients](../examples/ui/styling/stacked_gradients.rs) | An example demonstrating stacked gradients
636 [Standard Widgets](../examples/ui/widgets/standard_widgets.rs) | Demonstrates use of core (headless) widgets in Bevy UI
637 [Standard Widgets (w/Observers)](../examples/ui/widgets/standard_widgets_observers.rs) | Demonstrates use of core (headless) widgets in Bevy UI, with Observers
638 [Strikethrough and Underline](../examples/ui/text/strikethrough_and_underline.rs) | Demonstrates how to display text with strikethrough and underline.
639 [System Fonts](../examples/ui/text/system_fonts.rs) | Demonstrates how to use system fonts
640 [Tab Navigation](../examples/ui/widgets/tab_navigation.rs) | Demonstration of Tab Navigation between UI elements
641 [Text](../examples/ui/text/text.rs) | Illustrates creating and updating text
642 [Text Background Colors](../examples/ui/text/text_background_colors.rs) | Demonstrates text background colors
643 [Text Debug](../examples/ui/text/text_debug.rs) | An example for debugging text layout
644 [Text Input](../examples/ui/text/text_input.rs) | Demonstrates a simple, unstyled text input widget
645 [Text Wrap Debug](../examples/ui/text/text_wrap_debug.rs) | Demonstrates text wrapping
646 [Transparency UI](../examples/ui/styling/transparency_ui.rs) | Demonstrates transparency for UI
647 [UI Drag and Drop](../examples/ui/ui_drag_and_drop.rs) | Demonstrates dragging and dropping UI nodes
648 [UI Material](../examples/ui/ui_material.rs) | Demonstrates creating and using custom Ui materials
649 [UI Scaling](../examples/ui/ui_scaling.rs) | Illustrates how to scale the UI
650 [UI Target Camera](../examples/ui/ui_target_camera.rs) | Demonstrates how to use `UiTargetCamera` and camera ordering.
651 [UI Texture Atlas](../examples/ui/images/ui_texture_atlas.rs) | Illustrates how to use TextureAtlases in UI
652 [UI Texture Atlas Slice](../examples/ui/images/ui_texture_atlas_slice.rs) | Illustrates how to use 9 Slicing for TextureAtlases in UI
653 [UI Texture Slice](../examples/ui/images/ui_texture_slice.rs) | Illustrates how to use 9 Slicing in UI
654 [UI Texture Slice Flipping and Tiling](../examples/ui/images/ui_texture_slice_flip_and_tile.rs) | Illustrates how to flip and tile images with 9 Slicing in UI
655 [UI Transform](../examples/ui/ui_transform.rs) | An example demonstrating how to translate, rotate and scale UI elements.
656 [UI Z-Index](../examples/ui/layout/z_index.rs) | Demonstrates how to control the relative depth (z-position) of UI elements
657 [Vertical Slider](../examples/ui/widgets/vertical_slider.rs) | Simple example showing vertical and horizontal slider widgets with snap behavior and value labels
658 [Viewport Node](../examples/ui/widgets/viewport_node.rs) | Demonstrates how to create a viewport node with picking support
659 [Virtual Keyboard](../examples/ui/widgets/virtual_keyboard.rs) | Example demonstrating a virtual keyboard widget
660 [Window Fallthrough](../examples/ui/window_fallthrough.rs) | Illustrates how to access `winit::window::Window`'s `hittest` functionality.
661
662 ### Usage
663
664 Example | Description
665 --- | ---
666 [Character Creation with UI Widgets](../examples/usage/character_creation.rs) | Demonstrates how to use headless widgets to power a Character Creation Menu
667 [Context Menu](../examples/usage/context_menu.rs) | Example of a context menu
668 [Cooldown](../examples/usage/cooldown.rs) | Example for cooldown on button clicks
669 [Debug Frustum Culling](../examples/usage/debug_frustum_culling.rs) | Example demonstrating how to debug frustum culling
670
671 ### Window
672
673 Example | Description
674 --- | ---
675 [Clear Color](../examples/window/clear_color.rs) | Creates a solid color window
676 [Custom Cursor Image](../examples/window/custom_cursor_image.rs) | Demonstrates creating an animated custom cursor from an image
677 [Low Power](../examples/window/low_power.rs) | Demonstrates settings to reduce power use for bevy applications
678 [Monitor info](../examples/window/monitor_info.rs) | Displays information about available monitors (displays).
679 [Multiple Windows](../examples/window/multiple_windows.rs) | Demonstrates creating multiple windows, and rendering to them
680 [Scale Factor Override](../examples/window/scale_factor_override.rs) | Illustrates how to customize the default window settings
681 [Screenshot](../examples/window/screenshot.rs) | Shows how to save screenshots to disk
682 [Transparent Window](../examples/window/transparent_window.rs) | Illustrates making the window transparent and hiding the window decoration
683 [Window Drag Move](../examples/window/window_drag_move.rs) | Demonstrates drag move and drag resize without window decoration
684 [Window Resizing](../examples/window/window_resizing.rs) | Demonstrates resizing and responding to resizing a window
685 [Window Settings](../examples/window/window_settings.rs) | Demonstrates customizing default window settings
686
687 ### glTF
688
689 Example | Description
690 --- | ---
691 [Custom glTF vertex attribute 2D](../examples/gltf/custom_gltf_vertex_attribute.rs) | Renders a glTF mesh in 2D with a custom vertex attribute
692 [Edit glTF Material](../examples/gltf/edit_material_on_gltf.rs) | Showcases changing materials of a glTF after Scene spawn
693 [Load glTF](../examples/gltf/load_gltf.rs) | Loads and renders a glTF file as a scene
694 [Load glTF extras](../examples/gltf/load_gltf_extras.rs) | Loads and renders a glTF file as a scene, including the gltf extras
695 [Query glTF primitives](../examples/gltf/query_gltf_primitives.rs) | Query primitives in a glTF scene
696 [Update glTF Scene](../examples/gltf/update_gltf_scene.rs) | Update a scene from a glTF file, either by spawning the scene as a child of another entity, or by accessing the entities of the scene
697 [glTF Skinned Mesh](../examples/gltf/gltf_skinned_mesh.rs) | Skinned mesh example with mesh and joints data loaded from a glTF file
698 [glTF extension AnimationGraph](../examples/gltf/gltf_extension_animation_graph.rs) | Uses glTF data to build an AnimationGraph via extension processing
699 [glTF extension processing to build Mesh2ds from glTF data](../examples/gltf/gltf_extension_mesh_2d.rs) | Uses glTF extension data to convert incoming Mesh3d/MeshMaterial3d assets to 2d
700
701 ## Tests
702
703 Example | Description
704 --- | ---
705 [How to Test Apps](../tests/how_to_test_apps.rs) | How to test apps (simple integration testing)
706 [How to Test Systems](../tests/how_to_test_systems.rs) | How to test systems with commands, queries or resources
707
708 ## Platform-Specific Examples
709
710 `bevy_mobile_example` sets `strip = true` in the workspace `Cargo.toml` to keep app bundles reasonable. Remove the `strip` override if you need native debug symbols.
711
712 ### Android
713
714 #### Setup
715
716 ```sh
717 rustup target add aarch64-linux-android
718 cargo install cargo-ndk
719 ```
720
721 The Android SDK must be installed, and the environment variable `ANDROID_SDK_ROOT` set to the root Android `sdk` folder.
722
723 When using `NDK (Side by side)`, the environment variable `ANDROID_NDK_ROOT` must also be set to one of the NDKs in `sdk\ndk\[NDK number]`.
724
725 Alternatively, you can install Android Studio.
726
727 #### Build & Run
728
729 To build an Android app, you first need to build shared object files for the target architecture with `cargo-ndk`:
730
731 ```sh
732 cargo ndk -t <target_name> -P 26 -o <project_name>/app/src/main/jniLibs build
733 ```
734
735 For example, to compile to a 64-bit ARM platform:
736
737 ```sh
738 cargo ndk -t arm64-v8a -P 26 -o android_example/app/src/main/jniLibs build
739 ```
740
741 Setting the output path ensures the shared object files can be found in target-specific directories under `jniLibs` where the JNI can find them.
742
743 See the `cargo-ndk` [README](https://crates.io/crates/cargo-ndk) for other options.
744
745 After this you can build it with `gradlew`:
746
747 ```sh
748 ./gradlew build
749 ```
750
751 Or build it with Android Studio.
752
753 Then you can test it in your Android project.
754
755 #### Debugging
756
757 You can view the logs with the following command:
758
759 ```sh
760 adb logcat | grep 'RustStdoutStderr\|bevy\|wgpu'
761 ```
762
763 In case of an error getting a GPU or setting it up, you can try settings logs of `wgpu_hal` to `DEBUG` to get more information.
764
765 Sometimes, running the app complains about an unknown activity. This may be fixed by uninstalling the application:
766
767 ```sh
768 adb uninstall org.bevyengine.example
769 ```
770
771 #### Old phones
772
773 In its examples, Bevy targets the minimum Android API that Play Store <!-- markdown-link-check-disable -->
774 [requires](https://developer.android.com/distribute/best-practices/develop/target-sdk) to upload and update apps. <!-- markdown-link-check-enable -->
775 Users of older phones may want to use an older API when testing. By default, Bevy uses [`GameActivity`](https://developer.android.com/games/agdk/game-activity), which only works for Android API level 31 and higher, so if you want to use older API, you need to switch to `NativeActivity`.
776
777 Keep in mind that if you are using `bevy_audio` the minimum supported Android API version is 26 (Android 8/Oreo).
778
779 To use `NativeActivity`, you need to edit it in `cargo.toml` manually like this:
780
781 ```toml
782 bevy = { version = "0.19", features = ["android-native-activity"] }
783 ```
784
785 Then build it as the [Build & Run](#build--run) section stated above.
786
787 ##### About `cargo-apk`
788
789 You can also build an APK with `cargo-apk`, a simpler and deprecated tool which doesn't support `GameActivity`. If you want to use this, there is a [folder](./mobile/android_basic) inside the mobile example with instructions.
790
791 Example | File | Description
792 --- | --- | ---
793 `android` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound
794
795 ### iOS
796
797 #### Setup
798
799 You need to install the correct Rust targets:
800
801 - `aarch64-apple-ios`: iOS devices
802 - `x86_64-apple-ios`: iOS simulator on x86 processors
803 - `aarch64-apple-ios-sim`: iOS simulator on Apple processors
804
805 ```sh
806 rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim
807 ```
808
809 #### Build & Run
810
811 Using bash:
812
813 ```sh
814 cd examples/mobile
815 make run
816 ```
817
818 In an ideal world, this will boot up, install and run the app for the first
819 iOS simulator in your `xcrun simctl list devices`. If this fails, you can
820 specify the simulator device UUID via:
821
822 ```sh
823 DEVICE_ID=${YOUR_DEVICE_ID} make run
824 ```
825
826 If you'd like to see xcode do stuff, you can run
827
828 ```sh
829 open bevy_mobile_example.xcodeproj/
830 ```
831
832 which will open xcode. You then must push the zoom zoom play button and wait
833 for the magic.
834
835 Example | File | Description
836 --- | --- | ---
837 `ios` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound
838
839 ### Wasm
840
841 #### Setup
842
843 ```sh
844 rustup target add wasm32-unknown-unknown
845 cargo install wasm-bindgen-cli
846 ```
847
848 #### Build & Run
849
850 Following is an example for `lighting`. For other examples, change the `lighting` in the
851 following commands.
852
853 ```sh
854 cargo build --release --example lighting --target wasm32-unknown-unknown
855 wasm-bindgen --out-name wasm_example \
856 --out-dir examples/wasm/target \
857 --target web target/wasm32-unknown-unknown/release/examples/lighting.wasm
858 ```
859
860 The first command will build the example for the wasm target, creating a binary. Then,
861 [wasm-bindgen-cli](https://rustwasm.github.io/wasm-bindgen/reference/cli.html) is used to create
862 javascript bindings to this wasm file in the output file `examples/wasm/target/wasm_example.js`, which can be loaded using this
863 [example HTML file](./wasm/index.html).
864
865 Then serve `examples/wasm` directory to browser. i.e.
866
867 ```sh
868 ## cargo install basic-http-server
869 basic-http-server examples/wasm
870
871 ## with python
872 python3 -m http.server --directory examples/wasm
873
874 ## with ruby
875 ruby -run -ehttpd examples/wasm
876 ```
877
878 ##### WebGL2 and WebGPU
879
880 Bevy support for WebGPU is being worked on, but is currently experimental.
881
882 To build for WebGPU, you'll need to enable the `webgpu` feature. This will override the `webgl2` feature, and builds with the `webgpu` feature enabled won't be able to run on browsers that don't support WebGPU.
883
884 Bevy has a helper to build its examples:
885
886 - Build for WebGL2: `cargo run -p build-wasm-example -- --api webgl2 load_gltf`
887 - Build for WebGPU: `cargo run -p build-wasm-example -- --api webgpu load_gltf`
888 - Debug: `cargo run -p build-wasm-example -- --debug --api webgl2 load_gltf`
889
890 This helper will log the command used to build the examples.
891
892 #### Audio in the browsers
893
894 For the moment, everything is single threaded, this can lead to stuttering when playing audio in browsers. Not all browsers react the same way for all games, you will have to experiment for your game.
895
896 In browsers, audio is not authorized to start without being triggered by an user interaction. This is to avoid multiple tabs all starting to auto play some sounds. You can find more context and explanation for this on [Google Chrome blog](https://developer.chrome.com/blog/web-audio-autoplay/). This page also describes a JS workaround to resume audio as soon as the user interacts with your game.
897
898 #### Optimizing
899
900 On the web, it's useful to reduce the size of the files that are distributed.
901 With Rust, there are many ways to improve your executable sizes, starting with
902 the steps described in [the quick-start guide](https://bevy.org/learn/quick-start/getting-started/setup/#compile-with-performance-optimizations).
903
904 Now, when building the executable, use `--profile wasm-release` instead of `--release`:
905
906 ```sh
907 cargo build --profile wasm-release --example lighting --target wasm32-unknown-unknown
908 ```
909
910 To apply `wasm-opt`, first locate the `.wasm` file generated in the `--out-dir` of the
911 earlier `wasm-bindgen-cli` command (the filename should end with `_bg.wasm`), then run:
912
913 ```sh
914 wasm-opt -Oz --output optimized.wasm examples/wasm/target/lighting_bg.wasm
915 mv optimized.wasm examples/wasm/target/lighting_bg.wasm
916 ```
917
918 Make sure your final executable size is actually smaller. Some optimizations
919 may not be worth keeping due to compilation time increases.
920
921 For a small project with a basic 3d model and two lights,
922 the generated file sizes are, as of July 2022, as follows:
923
924 profile | wasm-opt | no wasm-opt
925 ----------------------------------|----------|-------------
926 Default | 8.5M | 13.0M
927 opt-level = "z" | 6.1M | 12.7M
928 "z" + lto = "thin" | 5.9M | 12M
929 "z" + lto = "fat" | 5.1M | 9.4M
930 "z" + "thin" + codegen-units = 1 | 5.3M | 11M
931 "z" + "fat" + codegen-units = 1 | 4.8M | 8.5M
932
933 #### Loading Assets
934
935 To load assets, they need to be available in the folder examples/wasm/assets. Cloning this
936 repository will set it up as a symlink on Linux and macOS, but you will need to manually move
937 the assets on Windows.