diff --git a/crates/benches_common_3d/src/lib.rs b/crates/benches_common_3d/src/lib.rs index 5875ece5..f6b622b6 100644 --- a/crates/benches_common_3d/src/lib.rs +++ b/crates/benches_common_3d/src/lib.rs @@ -18,7 +18,7 @@ pub fn bench_app( PhysicsPlugins::default(), )); - app.insert_resource(PhysicsTimestep::FixedOnce(1.0 / 60.0)); + app.insert_resource(Time::new_with(Physics::fixed_once_hz(1.0 / 60.0))); setup(&mut app); diff --git a/crates/bevy_xpbd_3d/examples/basic_dynamic_character.rs b/crates/bevy_xpbd_3d/examples/basic_dynamic_character.rs index b47aa521..f8e2593d 100644 --- a/crates/bevy_xpbd_3d/examples/basic_dynamic_character.rs +++ b/crates/bevy_xpbd_3d/examples/basic_dynamic_character.rs @@ -238,7 +238,7 @@ fn movement( // both the `f32` and `f64` features. Otherwise you don't need this. let delta_time = time.delta_seconds_f64().adjust_precision(); - for event in movement_event_reader.iter() { + for event in movement_event_reader.read() { for (movement_acceleration, jump_impulse, mut linear_velocity, is_grounded) in &mut controllers { diff --git a/crates/bevy_xpbd_3d/examples/basic_kinematic_character.rs b/crates/bevy_xpbd_3d/examples/basic_kinematic_character.rs index f254f3c8..7b370b37 100644 --- a/crates/bevy_xpbd_3d/examples/basic_kinematic_character.rs +++ b/crates/bevy_xpbd_3d/examples/basic_kinematic_character.rs @@ -255,7 +255,7 @@ fn movement( // both the `f32` and `f64` features. Otherwise you don't need this. let delta_time = time.delta_seconds_f64().adjust_precision(); - for event in movement_event_reader.iter() { + for event in movement_event_reader.read() { for (movement_acceleration, jump_impulse, mut linear_velocity, is_grounded) in &mut controllers { diff --git a/crates/bevy_xpbd_3d/snapshots/bevy_xpbd_3d__tests__cubes_simulation_is_deterministic_across_machines.snap b/crates/bevy_xpbd_3d/snapshots/bevy_xpbd_3d__tests__cubes_simulation_is_deterministic_across_machines.snap index c9bef862..e992a5ef 100644 --- a/crates/bevy_xpbd_3d/snapshots/bevy_xpbd_3d__tests__cubes_simulation_is_deterministic_across_machines.snap +++ b/crates/bevy_xpbd_3d/snapshots/bevy_xpbd_3d__tests__cubes_simulation_is_deterministic_across_machines.snap @@ -9,15 +9,15 @@ expression: bodies ), Transform { translation: Vec3( - -4.3423853, - 0.49998048, - -5.2260904, + -4.5413985, + 0.49999854, + -5.812303, ), rotation: Quat( - 7.0508534e-8, - -0.089453705, - 6.083998e-7, - 0.995991, + 3.129878e-6, + 0.10535714, + -3.053036e-6, + 0.9944345, ), scale: Vec3( 1.0, @@ -32,15 +32,15 @@ expression: bodies ), Transform { translation: Vec3( - -4.418144, - 0.49997675, - -2.319346, + -4.106035, + 0.49994144, + -2.6481476, ), rotation: Quat( - 5.2947416e-6, - -0.02984577, - -1.8464465e-5, - 0.9995545, + 7.5037683e-6, + -0.15262182, + -2.0970647e-5, + 0.98828465, ), scale: Vec3( 1.0, @@ -55,15 +55,15 @@ expression: bodies ), Transform { translation: Vec3( - -5.8100367, - 0.49999845, - 0.14385882, + -4.611196, + 0.49995783, + -0.34869525, ), rotation: Quat( - 1.0953618e-6, - 0.4049569, - -1.3033888e-6, - 0.9143358, + -1.42509e-5, + -0.1841588, + -1.738285e-5, + 0.9828965, ), scale: Vec3( 1.0, @@ -78,15 +78,15 @@ expression: bodies ), Transform { translation: Vec3( - -5.864746, - 0.49999946, - 10.72942, + -4.586858, + 0.49993232, + 2.755423, ), rotation: Quat( - 7.0495884e-7, - 0.044847287, - -4.824935e-7, - 0.9989939, + -1.952987e-5, + 0.028491925, + -6.243225e-6, + 0.99959403, ), scale: Vec3( 1.0, @@ -101,15 +101,15 @@ expression: bodies ), Transform { translation: Vec3( - -2.002046, - 0.49996984, - -6.000447, + -1.4441824, + 0.49993822, + -5.2373285, ), rotation: Quat( - 1.1079425e-5, - 0.11743741, - -3.759696e-7, - 0.99308026, + -2.5923798e-6, + -0.010303094, + 5.548739e-6, + 0.99994695, ), scale: Vec3( 1.0, @@ -124,15 +124,15 @@ expression: bodies ), Transform { translation: Vec3( - -1.9987766, - 0.49999425, - -2.0733616, + -1.9532473, + 0.499997, + -2.6331823, ), rotation: Quat( - 7.4080567e-6, - -0.09336918, - -4.787302e-6, - 0.9956316, + 4.5943334e-6, + -0.13999754, + -1.9448112e-6, + 0.9901519, ), scale: Vec3( 1.0, @@ -147,15 +147,15 @@ expression: bodies ), Transform { translation: Vec3( - -2.0880558, - 0.49999642, - -0.017637428, + -2.0969713, + 0.49996477, + 0.6139536, ), rotation: Quat( - 4.727055e-6, - -0.10346992, - -2.2053052e-6, - 0.9946326, + 2.196806e-5, + 0.16460687, + 3.748077e-6, + 0.98635924, ), scale: Vec3( 1.0, @@ -170,15 +170,15 @@ expression: bodies ), Transform { translation: Vec3( - -2.1696157, - 0.49999964, - 2.2321312, + -2.0876007, + 0.49996525, + 3.1129513, ), rotation: Quat( - 6.511592e-7, - 0.008408211, - -4.7466727e-7, - 0.99996465, + -1.3366616e-5, + 0.088801324, + -4.3129737e-7, + 0.99604934, ), scale: Vec3( 1.0, @@ -193,15 +193,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.4415929, - 0.49995127, - -5.2534013, + 0.86435765, + 0.4999979, + -5.4886947, ), rotation: Quat( - 6.3904095e-6, - -0.18920605, - -6.5382255e-7, - 0.9819374, + 4.5033175e-6, + -0.004078502, + -2.4095154e-6, + 0.99999166, ), scale: Vec3( 1.0, @@ -216,15 +216,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.1919279, - 0.49992722, - -2.4087517, + 0.31714392, + 0.4999555, + -2.8910909, ), rotation: Quat( - -3.3877075e-6, - -0.13829833, - -9.278761e-6, - 0.9903906, + 1.1530377e-5, + -0.11013199, + -1.6434492e-6, + 0.993917, ), scale: Vec3( 1.0, @@ -239,15 +239,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.09996043, - 0.49993744, - -0.17984411, + 0.12120628, + 0.49995583, + 0.16215812, ), rotation: Quat( - 2.442432e-6, - -0.13113676, - 4.214775e-6, - 0.9913643, + -1.2795071e-5, + 0.06465573, + -2.9045584e-6, + 0.99790764, ), scale: Vec3( 1.0, @@ -262,15 +262,15 @@ expression: bodies ), Transform { translation: Vec3( - -0.051802184, - 0.49998862, - 2.0947423, + 0.008304957, + 0.49996242, + 2.9027696, ), rotation: Quat( - 9.652017e-6, - -0.015585309, - 7.912948e-6, - 0.9998785, + -1.1133008e-5, + 0.038613528, + 1.0067933e-7, + 0.9992542, ), scale: Vec3( 1.0, @@ -285,15 +285,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.7893236, - 0.4999985, - -5.2901754, + 2.9220781, + 0.49997145, + -5.256576, ), rotation: Quat( - 2.594992e-6, - -0.11510058, - -1.3799596e-6, - 0.99335384, + 3.5157368e-6, + -0.02764599, + 3.0049337e-6, + 0.99961776, ), scale: Vec3( 1.0, @@ -308,15 +308,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.4225495, - 0.49998072, - -2.4689758, + 2.684553, + 0.49993816, + -2.6182067, ), rotation: Quat( - 1.859268e-5, - -0.10815832, - -1.1543215e-5, - 0.9941337, + 1.3352204e-5, + -0.131964, + -1.6313822e-6, + 0.9912545, ), scale: Vec3( 1.0, @@ -331,15 +331,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.3873122, - 0.49993768, - -0.24063475, + 2.9588585, + 0.4999956, + 0.04658448, ), rotation: Quat( - 2.4468218e-6, - -0.16636215, - -8.848898e-6, - 0.98606473, + 6.2459617e-6, + 0.038999673, + -5.0032672e-6, + 0.9992392, ), scale: Vec3( 1.0, @@ -354,15 +354,15 @@ expression: bodies ), Transform { translation: Vec3( - 1.9841691, - 0.49994135, - 2.2754827, + 2.2449956, + 0.49992496, + 2.2596865, ), rotation: Quat( - 1.1781266e-5, - -0.023749417, - -4.3152977e-5, - 0.99971795, + 1.9367231e-5, + -0.06939591, + -2.0735426e-5, + 0.9975892, ), scale: Vec3( 1.0, @@ -377,15 +377,15 @@ expression: bodies ), Transform { translation: Vec3( - -4.529952, - 2.4999797, - -5.612147, + -5.0492163, + 2.499931, + -6.0282993, ), rotation: Quat( - 3.3643862e-6, - -0.03329149, - -9.2582775e-7, - 0.9994457, + 7.3457845e-6, + 0.2680555, + 9.548841e-6, + 0.96340346, ), scale: Vec3( 1.0, @@ -400,15 +400,15 @@ expression: bodies ), Transform { translation: Vec3( - -7.554939, - 0.49999902, - -3.4886525, + -4.2983556, + 2.4999576, + -2.6122365, ), rotation: Quat( - -0.21654743, - -0.21654907, - 0.6731332, - 0.67313105, + 1.9716752e-5, + 0.0059951264, + -2.8919663e-5, + 0.999982, ), scale: Vec3( 1.0, @@ -423,15 +423,15 @@ expression: bodies ), Transform { translation: Vec3( - -4.1945376, - 2.499955, - -0.85283583, + -5.7273064, + 2.4999127, + 0.27412993, ), rotation: Quat( - 4.944634e-6, - -0.026082661, - -1.6879303e-5, - 0.9996598, + 1.3019328e-5, + -0.0023009102, + -4.6772425e-6, + 0.9999974, ), scale: Vec3( 1.0, @@ -446,15 +446,15 @@ expression: bodies ), Transform { translation: Vec3( - -7.0669084, - 0.4999817, - 5.029825, + -4.6012526, + 2.4998872, + 2.3980725, ), rotation: Quat( - 0.24390373, - 0.24391572, - 0.6637086, - 0.663707, + -1.559511e-5, + 0.12684205, + -8.130988e-6, + 0.9919229, ), scale: Vec3( 1.0, @@ -469,15 +469,15 @@ expression: bodies ), Transform { translation: Vec3( - -2.0876231, - 2.4999635, - -5.7480035, + -2.0423634, + 2.4999042, + -5.741327, ), rotation: Quat( - 5.8374267e-6, - 0.06578543, - -6.170088e-6, - 0.9978338, + 7.3595934e-6, + -0.08775672, + 5.5570363e-6, + 0.9961419, ), scale: Vec3( 1.0, @@ -492,15 +492,15 @@ expression: bodies ), Transform { translation: Vec3( - -3.1656625, - 2.4999433, - -3.4006693, + -2.0788274, + 2.499925, + -3.1981113, ), rotation: Quat( - -1.0061125e-5, - 0.054074667, - -1.8010569e-5, - 0.9985369, + 1.7169506e-6, + 0.0031044492, + -2.4486344e-6, + 0.9999952, ), scale: Vec3( 1.0, @@ -515,15 +515,15 @@ expression: bodies ), Transform { translation: Vec3( - -2.0551093, - 2.499902, - -0.59087205, + -2.7910721, + 2.499912, + -0.1088266, ), rotation: Quat( - 1.4003897e-5, - -0.008215803, - 5.9098907e-6, - 0.99996626, + 4.0439677e-6, + 0.02391229, + -1.3426011e-5, + 0.9997141, ), scale: Vec3( 1.0, @@ -538,15 +538,15 @@ expression: bodies ), Transform { translation: Vec3( - -1.8675312, - 2.4999292, - 2.4463406, + -2.1026957, + 2.4999423, + 2.126103, ), rotation: Quat( - 1.6631959e-5, - 0.010085788, - 2.8320439e-5, - 0.99994916, + -1.6472013e-5, + 0.07974657, + 1.6223809e-6, + 0.99681515, ), scale: Vec3( 1.0, @@ -561,15 +561,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.20580432, - 2.4999607, - -5.553546, + 0.4159867, + 2.4999456, + -5.671932, ), rotation: Quat( - 6.2164586e-6, - -0.070013724, - 1.2371928e-6, - 0.997546, + 4.7749563e-6, + -0.039806098, + -9.192825e-6, + 0.99920744, ), scale: Vec3( 1.0, @@ -584,15 +584,15 @@ expression: bodies ), Transform { translation: Vec3( - -0.046197403, - 2.4999087, - -3.1004553, + 0.009944088, + 2.4999382, + -2.9049952, ), rotation: Quat( - 9.907863e-6, - -0.07425172, - 6.9092234e-6, - 0.99723953, + 1.9832803e-5, + 0.025701132, + -7.679594e-6, + 0.9996697, ), scale: Vec3( 1.0, @@ -607,15 +607,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.43064442, - 2.499901, - -0.7200156, + -0.027705673, + 2.4999232, + -0.5255546, ), rotation: Quat( - -9.297384e-6, - -0.16916226, - 6.2180707e-6, - 0.9855882, + -1.3373039e-5, + -0.01249971, + -5.143375e-6, + 0.99992186, ), scale: Vec3( 1.0, @@ -630,15 +630,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.33319852, - 2.49993, - 1.7533458, + 0.15756427, + 0.4999831, + 6.2050114, ), rotation: Quat( - 5.2576897e-6, - 0.059048217, - 3.0032135e-5, - 0.99825513, + 0.70335186, + -0.07272717, + 0.07272766, + 0.7033617, ), scale: Vec3( 1.0, @@ -653,15 +653,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.5240598, - 2.49996, - -5.153598, + 2.7432377, + 2.4999712, + -5.2332006, ), rotation: Quat( - 5.4377747e-6, - 0.021316562, - -3.2456228e-6, - 0.9997728, + 2.948699e-6, + -0.109006666, + 6.1619716e-7, + 0.994041, ), scale: Vec3( 1.0, @@ -676,15 +676,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.2167573, - 2.4999037, - -3.0990813, + 2.3952043, + 2.499925, + -2.9313323, ), rotation: Quat( - 8.897506e-6, - 0.024538169, - -7.983371e-6, - 0.9996989, + 1.1294509e-5, + 0.057740428, + -4.81759e-6, + 0.9983316, ), scale: Vec3( 1.0, @@ -699,15 +699,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.777542, - 2.4999046, - -1.0145668, + 2.7014956, + 2.4999084, + -0.87327075, ), rotation: Quat( - 3.320995e-6, - -0.022053385, - -9.2231585e-6, - 0.9997568, + 4.2539327e-6, + 0.047411464, + -2.3938906e-6, + 0.99887544, ), scale: Vec3( 1.0, @@ -722,15 +722,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.9648414, - 2.5094926, - 2.0242882, + 2.5445023, + 2.4998665, + 2.3220227, ), rotation: Quat( - 0.011472185, - 0.16150488, - -0.05372108, - 0.98534185, + 2.1606564e-5, + 0.0590353, + -3.931226e-6, + 0.9982559, ), scale: Vec3( 1.0, @@ -745,15 +745,15 @@ expression: bodies ), Transform { translation: Vec3( - -5.765128, - 2.4999764, - -3.0840755, + -4.923007, + 4.49984, + -5.5812387, ), rotation: Quat( - 0.70354617, - -0.07088181, - 0.070885, - 0.7035438, + 2.8722194e-5, + 0.20180498, + 2.2941827e-5, + 0.9794257, ), scale: Vec3( 1.0, @@ -768,15 +768,15 @@ expression: bodies ), Transform { translation: Vec3( - -13.816517, - 0.49999946, - -2.6666658, + -4.3314514, + 4.4999013, + -2.0581, ), rotation: Quat( - 0.39274207, - 0.39274085, - 0.5880086, - 0.58800864, + 2.7312024e-5, + 0.066441074, + -1.8625373e-5, + 0.99779034, ), scale: Vec3( 1.0, @@ -791,15 +791,15 @@ expression: bodies ), Transform { translation: Vec3( - -4.890072, - 0.49999946, - 4.149463, + -4.310249, + 4.4998846, + 0.4880767, ), rotation: Quat( - 0.9906625, - -3.4722166e-7, - -0.13633691, - 7.805152e-7, + 1.5218269e-5, + 0.00909351, + 6.987888e-8, + 0.99995863, ), scale: Vec3( 1.0, @@ -814,15 +814,15 @@ expression: bodies ), Transform { translation: Vec3( - -5.3232884, - 0.49999946, - 7.5046816, + -4.576476, + 4.4998965, + 2.7488616, ), rotation: Quat( - 0.17287572, - -0.17287457, - -0.6856489, - 0.68564856, + -1.1975025e-5, + 0.034274474, + -3.9548036e-6, + 0.9994125, ), scale: Vec3( 1.0, @@ -837,15 +837,15 @@ expression: bodies ), Transform { translation: Vec3( - -2.519231, - 4.4999247, - -4.939171, + -2.1803253, + 4.499893, + -4.761975, ), rotation: Quat( - 8.879804e-6, - -0.062154848, - -9.166951e-6, - 0.99806654, + 4.559176e-6, + 0.03340758, + 6.472455e-6, + 0.9994418, ), scale: Vec3( 1.0, @@ -860,15 +860,15 @@ expression: bodies ), Transform { translation: Vec3( - -2.1316211, - 4.4999175, - -2.5869262, + -2.0722492, + 4.4999146, + -1.794916, ), rotation: Quat( - -5.219531e-6, - 0.14853707, - -1.6233678e-5, - 0.98890686, + 1.0337201e-5, + 0.0155743975, + -3.2420721e-6, + 0.9998787, ), scale: Vec3( 1.0, @@ -883,15 +883,15 @@ expression: bodies ), Transform { translation: Vec3( - -1.9301183, - 4.4998198, - 0.39429086, + -2.307627, + 4.49988, + 0.61351854, ), rotation: Quat( - 5.590077e-6, - 0.037300963, - -3.5825815e-7, - 0.99930406, + -8.7578326e-7, + 0.009089355, + -8.641349e-7, + 0.9999587, ), scale: Vec3( 1.0, @@ -906,15 +906,15 @@ expression: bodies ), Transform { translation: Vec3( - -1.9454087, - 4.499897, - 2.6208901, + -2.3021808, + 4.4998846, + 2.7617326, ), rotation: Quat( - 1.2467614e-5, - -0.011406328, - 9.658577e-6, - 0.999935, + -8.255966e-6, + 0.037309136, + 8.012342e-6, + 0.99930376, ), scale: Vec3( 1.0, @@ -929,15 +929,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.023093386, - 4.499903, - -4.805308, + 0.21563683, + 4.499931, + -5.2085485, ), rotation: Quat( - 1.35582595e-5, - -0.05320665, - -4.983353e-6, - 0.9985835, + 7.0251995e-6, + 0.09304502, + -1.8975404e-6, + 0.9956619, ), scale: Vec3( 1.0, @@ -952,15 +952,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.2381041, - 4.499887, - -2.1646936, + 0.07514802, + 4.4999037, + -1.7679547, ), rotation: Quat( - -3.4829784e-6, - 0.081186235, - 1.0766839e-5, - 0.996699, + -6.8500353e-6, + 0.06929297, + -8.173861e-6, + 0.9975964, ), scale: Vec3( 1.0, @@ -975,15 +975,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.123668894, - 4.499909, - 0.13765599, + 0.21849424, + 2.4999511, + 2.268026, ), rotation: Quat( - -1.2879159e-5, - 0.0511759, - 1.0409426e-5, - 0.99868965, + 0.7050691, + 0.05347584, + -0.053473327, + 0.70509464, ), scale: Vec3( 1.0, @@ -998,15 +998,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.38199478, - 4.4998755, - 2.155535, + -0.15893307, + 0.49999946, + 14.054075, ), rotation: Quat( - 1.7575554e-5, - 0.03409461, - 1.6102516e-5, - 0.9994186, + 0.24499272, + -0.6633089, + 0.66330916, + 0.24499154, ), scale: Vec3( 1.0, @@ -1021,15 +1021,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.3284, - 4.499923, - -4.5088305, + 2.741496, + 4.4999495, + -4.399559, ), rotation: Quat( - 1.7217164e-6, - 0.03293351, - -6.5417835e-6, - 0.99945754, + -4.817967e-7, + 0.12594306, + -1.3559584e-7, + 0.9920375, ), scale: Vec3( 1.0, @@ -1044,15 +1044,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.3431964, - 4.499921, - -2.214988, + 2.2909536, + 4.4998837, + -1.8916278, ), rotation: Quat( - -3.5771816e-7, - 0.0518102, - -7.923867e-6, - 0.9986569, + 1.621344e-5, + -0.010875906, + -7.4107456e-6, + 0.9999409, ), scale: Vec3( 1.0, @@ -1067,15 +1067,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.7946022, - 4.4998875, - -0.0139336735, + 2.6957374, + 4.4998984, + 0.84554696, ), rotation: Quat( - 1.5601541e-5, - 0.0833966, - -1.4010156e-5, - 0.9965164, + -9.056017e-6, + 0.10746751, + -4.5834727e-6, + 0.9942086, ), scale: Vec3( 1.0, @@ -1090,15 +1090,15 @@ expression: bodies ), Transform { translation: Vec3( - 3.0126758, - 4.515729, - 2.1400247, + 2.3865237, + 4.499817, + 3.011156, ), rotation: Quat( - 0.006832012, - 0.076710194, - -0.05451029, - 0.9955388, + 3.0853287e-5, + 0.06858917, + 3.6555857e-6, + 0.99764496, ), scale: Vec3( 1.0, @@ -1113,15 +1113,15 @@ expression: bodies ), Transform { translation: Vec3( - -5.9567966, - 0.49999946, - -15.039063, + -5.356343, + 6.499813, + -5.3526754, ), rotation: Quat( - -0.6367192, - -0.30755216, - -0.30755338, - 0.6367191, + 3.338445e-5, + -0.1598523, + 1.0022045e-5, + 0.98714095, ), scale: Vec3( 1.0, @@ -1136,15 +1136,15 @@ expression: bodies ), Transform { translation: Vec3( - -9.057555, - 0.49999946, - -16.593468, + -4.5087557, + 6.499899, + -1.9152997, ), rotation: Quat( - -5.39113e-7, - -0.3264162, - 6.6266443e-7, - -0.94522613, + 2.3485596e-5, + -0.04065414, + -2.5801583e-5, + 0.9991733, ), scale: Vec3( 1.0, @@ -1159,15 +1159,15 @@ expression: bodies ), Transform { translation: Vec3( - -7.4289837, - 2.49997, - 4.1270623, + -4.3715563, + 6.4998913, + 0.37903965, ), rotation: Quat( - 0.40007415, - -0.5830352, - 0.58305484, - 0.40007216, + 1.587369e-5, + -0.04997984, + -2.3563673e-6, + 0.9987502, ), scale: Vec3( 1.0, @@ -1182,15 +1182,15 @@ expression: bodies ), Transform { translation: Vec3( - -1.3038301, - 0.49999946, - 6.2001443, + -4.3700805, + 6.4998794, + 2.4656587, ), rotation: Quat( - 0.051233403, - -0.051232334, - -0.7052486, - 0.70524806, + 7.448714e-7, + -0.014588609, + -5.77096e-6, + 0.9998936, ), scale: Vec3( 1.0, @@ -1205,15 +1205,15 @@ expression: bodies ), Transform { translation: Vec3( - -3.125293, - 0.49999946, - -11.440222, + -2.0031815, + 6.4998455, + -5.58802, ), rotation: Quat( - 0.6702525, - -0.22530505, - -0.22530428, - -0.6702516, + -2.2420523e-5, + 0.083723344, + -7.609045e-8, + 0.99648905, ), scale: Vec3( 1.0, @@ -1228,15 +1228,15 @@ expression: bodies ), Transform { translation: Vec3( - -1.343801, - 8.49984, - -1.39195, + -2.1030593, + 6.499881, + -1.6630093, ), rotation: Quat( - -9.068188e-6, - 0.1468774, - 1.5842481e-5, - 0.9891547, + 1.4350294e-5, + -0.027450336, + 9.11208e-7, + 0.9996232, ), scale: Vec3( 1.0, @@ -1251,15 +1251,15 @@ expression: bodies ), Transform { translation: Vec3( - -1.9640384, - 6.4998183, - 0.043135934, + -2.2546158, + 6.4998837, + 1.0217232, ), rotation: Quat( - 7.724208e-7, - 0.05969343, - -5.3838295e-7, - 0.99821675, + -3.3091305e-6, + -0.048803434, + -1.8368564e-7, + 0.9988084, ), scale: Vec3( 1.0, @@ -1274,15 +1274,15 @@ expression: bodies ), Transform { translation: Vec3( - -2.1944664, - 6.49986, - 2.2293992, + -2.223439, + 6.4998918, + 3.0436418, ), rotation: Quat( - 1.1161066e-5, - 0.051818613, - 1.1157999e-5, - 0.9986565, + -3.5988558e-6, + -0.04613042, + 9.794142e-6, + 0.9989354, ), scale: Vec3( 1.0, @@ -1297,15 +1297,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.10358212, - 6.499878, - -4.4241066, + -0.34121677, + 0.49999946, + -12.28647, ), rotation: Quat( - 6.104767e-6, - 0.053888626, - -5.7036636e-6, - 0.99854696, + -0.7058801, + -0.04163728, + 0.04163834, + -0.7058795, ), scale: Vec3( 1.0, @@ -1320,15 +1320,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.20536682, - 6.499875, - -2.253804, + 0.21524978, + 6.499891, + -2.1798837, ), rotation: Quat( - -8.429002e-6, - 0.050227713, - 1.5702573e-5, - 0.9987378, + -2.7827295e-7, + 0.028934516, + -1.21381645e-5, + 0.99958134, ), scale: Vec3( 1.0, @@ -1343,15 +1343,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.17854159, - 6.4999056, - -0.03477119, + 0.21331881, + 4.4999504, + 1.0747148, ), rotation: Quat( - -1.2174453e-5, - 0.09614292, - 1.2362508e-5, - 0.9953675, + 0.70372194, + 0.069124065, + -0.06912637, + 0.7037178, ), scale: Vec3( 1.0, @@ -1366,15 +1366,15 @@ expression: bodies ), Transform { translation: Vec3( - 0.5086605, - 6.4998803, - 2.1787782, + 0.04732995, + 2.4999766, + 5.526497, ), rotation: Quat( - 1.47881665e-5, - 0.074487105, - 2.0442863e-5, - 0.997222, + -6.6093203e-6, + -0.19084512, + -4.316239e-7, + 0.98162013, ), scale: Vec3( 1.0, @@ -1389,15 +1389,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.1565268, - 6.499895, - -4.180186, + 2.5132034, + 0.49999946, + -12.6818905, ), rotation: Quat( - 1.2203349e-6, - 0.05432318, - -7.3620336e-6, - 0.9985234, + 0.4015998, + -0.58199495, + -0.5819949, + -0.4015986, ), scale: Vec3( 1.0, @@ -1412,15 +1412,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.2868984, - 6.499886, - -1.9875554, + 2.3392503, + 6.499887, + -2.1237445, ), rotation: Quat( - -6.299892e-6, - 0.06857006, - -1.2678447e-5, - 0.99764633, + 1.4020251e-5, + -0.024601525, + -1.0950789e-5, + 0.9996973, ), scale: Vec3( 1.0, @@ -1435,15 +1435,15 @@ expression: bodies ), Transform { translation: Vec3( - 2.5892315, - 6.572279, - 0.19461481, + 3.0234728, + 6.499886, + -0.015130474, ), rotation: Quat( - -0.006034577, - 0.16051215, - -0.037162755, - 0.98631555, + -6.812577e-6, + -0.011945665, + -4.023148e-6, + 0.99992865, ), scale: Vec3( 1.0, @@ -1458,15 +1458,15 @@ expression: bodies ), Transform { translation: Vec3( - 3.456651, - 6.4772625, - 2.4567757, + 2.1512942, + 6.4998126, + 3.0366783, ), rotation: Quat( - 0.01399032, - 0.20793366, - -0.053124662, - 0.97659904, + 3.4144425e-5, + 0.06691018, + 8.9876676e-7, + 0.997759, ), scale: Vec3( 1.0, diff --git a/crates/examples_common_2d/src/lib.rs b/crates/examples_common_2d/src/lib.rs index 51283b73..ccbfa54b 100644 --- a/crates/examples_common_2d/src/lib.rs +++ b/crates/examples_common_2d/src/lib.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use bevy::{ diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, prelude::*, @@ -12,8 +14,14 @@ impl Plugin for XpbdExamplePlugin { app.add_plugins((PhysicsPlugins::default(), FrameTimeDiagnosticsPlugin)) .add_state::() .add_systems(Startup, setup) - .add_systems(OnEnter(AppState::Paused), bevy_xpbd_2d::pause) - .add_systems(OnExit(AppState::Paused), bevy_xpbd_2d::resume) + .add_systems( + OnEnter(AppState::Paused), + |mut time: ResMut>| time.pause(), + ) + .add_systems( + OnExit(AppState::Paused), + |mut time: ResMut>| time.unpause(), + ) .add_systems(Update, update_fps_text) .add_systems(Update, pause_button) .add_systems(Update, step_button.run_if(in_state(AppState::Paused))); @@ -41,9 +49,9 @@ fn pause_button( } } -fn step_button(mut physics_loop: ResMut, keys: Res>) { +fn step_button(mut time: ResMut>, keys: Res>) { if keys.just_pressed(KeyCode::Return) { - physics_loop.step(); + time.advance_by(Duration::from_secs_f64(1.0 / 60.0)); } } diff --git a/crates/examples_common_3d/src/lib.rs b/crates/examples_common_3d/src/lib.rs index 6be41ad8..25f301c2 100644 --- a/crates/examples_common_3d/src/lib.rs +++ b/crates/examples_common_3d/src/lib.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use bevy::{ diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, prelude::*, @@ -12,8 +14,14 @@ impl Plugin for XpbdExamplePlugin { app.add_plugins((PhysicsPlugins::default(), FrameTimeDiagnosticsPlugin)) .add_state::() .add_systems(Startup, setup) - .add_systems(OnEnter(AppState::Paused), bevy_xpbd_3d::pause) - .add_systems(OnExit(AppState::Paused), bevy_xpbd_3d::resume) + .add_systems( + OnEnter(AppState::Paused), + |mut time: ResMut>| time.pause(), + ) + .add_systems( + OnExit(AppState::Paused), + |mut time: ResMut>| time.unpause(), + ) .add_systems(Update, update_fps_text) .add_systems(Update, pause_button) .add_systems(Update, step_button.run_if(in_state(AppState::Paused))); @@ -41,9 +49,9 @@ fn pause_button( } } -fn step_button(mut physics_loop: ResMut, keys: Res>) { +fn step_button(mut time: ResMut>, keys: Res>) { if keys.just_pressed(KeyCode::Return) { - physics_loop.step(); + time.advance_by(Duration::from_secs_f64(1.0 / 60.0)); } } diff --git a/src/constraints/mod.rs b/src/constraints/mod.rs index 3900ab7b..92073295 100644 --- a/src/constraints/mod.rs +++ b/src/constraints/mod.rs @@ -133,7 +133,7 @@ //! ``` //! //! where `w_i` is the inverse mass of particle `i`, `|▽C_i|` is the length of the gradient vector for particle `i`, -//! `α` is the constraint's compliance (inverse of stiffness) and `h` is the [substep size](SubDeltaTime). Using `α = 0` +//! `α` is the constraint's compliance (inverse of stiffness) and `h` is the substep size. Using `α = 0` //! corresponds to infinite stiffness. //! //! The minus sign is there because the gradients point in the direction in which `C` increases the most, diff --git a/src/lib.rs b/src/lib.rs index bffd1d2f..0f7153c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -164,8 +164,8 @@ //! ### Configuration //! //! - [Gravity] -//! - [Physics timestep](PhysicsTimestep) -//! - [Speed up or slow down time](PhysicsTimescale) +//! - [Physics timestep](Physics#usage) +//! - [Physics speed](Physics#physics-speed) //! - [Configure simulation fidelity with substeps](SubstepCount) //! - [Render physics objects for debugging](PhysicsDebugPlugin) //! @@ -177,8 +177,7 @@ //! - [`SubstepSchedule`] and [`SubstepSet`] //! - [`PostProcessCollisions`] schedule //! - [Configure the schedule used for running physics](PhysicsPlugins#custom-schedule) -//! - [Pausing, resuming and stepping the physics loop](PhysicsLoop) -//! - [Running physics manually](PhysicsPlugins#running-physics-manually) +//! - [Pausing, resuming and stepping physics](Physics#pausing-resuming-and-stepping-physics) //! - [Usage on servers](#can-the-engine-be-used-on-servers) //! //! ### Architecture @@ -315,11 +314,12 @@ //! ### Can the engine be used on servers? //! //! Yes! Networking often requires running the simulation in a specific schedule, and in Bevy XPBD you can -//! [set the schedule that runs physics](PhysicsPlugins#custom-schedule) and [configure the timestep](PhysicsTimestep) +//! [set the schedule that runs physics](PhysicsPlugins#custom-schedule) and [configure the timestep](Physics) //! to whatever you want. //! -//! One configuration is to run the client in `FixedUpdate`, and to use [`PhysicsTimestep::FixedOnce`] on both the -//! server and the client to make sure the physics simulation is only advanced by one step each time the schedule runs. +//! One configuration is to run the client in `FixedUpdate`, and to use a fixed timestep for `Time` +//! on both the server and the client to make sure the physics simulation is only advanced by one step +//! each time the schedule runs. //! //! Note that while Bevy XPBD should be locally deterministic, it can produce slightly different results on different //! machines. @@ -393,7 +393,7 @@ //! solve_velocities(particles and bodies) //! ``` //! -//! where `h` is the [substep size](SubDeltaTime), `q` is the [rotation](Rotation) as a quaternion, +//! where `h` is the substep size, `q` is the [rotation](Rotation) as a quaternion, //! `ω` is the [angular velocity](AngularVelocity), `I` is the [angular inertia tensor](`Inertia`) and `τ` is the //! [external torque](ExternalTorque). //! @@ -498,7 +498,6 @@ pub mod prelude { pub(crate) use crate::{math::*, *}; pub use bevy_xpbd_derive::*; } -pub use prelude::setup::{pause, resume}; mod utils; diff --git a/src/plugins/collision/broad_phase.rs b/src/plugins/collision/broad_phase.rs index 15e33239..a7fec4f1 100644 --- a/src/plugins/collision/broad_phase.rs +++ b/src/plugins/collision/broad_phase.rs @@ -68,10 +68,10 @@ fn update_aabb( (&Position, Option<&LinearVelocity>, Option<&AngularVelocity>), With, >, - dt: Res, + dt: Res