Skip to content

Commit

Permalink
Adding joints on first pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
illis committed Apr 20, 2021
1 parent e0543b3 commit c51478f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/physics/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub struct RapierPhysicsPlugin;
/// This stage is added right before the `POST_UPDATE` stage.
pub const TRANSFORM_SYNC_STAGE: &'static str = "rapier::transform_sync_stage";

#[derive(SystemLabel, Clone, Debug, Eq, Hash, PartialEq)]
/// Label for create_joints_system
pub struct CreateJointsSystem;

impl Plugin for RapierPhysicsPlugin {
fn build(&self, app: &mut AppBuilder) {
app.insert_resource(PhysicsPipeline::new())
Expand All @@ -46,13 +50,20 @@ impl Plugin for RapierPhysicsPlugin {
// are needed.
.add_system_to_stage(
CoreStage::PreUpdate,
physics::create_body_and_collider_system.system(),
physics::create_body_and_collider_system
.system()
.before(CreateJointsSystem),
)
.add_system_to_stage(
CoreStage::PreUpdate,
physics::update_collider_system.system(),
)
.add_system_to_stage(CoreStage::PreUpdate, physics::create_joints_system.system())
.add_system_to_stage(
CoreStage::PreUpdate,
physics::create_joints_system
.system()
.label(CreateJointsSystem),
)
.add_system_to_stage(CoreStage::Update, physics::step_world_system.system())
.add_stage_before(
CoreStage::PostUpdate,
Expand Down
9 changes: 4 additions & 5 deletions src/physics/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,12 @@ pub fn create_joints_system(
mut joints: ResMut<JointSet>,
mut entity_maps: ResMut<EntityMaps>,
query: Query<(Entity, &JointBuilderComponent)>,
query_bodyhandle: Query<&RigidBodyHandleComponent>,
) {
for (entity, joint) in &mut query.iter() {
let body1 = query_bodyhandle.get_component::<RigidBodyHandleComponent>(joint.entity1);
let body2 = query_bodyhandle.get_component::<RigidBodyHandleComponent>(joint.entity2);
if let (Ok(body1), Ok(body2)) = (body1, body2) {
let handle = joints.insert(&mut bodies, body1.handle(), body2.handle(), joint.params);
let body1 = entity_maps.bodies.get(&joint.entity1);
let body2 = entity_maps.bodies.get(&joint.entity2);
if let (Some(body1), Some(body2)) = (body1, body2) {
let handle = joints.insert(&mut bodies, *body1, *body2, joint.params);
commands
.entity(entity)
.insert(JointHandleComponent::new(
Expand Down

0 comments on commit c51478f

Please sign in to comment.