Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/physics_3d/physics_server_3d.h
11322 views
1
/**************************************************************************/
2
/* physics_server_3d.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/io/resource.h"
34
#include "core/object/gdvirtual.gen.inc"
35
36
constexpr int MAX_CONTACTS_REPORTED_3D_MAX = 4096;
37
38
class PhysicsDirectSpaceState3D;
39
template <typename T>
40
class TypedArray;
41
42
class PhysicsDirectBodyState3D : public Object {
43
GDCLASS(PhysicsDirectBodyState3D, Object);
44
45
protected:
46
static void _bind_methods();
47
48
public:
49
virtual Vector3 get_total_gravity() const = 0;
50
virtual real_t get_total_angular_damp() const = 0;
51
virtual real_t get_total_linear_damp() const = 0;
52
53
virtual Vector3 get_center_of_mass() const = 0;
54
virtual Vector3 get_center_of_mass_local() const = 0;
55
virtual Basis get_principal_inertia_axes() const = 0;
56
virtual real_t get_inverse_mass() const = 0; // get the mass
57
virtual Vector3 get_inverse_inertia() const = 0; // get density of this body space
58
virtual Basis get_inverse_inertia_tensor() const = 0; // get density of this body space
59
60
virtual void set_linear_velocity(const Vector3 &p_velocity) = 0;
61
virtual Vector3 get_linear_velocity() const = 0;
62
63
virtual void set_angular_velocity(const Vector3 &p_velocity) = 0;
64
virtual Vector3 get_angular_velocity() const = 0;
65
66
virtual void set_transform(const Transform3D &p_transform) = 0;
67
virtual Transform3D get_transform() const = 0;
68
69
virtual Vector3 get_velocity_at_local_position(const Vector3 &p_position) const = 0;
70
71
virtual void apply_central_impulse(const Vector3 &p_impulse) = 0;
72
virtual void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) = 0;
73
virtual void apply_torque_impulse(const Vector3 &p_impulse) = 0;
74
75
virtual void apply_central_force(const Vector3 &p_force) = 0;
76
virtual void apply_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()) = 0;
77
virtual void apply_torque(const Vector3 &p_torque) = 0;
78
79
virtual void add_constant_central_force(const Vector3 &p_force) = 0;
80
virtual void add_constant_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()) = 0;
81
virtual void add_constant_torque(const Vector3 &p_torque) = 0;
82
83
virtual void set_constant_force(const Vector3 &p_force) = 0;
84
virtual Vector3 get_constant_force() const = 0;
85
86
virtual void set_constant_torque(const Vector3 &p_torque) = 0;
87
virtual Vector3 get_constant_torque() const = 0;
88
89
virtual void set_sleep_state(bool p_sleep) = 0;
90
virtual bool is_sleeping() const = 0;
91
92
virtual void set_collision_layer(uint32_t p_layer) = 0;
93
virtual uint32_t get_collision_layer() const = 0;
94
95
virtual void set_collision_mask(uint32_t p_mask) = 0;
96
virtual uint32_t get_collision_mask() const = 0;
97
98
virtual int get_contact_count() const = 0;
99
100
virtual Vector3 get_contact_local_position(int p_contact_idx) const = 0;
101
virtual Vector3 get_contact_local_normal(int p_contact_idx) const = 0;
102
virtual Vector3 get_contact_impulse(int p_contact_idx) const = 0;
103
virtual int get_contact_local_shape(int p_contact_idx) const = 0;
104
virtual Vector3 get_contact_local_velocity_at_position(int p_contact_idx) const = 0;
105
106
virtual RID get_contact_collider(int p_contact_idx) const = 0;
107
virtual Vector3 get_contact_collider_position(int p_contact_idx) const = 0;
108
virtual ObjectID get_contact_collider_id(int p_contact_idx) const = 0;
109
virtual Object *get_contact_collider_object(int p_contact_idx) const;
110
virtual int get_contact_collider_shape(int p_contact_idx) const = 0;
111
virtual Vector3 get_contact_collider_velocity_at_position(int p_contact_idx) const = 0;
112
113
virtual real_t get_step() const = 0;
114
virtual void integrate_forces();
115
116
virtual PhysicsDirectSpaceState3D *get_space_state() = 0;
117
118
PhysicsDirectBodyState3D();
119
};
120
121
class PhysicsRayQueryParameters3D;
122
class PhysicsPointQueryParameters3D;
123
class PhysicsShapeQueryParameters3D;
124
125
class PhysicsDirectSpaceState3D : public Object {
126
GDCLASS(PhysicsDirectSpaceState3D, Object);
127
128
private:
129
Dictionary _intersect_ray(const Ref<PhysicsRayQueryParameters3D> &p_ray_query);
130
TypedArray<Dictionary> _intersect_point(const Ref<PhysicsPointQueryParameters3D> &p_point_query, int p_max_results = 32);
131
TypedArray<Dictionary> _intersect_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results = 32);
132
Vector<real_t> _cast_motion(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query);
133
TypedArray<Vector3> _collide_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results = 32);
134
Dictionary _get_rest_info(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query);
135
136
protected:
137
static void _bind_methods();
138
139
public:
140
struct RayParameters {
141
Vector3 from;
142
Vector3 to;
143
HashSet<RID> exclude;
144
uint32_t collision_mask = UINT32_MAX;
145
146
bool collide_with_bodies = true;
147
bool collide_with_areas = false;
148
149
bool hit_from_inside = false;
150
bool hit_back_faces = true;
151
152
bool pick_ray = false;
153
};
154
155
struct RayResult {
156
Vector3 position;
157
Vector3 normal;
158
RID rid;
159
ObjectID collider_id;
160
Object *collider = nullptr;
161
int shape = 0;
162
int face_index = -1;
163
};
164
165
virtual bool intersect_ray(const RayParameters &p_parameters, RayResult &r_result) = 0;
166
167
struct ShapeResult {
168
RID rid;
169
ObjectID collider_id;
170
Object *collider = nullptr;
171
int shape = 0;
172
};
173
174
struct PointParameters {
175
Vector3 position;
176
HashSet<RID> exclude;
177
uint32_t collision_mask = UINT32_MAX;
178
179
bool collide_with_bodies = true;
180
bool collide_with_areas = false;
181
};
182
183
virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) = 0;
184
185
struct ShapeParameters {
186
RID shape_rid;
187
Transform3D transform;
188
Vector3 motion;
189
real_t margin = 0.0;
190
HashSet<RID> exclude;
191
uint32_t collision_mask = UINT32_MAX;
192
193
bool collide_with_bodies = true;
194
bool collide_with_areas = false;
195
};
196
197
struct ShapeRestInfo {
198
Vector3 point;
199
Vector3 normal;
200
RID rid;
201
ObjectID collider_id;
202
int shape = 0;
203
Vector3 linear_velocity; // Velocity at contact point.
204
};
205
206
virtual int intersect_shape(const ShapeParameters &p_parameters, ShapeResult *r_results, int p_result_max) = 0;
207
virtual bool cast_motion(const ShapeParameters &p_parameters, real_t &p_closest_safe, real_t &p_closest_unsafe, ShapeRestInfo *r_info = nullptr) = 0;
208
virtual bool collide_shape(const ShapeParameters &p_parameters, Vector3 *r_results, int p_result_max, int &r_result_count) = 0;
209
virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) = 0;
210
211
virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const = 0;
212
213
PhysicsDirectSpaceState3D();
214
};
215
216
class PhysicsServer3DRenderingServerHandler : public Object {
217
GDCLASS(PhysicsServer3DRenderingServerHandler, Object)
218
protected:
219
GDVIRTUAL2_REQUIRED(_set_vertex, int, const Vector3 &)
220
GDVIRTUAL2_REQUIRED(_set_normal, int, const Vector3 &)
221
GDVIRTUAL1_REQUIRED(_set_aabb, const AABB &)
222
223
static void _bind_methods();
224
225
public:
226
virtual void set_vertex(int p_vertex_id, const Vector3 &p_vertex);
227
virtual void set_normal(int p_vertex_id, const Vector3 &p_normal);
228
virtual void set_aabb(const AABB &p_aabb);
229
230
virtual ~PhysicsServer3DRenderingServerHandler() {}
231
};
232
233
class PhysicsTestMotionParameters3D;
234
class PhysicsTestMotionResult3D;
235
236
class PhysicsServer3D : public Object {
237
GDCLASS(PhysicsServer3D, Object);
238
239
static PhysicsServer3D *singleton;
240
241
virtual bool _body_test_motion(RID p_body, const Ref<PhysicsTestMotionParameters3D> &p_parameters, const Ref<PhysicsTestMotionResult3D> &p_result = Ref<PhysicsTestMotionResult3D>());
242
243
protected:
244
static void _bind_methods();
245
246
public:
247
static PhysicsServer3D *get_singleton();
248
249
enum ShapeType {
250
SHAPE_WORLD_BOUNDARY, ///< plane:"plane"
251
SHAPE_SEPARATION_RAY, ///< float:"length"
252
SHAPE_SPHERE, ///< float:"radius"
253
SHAPE_BOX, ///< vec3:"extents"
254
SHAPE_CAPSULE, ///< dict( float:"radius", float:"height"):capsule
255
SHAPE_CYLINDER, ///< dict( float:"radius", float:"height"):cylinder
256
SHAPE_CONVEX_POLYGON, ///< array of planes:"planes"
257
SHAPE_CONCAVE_POLYGON, ///< vector3 array:"triangles" , or Dictionary with "indices" (int array) and "triangles" (Vector3 array)
258
SHAPE_HEIGHTMAP, ///< dict( int:"width", int:"depth",float:"cell_size", float_array:"heights"
259
SHAPE_SOFT_BODY, ///< Used internally, can't be created from the physics server.
260
SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_create() with this value will result in an error
261
};
262
263
RID shape_create(ShapeType p_shape);
264
265
virtual RID world_boundary_shape_create() = 0;
266
virtual RID separation_ray_shape_create() = 0;
267
virtual RID sphere_shape_create() = 0;
268
virtual RID box_shape_create() = 0;
269
virtual RID capsule_shape_create() = 0;
270
virtual RID cylinder_shape_create() = 0;
271
virtual RID convex_polygon_shape_create() = 0;
272
virtual RID concave_polygon_shape_create() = 0;
273
virtual RID heightmap_shape_create() = 0;
274
virtual RID custom_shape_create() = 0;
275
276
virtual void shape_set_data(RID p_shape, const Variant &p_data) = 0;
277
virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) = 0;
278
279
virtual ShapeType shape_get_type(RID p_shape) const = 0;
280
virtual Variant shape_get_data(RID p_shape) const = 0;
281
282
virtual void shape_set_margin(RID p_shape, real_t p_margin) = 0;
283
virtual real_t shape_get_margin(RID p_shape) const = 0;
284
285
virtual real_t shape_get_custom_solver_bias(RID p_shape) const = 0;
286
287
/* SPACE API */
288
289
virtual RID space_create() = 0;
290
virtual void space_set_active(RID p_space, bool p_active) = 0;
291
virtual bool space_is_active(RID p_space) const = 0;
292
293
enum SpaceParameter {
294
SPACE_PARAM_CONTACT_RECYCLE_RADIUS,
295
SPACE_PARAM_CONTACT_MAX_SEPARATION,
296
SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION,
297
SPACE_PARAM_CONTACT_DEFAULT_BIAS,
298
SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD,
299
SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD,
300
SPACE_PARAM_BODY_TIME_TO_SLEEP,
301
SPACE_PARAM_SOLVER_ITERATIONS,
302
};
303
304
virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0;
305
virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const = 0;
306
307
// this function only works on physics process, errors and returns null otherwise
308
virtual PhysicsDirectSpaceState3D *space_get_direct_state(RID p_space) = 0;
309
310
virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) = 0;
311
virtual Vector<Vector3> space_get_contacts(RID p_space) const = 0;
312
virtual int space_get_contact_count(RID p_space) const = 0;
313
314
//missing space parameters
315
316
/* AREA API */
317
318
//missing attenuation? missing better override?
319
320
enum AreaParameter {
321
AREA_PARAM_GRAVITY_OVERRIDE_MODE,
322
AREA_PARAM_GRAVITY,
323
AREA_PARAM_GRAVITY_VECTOR,
324
AREA_PARAM_GRAVITY_IS_POINT,
325
AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE,
326
AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE,
327
AREA_PARAM_LINEAR_DAMP,
328
AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE,
329
AREA_PARAM_ANGULAR_DAMP,
330
AREA_PARAM_PRIORITY,
331
AREA_PARAM_WIND_FORCE_MAGNITUDE,
332
AREA_PARAM_WIND_SOURCE,
333
AREA_PARAM_WIND_DIRECTION,
334
AREA_PARAM_WIND_ATTENUATION_FACTOR,
335
};
336
337
virtual RID area_create() = 0;
338
339
virtual void area_set_space(RID p_area, RID p_space) = 0;
340
virtual RID area_get_space(RID p_area) const = 0;
341
342
enum AreaSpaceOverrideMode {
343
AREA_SPACE_OVERRIDE_DISABLED,
344
AREA_SPACE_OVERRIDE_COMBINE,
345
AREA_SPACE_OVERRIDE_COMBINE_REPLACE,
346
AREA_SPACE_OVERRIDE_REPLACE,
347
AREA_SPACE_OVERRIDE_REPLACE_COMBINE
348
};
349
350
virtual void area_add_shape(RID p_area, RID p_shape, const Transform3D &p_transform = Transform3D(), bool p_disabled = false) = 0;
351
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) = 0;
352
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform3D &p_transform) = 0;
353
354
virtual int area_get_shape_count(RID p_area) const = 0;
355
virtual RID area_get_shape(RID p_area, int p_shape_idx) const = 0;
356
virtual Transform3D area_get_shape_transform(RID p_area, int p_shape_idx) const = 0;
357
358
virtual void area_remove_shape(RID p_area, int p_shape_idx) = 0;
359
virtual void area_clear_shapes(RID p_area) = 0;
360
361
virtual void area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) = 0;
362
363
virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id) = 0;
364
virtual ObjectID area_get_object_instance_id(RID p_area) const = 0;
365
366
virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) = 0;
367
virtual void area_set_transform(RID p_area, const Transform3D &p_transform) = 0;
368
369
virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const = 0;
370
virtual Transform3D area_get_transform(RID p_area) const = 0;
371
372
virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) = 0;
373
virtual uint32_t area_get_collision_layer(RID p_area) const = 0;
374
375
virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) = 0;
376
virtual uint32_t area_get_collision_mask(RID p_area) const = 0;
377
378
virtual void area_set_monitorable(RID p_area, bool p_monitorable) = 0;
379
380
virtual void area_set_monitor_callback(RID p_area, const Callable &p_callback) = 0;
381
virtual void area_set_area_monitor_callback(RID p_area, const Callable &p_callback) = 0;
382
383
virtual void area_set_ray_pickable(RID p_area, bool p_enable) = 0;
384
385
/* BODY API */
386
387
//missing ccd?
388
389
enum BodyMode {
390
BODY_MODE_STATIC,
391
BODY_MODE_KINEMATIC,
392
BODY_MODE_RIGID,
393
BODY_MODE_RIGID_LINEAR,
394
};
395
396
enum BodyDampMode {
397
BODY_DAMP_MODE_COMBINE,
398
BODY_DAMP_MODE_REPLACE,
399
};
400
401
virtual RID body_create() = 0;
402
403
virtual void body_set_space(RID p_body, RID p_space) = 0;
404
virtual RID body_get_space(RID p_body) const = 0;
405
406
virtual void body_set_mode(RID p_body, BodyMode p_mode) = 0;
407
virtual BodyMode body_get_mode(RID p_body) const = 0;
408
409
virtual void body_add_shape(RID p_body, RID p_shape, const Transform3D &p_transform = Transform3D(), bool p_disabled = false) = 0;
410
virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) = 0;
411
virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform3D &p_transform) = 0;
412
413
virtual int body_get_shape_count(RID p_body) const = 0;
414
virtual RID body_get_shape(RID p_body, int p_shape_idx) const = 0;
415
virtual Transform3D body_get_shape_transform(RID p_body, int p_shape_idx) const = 0;
416
417
virtual void body_remove_shape(RID p_body, int p_shape_idx) = 0;
418
virtual void body_clear_shapes(RID p_body) = 0;
419
420
virtual void body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) = 0;
421
422
virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id) = 0;
423
virtual ObjectID body_get_object_instance_id(RID p_body) const = 0;
424
425
virtual void body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) = 0;
426
virtual bool body_is_continuous_collision_detection_enabled(RID p_body) const = 0;
427
428
virtual void body_set_collision_layer(RID p_body, uint32_t p_layer) = 0;
429
virtual uint32_t body_get_collision_layer(RID p_body) const = 0;
430
431
virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) = 0;
432
virtual uint32_t body_get_collision_mask(RID p_body) const = 0;
433
434
virtual void body_set_collision_priority(RID p_body, real_t p_priority) = 0;
435
virtual real_t body_get_collision_priority(RID p_body) const = 0;
436
437
virtual void body_set_user_flags(RID p_body, uint32_t p_flags) = 0;
438
virtual uint32_t body_get_user_flags(RID p_body) const = 0;
439
440
// common body variables
441
enum BodyParameter {
442
BODY_PARAM_BOUNCE,
443
BODY_PARAM_FRICTION,
444
BODY_PARAM_MASS, ///< unused for static, always infinite
445
BODY_PARAM_INERTIA,
446
BODY_PARAM_CENTER_OF_MASS,
447
BODY_PARAM_GRAVITY_SCALE,
448
BODY_PARAM_LINEAR_DAMP_MODE,
449
BODY_PARAM_ANGULAR_DAMP_MODE,
450
BODY_PARAM_LINEAR_DAMP,
451
BODY_PARAM_ANGULAR_DAMP,
452
BODY_PARAM_MAX,
453
};
454
455
virtual void body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) = 0;
456
virtual Variant body_get_param(RID p_body, BodyParameter p_param) const = 0;
457
458
virtual void body_reset_mass_properties(RID p_body) = 0;
459
460
//state
461
enum BodyState {
462
BODY_STATE_TRANSFORM,
463
BODY_STATE_LINEAR_VELOCITY,
464
BODY_STATE_ANGULAR_VELOCITY,
465
BODY_STATE_SLEEPING,
466
BODY_STATE_CAN_SLEEP
467
};
468
469
virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) = 0;
470
virtual Variant body_get_state(RID p_body, BodyState p_state) const = 0;
471
472
virtual void body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) = 0;
473
virtual void body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) = 0;
474
virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) = 0;
475
476
virtual void body_apply_central_force(RID p_body, const Vector3 &p_force) = 0;
477
virtual void body_apply_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3()) = 0;
478
virtual void body_apply_torque(RID p_body, const Vector3 &p_torque) = 0;
479
480
virtual void body_add_constant_central_force(RID p_body, const Vector3 &p_force) = 0;
481
virtual void body_add_constant_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3()) = 0;
482
virtual void body_add_constant_torque(RID p_body, const Vector3 &p_torque) = 0;
483
484
virtual void body_set_constant_force(RID p_body, const Vector3 &p_force) = 0;
485
virtual Vector3 body_get_constant_force(RID p_body) const = 0;
486
487
virtual void body_set_constant_torque(RID p_body, const Vector3 &p_torque) = 0;
488
virtual Vector3 body_get_constant_torque(RID p_body) const = 0;
489
490
virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) = 0;
491
492
enum BodyAxis {
493
BODY_AXIS_LINEAR_X = 1 << 0,
494
BODY_AXIS_LINEAR_Y = 1 << 1,
495
BODY_AXIS_LINEAR_Z = 1 << 2,
496
BODY_AXIS_ANGULAR_X = 1 << 3,
497
BODY_AXIS_ANGULAR_Y = 1 << 4,
498
BODY_AXIS_ANGULAR_Z = 1 << 5
499
};
500
501
virtual void body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) = 0;
502
virtual bool body_is_axis_locked(RID p_body, BodyAxis p_axis) const = 0;
503
504
//fix
505
virtual void body_add_collision_exception(RID p_body, RID p_body_b) = 0;
506
virtual void body_remove_collision_exception(RID p_body, RID p_body_b) = 0;
507
virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) = 0;
508
509
virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) = 0;
510
virtual int body_get_max_contacts_reported(RID p_body) const = 0;
511
512
//missing remove
513
virtual void body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) = 0;
514
virtual real_t body_get_contacts_reported_depth_threshold(RID p_body) const = 0;
515
516
virtual void body_set_omit_force_integration(RID p_body, bool p_omit) = 0;
517
virtual bool body_is_omitting_force_integration(RID p_body) const = 0;
518
519
virtual void body_set_state_sync_callback(RID p_body, const Callable &p_callable) = 0;
520
virtual void body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata = Variant()) = 0;
521
522
virtual void body_set_ray_pickable(RID p_body, bool p_enable) = 0;
523
524
// this function only works on physics process, errors and returns null otherwise
525
virtual PhysicsDirectBodyState3D *body_get_direct_state(RID p_body) = 0;
526
527
struct MotionParameters {
528
Transform3D from;
529
Vector3 motion;
530
real_t margin = 0.001;
531
int max_collisions = 1;
532
bool collide_separation_ray = false;
533
HashSet<RID> exclude_bodies;
534
HashSet<ObjectID> exclude_objects;
535
bool recovery_as_collision = false;
536
537
MotionParameters() {}
538
539
MotionParameters(const Transform3D &p_from, const Vector3 &p_motion, real_t p_margin = 0.001) :
540
from(p_from),
541
motion(p_motion),
542
margin(p_margin) {}
543
};
544
545
struct MotionCollision {
546
Vector3 position;
547
Vector3 normal;
548
Vector3 collider_velocity;
549
Vector3 collider_angular_velocity;
550
real_t depth = 0.0;
551
int local_shape = 0;
552
ObjectID collider_id;
553
RID collider;
554
int collider_shape = 0;
555
556
real_t get_angle(Vector3 p_up_direction) const {
557
return Math::acos(normal.dot(p_up_direction));
558
}
559
};
560
561
struct MotionResult {
562
Vector3 travel;
563
Vector3 remainder;
564
real_t collision_depth = 0.0;
565
real_t collision_safe_fraction = 0.0;
566
real_t collision_unsafe_fraction = 0.0;
567
568
static const int MAX_COLLISIONS = 32;
569
MotionCollision collisions[MAX_COLLISIONS];
570
int collision_count = 0;
571
};
572
573
virtual bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) = 0;
574
575
/* SOFT BODY */
576
577
virtual RID soft_body_create() = 0;
578
579
virtual void soft_body_update_rendering_server(RID p_body, PhysicsServer3DRenderingServerHandler *p_rendering_server_handler) = 0;
580
581
virtual void soft_body_set_space(RID p_body, RID p_space) = 0;
582
virtual RID soft_body_get_space(RID p_body) const = 0;
583
584
virtual void soft_body_set_mesh(RID p_body, RID p_mesh) = 0;
585
586
virtual AABB soft_body_get_bounds(RID p_body) const = 0;
587
588
virtual void soft_body_set_collision_layer(RID p_body, uint32_t p_layer) = 0;
589
virtual uint32_t soft_body_get_collision_layer(RID p_body) const = 0;
590
591
virtual void soft_body_set_collision_mask(RID p_body, uint32_t p_mask) = 0;
592
virtual uint32_t soft_body_get_collision_mask(RID p_body) const = 0;
593
594
virtual void soft_body_add_collision_exception(RID p_body, RID p_body_b) = 0;
595
virtual void soft_body_remove_collision_exception(RID p_body, RID p_body_b) = 0;
596
virtual void soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) = 0;
597
598
virtual void soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) = 0;
599
virtual Variant soft_body_get_state(RID p_body, BodyState p_state) const = 0;
600
601
virtual void soft_body_set_transform(RID p_body, const Transform3D &p_transform) = 0;
602
603
virtual void soft_body_set_ray_pickable(RID p_body, bool p_enable) = 0;
604
605
virtual void soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) = 0;
606
virtual int soft_body_get_simulation_precision(RID p_body) const = 0;
607
608
virtual void soft_body_set_total_mass(RID p_body, real_t p_total_mass) = 0;
609
virtual real_t soft_body_get_total_mass(RID p_body) const = 0;
610
611
virtual void soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) = 0;
612
virtual real_t soft_body_get_linear_stiffness(RID p_body) const = 0;
613
614
virtual void soft_body_set_shrinking_factor(RID p_body, real_t p_shrinking_factor) = 0;
615
virtual real_t soft_body_get_shrinking_factor(RID p_body) const = 0;
616
617
virtual void soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) = 0;
618
virtual real_t soft_body_get_pressure_coefficient(RID p_body) const = 0;
619
620
virtual void soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) = 0;
621
virtual real_t soft_body_get_damping_coefficient(RID p_body) const = 0;
622
623
virtual void soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) = 0;
624
virtual real_t soft_body_get_drag_coefficient(RID p_body) const = 0;
625
626
virtual void soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) = 0;
627
virtual Vector3 soft_body_get_point_global_position(RID p_body, int p_point_index) const = 0;
628
629
virtual void soft_body_apply_point_impulse(RID p_body, int p_point_index, const Vector3 &p_impulse) = 0;
630
virtual void soft_body_apply_point_force(RID p_body, int p_point_index, const Vector3 &p_force) = 0;
631
virtual void soft_body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) = 0;
632
virtual void soft_body_apply_central_force(RID p_body, const Vector3 &p_force) = 0;
633
634
virtual void soft_body_remove_all_pinned_points(RID p_body) = 0;
635
virtual void soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) = 0;
636
virtual bool soft_body_is_point_pinned(RID p_body, int p_point_index) const = 0;
637
638
/* JOINT API */
639
640
enum JointType {
641
JOINT_TYPE_PIN,
642
JOINT_TYPE_HINGE,
643
JOINT_TYPE_SLIDER,
644
JOINT_TYPE_CONE_TWIST,
645
JOINT_TYPE_6DOF,
646
JOINT_TYPE_MAX,
647
648
};
649
650
virtual RID joint_create() = 0;
651
652
virtual void joint_clear(RID p_joint) = 0;
653
654
virtual JointType joint_get_type(RID p_joint) const = 0;
655
656
virtual void joint_set_solver_priority(RID p_joint, int p_priority) = 0;
657
virtual int joint_get_solver_priority(RID p_joint) const = 0;
658
659
virtual void joint_disable_collisions_between_bodies(RID p_joint, bool p_disable) = 0;
660
virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const = 0;
661
662
virtual void joint_make_pin(RID p_joint, RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) = 0;
663
664
enum PinJointParam {
665
PIN_JOINT_BIAS,
666
PIN_JOINT_DAMPING,
667
PIN_JOINT_IMPULSE_CLAMP
668
};
669
670
virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) = 0;
671
virtual real_t pin_joint_get_param(RID p_joint, PinJointParam p_param) const = 0;
672
673
virtual void pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) = 0;
674
virtual Vector3 pin_joint_get_local_a(RID p_joint) const = 0;
675
676
virtual void pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) = 0;
677
virtual Vector3 pin_joint_get_local_b(RID p_joint) const = 0;
678
679
enum HingeJointParam {
680
HINGE_JOINT_BIAS,
681
HINGE_JOINT_LIMIT_UPPER,
682
HINGE_JOINT_LIMIT_LOWER,
683
HINGE_JOINT_LIMIT_BIAS,
684
HINGE_JOINT_LIMIT_SOFTNESS,
685
HINGE_JOINT_LIMIT_RELAXATION,
686
HINGE_JOINT_MOTOR_TARGET_VELOCITY,
687
HINGE_JOINT_MOTOR_MAX_IMPULSE,
688
HINGE_JOINT_MAX
689
};
690
691
enum HingeJointFlag {
692
HINGE_JOINT_FLAG_USE_LIMIT,
693
HINGE_JOINT_FLAG_ENABLE_MOTOR,
694
HINGE_JOINT_FLAG_MAX
695
};
696
697
virtual void joint_make_hinge(RID p_joint, RID p_body_A, const Transform3D &p_hinge_A, RID p_body_B, const Transform3D &p_hinge_B) = 0;
698
virtual void joint_make_hinge_simple(RID p_joint, RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) = 0;
699
700
virtual void hinge_joint_set_param(RID p_joint, HingeJointParam p_param, real_t p_value) = 0;
701
virtual real_t hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const = 0;
702
703
virtual void hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_enabled) = 0;
704
virtual bool hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const = 0;
705
706
enum SliderJointParam {
707
SLIDER_JOINT_LINEAR_LIMIT_UPPER,
708
SLIDER_JOINT_LINEAR_LIMIT_LOWER,
709
SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS,
710
SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION,
711
SLIDER_JOINT_LINEAR_LIMIT_DAMPING,
712
SLIDER_JOINT_LINEAR_MOTION_SOFTNESS,
713
SLIDER_JOINT_LINEAR_MOTION_RESTITUTION,
714
SLIDER_JOINT_LINEAR_MOTION_DAMPING,
715
SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS,
716
SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION,
717
SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING,
718
719
SLIDER_JOINT_ANGULAR_LIMIT_UPPER,
720
SLIDER_JOINT_ANGULAR_LIMIT_LOWER,
721
SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS,
722
SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION,
723
SLIDER_JOINT_ANGULAR_LIMIT_DAMPING,
724
SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS,
725
SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION,
726
SLIDER_JOINT_ANGULAR_MOTION_DAMPING,
727
SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS,
728
SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION,
729
SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING,
730
SLIDER_JOINT_MAX
731
732
};
733
734
virtual void joint_make_slider(RID p_joint, RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) = 0; //reference frame is A
735
736
virtual void slider_joint_set_param(RID p_joint, SliderJointParam p_param, real_t p_value) = 0;
737
virtual real_t slider_joint_get_param(RID p_joint, SliderJointParam p_param) const = 0;
738
739
enum ConeTwistJointParam {
740
CONE_TWIST_JOINT_SWING_SPAN,
741
CONE_TWIST_JOINT_TWIST_SPAN,
742
CONE_TWIST_JOINT_BIAS,
743
CONE_TWIST_JOINT_SOFTNESS,
744
CONE_TWIST_JOINT_RELAXATION,
745
CONE_TWIST_MAX
746
};
747
748
virtual void joint_make_cone_twist(RID p_joint, RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) = 0; //reference frame is A
749
750
virtual void cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, real_t p_value) = 0;
751
virtual real_t cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const = 0;
752
753
enum G6DOFJointAxisParam {
754
G6DOF_JOINT_LINEAR_LOWER_LIMIT,
755
G6DOF_JOINT_LINEAR_UPPER_LIMIT,
756
G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS,
757
G6DOF_JOINT_LINEAR_RESTITUTION,
758
G6DOF_JOINT_LINEAR_DAMPING,
759
G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY,
760
G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT,
761
G6DOF_JOINT_LINEAR_SPRING_STIFFNESS,
762
G6DOF_JOINT_LINEAR_SPRING_DAMPING,
763
G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT,
764
G6DOF_JOINT_ANGULAR_LOWER_LIMIT,
765
G6DOF_JOINT_ANGULAR_UPPER_LIMIT,
766
G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS,
767
G6DOF_JOINT_ANGULAR_DAMPING,
768
G6DOF_JOINT_ANGULAR_RESTITUTION,
769
G6DOF_JOINT_ANGULAR_FORCE_LIMIT,
770
G6DOF_JOINT_ANGULAR_ERP,
771
G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY,
772
G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT,
773
G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS,
774
G6DOF_JOINT_ANGULAR_SPRING_DAMPING,
775
G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT,
776
G6DOF_JOINT_MAX
777
};
778
779
enum G6DOFJointAxisFlag {
780
G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT,
781
G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT,
782
G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING,
783
G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING,
784
G6DOF_JOINT_FLAG_ENABLE_MOTOR,
785
G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR,
786
G6DOF_JOINT_FLAG_MAX
787
};
788
789
virtual void joint_make_generic_6dof(RID p_joint, RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) = 0; //reference frame is A
790
791
virtual void generic_6dof_joint_set_param(RID p_joint, Vector3::Axis, G6DOFJointAxisParam p_param, real_t p_value) = 0;
792
virtual real_t generic_6dof_joint_get_param(RID p_joint, Vector3::Axis, G6DOFJointAxisParam p_param) const = 0;
793
794
virtual void generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis, G6DOFJointAxisFlag p_flag, bool p_enable) = 0;
795
virtual bool generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis, G6DOFJointAxisFlag p_flag) const = 0;
796
797
/* QUERY API */
798
799
enum AreaBodyStatus {
800
AREA_BODY_ADDED,
801
AREA_BODY_REMOVED
802
};
803
804
/* MISC */
805
806
virtual void free_rid(RID p_rid) = 0;
807
#ifndef DISABLE_DEPRECATED
808
[[deprecated("Use `free_rid()` instead.")]] void free(RID p_rid) {
809
free_rid(p_rid);
810
}
811
#endif // DISABLE_DEPRECATED
812
813
virtual void set_active(bool p_active) = 0;
814
virtual void init() = 0;
815
virtual void step(real_t p_step) = 0;
816
virtual void sync() = 0;
817
virtual void flush_queries() = 0;
818
virtual void end_sync() = 0;
819
virtual void finish() = 0;
820
821
virtual bool is_flushing_queries() const = 0;
822
823
enum ProcessInfo {
824
INFO_ACTIVE_OBJECTS,
825
INFO_COLLISION_PAIRS,
826
INFO_ISLAND_COUNT
827
};
828
829
virtual int get_process_info(ProcessInfo p_info) = 0;
830
831
PhysicsServer3D();
832
~PhysicsServer3D();
833
};
834
835
class PhysicsRayQueryParameters3D : public RefCounted {
836
GDCLASS(PhysicsRayQueryParameters3D, RefCounted);
837
838
PhysicsDirectSpaceState3D::RayParameters parameters;
839
840
protected:
841
static void _bind_methods();
842
843
public:
844
static Ref<PhysicsRayQueryParameters3D> create(Vector3 p_from, Vector3 p_to, uint32_t p_mask, const TypedArray<RID> &p_exclude);
845
const PhysicsDirectSpaceState3D::RayParameters &get_parameters() const { return parameters; }
846
847
void set_from(const Vector3 &p_from) { parameters.from = p_from; }
848
const Vector3 &get_from() const { return parameters.from; }
849
850
void set_to(const Vector3 &p_to) { parameters.to = p_to; }
851
const Vector3 &get_to() const { return parameters.to; }
852
853
void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
854
uint32_t get_collision_mask() const { return parameters.collision_mask; }
855
856
void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
857
bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
858
859
void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
860
bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
861
862
void set_hit_from_inside(bool p_enable) { parameters.hit_from_inside = p_enable; }
863
bool is_hit_from_inside_enabled() const { return parameters.hit_from_inside; }
864
865
void set_hit_back_faces(bool p_enable) { parameters.hit_back_faces = p_enable; }
866
bool is_hit_back_faces_enabled() const { return parameters.hit_back_faces; }
867
868
void set_exclude(const TypedArray<RID> &p_exclude);
869
TypedArray<RID> get_exclude() const;
870
};
871
872
class PhysicsPointQueryParameters3D : public RefCounted {
873
GDCLASS(PhysicsPointQueryParameters3D, RefCounted);
874
875
PhysicsDirectSpaceState3D::PointParameters parameters;
876
877
protected:
878
static void _bind_methods();
879
880
public:
881
const PhysicsDirectSpaceState3D::PointParameters &get_parameters() const { return parameters; }
882
883
void set_position(const Vector3 &p_position) { parameters.position = p_position; }
884
const Vector3 &get_position() const { return parameters.position; }
885
886
void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
887
uint32_t get_collision_mask() const { return parameters.collision_mask; }
888
889
void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
890
bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
891
892
void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
893
bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
894
895
void set_exclude(const TypedArray<RID> &p_exclude);
896
TypedArray<RID> get_exclude() const;
897
};
898
899
class PhysicsShapeQueryParameters3D : public RefCounted {
900
GDCLASS(PhysicsShapeQueryParameters3D, RefCounted);
901
902
PhysicsDirectSpaceState3D::ShapeParameters parameters;
903
904
Ref<Resource> shape_ref;
905
906
protected:
907
static void _bind_methods();
908
909
public:
910
const PhysicsDirectSpaceState3D::ShapeParameters &get_parameters() const { return parameters; }
911
912
void set_shape(const Ref<Resource> &p_shape_ref);
913
Ref<Resource> get_shape() const { return shape_ref; }
914
915
void set_shape_rid(const RID &p_shape);
916
RID get_shape_rid() const { return parameters.shape_rid; }
917
918
void set_transform(const Transform3D &p_transform) { parameters.transform = p_transform; }
919
const Transform3D &get_transform() const { return parameters.transform; }
920
921
void set_motion(const Vector3 &p_motion) { parameters.motion = p_motion; }
922
const Vector3 &get_motion() const { return parameters.motion; }
923
924
void set_margin(real_t p_margin) { parameters.margin = p_margin; }
925
real_t get_margin() const { return parameters.margin; }
926
927
void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
928
uint32_t get_collision_mask() const { return parameters.collision_mask; }
929
930
void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
931
bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
932
933
void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
934
bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
935
936
void set_exclude(const TypedArray<RID> &p_exclude);
937
TypedArray<RID> get_exclude() const;
938
};
939
940
class PhysicsTestMotionParameters3D : public RefCounted {
941
GDCLASS(PhysicsTestMotionParameters3D, RefCounted);
942
943
PhysicsServer3D::MotionParameters parameters;
944
945
protected:
946
static void _bind_methods();
947
948
public:
949
const PhysicsServer3D::MotionParameters &get_parameters() const { return parameters; }
950
951
const Transform3D &get_from() const { return parameters.from; }
952
void set_from(const Transform3D &p_from) { parameters.from = p_from; }
953
954
const Vector3 &get_motion() const { return parameters.motion; }
955
void set_motion(const Vector3 &p_motion) { parameters.motion = p_motion; }
956
957
real_t get_margin() const { return parameters.margin; }
958
void set_margin(real_t p_margin) { parameters.margin = p_margin; }
959
960
int get_max_collisions() const { return parameters.max_collisions; }
961
void set_max_collisions(int p_max_collisions) { parameters.max_collisions = p_max_collisions; }
962
963
bool is_collide_separation_ray_enabled() const { return parameters.collide_separation_ray; }
964
void set_collide_separation_ray_enabled(bool p_enabled) { parameters.collide_separation_ray = p_enabled; }
965
966
TypedArray<RID> get_exclude_bodies() const;
967
void set_exclude_bodies(const TypedArray<RID> &p_exclude);
968
969
TypedArray<uint64_t> get_exclude_objects() const;
970
void set_exclude_objects(const TypedArray<uint64_t> &p_exclude);
971
972
bool is_recovery_as_collision_enabled() const { return parameters.recovery_as_collision; }
973
void set_recovery_as_collision_enabled(bool p_enabled) { parameters.recovery_as_collision = p_enabled; }
974
};
975
976
class PhysicsTestMotionResult3D : public RefCounted {
977
GDCLASS(PhysicsTestMotionResult3D, RefCounted);
978
979
PhysicsServer3D::MotionResult result;
980
981
protected:
982
static void _bind_methods();
983
984
public:
985
PhysicsServer3D::MotionResult *get_result_ptr() { return &result; }
986
987
Vector3 get_travel() const;
988
Vector3 get_remainder() const;
989
real_t get_collision_safe_fraction() const;
990
real_t get_collision_unsafe_fraction() const;
991
992
int get_collision_count() const;
993
994
Vector3 get_collision_point(int p_collision_index = 0) const;
995
Vector3 get_collision_normal(int p_collision_index = 0) const;
996
Vector3 get_collider_velocity(int p_collision_index = 0) const;
997
ObjectID get_collider_id(int p_collision_index = 0) const;
998
RID get_collider_rid(int p_collision_index = 0) const;
999
Object *get_collider(int p_collision_index = 0) const;
1000
int get_collider_shape(int p_collision_index = 0) const;
1001
int get_collision_local_shape(int p_collision_index = 0) const;
1002
real_t get_collision_depth(int p_collision_index = 0) const;
1003
};
1004
1005
class PhysicsServer3DManager : public Object {
1006
GDCLASS(PhysicsServer3DManager, Object);
1007
1008
static PhysicsServer3DManager *singleton;
1009
1010
struct ClassInfo {
1011
String name;
1012
Callable create_callback;
1013
1014
ClassInfo() {}
1015
1016
ClassInfo(String p_name, Callable p_create_callback) :
1017
name(p_name),
1018
create_callback(p_create_callback) {}
1019
1020
ClassInfo(const ClassInfo &p_ci) :
1021
name(p_ci.name),
1022
create_callback(p_ci.create_callback) {}
1023
1024
void operator=(const ClassInfo &p_ci) {
1025
name = p_ci.name;
1026
create_callback = p_ci.create_callback;
1027
}
1028
};
1029
1030
Vector<ClassInfo> physics_servers;
1031
int default_server_id = -1;
1032
int default_server_priority = -1;
1033
1034
void on_servers_changed();
1035
1036
protected:
1037
static void _bind_methods();
1038
1039
public:
1040
static const String setting_property_name;
1041
1042
static PhysicsServer3DManager *get_singleton();
1043
1044
void register_server(const String &p_name, const Callable &p_create_callback);
1045
void set_default_server(const String &p_name, int p_priority = 0);
1046
int find_server_id(const String &p_name);
1047
int get_servers_count();
1048
String get_server_name(int p_id);
1049
PhysicsServer3D *new_default_server();
1050
PhysicsServer3D *new_server(const String &p_name);
1051
1052
PhysicsServer3DManager();
1053
~PhysicsServer3DManager();
1054
};
1055
1056
VARIANT_ENUM_CAST(PhysicsServer3D::ShapeType);
1057
VARIANT_ENUM_CAST(PhysicsServer3D::SpaceParameter);
1058
VARIANT_ENUM_CAST(PhysicsServer3D::AreaParameter);
1059
VARIANT_ENUM_CAST(PhysicsServer3D::AreaSpaceOverrideMode);
1060
VARIANT_ENUM_CAST(PhysicsServer3D::BodyMode);
1061
VARIANT_ENUM_CAST(PhysicsServer3D::BodyParameter);
1062
VARIANT_ENUM_CAST(PhysicsServer3D::BodyDampMode);
1063
VARIANT_ENUM_CAST(PhysicsServer3D::BodyState);
1064
VARIANT_ENUM_CAST(PhysicsServer3D::BodyAxis);
1065
VARIANT_ENUM_CAST(PhysicsServer3D::PinJointParam);
1066
VARIANT_ENUM_CAST(PhysicsServer3D::JointType);
1067
VARIANT_ENUM_CAST(PhysicsServer3D::HingeJointParam);
1068
VARIANT_ENUM_CAST(PhysicsServer3D::HingeJointFlag);
1069
VARIANT_ENUM_CAST(PhysicsServer3D::SliderJointParam);
1070
VARIANT_ENUM_CAST(PhysicsServer3D::ConeTwistJointParam);
1071
VARIANT_ENUM_CAST(PhysicsServer3D::G6DOFJointAxisParam);
1072
VARIANT_ENUM_CAST(PhysicsServer3D::G6DOFJointAxisFlag);
1073
VARIANT_ENUM_CAST(PhysicsServer3D::AreaBodyStatus);
1074
VARIANT_ENUM_CAST(PhysicsServer3D::ProcessInfo);
1075
1076