refactor(examples): Remove RigidBodyProxy (not necessary anymore) (#16)

This commit is contained in:
GitGhillie 2023-10-10 22:05:41 +02:00 committed by GitHub
parent 94b20bdf0e
commit 4866ce1620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1 additions and 70 deletions

View File

@ -17,7 +17,6 @@ impl Plugin for PhysicsPlugin {
app app
.register_type::<AutoAABBCollider>() .register_type::<AutoAABBCollider>()
.register_type::<physics_replace_proxies::Collider>() .register_type::<physics_replace_proxies::Collider>()
.register_type::<physics_replace_proxies::RigidBodyProxy>()
// find a way to make serde's stuff serializable // find a way to make serde's stuff serializable
// .register_type::<bevy_rapier3d::dynamics::CoefficientCombineRule>() // .register_type::<bevy_rapier3d::dynamics::CoefficientCombineRule>()

View File

@ -1,21 +1,10 @@
use bevy::prelude::*; use bevy::prelude::*;
// use bevy::render::primitives::Aabb; // use bevy::render::primitives::Aabb;
use bevy_rapier3d::geometry::Collider as RapierCollider; use bevy_rapier3d::geometry::Collider as RapierCollider;
use bevy_rapier3d::dynamics::RigidBody as RapierRigidBody;
use bevy_rapier3d::prelude::{ComputedColliderShape, ActiveEvents, ActiveCollisionTypes}; use bevy_rapier3d::prelude::{ComputedColliderShape, ActiveEvents, ActiveCollisionTypes};
use super::utils::*; use super::utils::*;
#[derive(Component, Reflect, Default, Debug, )]
#[reflect(Component)]
pub enum RigidBodyProxy{
#[default]
Dynamic,
Fixed,
Position,
Velocity
}
#[derive(Component, Reflect, Default, Debug, )] #[derive(Component, Reflect, Default, Debug, )]
#[reflect(Component)] #[reflect(Component)]
pub enum Collider { pub enum Collider {
@ -40,8 +29,6 @@ pub enum AutoAABBCollider {
pub fn physics_replace_proxies ( pub fn physics_replace_proxies (
meshes: Res<Assets<Mesh>>, meshes: Res<Assets<Mesh>>,
mesh_handles: Query<&Handle<Mesh>>, mesh_handles: Query<&Handle<Mesh>>,
// rigidbodies
proxy_rigidbodies: Query<(Entity, &RigidBodyProxy,), (Without<RapierRigidBody>, Added<RigidBodyProxy>)>,
mut proxy_colliders: Query<(Entity, &Collider, &Name, &mut Visibility), (Without<RapierCollider>, Added<Collider>)>, mut proxy_colliders: Query<(Entity, &Collider, &Name, &mut Visibility), (Without<RapierCollider>, Added<Collider>)>,
// needed for tri meshes // needed for tri meshes
children: Query<&Children>, children: Query<&Children>,
@ -96,26 +83,7 @@ pub fn physics_replace_proxies (
// break; // break;
// RapierCollider::convex_hull(points) // RapierCollider::convex_hull(points)
} }
} }
} }
} }
// rigidbodies
for (entity, proxy_rigidbody) in proxy_rigidbodies.iter() {
info!("Generation rigid body from Proxy rigid body !! {:?}", proxy_rigidbody );
let rigid_body:RapierRigidBody = match proxy_rigidbody {
RigidBodyProxy::Dynamic => RapierRigidBody::Dynamic,
RigidBodyProxy::Fixed=> RapierRigidBody::Fixed,
RigidBodyProxy::Position => RapierRigidBody::KinematicPositionBased,
RigidBodyProxy::Velocity => RapierRigidBody::KinematicVelocityBased,
};
commands.entity(entity)
.insert(rigid_body)
// IMPORTANT ! this allows collisions between dynamic & static(fixed) entities
// see https://rapier.rs/docs/user_guides/bevy_plugin/colliders#active-collision-types
.insert(ActiveCollisionTypes::default() | ActiveCollisionTypes::KINEMATIC_STATIC | ActiveCollisionTypes::STATIC_STATIC | ActiveCollisionTypes::DYNAMIC_STATIC)
.insert(ActiveEvents::COLLISION_EVENTS)
;
}
} }

View File

@ -7,7 +7,7 @@ use bevy_rapier3d::prelude::RigidBody;
use std::io::Write; use std::io::Write;
use std::fs::File; use std::fs::File;
use crate::core::physics::{Collider, RigidBodyProxy}; use crate::core::physics::Collider;
use crate::game::{Pickable, Player}; use crate::game::{Pickable, Player};
use super::Saveable; use super::Saveable;
@ -63,7 +63,6 @@ pub fn save_game(
.deny::<Collider>() .deny::<Collider>()
.deny::<RigidBody>() .deny::<RigidBody>()
.deny::<RigidBodyProxy>()
.deny::<Saveable>() .deny::<Saveable>()
// camera stuff // camera stuff

View File

@ -14,7 +14,6 @@ impl Plugin for PhysicsPlugin {
app app
.register_type::<AutoAABBCollider>() .register_type::<AutoAABBCollider>()
.register_type::<physics_replace_proxies::Collider>() .register_type::<physics_replace_proxies::Collider>()
.register_type::<physics_replace_proxies::RigidBodyProxy>()
// find a way to make serde's stuff serializable // find a way to make serde's stuff serializable
// .register_type::<bevy_rapier3d::dynamics::CoefficientCombineRule>() // .register_type::<bevy_rapier3d::dynamics::CoefficientCombineRule>()

View File

@ -1,21 +1,10 @@
use bevy::prelude::*; use bevy::prelude::*;
// use bevy::render::primitives::Aabb; // use bevy::render::primitives::Aabb;
use bevy_rapier3d::geometry::Collider as RapierCollider; use bevy_rapier3d::geometry::Collider as RapierCollider;
use bevy_rapier3d::dynamics::RigidBody as RapierRigidBody;
use bevy_rapier3d::prelude::{ComputedColliderShape, ActiveEvents, ActiveCollisionTypes}; use bevy_rapier3d::prelude::{ComputedColliderShape, ActiveEvents, ActiveCollisionTypes};
use super::utils::*; use super::utils::*;
#[derive(Component, Reflect, Default, Debug, )]
#[reflect(Component)]
pub enum RigidBodyProxy{
#[default]
Dynamic,
Fixed,
Position,
Velocity
}
#[derive(Component, Reflect, Default, Debug, )] #[derive(Component, Reflect, Default, Debug, )]
#[reflect(Component)] #[reflect(Component)]
pub enum Collider { pub enum Collider {
@ -26,7 +15,6 @@ pub enum Collider {
Mesh, Mesh,
} }
#[derive(Component, Reflect, Default, Debug, )] #[derive(Component, Reflect, Default, Debug, )]
#[reflect(Component)] #[reflect(Component)]
pub enum AutoAABBCollider { pub enum AutoAABBCollider {
@ -40,8 +28,6 @@ pub enum AutoAABBCollider {
pub fn physics_replace_proxies ( pub fn physics_replace_proxies (
meshes: Res<Assets<Mesh>>, meshes: Res<Assets<Mesh>>,
mesh_handles: Query<&Handle<Mesh>>, mesh_handles: Query<&Handle<Mesh>>,
// rigidbodies
proxy_rigidbodies: Query<(Entity, &RigidBodyProxy,), (Without<RapierRigidBody>, Added<RigidBodyProxy>)>,
mut proxy_colliders: Query<(Entity, &Collider, &Name, &mut Visibility), (Without<RapierCollider>, Added<Collider>)>, mut proxy_colliders: Query<(Entity, &Collider, &Name, &mut Visibility), (Without<RapierCollider>, Added<Collider>)>,
// needed for tri meshes // needed for tri meshes
children: Query<&Children>, children: Query<&Children>,
@ -96,27 +82,7 @@ pub fn physics_replace_proxies (
// break; // break;
// RapierCollider::convex_hull(points) // RapierCollider::convex_hull(points)
} }
} }
} }
} }
// rigidbodies
for (entity, proxy_rigidbody) in proxy_rigidbodies.iter() {
info!("Proxy rigid body !! {:?}", proxy_rigidbody );
let rigid_body:RapierRigidBody = match proxy_rigidbody {
RigidBodyProxy::Dynamic => RapierRigidBody::Dynamic,
RigidBodyProxy::Fixed=> RapierRigidBody::Fixed,
RigidBodyProxy::Position => RapierRigidBody::KinematicPositionBased,
RigidBodyProxy::Velocity => RapierRigidBody::KinematicVelocityBased,
};
println!("inserting rigidbody {:?}", rigid_body);
commands.entity(entity)
.insert(rigid_body)
// IMPORTANT ! this allows collisions between dynamic & static(fixed) entities
// see https://rapier.rs/docs/user_guides/bevy_plugin/colliders#active-collision-types
.insert(ActiveCollisionTypes::default() | ActiveCollisionTypes::KINEMATIC_STATIC | ActiveCollisionTypes::STATIC_STATIC | ActiveCollisionTypes::DYNAMIC_STATIC)
.insert(ActiveEvents::COLLISION_EVENTS)
;
}
} }