Initial project import
CI / Format, lint, test, build (push) Waiting to run

This commit is contained in:
Rbanh committed 2026-06-05 21:44:45 -04:00
commit f29712d158
259 files changed
+52069

No files matched your search

+97
View File
@@ -0,0 +1,97 @@
//! Avian physics from [`PhysicsBody`] authoring data.
use avian3d::prelude::*;
use bevy::prelude::*;
use crate::{
inspector_component_active, AuthoringRigidBody, ColliderDesc, ColliderShapeDesc,
InspectorOrder, LevelObject, PhysicsBody, RigidBodyDesc, COMPONENT_COLLIDER_DESC,
COMPONENT_PHYSICS_BODY, COMPONENT_RIGID_BODY_DESC,
};
#[allow(clippy::type_complexity)]
pub fn hydrate_physics(
mut commands: Commands,
physics: Query<
(Entity, &PhysicsBody, Option<&InspectorOrder>),
(
With<LevelObject>,
Or<(Changed<PhysicsBody>, Changed<InspectorOrder>)>,
),
>,
new_physics: Query<
(Entity, &PhysicsBody, Option<&InspectorOrder>),
(With<LevelObject>, Added<PhysicsBody>),
>,
split_physics: Query<
(
Entity,
Option<&RigidBodyDesc>,
Option<&ColliderDesc>,
Option<&InspectorOrder>,
),
(
With<LevelObject>,
Or<(
Changed<RigidBodyDesc>,
Added<RigidBodyDesc>,
Changed<ColliderDesc>,
Added<ColliderDesc>,
Changed<InspectorOrder>,
)>,
),
>,
) {
for (entity, body, order) in new_physics.iter().chain(physics.iter()) {
if !inspector_component_active(order, COMPONENT_PHYSICS_BODY) {
commands
.entity(entity)
.remove::<RigidBody>()
.remove::<Collider>();
continue;
}
let rigid_body = match body.body {
AuthoringRigidBody::Static => RigidBody::Static,
AuthoringRigidBody::Kinematic => RigidBody::Kinematic,
AuthoringRigidBody::Dynamic => RigidBody::Dynamic,
};
commands
.entity(entity)
.remove::<RigidBody>()
.remove::<Collider>()
.insert((rigid_body, body.collider.clone()));
}
for (entity, rigid_body, collider, order) in &split_physics {
let mut entity_commands = commands.entity(entity);
entity_commands.remove::<RigidBody>().remove::<Collider>();
if let Some(rigid_body) =
rigid_body.filter(|_| inspector_component_active(order, COMPONENT_RIGID_BODY_DESC))
{
entity_commands.insert(rigid_body_from_desc(rigid_body.body));
}
let Some(collider) = collider else {
continue;
};
if !inspector_component_active(order, COMPONENT_COLLIDER_DESC) {
continue;
}
if !collider.enabled || matches!(collider.shape, ColliderShapeDesc::StaticMesh { .. }) {
continue;
}
if let Some(constructor) = collider.shape.to_constructor() {
entity_commands.insert(constructor);
}
}
}
pub fn rigid_body_from_desc(body: AuthoringRigidBody) -> RigidBody {
match body {
AuthoringRigidBody::Static => RigidBody::Static,
AuthoringRigidBody::Kinematic => RigidBody::Kinematic,
AuthoringRigidBody::Dynamic => RigidBody::Dynamic,
}
}