Can't find rigidbody for some reason

This commit is contained in:
Franklin 2023-11-16 18:32:17 -04:00
parent 94c9d4aae2
commit 25206af09b
5 changed files with 30 additions and 7 deletions

Binary file not shown.

View File

@ -1,4 +1,5 @@
use bevy::prelude::*;
use bevy_rapier3d::dynamics::RigidBody as RapierRigidBody;
// use bevy::render::primitives::Aabb;
use bevy_rapier3d::geometry::Collider as RapierCollider;
use bevy_rapier3d::prelude::{ActiveEvents, ComputedColliderShape};
@ -15,6 +16,14 @@ pub enum Collider {
Mesh,
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub enum RigidBody {
#[default]
Fixed,
Dynamic,
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub enum AutoAABBCollider {
@ -32,6 +41,10 @@ pub fn physics_replace_proxies(
(Entity, &Collider, &Name, &mut Visibility),
(Without<RapierCollider>, Added<Collider>),
>,
proxy_rigidbodies: Query<
(Entity, &RigidBody),
(Without<RapierRigidBody>, Added<RigidBody>),
>,
// needed for tri meshes
children: Query<&Children>,
@ -71,20 +84,19 @@ pub fn physics_replace_proxies(
;
}
Collider::Mesh => {
println!("proxy: mesh");
for (_, collider_mesh) in
Mesh::search_in_children(entity, &children, &meshes, &mesh_handles)
{
println!("Mesh");
rapier_collider = RapierCollider::from_bevy_mesh(
collider_mesh,
&ComputedColliderShape::TriMesh,
&ComputedColliderShape::ConvexHull,
)
.unwrap();
commands
.entity(entity)
.insert(rapier_collider);
// FIXME: this is just for demo purposes !!!;
//.insert(ActiveEvents::COLLISION_EVENTS);
// .insert(ActiveEvents::COLLISION_EVENTS)
// break;
@ -92,4 +104,14 @@ pub fn physics_replace_proxies(
}
}
}
for (entity, proxy_rigidbody) in proxy_rigidbodies.iter() {
let rapier_rigidbody: RapierRigidBody;
match proxy_rigidbody {
RigidBody::Fixed => rapier_rigidbody = RapierRigidBody::Fixed,
RigidBody::Dynamic => rapier_rigidbody = RapierRigidBody::Dynamic,
}
commands
.entity(entity)
.insert(rapier_rigidbody);
}
}

View File

@ -22,6 +22,7 @@ impl Plugin for ProxyComponentsPlugin {
// Physics
app.register_type::<AutoAABBCollider>();
app.register_type::<physics::rapier::Collider>();
app.register_type::<physics::rapier::RigidBody>();
app.add_systems(Update, (physics_replace_proxies, update_game_load_state));
}
}

View File

@ -31,13 +31,13 @@ fn setup_plugins(application: &mut App) {
.add_plugins(DefaultPlugins.set(AssetPlugin::default()))
//.add_plugins(DefaultInspectorConfigPlugin)
.add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
.add_plugins(RapierDebugRenderPlugin::default())
.add_plugins(ComponentsFromGltfPlugin)
//.add_plugins(bevy_egui::EguiPlugin)
//.add_plugins(WorldInspectorPlugin::new())
.add_plugins(proxy::plugin::ProxyComponentsPlugin)
.add_plugins(MainGameUIPlugin)
.add_plugins(MainEditorUiPlugin)
;//.add_plugins(RapierDebugRenderPlugin::default());
.add_plugins(MainEditorUiPlugin);
}
fn load(application: &mut App) {

View File

@ -23,7 +23,7 @@ pub fn update_game_load_state(
mut asset_event_reader: EventReader<AssetEvent<Gltf>>,
gltf_assets: Res<GltfAssets>,
) {
if let Some(asset_event) = asset_event_reader.read().next() {
for asset_event in asset_event_reader.read() {
match asset_event {
AssetEvent::Added { id } => {
game_state.loaded_assets.push(*id);