This commit is contained in:
1 parent
0e7aed40f1
commit
0ce43fc399
19 files changed
+1180
-127
No files matched your search
@@ -5,16 +5,12 @@ use std::time::Duration;
|
||||
|
||||
use avian3d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
use shared::{
|
||||
authoring_component_active, AuthoringComponentStates, ColliderDesc, InspectorOrder,
|
||||
PhysicsBody, RigidBodyDesc, COMPONENT_COLLIDER_DESC, COMPONENT_PHYSICS_BODY,
|
||||
COMPONENT_RIGID_BODY_DESC,
|
||||
};
|
||||
|
||||
use crate::history::set_transform_group_with_history;
|
||||
use crate::operators::{ActiveOperator, OperatorPhase, OperatorStatus};
|
||||
use crate::state::EditorMode;
|
||||
use crate::ui::selection_ops::{entity_name, is_mutable_level_object};
|
||||
use crate::viewport::collider_diagnostics::physics_placement_prerequisite_problems;
|
||||
|
||||
const STEP_HZ: f64 = 120.0;
|
||||
const STEPS_PER_FRAME: usize = 4;
|
||||
@@ -369,33 +365,7 @@ fn validate_selection(world: &mut World, selected: &[Entity]) -> Result<(), Stri
|
||||
));
|
||||
continue;
|
||||
}
|
||||
let states = world.get::<AuthoringComponentStates>(*entity);
|
||||
let order = world.get::<InspectorOrder>(*entity);
|
||||
let split_body = world.get::<RigidBodyDesc>(*entity).is_some()
|
||||
&& authoring_component_active(states, order, COMPONENT_RIGID_BODY_DESC);
|
||||
let split_collider = world.get::<ColliderDesc>(*entity).filter(|collider| {
|
||||
collider.enabled
|
||||
&& !collider.is_trigger
|
||||
&& authoring_component_active(states, order, COMPONENT_COLLIDER_DESC)
|
||||
});
|
||||
let legacy = world.get::<PhysicsBody>(*entity).is_some()
|
||||
&& authoring_component_active(states, order, COMPONENT_PHYSICS_BODY);
|
||||
if !split_body && !legacy {
|
||||
problems.push(format!("{name}: add and enable a Rigid Body component"));
|
||||
}
|
||||
if split_collider.is_none() && !legacy {
|
||||
problems.push(format!(
|
||||
"{name}: add and enable a non-trigger Collider component"
|
||||
));
|
||||
}
|
||||
if world.get::<RigidBody>(*entity).is_none() {
|
||||
problems.push(format!("{name}: rigid body has not hydrated yet"));
|
||||
}
|
||||
if !has_runtime_collider(world, *entity) {
|
||||
problems.push(format!(
|
||||
"{name}: collider has not hydrated or finished cooking"
|
||||
));
|
||||
}
|
||||
problems.extend(physics_placement_prerequisite_problems(world, *entity));
|
||||
}
|
||||
if problems.is_empty() {
|
||||
Ok(())
|
||||
@@ -404,19 +374,6 @@ fn validate_selection(world: &mut World, selected: &[Entity]) -> Result<(), Stri
|
||||
}
|
||||
}
|
||||
|
||||
fn has_runtime_collider(world: &World, root: Entity) -> bool {
|
||||
let mut pending = vec![root];
|
||||
while let Some(entity) = pending.pop() {
|
||||
if world.get::<Collider>(entity).is_some() {
|
||||
return true;
|
||||
}
|
||||
if let Some(children) = world.get::<Children>(entity) {
|
||||
pending.extend(children.iter());
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn restore_snapshot(world: &mut World, snapshot: &BodySnapshot, restore_pose: bool) {
|
||||
let Ok(mut entity) = world.get_entity_mut(snapshot.entity) else {
|
||||
return;
|
||||
@@ -498,7 +455,7 @@ mod tests {
|
||||
use crate::history::{apply_command_undo, EditorHistory};
|
||||
use bevy::asset::{AssetApp, AssetPlugin};
|
||||
use bevy::state::app::StatesPlugin;
|
||||
use shared::LevelObject;
|
||||
use shared::{ColliderDesc, LevelObject, RigidBodyDesc};
|
||||
|
||||
fn app_with_physics() -> App {
|
||||
let mut app = App::new();
|
||||
|
||||
Reference in new issue
Block a user