Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.19.0

- Changed: updated to Bevy 0.15.
- Use `Dir3` instead of `Vec3` for normalized directions in `Ray3d::new`

# 0.18.0

- Changed: updated to Bevy 0.14.
Expand Down
30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_raycast"
version = "0.18.0"
version = "0.19.0"
authors = ["Aevyrie <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -11,23 +11,23 @@ categories = ["game-engines", "rendering"]
resolver = "2"

[dependencies]
bevy_app = { version = "0.14.0", default-features = false }
bevy_asset = { version = "0.14.0", default-features = false }
bevy_derive = { version = "0.14.0", default-features = false }
bevy_ecs = { version = "0.14.0", default-features = false }
bevy_gizmos = { version = "0.14.0", optional = true, default-features = false }
bevy_math = { version = "0.14.0", default-features = false }
bevy_reflect = { version = "0.14.0", default-features = false }
bevy_render = { version = "0.14.0", default-features = false }
bevy_sprite = { version = "0.14.0", optional = true, default-features = false }
bevy_transform = { version = "0.14.0", default-features = false }
bevy_utils = { version = "0.14.0", default-features = false }
bevy_window = { version = "0.14.0", default-features = false }
bevy_color = { version = "0.14.0", default-features = false }
bevy_app = { version = "0.15.0", default-features = false }
bevy_asset = { version = "0.15.0", default-features = false }
bevy_derive = { version = "0.15.0", default-features = false }
bevy_ecs = { version = "0.15.0", default-features = false }
bevy_gizmos = { version = "0.15.0", optional = true, default-features = false }
bevy_math = { version = "0.15.0", default-features = false }
bevy_reflect = { version = "0.15.0", default-features = false }
bevy_render = { version = "0.15.0", default-features = false }
bevy_sprite = { version = "0.15.0", optional = true, default-features = false }
bevy_transform = { version = "0.15.0", default-features = false }
bevy_utils = { version = "0.15.0", default-features = false }
bevy_window = { version = "0.15.0", default-features = false }
bevy_color = { version = "0.15.0", default-features = false }
crossbeam-channel = "0.5"

[dev-dependencies]
bevy = { version = "0.14.0", default-features = true, features = [
bevy = { version = "0.15.0", default-features = true, features = [
"default_font",
"ktx2",
"tonemapping_luts",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ I intend to track the `main` branch of Bevy. PRs supporting this are welcome!

| bevy | bevy_mod_raycast |
| ---- | ---------------- |
| 0.15 | 0.19 |
| 0.14 | 0.18 |
| 0.13 | 0.17 |
| 0.12 | 0.16 |
Expand Down
19 changes: 9 additions & 10 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fn main() {
const RAY_DIST: Vec3 = Vec3::new(0.0, 0.0, -7.0);

fn raycast(mut raycast: Raycast, mut gizmos: Gizmos, time: Res<Time>) {
let t = time.elapsed_seconds();
let t = time.elapsed_secs();
let pos = Vec3::new(t.sin(), (t * 1.5).cos() * 2.0, t.cos()) * 1.5 + RAY_DIST;
let dir = (RAY_DIST - pos).normalize();
let dir = Dir3::new(RAY_DIST - pos).unwrap();
// This is all that is needed to raycast into the world! You can also use the normal, non-debug
// version (raycast.cast_ray) when you don't need to visualize the ray or intersections.
raycast.debug_cast_ray(Ray3d::new(pos, dir), &default(), &mut gizmos);
Expand All @@ -29,12 +29,11 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn(Camera3dBundle::default());
commands.spawn(PointLightBundle::default());
commands.spawn(PbrBundle {
mesh: meshes.add(Capsule3d::default()),
material: materials.add(Color::srgb(1.0, 1.0, 1.0)),
transform: Transform::from_translation(RAY_DIST),
..default()
});
commands.spawn(Camera3d::default());
commands.spawn(PointLight::default());
commands.spawn((
Mesh3d(meshes.add(Capsule3d::default())),
MeshMaterial3d(materials.add(Color::srgb(1.0, 1.0, 1.0))),
Transform::from_translation(RAY_DIST),
));
}
18 changes: 8 additions & 10 deletions examples/minimal_deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct MyRaycastSet; // Groups raycast sources with meshes, can use `()` instead
struct MovingRaycaster;

fn move_ray(time: Res<Time>, mut query: Query<&mut Transform, With<MovingRaycaster>>) {
let t = time.elapsed_seconds();
let t = time.elapsed_secs();
let pos = Vec3::new(t.sin(), (t * 1.5).cos() * 2.0, t.cos()) * 1.5 + RAY_DIST;
let dir = (RAY_DIST - pos).normalize();
*query.single_mut() = Transform::from_translation(pos).looking_to(dir, Vec3::Y);
Expand All @@ -36,22 +36,20 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn(Camera3dBundle::default());
commands.spawn(PointLightBundle::default());
commands.spawn(Camera3d::default());
commands.spawn(PointLight::default());
// Unlike the immediate mode API where the raycast is built every frame in a system, instead we
// spawn an entity and mark it as a raycasting source, using its `GlobalTransform`.
commands.spawn((
MovingRaycaster,
SpatialBundle::default(),
Transform::default(),
Visibility::default(),
RaycastSource::<MyRaycastSet>::new_transform_empty(),
));
commands.spawn((
PbrBundle {
mesh: meshes.add(Capsule3d::default()),
material: materials.add(Color::srgb(1.0, 1.0, 1.0)),
transform: Transform::from_translation(RAY_DIST),
..default()
},
Mesh3d(meshes.add(Capsule3d::default())),
MeshMaterial3d(materials.add(Color::srgb(1.0, 1.0, 1.0))),
Transform::from_translation(RAY_DIST),
RaycastMesh::<MyRaycastSet>::default(), // Make this mesh ray cast-able
));
}
15 changes: 7 additions & 8 deletions examples/mouse_picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn(Camera3dBundle::default());
commands.spawn(PointLightBundle::default());
commands.spawn(PbrBundle {
mesh: meshes.add(Sphere::default()),
material: materials.add(Color::from(css::GRAY)),
transform: Transform::from_xyz(0.0, 0.0, -5.0),
..default()
});
commands.spawn(Camera3d::default());
commands.spawn(PointLight::default());
commands.spawn((
Mesh3d(meshes.add(Sphere::default())),
MeshMaterial3d(materials.add(Color::from(css::GRAY))),
Transform::from_xyz(0.0, 0.0, -5.0),
));
}
15 changes: 6 additions & 9 deletions examples/mouse_picking_2d.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::{color::palettes::css, prelude::*, sprite::MaterialMesh2dBundle};
use bevy::{color::palettes::css, prelude::*};
use bevy_mod_raycast::prelude::*;

fn main() {
Expand All @@ -16,16 +16,13 @@ fn main() {
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn((Camera2dBundle::default(), RaycastSource::<()>::new_cursor()));
commands.spawn((Camera2d::default(), RaycastSource::<()>::new_cursor()));
commands.spawn((
MaterialMesh2dBundle {
mesh: meshes.add(Circle::default()).into(),
transform: Transform::default().with_scale(Vec3::splat(128.)),
material: materials.add(ColorMaterial::from(Color::from(css::PURPLE))),
..default()
},
Mesh3d(meshes.add(Circle::default()).into()),
MeshMaterial3d(materials.add(Color::from(css::PURPLE))),
Transform::default().with_scale(Vec3::splat(128.)),
RaycastMesh::<()>::default(), // Make this mesh ray cast-able;
));
}
13 changes: 5 additions & 8 deletions examples/mouse_picking_deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn((
Camera3dBundle::default(),
Camera3d::default(),
RaycastSource::<()>::new_cursor(), // Set this camera as a raycaster using the mouse cursor
));
commands.spawn(PointLightBundle::default());
commands.spawn(PointLight::default());
commands.spawn((
PbrBundle {
mesh: meshes.add(Sphere::default()),
material: materials.add(Color::from(css::GRAY)),
transform: Transform::from_xyz(0.0, 0.0, -5.0),
..default()
},
Mesh3d(meshes.add(Sphere::default())),
MeshMaterial3d(materials.add(Color::from(css::GRAY))),
Transform::from_xyz(0.0, 0.0, -5.0),
RaycastMesh::<()>::default(), // Make this mesh ray cast-able;
));
}
51 changes: 24 additions & 27 deletions examples/reflecting_laser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::f32::consts::{FRAC_PI_2, PI};

use bevy::{color::palettes::css, core_pipeline::bloom::BloomSettings, math::vec3, prelude::*};
use bevy::{color::palettes::css, core_pipeline::tonemapping::Tonemapping, math::vec3, prelude::*};
use bevy_mod_raycast::prelude::*;

fn main() {
Expand All @@ -30,11 +30,11 @@ fn bouncing_raycast(
time: Res<Time>,
cursor_ray: Res<CursorRay>,
) {
let t = ((time.elapsed_seconds() - 4.0).max(0.0) * LASER_SPEED).cos() * std::f32::consts::PI;
let t = ((time.elapsed_secs() - 4.0).max(0.0) * LASER_SPEED).cos() * std::f32::consts::PI;
let ray_pos = Vec3::new(t.sin(), (3.0 * t).cos() * 0.5, t.cos()) * 0.5;
let ray_dir = (-ray_pos).normalize();
let ray_dir = Dir3::new(-ray_pos).unwrap();
let ray = Ray3d::new(ray_pos, ray_dir);
gizmos.sphere(ray_pos, Quat::IDENTITY, 0.1, Color::WHITE);
gizmos.sphere(Isometry3d::from_translation(ray_pos), 0.1, Color::WHITE);
bounce_ray(ray, &mut raycast, &mut gizmos, Color::from(css::RED));

if let Some(cursor_ray) = **cursor_ray {
Expand All @@ -56,8 +56,7 @@ fn bounce_ray(mut ray: Ray3d, raycast: &mut Raycast, gizmos: &mut Gizmos, color:
let bright = 1.0 + 10.0 * (1.0 - i as f32 / MAX_BOUNCES as f32);
intersections.push((hit.position(), Color::BLACK.mix(&color, bright)));
gizmos.sphere(
hit.position(),
Quat::IDENTITY,
Isometry3d::from_translation(hit.position()),
0.005,
Color::BLACK.mix(&color, bright * 2.0),
);
Expand All @@ -79,32 +78,30 @@ fn setup_scene(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn(DirectionalLightBundle {
transform: Transform::from_rotation(Quat::from_euler(EulerRot::XYZ, -0.1, 0.2, 0.0)),
..default()
});
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(1.5, 1.5, 1.5).looking_at(Vec3::ZERO, Vec3::Y),
camera: Camera {
hdr: true,
..default()
},
tonemapping: bevy::core_pipeline::tonemapping::Tonemapping::TonyMcMapface,
DirectionalLight::default(),
Transform::from_rotation(Quat::from_euler(EulerRot::XYZ, -0.1, 0.2, 0.0)),
));
commands.spawn((
Transform::from_xyz(1.5, 1.5, 1.5).looking_at(Vec3::ZERO, Vec3::Y),
Camera3d::default(),
Camera {
hdr: true,
..default()
},
BloomSettings::default(),
Tonemapping::TonyMcMapface,
));
// Make a box of planes facing inward so the laser gets trapped inside:
let plane = PbrBundle {
mesh: meshes.add(Plane3d::default()),
material: materials.add(Color::from(css::GRAY).with_alpha(0.01)),
..default()
};
let pbr_bundle = move |translation, rotation| PbrBundle {
transform: Transform::from_translation(translation)
.with_rotation(Quat::from_scaled_axis(rotation)),
..plane.clone()
let plane = (
Mesh3d(meshes.add(Plane3d::default())),
MeshMaterial3d(materials.add(Color::from(css::GRAY).with_alpha(0.01))),
);
let pbr_bundle = move |translation, rotation| {
(
Transform::from_translation(translation)
.with_rotation(Quat::from_scaled_axis(rotation)),
plane.clone(),
)
};
commands.spawn(pbr_bundle(vec3(0.0, 0.5, 0.0), Vec3::X * PI));
commands.spawn(pbr_bundle(vec3(0.0, -0.5, 0.0), Vec3::ZERO));
Expand Down
Loading