use crate::prelude::*;
use bevy::prelude::*;
#[cfg_attr(feature = "2d", doc = "use bevy_xpbd_2d::prelude::*;")]
#[cfg_attr(feature = "3d", doc = "use bevy_xpbd_3d::prelude::*;")]
#[derive(Reflect, Resource)]
#[reflect(Resource)]
pub struct PhysicsDebugConfig {
pub enabled: bool,
pub axis_lengths: Option<Vector>,
pub aabb_color: Option<Color>,
pub collider_color: Option<Color>,
pub sleeping_color_multiplier: Option<[f32; 4]>,
pub contact_color: Option<Color>,
pub joint_anchor_color: Option<Color>,
pub joint_separation_color: Option<Color>,
pub raycast_color: Option<Color>,
pub raycast_point_color: Option<Color>,
pub raycast_normal_color: Option<Color>,
pub shapecast_color: Option<Color>,
pub shapecast_shape_color: Option<Color>,
pub shapecast_point_color: Option<Color>,
pub shapecast_normal_color: Option<Color>,
pub hide_meshes: bool,
}
impl Default for PhysicsDebugConfig {
fn default() -> Self {
Self {
enabled: true,
#[cfg(feature = "2d")]
axis_lengths: Some(Vector::new(5.0, 5.0)),
#[cfg(feature = "3d")]
axis_lengths: Some(Vector::new(0.5, 0.5, 0.5)),
aabb_color: None,
collider_color: Some(Color::ORANGE),
sleeping_color_multiplier: Some([1.0, 1.0, 0.4, 1.0]),
contact_color: None,
joint_anchor_color: Some(Color::PINK),
joint_separation_color: Some(Color::RED),
raycast_color: Some(Color::RED),
raycast_point_color: Some(Color::YELLOW),
raycast_normal_color: Some(Color::PINK),
shapecast_color: Some(Color::RED),
shapecast_shape_color: Some(Color::rgb(0.4, 0.6, 1.0)),
shapecast_point_color: Some(Color::YELLOW),
shapecast_normal_color: Some(Color::PINK),
hide_meshes: false,
}
}
}
impl PhysicsDebugConfig {
pub fn all() -> Self {
Self {
enabled: true,
#[cfg(feature = "2d")]
axis_lengths: Some(Vector::new(5.0, 5.0)),
#[cfg(feature = "3d")]
axis_lengths: Some(Vector::new(0.5, 0.5, 0.5)),
aabb_color: Some(Color::rgb(0.8, 0.8, 0.8)),
collider_color: Some(Color::ORANGE),
sleeping_color_multiplier: Some([1.0, 1.0, 0.4, 1.0]),
contact_color: Some(Color::CYAN),
joint_anchor_color: Some(Color::PINK),
joint_separation_color: Some(Color::RED),
raycast_color: Some(Color::RED),
raycast_point_color: Some(Color::YELLOW),
raycast_normal_color: Some(Color::PINK),
shapecast_color: Some(Color::RED),
shapecast_shape_color: Some(Color::rgb(0.4, 0.6, 1.0)),
shapecast_point_color: Some(Color::YELLOW),
shapecast_normal_color: Some(Color::PINK),
hide_meshes: true,
}
}
pub fn none() -> Self {
Self {
enabled: true,
axis_lengths: None,
aabb_color: None,
collider_color: None,
sleeping_color_multiplier: None,
contact_color: None,
joint_anchor_color: None,
joint_separation_color: None,
raycast_color: None,
raycast_point_color: None,
raycast_normal_color: None,
shapecast_color: None,
shapecast_shape_color: None,
shapecast_point_color: None,
shapecast_normal_color: None,
hide_meshes: false,
}
}
pub fn axes(axis_lengths: Vector) -> Self {
Self {
axis_lengths: Some(axis_lengths),
..Self::none()
}
}
pub fn aabbs(color: Color) -> Self {
Self {
aabb_color: Some(color),
..Self::none()
}
}
pub fn colliders(color: Color) -> Self {
Self {
collider_color: Some(color),
..Self::none()
}
}
pub fn contacts(color: Color) -> Self {
Self {
contact_color: Some(color),
..Self::none()
}
}
pub fn joints(anchor_color: Option<Color>, separation_color: Option<Color>) -> Self {
Self {
joint_anchor_color: anchor_color,
joint_separation_color: separation_color,
..Self::none()
}
}
pub fn with_axes(mut self, axis_lengths: Vector) -> Self {
self.axis_lengths = Some(axis_lengths);
self
}
pub fn with_aabb_color(mut self, color: Color) -> Self {
self.aabb_color = Some(color);
self
}
pub fn with_collider_color(mut self, color: Color) -> Self {
self.collider_color = Some(color);
self
}
pub fn with_sleeping_color_multiplier(mut self, color_multiplier: [f32; 4]) -> Self {
self.sleeping_color_multiplier = Some(color_multiplier);
self
}
pub fn with_contact_color(mut self, color: Color) -> Self {
self.contact_color = Some(color);
self
}
pub fn with_joint_colors(anchor_color: Option<Color>, separation_color: Option<Color>) -> Self {
Self {
joint_anchor_color: anchor_color,
joint_separation_color: separation_color,
..Self::none()
}
}
pub fn with_raycast_colors(
mut self,
ray: Option<Color>,
hit_point: Option<Color>,
hit_normal: Option<Color>,
) -> Self {
self.raycast_color = ray;
self.raycast_point_color = hit_point;
self.raycast_normal_color = hit_normal;
self
}
pub fn with_shapecast_colors(
mut self,
ray: Option<Color>,
shape: Option<Color>,
hit_point: Option<Color>,
hit_normal: Option<Color>,
) -> Self {
self.shapecast_color = ray;
self.shapecast_shape_color = shape;
self.shapecast_point_color = hit_point;
self.shapecast_normal_color = hit_normal;
self
}
pub fn with_mesh_visibility(mut self, is_visible: bool) -> Self {
self.hide_meshes = !is_visible;
self
}
pub fn without_axes(mut self) -> Self {
self.axis_lengths = None;
self
}
pub fn without_aabbs(mut self) -> Self {
self.aabb_color = None;
self
}
pub fn without_colliders(mut self) -> Self {
self.collider_color = None;
self
}
pub fn without_contacts(mut self) -> Self {
self.contact_color = None;
self
}
pub fn without_joints(mut self) -> Self {
self.joint_anchor_color = None;
self.joint_separation_color = None;
self
}
pub fn without_raycasts(mut self) -> Self {
self.raycast_color = None;
self.raycast_point_color = None;
self.raycast_normal_color = None;
self
}
pub fn without_shapecasts(mut self) -> Self {
self.shapecast_color = None;
self.shapecast_shape_color = None;
self.shapecast_point_color = None;
self.shapecast_normal_color = None;
self
}
}
#[cfg_attr(feature = "2d", doc = "use bevy_xpbd_2d::prelude::*;")]
#[cfg_attr(feature = "3d", doc = "use bevy_xpbd_3d::prelude::*;")]
#[derive(Component, Reflect, Clone, Copy, PartialEq)]
#[reflect(Component)]
pub struct DebugRender {
pub axis_lengths: Option<Vector>,
pub aabb_color: Option<Color>,
pub collider_color: Option<Color>,
pub sleeping_color_multiplier: Option<[f32; 4]>,
pub hide_mesh: bool,
}
impl Default for DebugRender {
fn default() -> Self {
Self {
#[cfg(feature = "2d")]
axis_lengths: Some(Vector::new(5.0, 5.0)),
#[cfg(feature = "3d")]
axis_lengths: Some(Vector::new(0.5, 0.5, 0.5)),
aabb_color: None,
collider_color: Some(Color::ORANGE),
sleeping_color_multiplier: Some([1.0, 1.0, 0.4, 1.0]),
hide_mesh: false,
}
}
}
impl DebugRender {
pub fn all() -> Self {
Self {
#[cfg(feature = "2d")]
axis_lengths: Some(Vector::new(5.0, 5.0)),
#[cfg(feature = "3d")]
axis_lengths: Some(Vector::new(0.5, 0.5, 0.5)),
aabb_color: Some(Color::rgb(0.8, 0.8, 0.8)),
collider_color: Some(Color::ORANGE),
sleeping_color_multiplier: Some([1.0, 1.0, 0.4, 1.0]),
hide_mesh: true,
}
}
pub fn none() -> Self {
Self {
axis_lengths: None,
aabb_color: None,
collider_color: None,
sleeping_color_multiplier: None,
hide_mesh: false,
}
}
pub fn axes(axis_lengths: Vector) -> Self {
Self {
axis_lengths: Some(axis_lengths),
..Self::none()
}
}
pub fn aabb(color: Color) -> Self {
Self {
aabb_color: Some(color),
..Self::none()
}
}
pub fn collider(color: Color) -> Self {
Self {
collider_color: Some(color),
..Self::none()
}
}
pub fn with_axes(mut self, axis_lengths: Vector) -> Self {
self.axis_lengths = Some(axis_lengths);
self
}
pub fn with_aabb_color(mut self, color: Color) -> Self {
self.aabb_color = Some(color);
self
}
pub fn with_collider_color(mut self, color: Color) -> Self {
self.collider_color = Some(color);
self
}
pub fn with_sleeping_color_multiplier(mut self, color_multiplier: [f32; 4]) -> Self {
self.sleeping_color_multiplier = Some(color_multiplier);
self
}
pub fn with_mesh_visibility(mut self, is_visible: bool) -> Self {
self.hide_mesh = !is_visible;
self
}
pub fn without_axes(mut self) -> Self {
self.axis_lengths = None;
self
}
pub fn without_aabb(mut self) -> Self {
self.aabb_color = None;
self
}
pub fn without_collider(mut self) -> Self {
self.collider_color = None;
self
}
}