1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
#![deny(unsafe_code)]
#![warn(
clippy::all,
clippy::await_holding_lock,
clippy::char_lit_as_u8,
clippy::checked_conversions,
clippy::dbg_macro,
clippy::debug_assert_with_mut_call,
clippy::doc_markdown,
clippy::empty_enum,
clippy::enum_glob_use,
clippy::exit,
clippy::expl_impl_clone_on_copy,
clippy::explicit_deref_methods,
clippy::explicit_into_iter_loop,
clippy::fallible_impl_from,
clippy::filter_map_next,
clippy::flat_map_option,
clippy::float_cmp_const,
clippy::fn_params_excessive_bools,
clippy::from_iter_instead_of_collect,
clippy::if_let_mutex,
clippy::implicit_clone,
clippy::imprecise_flops,
clippy::inefficient_to_string,
clippy::invalid_upcast_comparisons,
clippy::large_digit_groups,
clippy::large_stack_arrays,
clippy::large_types_passed_by_value,
clippy::let_unit_value,
clippy::linkedlist,
clippy::lossy_float_literal,
clippy::macro_use_imports,
clippy::manual_ok_or,
clippy::map_err_ignore,
clippy::map_flatten,
clippy::map_unwrap_or,
clippy::match_on_vec_items,
clippy::match_same_arms,
clippy::match_wild_err_arm,
clippy::match_wildcard_for_single_variants,
clippy::mem_forget,
clippy::mismatched_target_os,
clippy::missing_enforced_import_renames,
clippy::mut_mut,
clippy::mutex_integer,
clippy::needless_borrow,
clippy::needless_continue,
clippy::needless_for_each,
clippy::option_option,
clippy::path_buf_push_overwrite,
clippy::ptr_as_ptr,
clippy::rc_mutex,
clippy::ref_option_ref,
clippy::rest_pat_in_fully_bound_structs,
clippy::same_functions_in_if_condition,
clippy::semicolon_if_nothing_returned,
clippy::single_match_else,
clippy::string_add_assign,
clippy::string_add,
clippy::string_lit_as_bytes,
clippy::string_to_string,
clippy::todo,
clippy::trait_duplication_in_bounds,
clippy::unimplemented,
clippy::unnested_or_patterns,
clippy::unused_self,
clippy::useless_transmute,
clippy::verbose_file_reads,
clippy::zero_sized_map_values,
future_incompatible,
nonstandard_style,
rust_2018_idioms
)]
#![allow(
unsafe_code,
non_upper_case_globals,
non_camel_case_types,
non_snake_case,
clippy::doc_markdown, clippy::unreadable_literal,
clippy::unused_unit,
clippy::upper_case_acronyms
)]
#[cfg(feature = "structgen")]
include!(concat!(env!("OUT_DIR"), "/structgen_out.rs"));
#[cfg(all(
not(feature = "structgen"),
target_os = "linux",
target_arch = "x86_64",
))]
include!("generated/x86_64-unknown-linux/structgen.rs");
#[cfg(all(
not(feature = "structgen"),
target_os = "linux",
target_arch = "aarch64",
))]
include!("generated/aarch64-unknown-linux-gnu/structgen.rs");
#[cfg(all(
not(feature = "structgen"),
target_os = "android",
target_arch = "aarch64",
))]
include!("generated/aarch64-linux-android/structgen.rs");
#[cfg(all(
not(feature = "structgen"),
target_os = "macos",
target_arch = "x86_64",
))]
include!("generated/x86_64-apple-darwin/structgen.rs");
#[cfg(all(
not(feature = "structgen"),
target_os = "macos",
target_arch = "aarch64",
))]
include!("generated/aarch64-apple-darwin/structgen.rs");
#[cfg(all(
not(feature = "structgen"),
target_os = "windows",
target_arch = "x86_64",
target_env = "msvc",
))]
include!("generated/x86_64-pc-windows-msvc/structgen.rs");
include!("physx_generated.rs");
use std::ffi::c_void;
pub const fn version(major: u32, minor: u32, patch: u32) -> u32 {
(major << 24) + (minor << 16) + (patch << 8)
}
pub type CollisionCallback =
unsafe extern "C" fn(*mut c_void, *const PxContactPairHeader, *const PxContactPair, u32);
pub type TriggerCallback = unsafe extern "C" fn(*mut c_void, *const PxTriggerPair, u32);
pub type ConstraintBreakCallback = unsafe extern "C" fn(*mut c_void, *const PxConstraintInfo, u32);
pub type WakeSleepCallback = unsafe extern "C" fn(*mut c_void, *const *const PxActor, u32, bool);
pub type AdvanceCallback =
unsafe extern "C" fn(*mut c_void, *const *const PxRigidBody, *const PxTransform, u32);
#[repr(C)]
pub struct SimulationEventCallbackInfo {
pub collision_callback: Option<CollisionCallback>,
pub collision_user_data: *mut c_void,
pub trigger_callback: Option<TriggerCallback>,
pub trigger_user_data: *mut c_void,
pub constraint_break_callback: Option<ConstraintBreakCallback>,
pub constraint_break_user_data: *mut c_void,
pub wake_sleep_callback: Option<WakeSleepCallback>,
pub wake_sleep_user_data: *mut c_void,
pub advance_callback: Option<AdvanceCallback>,
pub advance_user_data: *mut c_void,
}
impl Default for SimulationEventCallbackInfo {
fn default() -> Self {
Self {
collision_callback: None,
collision_user_data: std::ptr::null_mut(),
trigger_callback: None,
trigger_user_data: std::ptr::null_mut(),
constraint_break_callback: None,
constraint_break_user_data: std::ptr::null_mut(),
wake_sleep_callback: None,
wake_sleep_user_data: std::ptr::null_mut(),
advance_callback: None,
advance_user_data: std::ptr::null_mut(),
}
}
}
pub type RaycastHitCallback = unsafe extern "C" fn(
*const PxRigidActor,
*const PxFilterData,
*const PxShape,
hit_flags: u32,
*const c_void,
) -> u32;
#[repr(C)]
pub struct FilterShaderCallbackInfo {
pub attributes0: u32,
pub attributes1: u32,
pub filterData0: PxFilterData,
pub filterData1: PxFilterData,
pub pairFlags: *mut PxPairFlags,
pub constantBlock: *const std::ffi::c_void,
pub constantBlockSize: u32,
}
pub type SimulationFilterShader = unsafe extern "C" fn(*mut FilterShaderCallbackInfo) -> u16;
pub type AllocCallback =
unsafe extern "C" fn(u64, *const c_void, *const c_void, u32, *const c_void) -> *mut c_void;
pub type DeallocCallback = unsafe extern "C" fn(*const c_void, *const c_void);
pub type ZoneStartCallback =
unsafe extern "C" fn(*const i8, bool, u64, *const c_void) -> *mut c_void;
pub type ZoneEndCallback = unsafe extern "C" fn(*const c_void, *const i8, bool, u64, *const c_void);
pub type ErrorCallback =
unsafe extern "C" fn(PxErrorCode::Enum, *const i8, *const i8, u32, *const c_void);
extern "C" {
pub fn physx_create_foundation() -> *mut PxFoundation;
pub fn physx_create_foundation_with_alloc(
allocator: *mut PxDefaultAllocator,
) -> *mut PxFoundation;
pub fn physx_create_physics(foundation: *mut PxFoundation) -> *mut PxPhysics;
pub fn get_default_allocator() -> *mut PxDefaultAllocator;
pub fn get_default_error_callback() -> *mut PxDefaultErrorCallback;
pub fn create_raycast_filter_callback(
actor_to_ignore: *const PxRigidActor,
) -> *mut PxQueryFilterCallback;
pub fn create_raycast_filter_callback_func(
callback: RaycastHitCallback,
userdata: *mut c_void,
) -> *mut PxQueryFilterCallback;
pub fn create_alloc_callback(
alloc_callback: AllocCallback,
dealloc_callback: DeallocCallback,
userdata: *mut c_void,
) -> *mut PxAllocatorCallback;
pub fn create_profiler_callback(
zone_start_callback: ZoneStartCallback,
zone_end_callback: ZoneEndCallback,
userdata: *mut c_void,
) -> *mut PxProfilerCallback;
pub fn get_alloc_callback_user_data(alloc_callback: *mut PxAllocatorCallback) -> *mut c_void;
pub fn create_error_callback(
error_callback: ErrorCallback,
userdata: *mut c_void,
) -> *mut PxErrorCallback;
pub fn get_default_simulation_filter_shader() -> *mut c_void;
#[deprecated]
pub fn create_contact_callback(
callback: CollisionCallback,
userdata: *mut c_void,
) -> *mut PxSimulationEventCallback;
#[deprecated()]
pub fn destroy_contact_callback(callback: *mut PxSimulationEventCallback);
pub fn create_simulation_event_callbacks(
callbacks: *const SimulationEventCallbackInfo,
) -> *mut PxSimulationEventCallback;
pub fn get_simulation_event_info(
callback: *mut PxSimulationEventCallback,
) -> *mut SimulationEventCallbackInfo;
pub fn destroy_simulation_event_callbacks(callback: *mut PxSimulationEventCallback);
pub fn enable_custom_filter_shader(
scene_desc: *mut PxSceneDesc,
shader: SimulationFilterShader,
call_default_filter_shader_first: u32,
);
}