From 55373b3fa6af97bb9c2e177da06af0cf1465ce8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 10 Dec 2023 12:11:20 +0100 Subject: [PATCH] chore: update testbed to bevy 0.12 --- crates/rapier_testbed2d-f64/Cargo.toml | 14 +-- crates/rapier_testbed2d/Cargo.toml | 14 +-- crates/rapier_testbed3d-f64/Cargo.toml | 14 +-- crates/rapier_testbed3d/Cargo.toml | 14 +-- src_testbed/camera3d.rs | 4 +- src_testbed/physx_backend.rs | 136 +++++++++++-------------- 6 files changed, 92 insertions(+), 104 deletions(-) diff --git a/crates/rapier_testbed2d-f64/Cargo.toml b/crates/rapier_testbed2d-f64/Cargo.toml index 23bac9fae..03390f34d 100644 --- a/crates/rapier_testbed2d-f64/Cargo.toml +++ b/crates/rapier_testbed2d-f64/Cargo.toml @@ -40,20 +40,20 @@ bincode = "1" Inflector = "0.11" md5 = "0.7" -bevy_egui = "0.22" -bevy_ecs = "0.11" -bevy_core_pipeline = "0.11" -bevy_pbr = "0.11" -bevy_sprite = "0.11" +bevy_egui = "0.23" +bevy_ecs = "0.12" +bevy_core_pipeline = "0.12" +bevy_pbr = "0.12" +bevy_sprite = "0.12" #bevy_prototype_debug_lines = "0.7" # Dependencies for native only. [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -bevy = {version = "0.11", default-features = false, features = ["bevy_asset", "bevy_winit", "x11", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} +bevy = {version = "0.12", default-features = false, features = ["bevy_asset", "bevy_winit", "x11", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} # Dependencies for WASM only. [target.'cfg(target_arch = "wasm32")'.dependencies] -bevy = {version = "0.11", default-features = false, features = ["bevy_asset", "bevy_winit", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} +bevy = {version = "0.12", default-features = false, features = ["bevy_asset", "bevy_winit", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} #bevy_webgl2 = "0.5" [dependencies.rapier] diff --git a/crates/rapier_testbed2d/Cargo.toml b/crates/rapier_testbed2d/Cargo.toml index 97fc6de3b..84687719e 100644 --- a/crates/rapier_testbed2d/Cargo.toml +++ b/crates/rapier_testbed2d/Cargo.toml @@ -40,20 +40,20 @@ bincode = "1" Inflector = "0.11" md5 = "0.7" -bevy_egui = "0.22" -bevy_ecs = "0.11" -bevy_core_pipeline = "0.11" -bevy_pbr = "0.11" -bevy_sprite = "0.11" +bevy_egui = "0.23" +bevy_ecs = "0.12" +bevy_core_pipeline = "0.12" +bevy_pbr = "0.12" +bevy_sprite = "0.12" #bevy_prototype_debug_lines = "0.7" # Dependencies for native only. [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -bevy = {version = "0.11", default-features = false, features = ["bevy_sprite", "bevy_winit", "x11", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} +bevy = {version = "0.12", default-features = false, features = ["bevy_sprite", "bevy_winit", "x11", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} # Dependencies for WASM only. [target.'cfg(target_arch = "wasm32")'.dependencies] -bevy = {version = "0.11", default-features = false, features = ["bevy_sprite", "bevy_winit", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} +bevy = {version = "0.12", default-features = false, features = ["bevy_sprite", "bevy_winit", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} #bevy_webgl2 = "0.5" [dependencies.rapier] diff --git a/crates/rapier_testbed3d-f64/Cargo.toml b/crates/rapier_testbed3d-f64/Cargo.toml index 40ae54fe2..5d86ae8cc 100644 --- a/crates/rapier_testbed3d-f64/Cargo.toml +++ b/crates/rapier_testbed3d-f64/Cargo.toml @@ -39,20 +39,20 @@ md5 = "0.7" Inflector = "0.11" serde = { version = "1", features = [ "derive" ] } -bevy_egui = "0.22" -bevy_ecs = "0.11" -bevy_core_pipeline = "0.11" -bevy_pbr = "0.11" -bevy_sprite = "0.11" +bevy_egui = "0.23" +bevy_ecs = "0.12" +bevy_core_pipeline = "0.12" +bevy_pbr = "0.12" +bevy_sprite = "0.12" #bevy_prototype_debug_lines = { version = "0.7", features = [ "3d" ] } # Dependencies for native only. [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -bevy = {version = "0.11", default-features = false, features = ["bevy_winit", "x11", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} +bevy = {version = "0.12", default-features = false, features = ["bevy_winit", "x11", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} # Dependencies for WASM only. [target.'cfg(target_arch = "wasm32")'.dependencies] -bevy = {version = "0.11", default-features = false, features = ["bevy_winit", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} +bevy = {version = "0.12", default-features = false, features = ["bevy_winit", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} #bevy_webgl2 = "0.5" [dependencies.rapier] diff --git a/crates/rapier_testbed3d/Cargo.toml b/crates/rapier_testbed3d/Cargo.toml index fc52bc328..d86975f05 100644 --- a/crates/rapier_testbed3d/Cargo.toml +++ b/crates/rapier_testbed3d/Cargo.toml @@ -43,20 +43,20 @@ md5 = "0.7" Inflector = "0.11" serde = { version = "1", features = [ "derive" ] } -bevy_egui = "0.22" -bevy_ecs = "0.11" -bevy_core_pipeline = "0.11" -bevy_pbr = "0.11" -bevy_sprite = "0.11" +bevy_egui = "0.23" +bevy_ecs = "0.12" +bevy_core_pipeline = "0.12" +bevy_pbr = "0.12" +bevy_sprite = "0.12" #bevy_prototype_debug_lines = { version = "0.7", features = [ "3d" ] } # Dependencies for native only. [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -bevy = {version = "0.11", default-features = false, features = ["bevy_winit", "x11", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} +bevy = {version = "0.12", default-features = false, features = ["bevy_winit", "x11", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} # Dependencies for WASM only. [target.'cfg(target_arch = "wasm32")'.dependencies] -bevy = {version = "0.11", default-features = false, features = ["bevy_winit", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} +bevy = {version = "0.12", default-features = false, features = ["bevy_winit", "tonemapping_luts", "ktx2", "zstd", "bevy_render", "bevy_pbr", "bevy_gizmos"]} #bevy_webgl2 = "0.5" [dependencies.rapier] diff --git a/src_testbed/camera3d.rs b/src_testbed/camera3d.rs index 7621c5053..e7c294540 100644 --- a/src_testbed/camera3d.rs +++ b/src_testbed/camera3d.rs @@ -64,7 +64,7 @@ impl OrbitCameraPlugin { mut query: Query<(&mut OrbitCamera, &mut Transform, &mut Camera)>, ) { let mut delta = Vec2::ZERO; - for event in mouse_motion_events.iter() { + for event in mouse_motion_events.read() { delta += event.delta; } for (mut camera, transform, _) in query.iter_mut() { @@ -97,7 +97,7 @@ impl OrbitCameraPlugin { mut query: Query<&mut OrbitCamera, With>, ) { let mut total = 0.0; - for event in mouse_wheel_events.iter() { + for event in mouse_wheel_events.read() { total += event.y * match event.unit { Line => 1.0, diff --git a/src_testbed/physx_backend.rs b/src_testbed/physx_backend.rs index d4b2a7500..208426cba 100644 --- a/src_testbed/physx_backend.rs +++ b/src_testbed/physx_backend.rs @@ -1,19 +1,18 @@ #![allow(dead_code)] use na::{Isometry3, Matrix4, Point3, Quaternion, Translation3, Unit, UnitQuaternion, Vector3}; -use physx::articulation_joint_base::JointMap; use physx::cooking::{ - ConvexMeshCookingResult, PxConvexMeshDesc, PxCooking, PxCookingParams, PxHeightFieldDesc, + ConvexMeshCookingResult, PxConvexMeshDesc, PxCookingParams, PxHeightFieldDesc, PxTriangleMeshDesc, TriangleMeshCookingResult, }; use physx::foundation::DefaultAllocator; use physx::prelude::*; -use physx::scene::FrictionType; +use physx::scene::{FrictionType, SceneFlags}; use physx::traits::Class; +use physx_sys::PxFilterFlags; use physx_sys::{ - FilterShaderCallbackInfo, PxArticulationLink_getInboundJoint, PxBitAndByte, PxConvexFlags, - PxConvexMeshGeometryFlags, PxHeightFieldSample, PxMeshGeometryFlags, PxMeshScale_new, - PxRigidActor, + FilterShaderCallbackInfo, PxBitAndByte, PxConvexFlags, PxConvexMeshGeometryFlags, + PxHeightFieldSample, PxMeshGeometryFlags, PxMeshScale_new, PxRigidActor, }; use rapier::counters::Counters; use rapier::dynamics::{ @@ -134,7 +133,6 @@ pub static FOUNDATION: std::cell::RefCell = std::cell::RefC pub struct PhysxWorld { // physics: Physics, - // cooking: Cooking, materials: Vec>, shapes: Vec>, scene: Option>, @@ -173,7 +171,7 @@ impl PhysxWorld { let mut scene_desc = SceneDescriptor { gravity: gravity.into_physx(), thread_count: num_threads as u32, - broad_phase_type: BroadPhaseType::AutomaticBoxPruning, + broad_phase_type: BroadPhaseType::Abp, solver_type: SolverType::Pgs, friction_type, ccd_max_passes: integration_parameters.max_ccd_substeps as u32, @@ -185,17 +183,13 @@ impl PhysxWorld { if ccd_enabled { scene_desc.simulation_filter_shader = FilterShaderDescriptor::CallDefaultFirst(ccd_filter_shader); - scene_desc.flags.insert(SceneFlag::EnableCcd); + scene_desc.flags.insert(SceneFlags::EnableCcd); } let mut scene: Owner = physics.create(scene_desc).unwrap(); let mut rapier2dynamic = HashMap::new(); let mut rapier2static = HashMap::new(); let mut rapier2link = HashMap::new(); - let cooking_params = - PxCookingParams::new(&*physics).expect("Failed to init PhysX cooking."); - let mut cooking = PxCooking::new(physics.foundation_mut(), &cooking_params) - .expect("Failed to init PhysX cooking"); /* * @@ -231,6 +225,7 @@ impl PhysxWorld { /* * Articulations. */ + /* for multibody in multibody_joints.multibodies() { let mut articulation: Owner = physics.create_articulation_reduced_coordinate(()).unwrap(); @@ -251,12 +246,9 @@ impl PhysxWorld { .unwrap(); // TODO: there is no get_inbound_joint_mut? - if let Some(px_inbound_joint) = unsafe { - (PxArticulationLink_getInboundJoint(px_link.as_ptr()) - as *mut physx_sys::PxArticulationJointBase - as *mut JointMap) - .as_mut() - } { + if let Some(px_inbound_joint) = + unsafe { (PxArticulationLink_getInboundJoint(px_link.as_ptr())).as_mut() } + { let frame1 = link.joint().data.local_frame1.into_physx(); let frame2 = link.joint().data.local_frame2.into_physx(); @@ -301,6 +293,8 @@ impl PhysxWorld { scene.add_articulation(articulation); } + */ + /* * * Colliders @@ -308,7 +302,7 @@ impl PhysxWorld { */ for (_, collider) in colliders.iter() { if let Some((mut px_shape, px_material, collider_pos)) = - physx_collider_from_rapier_collider(&mut *physics, &mut cooking, &collider) + physx_collider_from_rapier_collider(&mut *physics, &collider) { if let Some(parent_handle) = collider.parent() { let parent_body = &bodies[parent_handle]; @@ -360,7 +354,7 @@ impl PhysxWorld { continue; }; - physx_sys::PxRigidBodyExt_updateMassAndInertia_mut( + physx_sys::PxRigidBodyExt_updateMassAndInertia( actor, densities.as_ptr(), densities.len() as u32, @@ -371,7 +365,7 @@ impl PhysxWorld { if rb.is_ccd_enabled() { physx_sys::PxRigidBody_setRigidBodyFlag_mut( actor, - RigidBodyFlag::EnableCcd as u32, + RigidBodyFlag::EnableCcd, true, ); } @@ -449,64 +443,60 @@ impl PhysxWorld { ); let motion_x = if joint.1.data.limit_axes.contains(JointAxesMask::X) { - physx_sys::PxD6Motion::eLIMITED + physx_sys::PxD6Motion::Limited } else if !joint.1.data.locked_axes.contains(JointAxesMask::X) { - physx_sys::PxD6Motion::eFREE + physx_sys::PxD6Motion::Free } else { - physx_sys::PxD6Motion::eLOCKED + physx_sys::PxD6Motion::Locked }; let motion_y = if joint.1.data.limit_axes.contains(JointAxesMask::Y) { - physx_sys::PxD6Motion::eLIMITED + physx_sys::PxD6Motion::Limited } else if !joint.1.data.locked_axes.contains(JointAxesMask::Y) { - physx_sys::PxD6Motion::eFREE + physx_sys::PxD6Motion::Free } else { - physx_sys::PxD6Motion::eLOCKED + physx_sys::PxD6Motion::Locked }; let motion_z = if joint.1.data.limit_axes.contains(JointAxesMask::Z) { - physx_sys::PxD6Motion::eLIMITED + physx_sys::PxD6Motion::Limited } else if !joint.1.data.locked_axes.contains(JointAxesMask::Z) { - physx_sys::PxD6Motion::eFREE + physx_sys::PxD6Motion::Free } else { - physx_sys::PxD6Motion::eLOCKED + physx_sys::PxD6Motion::Locked }; let motion_ax = if joint.1.data.limit_axes.contains(JointAxesMask::ANG_X) { - physx_sys::PxD6Motion::eLIMITED + physx_sys::PxD6Motion::Limited } else if !joint.1.data.locked_axes.contains(JointAxesMask::ANG_X) { - physx_sys::PxD6Motion::eFREE + physx_sys::PxD6Motion::Free } else { - physx_sys::PxD6Motion::eLOCKED + physx_sys::PxD6Motion::Locked }; let motion_ay = if joint.1.data.limit_axes.contains(JointAxesMask::ANG_Y) { - physx_sys::PxD6Motion::eLIMITED + physx_sys::PxD6Motion::Limited } else if !joint.1.data.locked_axes.contains(JointAxesMask::ANG_Y) { - physx_sys::PxD6Motion::eFREE + physx_sys::PxD6Motion::Free } else { - physx_sys::PxD6Motion::eLOCKED + physx_sys::PxD6Motion::Locked }; let motion_az = if joint.1.data.limit_axes.contains(JointAxesMask::ANG_Z) { - physx_sys::PxD6Motion::eLIMITED + physx_sys::PxD6Motion::Limited } else if !joint.1.data.locked_axes.contains(JointAxesMask::ANG_Z) { - physx_sys::PxD6Motion::eFREE + physx_sys::PxD6Motion::Free } else { - physx_sys::PxD6Motion::eLOCKED + physx_sys::PxD6Motion::Locked }; - physx_sys::PxD6Joint_setMotion_mut(px_joint, physx_sys::PxD6Axis::eX, motion_x); - physx_sys::PxD6Joint_setMotion_mut(px_joint, physx_sys::PxD6Axis::eY, motion_y); - physx_sys::PxD6Joint_setMotion_mut(px_joint, physx_sys::PxD6Axis::eZ, motion_z); - physx_sys::PxD6Joint_setMotion_mut( - px_joint, - physx_sys::PxD6Axis::eTWIST, - motion_ax, - ); + physx_sys::PxD6Joint_setMotion_mut(px_joint, physx_sys::PxD6Axis::X, motion_x); + physx_sys::PxD6Joint_setMotion_mut(px_joint, physx_sys::PxD6Axis::Y, motion_y); + physx_sys::PxD6Joint_setMotion_mut(px_joint, physx_sys::PxD6Axis::Z, motion_z); + physx_sys::PxD6Joint_setMotion_mut(px_joint, physx_sys::PxD6Axis::Twist, motion_ax); physx_sys::PxD6Joint_setMotion_mut( px_joint, - physx_sys::PxD6Axis::eSWING1, + physx_sys::PxD6Axis::Swing1, motion_ay, ); physx_sys::PxD6Joint_setMotion_mut( px_joint, - physx_sys::PxD6Axis::eSWING2, + physx_sys::PxD6Axis::Swing2, motion_az, ); } @@ -549,6 +539,7 @@ impl PhysxWorld { sync_pos(handle, pos); } + /* for articulation in self.scene.as_mut().unwrap().get_articulations() { if let Some(articulation) = articulation.as_articulation_reduced_coordinate() { for link in articulation.get_links() { @@ -558,20 +549,22 @@ impl PhysxWorld { } } } + + */ } } fn physx_collider_from_rapier_collider( physics: &mut PxPhysicsFoundation, - cooking: &PxCooking, collider: &Collider, ) -> Option<(Owner, Owner, Isometry3)> { let mut local_pose = collider.position_wrt_parent().copied().unwrap_or(na::one()); + let cooking_params = PxCookingParams::new(physics).unwrap(); let shape = collider.shape(); let shape_flags = if collider.is_sensor() { - ShapeFlag::TriggerShape.into() + ShapeFlags::TriggerShape } else { - ShapeFlag::SimulationShape.into() + ShapeFlags::SimulationShape }; let mut material = physics .create_material( @@ -618,8 +611,12 @@ fn physx_collider_from_rapier_collider( .iter() .map(|h| PxHeightFieldSample { height: (*h * Y_FACTOR) as i16, - materialIndex0: PxBitAndByte { mData: 0 }, - materialIndex1: PxBitAndByte { mData: 0 }, + materialIndex0: PxBitAndByte { + structgen_pad0: [0; 1], + }, + materialIndex1: PxBitAndByte { + structgen_pad0: [0; 1], + }, }) .collect(); heightfield_desc = physx_sys::PxHeightFieldDesc_new(); @@ -632,12 +629,10 @@ fn physx_collider_from_rapier_collider( let heightfield_desc = PxHeightFieldDesc { obj: heightfield_desc, }; - let heightfield = cooking.create_height_field(physics, &heightfield_desc); + let heightfield = physx::cooking::create_height_field(physics, &heightfield_desc); if let Some(mut heightfield) = heightfield { - let flags = PxMeshGeometryFlags { - mBits: physx_sys::PxMeshGeometryFlag::eDOUBLE_SIDED as u8, - }; + let flags = PxMeshGeometryFlags::DoubleSided; let geometry = PxHeightFieldGeometry::new( &mut *heightfield, flags, @@ -661,16 +656,14 @@ fn physx_collider_from_rapier_collider( convex_desc.points.count = vertices.len() as u32; convex_desc.points.stride = (3 * std::mem::size_of::()) as u32; convex_desc.points.data = vertices.as_ptr() as *const std::ffi::c_void; - convex_desc.flags = PxConvexFlags { - mBits: physx_sys::PxConvexFlag::eCOMPUTE_CONVEX as u16, - }; + convex_desc.flags = PxConvexFlags::ComputeConvex; } let convex_desc = PxConvexMeshDesc { obj: convex_desc }; - let convex = cooking.create_convex_mesh(physics, &convex_desc); + let convex = physx::cooking::create_convex_mesh(physics, &cooking_params, &convex_desc); if let ConvexMeshCookingResult::Success(mut convex) = convex { - let flags = PxConvexMeshGeometryFlags { mBits: 0 }; + let flags = PxConvexMeshGeometryFlags::empty(); let scaling = unsafe { PxMeshScale_new() }; let geometry = PxConvexMeshGeometry::new(&mut convex, &scaling, flags); physics.create_shape(&geometry, materials, true, shape_flags, ()) @@ -696,13 +689,10 @@ fn physx_collider_from_rapier_collider( } let mesh_desc = PxTriangleMeshDesc { obj: mesh_desc }; - let trimesh = cooking.create_triangle_mesh(physics, &mesh_desc); + let trimesh = physx::cooking::create_triangle_mesh(physics, &cooking_params, &mesh_desc); if let TriangleMeshCookingResult::Success(mut trimesh) = trimesh { - let flags = PxMeshGeometryFlags { - mBits: physx_sys::PxMeshGeometryFlag::eDOUBLE_SIDED as u8, - }; - + let flags = PxMeshGeometryFlags::DoubleSided; let scaling = unsafe { PxMeshScale_new() }; let geometry = PxTriangleMeshGeometry::new(&mut trimesh, &scaling, flags); physics.create_shape(&geometry, materials, true, shape_flags, ()) @@ -724,7 +714,6 @@ type PxShape = physx::shape::PxShape<(), PxMaterial>; type PxArticulationLink = physx::articulation_link::PxArticulationLink; type PxRigidStatic = physx::rigid_static::PxRigidStatic<(), PxShape>; type PxRigidDynamic = physx::rigid_dynamic::PxRigidDynamic; -type PxArticulation = physx::articulation::PxArticulation<(), PxArticulationLink>; type PxArticulationReducedCoordinate = physx::articulation_reduced_coordinate::PxArticulationReducedCoordinate<(), PxArticulationLink>; type PxScene = physx::scene::PxScene< @@ -732,7 +721,6 @@ type PxScene = physx::scene::PxScene< PxArticulationLink, PxRigidStatic, PxRigidDynamic, - PxArticulation, PxArticulationReducedCoordinate, OnCollision, OnTrigger, @@ -781,7 +769,7 @@ impl AdvanceCallback for OnAdvance { } } -unsafe extern "C" fn ccd_filter_shader(data: *mut FilterShaderCallbackInfo) -> u16 { - (*(*data).pairFlags).mBits |= physx_sys::PxPairFlag::eDETECT_CCD_CONTACT as u16; - 0 +unsafe extern "C" fn ccd_filter_shader(data: *mut FilterShaderCallbackInfo) -> PxFilterFlags { + (*(*data).pairFlags) |= physx_sys::PxPairFlags::DetectCcdContact; + PxFilterFlags::empty() }