Skip to content

Instantly share code, notes, and snippets.

@rparrett
rparrett / notes.md
Created June 7, 2024 20:03
Bevy 0.14 migration notes

It would be nice to also mention the new type path for States:

// 0.13
bevy::ecs::schedule::{NextState, OnEnter, OnExit, OnTransition, State, States}
// 0.14
bevy::state::state::{NextState, OnEnter, OnExit, OnTransition, State, States}
@rparrett
rparrett / many_texts.rs
Last active May 14, 2024 19:55
Bevy 0.13 adding Aabb to Text2d
//! Renders a lot of `Text2dBundle`s and adds `Aabb`s so they get automatically culled when out of view.
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
math::Vec3A,
prelude::*,
render::primitives::Aabb,
text::TextLayoutInfo,
};
@rparrett
rparrett / has-two-approvals.jq
Last active February 19, 2024 14:05
Find Bevy PRs that have two approvals but lack the `S-Ready-For-Final-Review` label
def filter(cond): map(select(cond));
.[] | [
.number,
(.reviews | filter(.state=="APPROVED") | unique_by(.author.login) | length),
(.labels | any(.name == "S-Ready-For-Final-Review" or .name == "S-Blocked" or .name == "S-Needs-Benchmarking" or .name == "S-Needs-Design" or .name == "S-Adopt-Me" or .name == "S-Needs-RFC" ) | not)
] | select((.[1] >= 2) and .[2]) | ("<a href=\"https://github.com/bevyengine/bevy/pull/" + (.[0] | tostring) + "\">" + (.[0] | tostring) + "</a><br/>")
@rparrett
rparrett / debug_normals.rs
Last active February 14, 2024 19:54
Bevy 0.13 `3d_shapes.rs` but with normal debugging gizmos and wireframes
//! This example demonstrates the built-in 3d shapes in Bevy.
//! The scene includes a patterned texture and a rotation for visualizing the normals and UVs.
use std::f32::consts::PI;
use bevy::{
input::common_conditions::input_just_pressed,
pbr::wireframe::{Wireframe, WireframePlugin},
prelude::*,
render::{
@rparrett
rparrett / repeat.rs
Last active January 11, 2024 22:29
Bevy 0.12 2d Repeating Image
use bevy::{
prelude::*,
render::{
mesh::VertexAttributeValues,
texture::{ImageAddressMode, ImageLoaderSettings, ImageSampler, ImageSamplerDescriptor},
},
sprite::MaterialMesh2dBundle,
};
fn main() {
@rparrett
rparrett / hollow_circle.rs
Last active June 6, 2024 21:43
Bevy 0.12 hollow circle mesh
// This sort of thing will be built into Bevy in version 0.14 by meshing the new `Annulus` primitive.
pub fn hollow_circle(inner_radius: f32, thickness: f32, sides: usize) -> Mesh {
let outer_radius = inner_radius + thickness;
debug_assert!(sides > 2, "hollow_circle requires at least 3 sides.");
let vertices = sides * 2;
let mut positions = Vec::with_capacity(vertices);
@rparrett
rparrett / modify_gltf_material.rs
Last active October 15, 2023 14:19
Bevy 0.11: Modify a material in GLTF file after spawning it without changing other GLTFs
use bevy::{prelude::*, scene::SceneInstance};
#[derive(Component)]
struct RedFox;
#[derive(Component)]
struct Decorated;
#[derive(Resource)]
struct RedMaterial(Handle<StandardMaterial>);
@rparrett
rparrett / no_focus_on_mac.patch
Last active August 31, 2023 14:24
(macos) Make new windows from bevy's example-showcase --screenshot not steal focus
diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs
index 8c79494de..7bd737744 100644
--- a/crates/bevy_winit/src/lib.rs
+++ b/crates/bevy_winit/src/lib.rs
@@ -47,6 +47,9 @@ use bevy_window::{
#[cfg(target_os = "android")]
pub use winit::platform::android::activity::AndroidApp;
+#[cfg(target_os = "macos")]
+use winit::platform::macos::EventLoopBuilderExtMacOS;
@rparrett
rparrett / diff.diff
Created July 10, 2023 14:31
bevy_ecs_tilemap shaders 0.11
diff --git a/src/render/shaders/tilemap_fragment.wgsl b/src/render/shaders/tilemap_fragment.wgsl
index be535aa..e515117 100644
--- a/src/render/shaders/tilemap_fragment.wgsl
+++ b/src/render/shaders/tilemap_fragment.wgsl
@@ -1,15 +1,9 @@
+#import bevy_ecs_tilemap::vertex_output MeshVertexOutput
+#import bevy_ecs_tilemap::common tilemap_data
#import bevy_ecs_tilemap::common sprite_texture, sprite_sampler
-struct VertexOutput {
@rparrett
rparrett / change.diff
Last active March 14, 2023 18:11
bevy_mod_parallax scaling
diff --git a/examples/cyberpunk.rs b/examples/cyberpunk.rs
index 1d27172..45ff7eb 100644
--- a/examples/cyberpunk.rs
+++ b/examples/cyberpunk.rs
@@ -1,9 +1,11 @@
use bevy::prelude::*;
use bevy_parallax::{
- LayerData, LayerSpeed, ParallaxCameraComponent, ParallaxMoveEvent, ParallaxPlugin,
- ParallaxResource,
+ LayerComponent, LayerData, LayerSpeed, ParallaxCameraComponent, ParallaxMoveEvent,