Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/jolt_physics/jolt_physics_server_3d.cpp
20951 views
1
/**************************************************************************/
2
/* jolt_physics_server_3d.cpp */
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
#include "jolt_physics_server_3d.h"
32
33
#include "joints/jolt_cone_twist_joint_3d.h"
34
#include "joints/jolt_generic_6dof_joint_3d.h"
35
#include "joints/jolt_hinge_joint_3d.h"
36
#include "joints/jolt_joint_3d.h"
37
#include "joints/jolt_pin_joint_3d.h"
38
#include "joints/jolt_slider_joint_3d.h"
39
#include "objects/jolt_area_3d.h"
40
#include "objects/jolt_body_3d.h"
41
#include "objects/jolt_soft_body_3d.h"
42
#include "servers/physics_3d/physics_server_3d_wrap_mt.h"
43
#include "shapes/jolt_box_shape_3d.h"
44
#include "shapes/jolt_capsule_shape_3d.h"
45
#include "shapes/jolt_concave_polygon_shape_3d.h"
46
#include "shapes/jolt_convex_polygon_shape_3d.h"
47
#include "shapes/jolt_cylinder_shape_3d.h"
48
#include "shapes/jolt_height_map_shape_3d.h"
49
#include "shapes/jolt_separation_ray_shape_3d.h"
50
#include "shapes/jolt_sphere_shape_3d.h"
51
#include "shapes/jolt_world_boundary_shape_3d.h"
52
#include "spaces/jolt_job_system.h"
53
#include "spaces/jolt_physics_direct_space_state_3d.h"
54
#include "spaces/jolt_space_3d.h"
55
56
JoltPhysicsServer3D::JoltPhysicsServer3D(bool p_on_separate_thread) :
57
on_separate_thread(p_on_separate_thread) {
58
singleton = this;
59
}
60
61
JoltPhysicsServer3D::~JoltPhysicsServer3D() {
62
if (singleton == this) {
63
singleton = nullptr;
64
}
65
}
66
67
RID JoltPhysicsServer3D::world_boundary_shape_create() {
68
JoltShape3D *shape = memnew(JoltWorldBoundaryShape3D);
69
RID rid = shape_owner.make_rid(shape);
70
shape->set_rid(rid);
71
return rid;
72
}
73
74
RID JoltPhysicsServer3D::separation_ray_shape_create() {
75
JoltShape3D *shape = memnew(JoltSeparationRayShape3D);
76
RID rid = shape_owner.make_rid(shape);
77
shape->set_rid(rid);
78
return rid;
79
}
80
81
RID JoltPhysicsServer3D::sphere_shape_create() {
82
JoltShape3D *shape = memnew(JoltSphereShape3D);
83
RID rid = shape_owner.make_rid(shape);
84
shape->set_rid(rid);
85
return rid;
86
}
87
88
RID JoltPhysicsServer3D::box_shape_create() {
89
JoltShape3D *shape = memnew(JoltBoxShape3D);
90
RID rid = shape_owner.make_rid(shape);
91
shape->set_rid(rid);
92
return rid;
93
}
94
95
RID JoltPhysicsServer3D::capsule_shape_create() {
96
JoltShape3D *shape = memnew(JoltCapsuleShape3D);
97
RID rid = shape_owner.make_rid(shape);
98
shape->set_rid(rid);
99
return rid;
100
}
101
102
RID JoltPhysicsServer3D::cylinder_shape_create() {
103
JoltShape3D *shape = memnew(JoltCylinderShape3D);
104
RID rid = shape_owner.make_rid(shape);
105
shape->set_rid(rid);
106
return rid;
107
}
108
109
RID JoltPhysicsServer3D::convex_polygon_shape_create() {
110
JoltShape3D *shape = memnew(JoltConvexPolygonShape3D);
111
RID rid = shape_owner.make_rid(shape);
112
shape->set_rid(rid);
113
return rid;
114
}
115
116
RID JoltPhysicsServer3D::concave_polygon_shape_create() {
117
JoltShape3D *shape = memnew(JoltConcavePolygonShape3D);
118
RID rid = shape_owner.make_rid(shape);
119
shape->set_rid(rid);
120
return rid;
121
}
122
123
RID JoltPhysicsServer3D::heightmap_shape_create() {
124
JoltShape3D *shape = memnew(JoltHeightMapShape3D);
125
RID rid = shape_owner.make_rid(shape);
126
shape->set_rid(rid);
127
return rid;
128
}
129
130
RID JoltPhysicsServer3D::custom_shape_create() {
131
ERR_FAIL_V_MSG(RID(), "Custom shapes are not supported.");
132
}
133
134
void JoltPhysicsServer3D::shape_set_data(RID p_shape, const Variant &p_data) {
135
JoltShape3D *shape = shape_owner.get_or_null(p_shape);
136
ERR_FAIL_NULL(shape);
137
138
shape->set_data(p_data);
139
}
140
141
Variant JoltPhysicsServer3D::shape_get_data(RID p_shape) const {
142
const JoltShape3D *shape = shape_owner.get_or_null(p_shape);
143
ERR_FAIL_NULL_V(shape, Variant());
144
145
return shape->get_data();
146
}
147
148
void JoltPhysicsServer3D::shape_set_custom_solver_bias(RID p_shape, real_t p_bias) {
149
JoltShape3D *shape = shape_owner.get_or_null(p_shape);
150
ERR_FAIL_NULL(shape);
151
152
shape->set_solver_bias((float)p_bias);
153
}
154
155
PhysicsServer3D::ShapeType JoltPhysicsServer3D::shape_get_type(RID p_shape) const {
156
const JoltShape3D *shape = shape_owner.get_or_null(p_shape);
157
ERR_FAIL_NULL_V(shape, SHAPE_CUSTOM);
158
159
return shape->get_type();
160
}
161
162
void JoltPhysicsServer3D::shape_set_margin(RID p_shape, real_t p_margin) {
163
JoltShape3D *shape = shape_owner.get_or_null(p_shape);
164
ERR_FAIL_NULL(shape);
165
166
shape->set_margin((float)p_margin);
167
}
168
169
real_t JoltPhysicsServer3D::shape_get_margin(RID p_shape) const {
170
const JoltShape3D *shape = shape_owner.get_or_null(p_shape);
171
ERR_FAIL_NULL_V(shape, 0.0);
172
173
return (real_t)shape->get_margin();
174
}
175
176
real_t JoltPhysicsServer3D::shape_get_custom_solver_bias(RID p_shape) const {
177
const JoltShape3D *shape = shape_owner.get_or_null(p_shape);
178
ERR_FAIL_NULL_V(shape, 0.0);
179
180
return (real_t)shape->get_solver_bias();
181
}
182
183
RID JoltPhysicsServer3D::space_create() {
184
JoltSpace3D *space = memnew(JoltSpace3D(job_system));
185
RID rid = space_owner.make_rid(space);
186
space->set_rid(rid);
187
188
const RID default_area_rid = area_create();
189
JoltArea3D *default_area = area_owner.get_or_null(default_area_rid);
190
ERR_FAIL_NULL_V(default_area, RID());
191
space->set_default_area(default_area);
192
default_area->set_space(space);
193
194
return rid;
195
}
196
197
void JoltPhysicsServer3D::space_set_active(RID p_space, bool p_active) {
198
JoltSpace3D *space = space_owner.get_or_null(p_space);
199
ERR_FAIL_NULL(space);
200
201
if (p_active) {
202
space->set_active(true);
203
active_spaces.insert(space);
204
} else {
205
space->set_active(false);
206
active_spaces.erase(space);
207
}
208
}
209
210
bool JoltPhysicsServer3D::space_is_active(RID p_space) const {
211
JoltSpace3D *space = space_owner.get_or_null(p_space);
212
ERR_FAIL_NULL_V(space, false);
213
214
return active_spaces.has(space);
215
}
216
217
void JoltPhysicsServer3D::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) {
218
JoltSpace3D *space = space_owner.get_or_null(p_space);
219
ERR_FAIL_NULL(space);
220
221
space->set_param(p_param, (double)p_value);
222
}
223
224
real_t JoltPhysicsServer3D::space_get_param(RID p_space, SpaceParameter p_param) const {
225
const JoltSpace3D *space = space_owner.get_or_null(p_space);
226
ERR_FAIL_NULL_V(space, 0.0);
227
228
return (real_t)space->get_param(p_param);
229
}
230
231
PhysicsDirectSpaceState3D *JoltPhysicsServer3D::space_get_direct_state(RID p_space) {
232
JoltSpace3D *space = space_owner.get_or_null(p_space);
233
ERR_FAIL_NULL_V(space, nullptr);
234
ERR_FAIL_COND_V_MSG((on_separate_thread && !doing_sync) || space->is_stepping(), nullptr, "Space state is inaccessible right now, wait for iteration or physics process notification.");
235
236
return space->get_direct_state();
237
}
238
239
void JoltPhysicsServer3D::space_set_debug_contacts(RID p_space, int p_max_contacts) {
240
#ifdef DEBUG_ENABLED
241
JoltSpace3D *space = space_owner.get_or_null(p_space);
242
ERR_FAIL_NULL(space);
243
244
space->set_max_debug_contacts(p_max_contacts);
245
#endif
246
}
247
248
PackedVector3Array JoltPhysicsServer3D::space_get_contacts(RID p_space) const {
249
#ifdef DEBUG_ENABLED
250
JoltSpace3D *space = space_owner.get_or_null(p_space);
251
ERR_FAIL_NULL_V(space, PackedVector3Array());
252
253
return space->get_debug_contacts();
254
#else
255
return PackedVector3Array();
256
#endif
257
}
258
259
int JoltPhysicsServer3D::space_get_contact_count(RID p_space) const {
260
#ifdef DEBUG_ENABLED
261
JoltSpace3D *space = space_owner.get_or_null(p_space);
262
ERR_FAIL_NULL_V(space, 0);
263
264
return space->get_debug_contact_count();
265
#else
266
return 0;
267
#endif
268
}
269
270
RID JoltPhysicsServer3D::area_create() {
271
JoltArea3D *area = memnew(JoltArea3D);
272
RID rid = area_owner.make_rid(area);
273
area->set_rid(rid);
274
return rid;
275
}
276
277
void JoltPhysicsServer3D::area_set_space(RID p_area, RID p_space) {
278
JoltArea3D *area = area_owner.get_or_null(p_area);
279
ERR_FAIL_NULL(area);
280
281
JoltSpace3D *space = nullptr;
282
283
if (p_space.is_valid()) {
284
space = space_owner.get_or_null(p_space);
285
ERR_FAIL_NULL(space);
286
}
287
288
area->set_space(space);
289
}
290
291
void JoltPhysicsServer3D::soft_body_apply_point_impulse(RID p_body, int p_point_index, const Vector3 &p_impulse) {
292
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
293
ERR_FAIL_NULL(body);
294
295
body->apply_vertex_impulse(p_point_index, p_impulse);
296
}
297
298
void JoltPhysicsServer3D::soft_body_apply_point_force(RID p_body, int p_point_index, const Vector3 &p_force) {
299
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
300
ERR_FAIL_NULL(body);
301
302
body->apply_vertex_force(p_point_index, p_force);
303
}
304
305
void JoltPhysicsServer3D::soft_body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {
306
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
307
ERR_FAIL_NULL(body);
308
309
body->apply_central_impulse(p_impulse);
310
}
311
312
void JoltPhysicsServer3D::soft_body_apply_central_force(RID p_body, const Vector3 &p_force) {
313
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
314
ERR_FAIL_NULL(body);
315
316
body->apply_central_force(p_force);
317
}
318
319
RID JoltPhysicsServer3D::area_get_space(RID p_area) const {
320
const JoltArea3D *area = area_owner.get_or_null(p_area);
321
ERR_FAIL_NULL_V(area, RID());
322
323
const JoltSpace3D *space = area->get_space();
324
325
if (space == nullptr) {
326
return RID();
327
}
328
329
return space->get_rid();
330
}
331
332
void JoltPhysicsServer3D::area_add_shape(RID p_area, RID p_shape, const Transform3D &p_transform, bool p_disabled) {
333
JoltArea3D *area = area_owner.get_or_null(p_area);
334
ERR_FAIL_NULL(area);
335
336
JoltShape3D *shape = shape_owner.get_or_null(p_shape);
337
ERR_FAIL_NULL(shape);
338
339
area->add_shape(shape, p_transform, p_disabled);
340
}
341
342
void JoltPhysicsServer3D::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {
343
JoltArea3D *area = area_owner.get_or_null(p_area);
344
ERR_FAIL_NULL(area);
345
346
JoltShape3D *shape = shape_owner.get_or_null(p_shape);
347
ERR_FAIL_NULL(shape);
348
349
area->set_shape(p_shape_idx, shape);
350
}
351
352
RID JoltPhysicsServer3D::area_get_shape(RID p_area, int p_shape_idx) const {
353
const JoltArea3D *area = area_owner.get_or_null(p_area);
354
ERR_FAIL_NULL_V(area, RID());
355
356
const JoltShape3D *shape = area->get_shape(p_shape_idx);
357
ERR_FAIL_NULL_V(shape, RID());
358
359
return shape->get_rid();
360
}
361
362
void JoltPhysicsServer3D::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform3D &p_transform) {
363
JoltArea3D *area = area_owner.get_or_null(p_area);
364
ERR_FAIL_NULL(area);
365
366
area->set_shape_transform(p_shape_idx, p_transform);
367
}
368
369
Transform3D JoltPhysicsServer3D::area_get_shape_transform(RID p_area, int p_shape_idx) const {
370
const JoltArea3D *area = area_owner.get_or_null(p_area);
371
ERR_FAIL_NULL_V(area, Transform3D());
372
373
return area->get_shape_transform_scaled(p_shape_idx);
374
}
375
376
int JoltPhysicsServer3D::area_get_shape_count(RID p_area) const {
377
const JoltArea3D *area = area_owner.get_or_null(p_area);
378
ERR_FAIL_NULL_V(area, 0);
379
380
return area->get_shape_count();
381
}
382
383
void JoltPhysicsServer3D::area_remove_shape(RID p_area, int p_shape_idx) {
384
JoltArea3D *area = area_owner.get_or_null(p_area);
385
ERR_FAIL_NULL(area);
386
387
area->remove_shape(p_shape_idx);
388
}
389
390
void JoltPhysicsServer3D::area_clear_shapes(RID p_area) {
391
JoltArea3D *area = area_owner.get_or_null(p_area);
392
ERR_FAIL_NULL(area);
393
394
area->clear_shapes();
395
}
396
397
void JoltPhysicsServer3D::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) {
398
JoltArea3D *area = area_owner.get_or_null(p_area);
399
ERR_FAIL_NULL(area);
400
401
area->set_shape_disabled(p_shape_idx, p_disabled);
402
}
403
404
void JoltPhysicsServer3D::area_attach_object_instance_id(RID p_area, ObjectID p_id) {
405
RID area_rid = p_area;
406
407
if (space_owner.owns(area_rid)) {
408
const JoltSpace3D *space = space_owner.get_or_null(area_rid);
409
area_rid = space->get_default_area()->get_rid();
410
}
411
412
JoltArea3D *area = area_owner.get_or_null(area_rid);
413
ERR_FAIL_NULL(area);
414
415
area->set_instance_id(p_id);
416
}
417
418
ObjectID JoltPhysicsServer3D::area_get_object_instance_id(RID p_area) const {
419
RID area_rid = p_area;
420
421
if (space_owner.owns(area_rid)) {
422
const JoltSpace3D *space = space_owner.get_or_null(area_rid);
423
area_rid = space->get_default_area()->get_rid();
424
}
425
426
JoltArea3D *area = area_owner.get_or_null(area_rid);
427
ERR_FAIL_NULL_V(area, ObjectID());
428
429
return area->get_instance_id();
430
}
431
432
void JoltPhysicsServer3D::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) {
433
RID area_rid = p_area;
434
435
if (space_owner.owns(area_rid)) {
436
const JoltSpace3D *space = space_owner.get_or_null(area_rid);
437
area_rid = space->get_default_area()->get_rid();
438
}
439
440
JoltArea3D *area = area_owner.get_or_null(area_rid);
441
ERR_FAIL_NULL(area);
442
443
area->set_param(p_param, p_value);
444
}
445
446
Variant JoltPhysicsServer3D::area_get_param(RID p_area, AreaParameter p_param) const {
447
RID area_rid = p_area;
448
449
if (space_owner.owns(area_rid)) {
450
const JoltSpace3D *space = space_owner.get_or_null(area_rid);
451
area_rid = space->get_default_area()->get_rid();
452
}
453
454
JoltArea3D *area = area_owner.get_or_null(area_rid);
455
ERR_FAIL_NULL_V(area, Variant());
456
457
return area->get_param(p_param);
458
}
459
460
void JoltPhysicsServer3D::area_set_transform(RID p_area, const Transform3D &p_transform) {
461
JoltArea3D *area = area_owner.get_or_null(p_area);
462
ERR_FAIL_NULL(area);
463
464
return area->set_transform(p_transform);
465
}
466
467
Transform3D JoltPhysicsServer3D::area_get_transform(RID p_area) const {
468
const JoltArea3D *area = area_owner.get_or_null(p_area);
469
ERR_FAIL_NULL_V(area, Transform3D());
470
471
return area->get_transform_scaled();
472
}
473
474
void JoltPhysicsServer3D::area_set_collision_mask(RID p_area, uint32_t p_mask) {
475
JoltArea3D *area = area_owner.get_or_null(p_area);
476
ERR_FAIL_NULL(area);
477
478
area->set_collision_mask(p_mask);
479
}
480
481
uint32_t JoltPhysicsServer3D::area_get_collision_mask(RID p_area) const {
482
const JoltArea3D *area = area_owner.get_or_null(p_area);
483
ERR_FAIL_NULL_V(area, 0);
484
485
return area->get_collision_mask();
486
}
487
488
void JoltPhysicsServer3D::area_set_collision_layer(RID p_area, uint32_t p_layer) {
489
JoltArea3D *area = area_owner.get_or_null(p_area);
490
ERR_FAIL_NULL(area);
491
492
area->set_collision_layer(p_layer);
493
}
494
495
uint32_t JoltPhysicsServer3D::area_get_collision_layer(RID p_area) const {
496
const JoltArea3D *area = area_owner.get_or_null(p_area);
497
ERR_FAIL_NULL_V(area, 0);
498
499
return area->get_collision_layer();
500
}
501
502
void JoltPhysicsServer3D::area_set_monitorable(RID p_area, bool p_monitorable) {
503
JoltArea3D *area = area_owner.get_or_null(p_area);
504
ERR_FAIL_NULL(area);
505
506
area->set_monitorable(p_monitorable);
507
}
508
509
void JoltPhysicsServer3D::area_set_monitor_callback(RID p_area, const Callable &p_callback) {
510
JoltArea3D *area = area_owner.get_or_null(p_area);
511
ERR_FAIL_NULL(area);
512
513
area->set_body_monitor_callback(p_callback);
514
}
515
516
void JoltPhysicsServer3D::area_set_area_monitor_callback(RID p_area, const Callable &p_callback) {
517
JoltArea3D *area = area_owner.get_or_null(p_area);
518
ERR_FAIL_NULL(area);
519
520
area->set_area_monitor_callback(p_callback);
521
}
522
523
void JoltPhysicsServer3D::area_set_ray_pickable(RID p_area, bool p_enable) {
524
JoltArea3D *area = area_owner.get_or_null(p_area);
525
ERR_FAIL_NULL(area);
526
527
area->set_pickable(p_enable);
528
}
529
530
RID JoltPhysicsServer3D::body_create() {
531
JoltBody3D *body = memnew(JoltBody3D);
532
RID rid = body_owner.make_rid(body);
533
body->set_rid(rid);
534
return rid;
535
}
536
537
void JoltPhysicsServer3D::body_set_space(RID p_body, RID p_space) {
538
JoltBody3D *body = body_owner.get_or_null(p_body);
539
ERR_FAIL_NULL(body);
540
541
JoltSpace3D *space = nullptr;
542
543
if (p_space.is_valid()) {
544
space = space_owner.get_or_null(p_space);
545
ERR_FAIL_NULL(space);
546
}
547
548
body->set_space(space);
549
}
550
551
RID JoltPhysicsServer3D::body_get_space(RID p_body) const {
552
const JoltBody3D *body = body_owner.get_or_null(p_body);
553
ERR_FAIL_NULL_V(body, RID());
554
555
const JoltSpace3D *space = body->get_space();
556
557
if (space == nullptr) {
558
return RID();
559
}
560
561
return space->get_rid();
562
}
563
564
void JoltPhysicsServer3D::body_set_mode(RID p_body, BodyMode p_mode) {
565
JoltBody3D *body = body_owner.get_or_null(p_body);
566
ERR_FAIL_NULL(body);
567
568
body->set_mode(p_mode);
569
}
570
571
PhysicsServer3D::BodyMode JoltPhysicsServer3D::body_get_mode(RID p_body) const {
572
const JoltBody3D *body = body_owner.get_or_null(p_body);
573
ERR_FAIL_NULL_V(body, BODY_MODE_STATIC);
574
575
return body->get_mode();
576
}
577
578
void JoltPhysicsServer3D::body_add_shape(RID p_body, RID p_shape, const Transform3D &p_transform, bool p_disabled) {
579
JoltBody3D *body = body_owner.get_or_null(p_body);
580
ERR_FAIL_NULL(body);
581
582
JoltShape3D *shape = shape_owner.get_or_null(p_shape);
583
ERR_FAIL_NULL(shape);
584
585
body->add_shape(shape, p_transform, p_disabled);
586
}
587
588
void JoltPhysicsServer3D::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {
589
JoltBody3D *body = body_owner.get_or_null(p_body);
590
ERR_FAIL_NULL(body);
591
592
JoltShape3D *shape = shape_owner.get_or_null(p_shape);
593
ERR_FAIL_NULL(shape);
594
595
body->set_shape(p_shape_idx, shape);
596
}
597
598
RID JoltPhysicsServer3D::body_get_shape(RID p_body, int p_shape_idx) const {
599
const JoltBody3D *body = body_owner.get_or_null(p_body);
600
ERR_FAIL_NULL_V(body, RID());
601
602
const JoltShape3D *shape = body->get_shape(p_shape_idx);
603
ERR_FAIL_NULL_V(shape, RID());
604
605
return shape->get_rid();
606
}
607
608
void JoltPhysicsServer3D::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform3D &p_transform) {
609
JoltBody3D *body = body_owner.get_or_null(p_body);
610
ERR_FAIL_NULL(body);
611
612
body->set_shape_transform(p_shape_idx, p_transform);
613
}
614
615
Transform3D JoltPhysicsServer3D::body_get_shape_transform(RID p_body, int p_shape_idx) const {
616
const JoltBody3D *body = body_owner.get_or_null(p_body);
617
ERR_FAIL_NULL_V(body, Transform3D());
618
619
return body->get_shape_transform_scaled(p_shape_idx);
620
}
621
622
int JoltPhysicsServer3D::body_get_shape_count(RID p_body) const {
623
const JoltBody3D *body = body_owner.get_or_null(p_body);
624
ERR_FAIL_NULL_V(body, 0);
625
626
return body->get_shape_count();
627
}
628
629
void JoltPhysicsServer3D::body_remove_shape(RID p_body, int p_shape_idx) {
630
JoltBody3D *body = body_owner.get_or_null(p_body);
631
ERR_FAIL_NULL(body);
632
633
body->remove_shape(p_shape_idx);
634
}
635
636
void JoltPhysicsServer3D::body_clear_shapes(RID p_body) {
637
JoltBody3D *body = body_owner.get_or_null(p_body);
638
ERR_FAIL_NULL(body);
639
640
body->clear_shapes();
641
}
642
643
void JoltPhysicsServer3D::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) {
644
JoltBody3D *body = body_owner.get_or_null(p_body);
645
ERR_FAIL_NULL(body);
646
647
body->set_shape_disabled(p_shape_idx, p_disabled);
648
}
649
650
void JoltPhysicsServer3D::body_attach_object_instance_id(RID p_body, ObjectID p_id) {
651
if (JoltBody3D *body = body_owner.get_or_null(p_body)) {
652
body->set_instance_id(p_id);
653
} else if (JoltSoftBody3D *soft_body = soft_body_owner.get_or_null(p_body)) {
654
soft_body->set_instance_id(p_id);
655
} else {
656
ERR_FAIL();
657
}
658
}
659
660
ObjectID JoltPhysicsServer3D::body_get_object_instance_id(RID p_body) const {
661
const JoltBody3D *body = body_owner.get_or_null(p_body);
662
ERR_FAIL_NULL_V(body, ObjectID());
663
664
return body->get_instance_id();
665
}
666
667
void JoltPhysicsServer3D::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) {
668
JoltBody3D *body = body_owner.get_or_null(p_body);
669
ERR_FAIL_NULL(body);
670
671
body->set_ccd_enabled(p_enable);
672
}
673
674
bool JoltPhysicsServer3D::body_is_continuous_collision_detection_enabled(RID p_body) const {
675
const JoltBody3D *body = body_owner.get_or_null(p_body);
676
ERR_FAIL_NULL_V(body, false);
677
678
return body->is_ccd_enabled();
679
}
680
681
void JoltPhysicsServer3D::body_set_collision_layer(RID p_body, uint32_t p_layer) {
682
JoltBody3D *body = body_owner.get_or_null(p_body);
683
ERR_FAIL_NULL(body);
684
685
body->set_collision_layer(p_layer);
686
}
687
688
uint32_t JoltPhysicsServer3D::body_get_collision_layer(RID p_body) const {
689
const JoltBody3D *body = body_owner.get_or_null(p_body);
690
ERR_FAIL_NULL_V(body, 0);
691
692
return body->get_collision_layer();
693
}
694
695
void JoltPhysicsServer3D::body_set_collision_mask(RID p_body, uint32_t p_mask) {
696
JoltBody3D *body = body_owner.get_or_null(p_body);
697
ERR_FAIL_NULL(body);
698
699
body->set_collision_mask(p_mask);
700
}
701
702
uint32_t JoltPhysicsServer3D::body_get_collision_mask(RID p_body) const {
703
const JoltBody3D *body = body_owner.get_or_null(p_body);
704
ERR_FAIL_NULL_V(body, 0);
705
706
return body->get_collision_mask();
707
}
708
709
void JoltPhysicsServer3D::body_set_collision_priority(RID p_body, real_t p_priority) {
710
JoltBody3D *body = body_owner.get_or_null(p_body);
711
ERR_FAIL_NULL(body);
712
713
body->set_collision_priority((float)p_priority);
714
}
715
716
real_t JoltPhysicsServer3D::body_get_collision_priority(RID p_body) const {
717
const JoltBody3D *body = body_owner.get_or_null(p_body);
718
ERR_FAIL_NULL_V(body, 0.0);
719
720
return (real_t)body->get_collision_priority();
721
}
722
723
void JoltPhysicsServer3D::body_set_user_flags(RID p_body, uint32_t p_flags) {
724
WARN_PRINT("Body user flags are not supported. Any such value will be ignored.");
725
}
726
727
uint32_t JoltPhysicsServer3D::body_get_user_flags(RID p_body) const {
728
return 0;
729
}
730
731
void JoltPhysicsServer3D::body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) {
732
JoltBody3D *body = body_owner.get_or_null(p_body);
733
ERR_FAIL_NULL(body);
734
735
body->set_param(p_param, p_value);
736
}
737
738
Variant JoltPhysicsServer3D::body_get_param(RID p_body, BodyParameter p_param) const {
739
const JoltBody3D *body = body_owner.get_or_null(p_body);
740
ERR_FAIL_NULL_V(body, Variant());
741
742
return body->get_param(p_param);
743
}
744
745
void JoltPhysicsServer3D::body_reset_mass_properties(RID p_body) {
746
JoltBody3D *body = body_owner.get_or_null(p_body);
747
ERR_FAIL_NULL(body);
748
749
body->reset_mass_properties();
750
}
751
752
void JoltPhysicsServer3D::body_set_state(RID p_body, BodyState p_state, const Variant &p_value) {
753
JoltBody3D *body = body_owner.get_or_null(p_body);
754
ERR_FAIL_NULL(body);
755
756
body->set_state(p_state, p_value);
757
}
758
759
Variant JoltPhysicsServer3D::body_get_state(RID p_body, BodyState p_state) const {
760
JoltBody3D *body = body_owner.get_or_null(p_body);
761
ERR_FAIL_NULL_V(body, Variant());
762
763
return body->get_state(p_state);
764
}
765
766
void JoltPhysicsServer3D::body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {
767
JoltBody3D *body = body_owner.get_or_null(p_body);
768
ERR_FAIL_NULL(body);
769
770
return body->apply_central_impulse(p_impulse);
771
}
772
773
void JoltPhysicsServer3D::body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position) {
774
JoltBody3D *body = body_owner.get_or_null(p_body);
775
ERR_FAIL_NULL(body);
776
777
return body->apply_impulse(p_impulse, p_position);
778
}
779
780
void JoltPhysicsServer3D::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) {
781
JoltBody3D *body = body_owner.get_or_null(p_body);
782
ERR_FAIL_NULL(body);
783
784
return body->apply_torque_impulse(p_impulse);
785
}
786
787
void JoltPhysicsServer3D::body_apply_central_force(RID p_body, const Vector3 &p_force) {
788
JoltBody3D *body = body_owner.get_or_null(p_body);
789
ERR_FAIL_NULL(body);
790
791
return body->apply_central_force(p_force);
792
}
793
794
void JoltPhysicsServer3D::body_apply_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position) {
795
JoltBody3D *body = body_owner.get_or_null(p_body);
796
ERR_FAIL_NULL(body);
797
798
return body->apply_force(p_force, p_position);
799
}
800
801
void JoltPhysicsServer3D::body_apply_torque(RID p_body, const Vector3 &p_torque) {
802
JoltBody3D *body = body_owner.get_or_null(p_body);
803
ERR_FAIL_NULL(body);
804
805
return body->apply_torque(p_torque);
806
}
807
808
void JoltPhysicsServer3D::body_add_constant_central_force(RID p_body, const Vector3 &p_force) {
809
JoltBody3D *body = body_owner.get_or_null(p_body);
810
ERR_FAIL_NULL(body);
811
812
body->add_constant_central_force(p_force);
813
}
814
815
void JoltPhysicsServer3D::body_add_constant_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position) {
816
JoltBody3D *body = body_owner.get_or_null(p_body);
817
ERR_FAIL_NULL(body);
818
819
body->add_constant_force(p_force, p_position);
820
}
821
822
void JoltPhysicsServer3D::body_add_constant_torque(RID p_body, const Vector3 &p_torque) {
823
JoltBody3D *body = body_owner.get_or_null(p_body);
824
ERR_FAIL_NULL(body);
825
826
body->add_constant_torque(p_torque);
827
}
828
829
void JoltPhysicsServer3D::body_set_constant_force(RID p_body, const Vector3 &p_force) {
830
JoltBody3D *body = body_owner.get_or_null(p_body);
831
ERR_FAIL_NULL(body);
832
833
body->set_constant_force(p_force);
834
}
835
836
Vector3 JoltPhysicsServer3D::body_get_constant_force(RID p_body) const {
837
const JoltBody3D *body = body_owner.get_or_null(p_body);
838
ERR_FAIL_NULL_V(body, Vector3());
839
840
return body->get_constant_force();
841
}
842
843
void JoltPhysicsServer3D::body_set_constant_torque(RID p_body, const Vector3 &p_torque) {
844
JoltBody3D *body = body_owner.get_or_null(p_body);
845
ERR_FAIL_NULL(body);
846
847
body->set_constant_torque(p_torque);
848
}
849
850
Vector3 JoltPhysicsServer3D::body_get_constant_torque(RID p_body) const {
851
const JoltBody3D *body = body_owner.get_or_null(p_body);
852
ERR_FAIL_NULL_V(body, Vector3());
853
854
return body->get_constant_torque();
855
}
856
857
void JoltPhysicsServer3D::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) {
858
JoltBody3D *body = body_owner.get_or_null(p_body);
859
ERR_FAIL_NULL(body);
860
861
body->set_axis_velocity(p_axis_velocity);
862
}
863
864
void JoltPhysicsServer3D::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) {
865
JoltBody3D *body = body_owner.get_or_null(p_body);
866
ERR_FAIL_NULL(body);
867
868
body->set_axis_lock(p_axis, p_lock);
869
}
870
871
bool JoltPhysicsServer3D::body_is_axis_locked(RID p_body, BodyAxis p_axis) const {
872
const JoltBody3D *body = body_owner.get_or_null(p_body);
873
ERR_FAIL_NULL_V(body, false);
874
875
return body->is_axis_locked(p_axis);
876
}
877
878
void JoltPhysicsServer3D::body_add_collision_exception(RID p_body, RID p_excepted_body) {
879
JoltBody3D *body = body_owner.get_or_null(p_body);
880
ERR_FAIL_NULL(body);
881
882
body->add_collision_exception(p_excepted_body);
883
}
884
885
void JoltPhysicsServer3D::body_remove_collision_exception(RID p_body, RID p_excepted_body) {
886
JoltBody3D *body = body_owner.get_or_null(p_body);
887
ERR_FAIL_NULL(body);
888
889
body->remove_collision_exception(p_excepted_body);
890
}
891
892
void JoltPhysicsServer3D::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
893
const JoltBody3D *body = body_owner.get_or_null(p_body);
894
ERR_FAIL_NULL(body);
895
896
for (const RID &exception : body->get_collision_exceptions()) {
897
p_exceptions->push_back(exception);
898
}
899
}
900
901
void JoltPhysicsServer3D::body_set_max_contacts_reported(RID p_body, int p_amount) {
902
JoltBody3D *body = body_owner.get_or_null(p_body);
903
ERR_FAIL_NULL(body);
904
905
return body->set_max_contacts_reported(p_amount);
906
}
907
908
int JoltPhysicsServer3D::body_get_max_contacts_reported(RID p_body) const {
909
const JoltBody3D *body = body_owner.get_or_null(p_body);
910
ERR_FAIL_NULL_V(body, 0);
911
912
return body->get_max_contacts_reported();
913
}
914
915
void JoltPhysicsServer3D::body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) {
916
WARN_PRINT("Per-body contact depth threshold is not supported. Any such value will be ignored.");
917
}
918
919
real_t JoltPhysicsServer3D::body_get_contacts_reported_depth_threshold(RID p_body) const {
920
return 0.0;
921
}
922
923
void JoltPhysicsServer3D::body_set_omit_force_integration(RID p_body, bool p_enable) {
924
JoltBody3D *body = body_owner.get_or_null(p_body);
925
ERR_FAIL_NULL(body);
926
927
body->set_custom_integrator(p_enable);
928
}
929
930
bool JoltPhysicsServer3D::body_is_omitting_force_integration(RID p_body) const {
931
JoltBody3D *body = body_owner.get_or_null(p_body);
932
ERR_FAIL_NULL_V(body, false);
933
934
return body->has_custom_integrator();
935
}
936
937
void JoltPhysicsServer3D::body_set_state_sync_callback(RID p_body, const Callable &p_callable) {
938
JoltBody3D *body = body_owner.get_or_null(p_body);
939
ERR_FAIL_NULL(body);
940
941
body->set_state_sync_callback(p_callable);
942
}
943
944
void JoltPhysicsServer3D::body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_userdata) {
945
JoltBody3D *body = body_owner.get_or_null(p_body);
946
ERR_FAIL_NULL(body);
947
948
body->set_custom_integration_callback(p_callable, p_userdata);
949
}
950
951
void JoltPhysicsServer3D::body_set_ray_pickable(RID p_body, bool p_enable) {
952
JoltBody3D *body = body_owner.get_or_null(p_body);
953
ERR_FAIL_NULL(body);
954
955
body->set_pickable(p_enable);
956
}
957
958
bool JoltPhysicsServer3D::body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result) {
959
JoltBody3D *body = body_owner.get_or_null(p_body);
960
ERR_FAIL_NULL_V(body, false);
961
962
JoltSpace3D *space = body->get_space();
963
ERR_FAIL_NULL_V(space, false);
964
965
return space->get_direct_state()->body_test_motion(*body, p_parameters, r_result);
966
}
967
968
PhysicsDirectBodyState3D *JoltPhysicsServer3D::body_get_direct_state(RID p_body) {
969
ERR_FAIL_COND_V_MSG((on_separate_thread && !doing_sync), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification.");
970
971
JoltBody3D *body = body_owner.get_or_null(p_body);
972
if (unlikely(body == nullptr || body->get_space() == nullptr)) {
973
return nullptr;
974
}
975
976
ERR_FAIL_COND_V_MSG(body->get_space()->is_stepping(), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification.");
977
978
return body->get_direct_state();
979
}
980
981
RID JoltPhysicsServer3D::soft_body_create() {
982
JoltSoftBody3D *body = memnew(JoltSoftBody3D);
983
RID rid = soft_body_owner.make_rid(body);
984
body->set_rid(rid);
985
return rid;
986
}
987
988
void JoltPhysicsServer3D::soft_body_update_rendering_server(RID p_body, RequiredParam<PhysicsServer3DRenderingServerHandler> rp_rendering_server_handler) {
989
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
990
ERR_FAIL_NULL(body);
991
EXTRACT_PARAM_OR_FAIL(p_rendering_server_handler, rp_rendering_server_handler);
992
993
return body->update_rendering_server(p_rendering_server_handler);
994
}
995
996
void JoltPhysicsServer3D::soft_body_set_space(RID p_body, RID p_space) {
997
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
998
ERR_FAIL_NULL(body);
999
1000
JoltSpace3D *space = nullptr;
1001
1002
if (p_space.is_valid()) {
1003
space = space_owner.get_or_null(p_space);
1004
ERR_FAIL_NULL(space);
1005
}
1006
1007
body->set_space(space);
1008
}
1009
1010
RID JoltPhysicsServer3D::soft_body_get_space(RID p_body) const {
1011
const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1012
ERR_FAIL_NULL_V(body, RID());
1013
1014
const JoltSpace3D *space = body->get_space();
1015
1016
if (space == nullptr) {
1017
return RID();
1018
}
1019
1020
return space->get_rid();
1021
}
1022
1023
void JoltPhysicsServer3D::soft_body_set_mesh(RID p_body, RID p_mesh) {
1024
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1025
ERR_FAIL_NULL(body);
1026
1027
body->set_mesh(p_mesh);
1028
}
1029
1030
AABB JoltPhysicsServer3D::soft_body_get_bounds(RID p_body) const {
1031
const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1032
ERR_FAIL_NULL_V(body, AABB());
1033
1034
return body->get_bounds();
1035
}
1036
1037
void JoltPhysicsServer3D::soft_body_set_collision_layer(RID p_body, uint32_t p_layer) {
1038
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1039
ERR_FAIL_NULL(body);
1040
1041
body->set_collision_layer(p_layer);
1042
}
1043
1044
uint32_t JoltPhysicsServer3D::soft_body_get_collision_layer(RID p_body) const {
1045
const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1046
ERR_FAIL_NULL_V(body, 0);
1047
1048
return body->get_collision_layer();
1049
}
1050
1051
void JoltPhysicsServer3D::soft_body_set_collision_mask(RID p_body, uint32_t p_mask) {
1052
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1053
ERR_FAIL_NULL(body);
1054
1055
body->set_collision_mask(p_mask);
1056
}
1057
1058
uint32_t JoltPhysicsServer3D::soft_body_get_collision_mask(RID p_body) const {
1059
const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1060
ERR_FAIL_NULL_V(body, 0);
1061
1062
return body->get_collision_mask();
1063
}
1064
1065
void JoltPhysicsServer3D::soft_body_add_collision_exception(RID p_body, RID p_excepted_body) {
1066
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1067
ERR_FAIL_NULL(body);
1068
1069
body->add_collision_exception(p_excepted_body);
1070
}
1071
1072
void JoltPhysicsServer3D::soft_body_remove_collision_exception(RID p_body, RID p_excepted_body) {
1073
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1074
ERR_FAIL_NULL(body);
1075
1076
body->remove_collision_exception(p_excepted_body);
1077
}
1078
1079
void JoltPhysicsServer3D::soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
1080
const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1081
ERR_FAIL_NULL(body);
1082
1083
for (const RID &exception : body->get_collision_exceptions()) {
1084
p_exceptions->push_back(exception);
1085
}
1086
}
1087
1088
void JoltPhysicsServer3D::soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_value) {
1089
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1090
ERR_FAIL_NULL(body);
1091
1092
body->set_state(p_state, p_value);
1093
}
1094
1095
Variant JoltPhysicsServer3D::soft_body_get_state(RID p_body, BodyState p_state) const {
1096
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1097
ERR_FAIL_NULL_V(body, Variant());
1098
1099
return body->get_state(p_state);
1100
}
1101
1102
void JoltPhysicsServer3D::soft_body_set_transform(RID p_body, const Transform3D &p_transform) {
1103
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1104
ERR_FAIL_NULL(body);
1105
1106
return body->set_transform(p_transform);
1107
}
1108
1109
void JoltPhysicsServer3D::soft_body_set_ray_pickable(RID p_body, bool p_enable) {
1110
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1111
ERR_FAIL_NULL(body);
1112
1113
return body->set_pickable(p_enable);
1114
}
1115
1116
void JoltPhysicsServer3D::soft_body_set_simulation_precision(RID p_body, int p_precision) {
1117
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1118
ERR_FAIL_NULL(body);
1119
1120
return body->set_simulation_precision(p_precision);
1121
}
1122
1123
int JoltPhysicsServer3D::soft_body_get_simulation_precision(RID p_body) const {
1124
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1125
ERR_FAIL_NULL_V(body, 0);
1126
1127
return body->get_simulation_precision();
1128
}
1129
1130
void JoltPhysicsServer3D::soft_body_set_total_mass(RID p_body, real_t p_total_mass) {
1131
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1132
ERR_FAIL_NULL(body);
1133
1134
return body->set_mass((float)p_total_mass);
1135
}
1136
1137
real_t JoltPhysicsServer3D::soft_body_get_total_mass(RID p_body) const {
1138
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1139
ERR_FAIL_NULL_V(body, 0.0);
1140
1141
return (real_t)body->get_mass();
1142
}
1143
1144
void JoltPhysicsServer3D::soft_body_set_linear_stiffness(RID p_body, real_t p_coefficient) {
1145
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1146
ERR_FAIL_NULL(body);
1147
1148
return body->set_stiffness_coefficient((float)p_coefficient);
1149
}
1150
1151
real_t JoltPhysicsServer3D::soft_body_get_linear_stiffness(RID p_body) const {
1152
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1153
ERR_FAIL_NULL_V(body, 0.0);
1154
1155
return (real_t)body->get_stiffness_coefficient();
1156
}
1157
1158
void JoltPhysicsServer3D::soft_body_set_shrinking_factor(RID p_body, real_t p_shrinking_factor) {
1159
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1160
ERR_FAIL_NULL(body);
1161
1162
return body->set_shrinking_factor((float)p_shrinking_factor);
1163
}
1164
1165
real_t JoltPhysicsServer3D::soft_body_get_shrinking_factor(RID p_body) const {
1166
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1167
ERR_FAIL_NULL_V(body, 0.0);
1168
1169
return (real_t)body->get_shrinking_factor();
1170
}
1171
1172
void JoltPhysicsServer3D::soft_body_set_pressure_coefficient(RID p_body, real_t p_coefficient) {
1173
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1174
ERR_FAIL_NULL(body);
1175
1176
return body->set_pressure((float)p_coefficient);
1177
}
1178
1179
real_t JoltPhysicsServer3D::soft_body_get_pressure_coefficient(RID p_body) const {
1180
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1181
ERR_FAIL_NULL_V(body, 0.0);
1182
1183
return (real_t)body->get_pressure();
1184
}
1185
1186
void JoltPhysicsServer3D::soft_body_set_damping_coefficient(RID p_body, real_t p_coefficient) {
1187
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1188
ERR_FAIL_NULL(body);
1189
1190
return body->set_linear_damping((float)p_coefficient);
1191
}
1192
1193
real_t JoltPhysicsServer3D::soft_body_get_damping_coefficient(RID p_body) const {
1194
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1195
ERR_FAIL_NULL_V(body, 0.0);
1196
1197
return (real_t)body->get_linear_damping();
1198
}
1199
1200
void JoltPhysicsServer3D::soft_body_set_drag_coefficient(RID p_body, real_t p_coefficient) {
1201
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1202
ERR_FAIL_NULL(body);
1203
1204
return body->set_drag((float)p_coefficient);
1205
}
1206
1207
real_t JoltPhysicsServer3D::soft_body_get_drag_coefficient(RID p_body) const {
1208
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1209
ERR_FAIL_NULL_V(body, 0.0);
1210
1211
return (real_t)body->get_drag();
1212
}
1213
1214
void JoltPhysicsServer3D::soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) {
1215
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1216
ERR_FAIL_NULL(body);
1217
1218
body->set_vertex_position(p_point_index, p_global_position);
1219
}
1220
1221
Vector3 JoltPhysicsServer3D::soft_body_get_point_global_position(RID p_body, int p_point_index) const {
1222
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1223
ERR_FAIL_NULL_V(body, Vector3());
1224
1225
return body->get_vertex_position(p_point_index);
1226
}
1227
1228
void JoltPhysicsServer3D::soft_body_remove_all_pinned_points(RID p_body) {
1229
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1230
ERR_FAIL_NULL(body);
1231
1232
body->unpin_all_vertices();
1233
}
1234
1235
void JoltPhysicsServer3D::soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) {
1236
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1237
ERR_FAIL_NULL(body);
1238
1239
if (p_pin) {
1240
body->pin_vertex(p_point_index);
1241
} else {
1242
body->unpin_vertex(p_point_index);
1243
}
1244
}
1245
1246
bool JoltPhysicsServer3D::soft_body_is_point_pinned(RID p_body, int p_point_index) const {
1247
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1248
ERR_FAIL_NULL_V(body, false);
1249
1250
return body->is_vertex_pinned(p_point_index);
1251
}
1252
1253
RID JoltPhysicsServer3D::joint_create() {
1254
JoltJoint3D *joint = memnew(JoltJoint3D);
1255
RID rid = joint_owner.make_rid(joint);
1256
joint->set_rid(rid);
1257
return rid;
1258
}
1259
1260
void JoltPhysicsServer3D::joint_clear(RID p_joint) {
1261
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1262
ERR_FAIL_NULL(joint);
1263
1264
if (joint->get_type() != JOINT_TYPE_MAX) {
1265
JoltJoint3D *empty_joint = memnew(JoltJoint3D);
1266
empty_joint->set_rid(joint->get_rid());
1267
1268
memdelete(joint);
1269
joint = nullptr;
1270
1271
joint_owner.replace(p_joint, empty_joint);
1272
}
1273
}
1274
1275
void JoltPhysicsServer3D::joint_make_pin(RID p_joint, RID p_body_a, const Vector3 &p_local_a, RID p_body_b, const Vector3 &p_local_b) {
1276
JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);
1277
ERR_FAIL_NULL(old_joint);
1278
1279
JoltBody3D *body_a = body_owner.get_or_null(p_body_a);
1280
ERR_FAIL_NULL(body_a);
1281
1282
JoltBody3D *body_b = body_owner.get_or_null(p_body_b);
1283
ERR_FAIL_COND(body_a == body_b);
1284
1285
JoltJoint3D *new_joint = memnew(JoltPinJoint3D(*old_joint, body_a, body_b, p_local_a, p_local_b));
1286
1287
memdelete(old_joint);
1288
old_joint = nullptr;
1289
1290
joint_owner.replace(p_joint, new_joint);
1291
}
1292
1293
void JoltPhysicsServer3D::pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) {
1294
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1295
ERR_FAIL_NULL(joint);
1296
1297
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_PIN);
1298
JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);
1299
1300
pin_joint->set_param(p_param, (double)p_value);
1301
}
1302
1303
real_t JoltPhysicsServer3D::pin_joint_get_param(RID p_joint, PinJointParam p_param) const {
1304
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1305
ERR_FAIL_NULL_V(joint, 0.0);
1306
1307
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, 0.0);
1308
const JoltPinJoint3D *pin_joint = static_cast<const JoltPinJoint3D *>(joint);
1309
1310
return (real_t)pin_joint->get_param(p_param);
1311
}
1312
1313
void JoltPhysicsServer3D::pin_joint_set_local_a(RID p_joint, const Vector3 &p_local_a) {
1314
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1315
ERR_FAIL_NULL(joint);
1316
1317
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_PIN);
1318
JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);
1319
1320
pin_joint->set_local_a(p_local_a);
1321
}
1322
1323
Vector3 JoltPhysicsServer3D::pin_joint_get_local_a(RID p_joint) const {
1324
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1325
ERR_FAIL_NULL_V(joint, Vector3());
1326
1327
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, Vector3());
1328
const JoltPinJoint3D *pin_joint = static_cast<const JoltPinJoint3D *>(joint);
1329
1330
return pin_joint->get_local_a();
1331
}
1332
1333
void JoltPhysicsServer3D::pin_joint_set_local_b(RID p_joint, const Vector3 &p_local_b) {
1334
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1335
ERR_FAIL_NULL(joint);
1336
1337
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_PIN);
1338
JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);
1339
1340
pin_joint->set_local_b(p_local_b);
1341
}
1342
1343
Vector3 JoltPhysicsServer3D::pin_joint_get_local_b(RID p_joint) const {
1344
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1345
ERR_FAIL_NULL_V(joint, Vector3());
1346
1347
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, Vector3());
1348
const JoltPinJoint3D *pin_joint = static_cast<const JoltPinJoint3D *>(joint);
1349
1350
return pin_joint->get_local_b();
1351
}
1352
1353
void JoltPhysicsServer3D::joint_make_hinge(RID p_joint, RID p_body_a, const Transform3D &p_hinge_a, RID p_body_b, const Transform3D &p_hinge_b) {
1354
JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);
1355
ERR_FAIL_NULL(old_joint);
1356
1357
JoltBody3D *body_a = body_owner.get_or_null(p_body_a);
1358
ERR_FAIL_NULL(body_a);
1359
1360
JoltBody3D *body_b = body_owner.get_or_null(p_body_b);
1361
ERR_FAIL_COND(body_a == body_b);
1362
1363
JoltJoint3D *new_joint = memnew(JoltHingeJoint3D(*old_joint, body_a, body_b, p_hinge_a, p_hinge_b));
1364
1365
memdelete(old_joint);
1366
old_joint = nullptr;
1367
1368
joint_owner.replace(p_joint, new_joint);
1369
}
1370
1371
void JoltPhysicsServer3D::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) {
1372
ERR_FAIL_MSG("Simple hinge joints are not supported when using Jolt Physics.");
1373
}
1374
1375
void JoltPhysicsServer3D::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, real_t p_value) {
1376
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1377
ERR_FAIL_NULL(joint);
1378
1379
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);
1380
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1381
1382
return hinge_joint->set_param(p_param, (double)p_value);
1383
}
1384
1385
real_t JoltPhysicsServer3D::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const {
1386
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1387
ERR_FAIL_NULL_V(joint, 0.0);
1388
1389
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0);
1390
const JoltHingeJoint3D *hinge_joint = static_cast<const JoltHingeJoint3D *>(joint);
1391
1392
return (real_t)hinge_joint->get_param(p_param);
1393
}
1394
1395
void JoltPhysicsServer3D::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_enabled) {
1396
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1397
ERR_FAIL_NULL(joint);
1398
1399
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);
1400
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1401
1402
return hinge_joint->set_flag(p_flag, p_enabled);
1403
}
1404
1405
bool JoltPhysicsServer3D::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const {
1406
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1407
ERR_FAIL_NULL_V(joint, false);
1408
1409
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, false);
1410
const JoltHingeJoint3D *hinge_joint = static_cast<const JoltHingeJoint3D *>(joint);
1411
1412
return hinge_joint->get_flag(p_flag);
1413
}
1414
1415
void JoltPhysicsServer3D::joint_make_slider(RID p_joint, RID p_body_a, const Transform3D &p_local_ref_a, RID p_body_b, const Transform3D &p_local_ref_b) {
1416
JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);
1417
ERR_FAIL_NULL(old_joint);
1418
1419
JoltBody3D *body_a = body_owner.get_or_null(p_body_a);
1420
ERR_FAIL_NULL(body_a);
1421
1422
JoltBody3D *body_b = body_owner.get_or_null(p_body_b);
1423
ERR_FAIL_COND(body_a == body_b);
1424
1425
JoltJoint3D *new_joint = memnew(JoltSliderJoint3D(*old_joint, body_a, body_b, p_local_ref_a, p_local_ref_b));
1426
1427
memdelete(old_joint);
1428
old_joint = nullptr;
1429
1430
joint_owner.replace(p_joint, new_joint);
1431
}
1432
1433
void JoltPhysicsServer3D::slider_joint_set_param(RID p_joint, SliderJointParam p_param, real_t p_value) {
1434
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1435
ERR_FAIL_NULL(joint);
1436
1437
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_SLIDER);
1438
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1439
1440
return slider_joint->set_param(p_param, (real_t)p_value);
1441
}
1442
1443
real_t JoltPhysicsServer3D::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const {
1444
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1445
ERR_FAIL_NULL_V(joint, 0.0);
1446
1447
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0);
1448
const JoltSliderJoint3D *slider_joint = static_cast<const JoltSliderJoint3D *>(joint);
1449
1450
return slider_joint->get_param(p_param);
1451
}
1452
1453
void JoltPhysicsServer3D::joint_make_cone_twist(RID p_joint, RID p_body_a, const Transform3D &p_local_ref_a, RID p_body_b, const Transform3D &p_local_ref_b) {
1454
JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);
1455
ERR_FAIL_NULL(old_joint);
1456
1457
JoltBody3D *body_a = body_owner.get_or_null(p_body_a);
1458
ERR_FAIL_NULL(body_a);
1459
1460
JoltBody3D *body_b = body_owner.get_or_null(p_body_b);
1461
ERR_FAIL_COND(body_a == body_b);
1462
1463
JoltJoint3D *new_joint = memnew(JoltConeTwistJoint3D(*old_joint, body_a, body_b, p_local_ref_a, p_local_ref_b));
1464
1465
memdelete(old_joint);
1466
old_joint = nullptr;
1467
1468
joint_owner.replace(p_joint, new_joint);
1469
}
1470
1471
void JoltPhysicsServer3D::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, real_t p_value) {
1472
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1473
ERR_FAIL_NULL(joint);
1474
1475
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_CONE_TWIST);
1476
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1477
1478
return cone_twist_joint->set_param(p_param, (double)p_value);
1479
}
1480
1481
real_t JoltPhysicsServer3D::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const {
1482
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1483
ERR_FAIL_NULL_V(joint, 0.0);
1484
1485
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0);
1486
const JoltConeTwistJoint3D *cone_twist_joint = static_cast<const JoltConeTwistJoint3D *>(joint);
1487
1488
return (real_t)cone_twist_joint->get_param(p_param);
1489
}
1490
1491
void JoltPhysicsServer3D::joint_make_generic_6dof(RID p_joint, RID p_body_a, const Transform3D &p_local_ref_a, RID p_body_b, const Transform3D &p_local_ref_b) {
1492
JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);
1493
ERR_FAIL_NULL(old_joint);
1494
1495
JoltBody3D *body_a = body_owner.get_or_null(p_body_a);
1496
ERR_FAIL_NULL(body_a);
1497
1498
JoltBody3D *body_b = body_owner.get_or_null(p_body_b);
1499
ERR_FAIL_COND(body_a == body_b);
1500
1501
JoltJoint3D *new_joint = memnew(JoltGeneric6DOFJoint3D(*old_joint, body_a, body_b, p_local_ref_a, p_local_ref_b));
1502
1503
memdelete(old_joint);
1504
old_joint = nullptr;
1505
1506
joint_owner.replace(p_joint, new_joint);
1507
}
1508
1509
void JoltPhysicsServer3D::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param, real_t p_value) {
1510
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1511
ERR_FAIL_NULL(joint);
1512
1513
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);
1514
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
1515
1516
return g6dof_joint->set_param(p_axis, p_param, (double)p_value);
1517
}
1518
1519
real_t JoltPhysicsServer3D::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param) const {
1520
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1521
ERR_FAIL_NULL_V(joint, 0.0);
1522
1523
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0);
1524
const JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<const JoltGeneric6DOFJoint3D *>(joint);
1525
1526
return (real_t)g6dof_joint->get_param(p_axis, p_param);
1527
}
1528
1529
void JoltPhysicsServer3D::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag, bool p_enable) {
1530
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1531
ERR_FAIL_NULL(joint);
1532
1533
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);
1534
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
1535
1536
return g6dof_joint->set_flag(p_axis, p_flag, p_enable);
1537
}
1538
1539
bool JoltPhysicsServer3D::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag) const {
1540
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1541
ERR_FAIL_NULL_V(joint, false);
1542
1543
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, false);
1544
const JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<const JoltGeneric6DOFJoint3D *>(joint);
1545
1546
return g6dof_joint->get_flag(p_axis, p_flag);
1547
}
1548
1549
PhysicsServer3D::JointType JoltPhysicsServer3D::joint_get_type(RID p_joint) const {
1550
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1551
ERR_FAIL_NULL_V(joint, JOINT_TYPE_PIN);
1552
1553
return joint->get_type();
1554
}
1555
1556
void JoltPhysicsServer3D::joint_set_solver_priority(RID p_joint, int p_priority) {
1557
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1558
ERR_FAIL_NULL(joint);
1559
1560
joint->set_solver_priority(p_priority);
1561
}
1562
1563
int JoltPhysicsServer3D::joint_get_solver_priority(RID p_joint) const {
1564
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1565
ERR_FAIL_NULL_V(joint, 0);
1566
1567
return joint->get_solver_priority();
1568
}
1569
1570
void JoltPhysicsServer3D::joint_disable_collisions_between_bodies(RID p_joint, bool p_disable) {
1571
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1572
ERR_FAIL_NULL(joint);
1573
1574
joint->set_collision_disabled(p_disable);
1575
}
1576
1577
bool JoltPhysicsServer3D::joint_is_disabled_collisions_between_bodies(RID p_joint) const {
1578
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1579
ERR_FAIL_NULL_V(joint, false);
1580
1581
return joint->is_collision_disabled();
1582
}
1583
1584
void JoltPhysicsServer3D::free_rid(RID p_rid) {
1585
if (JoltShape3D *shape = shape_owner.get_or_null(p_rid)) {
1586
free_shape(shape);
1587
} else if (JoltBody3D *body = body_owner.get_or_null(p_rid)) {
1588
free_body(body);
1589
} else if (JoltJoint3D *joint = joint_owner.get_or_null(p_rid)) {
1590
free_joint(joint);
1591
} else if (JoltArea3D *area = area_owner.get_or_null(p_rid)) {
1592
free_area(area);
1593
} else if (JoltSoftBody3D *soft_body = soft_body_owner.get_or_null(p_rid)) {
1594
free_soft_body(soft_body);
1595
} else if (JoltSpace3D *space = space_owner.get_or_null(p_rid)) {
1596
free_space(space);
1597
} else {
1598
ERR_FAIL_MSG("Failed to free RID: The specified RID has no owner.");
1599
}
1600
}
1601
1602
void JoltPhysicsServer3D::set_active(bool p_active) {
1603
active = p_active;
1604
}
1605
1606
void JoltPhysicsServer3D::init() {
1607
job_system = new JoltJobSystem();
1608
}
1609
1610
void JoltPhysicsServer3D::finish() {
1611
if (job_system != nullptr) {
1612
delete job_system;
1613
job_system = nullptr;
1614
}
1615
}
1616
1617
void JoltPhysicsServer3D::step(real_t p_step) {
1618
if (!active) {
1619
return;
1620
}
1621
1622
for (JoltSpace3D *active_space : active_spaces) {
1623
job_system->pre_step();
1624
1625
active_space->step((float)p_step);
1626
1627
job_system->post_step();
1628
}
1629
}
1630
1631
void JoltPhysicsServer3D::sync() {
1632
doing_sync = true;
1633
}
1634
1635
void JoltPhysicsServer3D::end_sync() {
1636
doing_sync = false;
1637
}
1638
1639
void JoltPhysicsServer3D::flush_queries() {
1640
if (!active) {
1641
return;
1642
}
1643
1644
flushing_queries = true;
1645
1646
for (JoltSpace3D *space : active_spaces) {
1647
space->call_queries();
1648
}
1649
1650
flushing_queries = false;
1651
1652
#ifdef DEBUG_ENABLED
1653
job_system->flush_timings();
1654
#endif
1655
}
1656
1657
bool JoltPhysicsServer3D::is_flushing_queries() const {
1658
return flushing_queries;
1659
}
1660
1661
int JoltPhysicsServer3D::get_process_info(ProcessInfo p_process_info) {
1662
return 0;
1663
}
1664
1665
void JoltPhysicsServer3D::free_space(JoltSpace3D *p_space) {
1666
ERR_FAIL_NULL(p_space);
1667
1668
free_area(p_space->get_default_area());
1669
space_set_active(p_space->get_rid(), false);
1670
space_owner.free(p_space->get_rid());
1671
memdelete(p_space);
1672
}
1673
1674
void JoltPhysicsServer3D::free_area(JoltArea3D *p_area) {
1675
ERR_FAIL_NULL(p_area);
1676
1677
p_area->set_space(nullptr);
1678
area_owner.free(p_area->get_rid());
1679
memdelete(p_area);
1680
}
1681
1682
void JoltPhysicsServer3D::free_body(JoltBody3D *p_body) {
1683
ERR_FAIL_NULL(p_body);
1684
1685
p_body->set_space(nullptr);
1686
body_owner.free(p_body->get_rid());
1687
memdelete(p_body);
1688
}
1689
1690
void JoltPhysicsServer3D::free_soft_body(JoltSoftBody3D *p_body) {
1691
ERR_FAIL_NULL(p_body);
1692
1693
p_body->set_space(nullptr);
1694
soft_body_owner.free(p_body->get_rid());
1695
memdelete(p_body);
1696
}
1697
1698
void JoltPhysicsServer3D::free_shape(JoltShape3D *p_shape) {
1699
ERR_FAIL_NULL(p_shape);
1700
1701
p_shape->remove_self();
1702
shape_owner.free(p_shape->get_rid());
1703
memdelete(p_shape);
1704
}
1705
1706
void JoltPhysicsServer3D::free_joint(JoltJoint3D *p_joint) {
1707
ERR_FAIL_NULL(p_joint);
1708
1709
joint_owner.free(p_joint->get_rid());
1710
memdelete(p_joint);
1711
}
1712
1713
#ifdef DEBUG_ENABLED
1714
1715
void JoltPhysicsServer3D::dump_debug_snapshots(const String &p_dir) {
1716
for (JoltSpace3D *space : active_spaces) {
1717
space->dump_debug_snapshot(p_dir);
1718
}
1719
}
1720
1721
void JoltPhysicsServer3D::space_dump_debug_snapshot(RID p_space, const String &p_dir) {
1722
JoltSpace3D *space = space_owner.get_or_null(p_space);
1723
ERR_FAIL_NULL(space);
1724
1725
space->dump_debug_snapshot(p_dir);
1726
}
1727
1728
#endif
1729
1730
bool JoltPhysicsServer3D::joint_get_enabled(RID p_joint) const {
1731
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1732
ERR_FAIL_NULL_V(joint, false);
1733
1734
return joint->is_enabled();
1735
}
1736
1737
void JoltPhysicsServer3D::joint_set_enabled(RID p_joint, bool p_enabled) {
1738
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1739
ERR_FAIL_NULL(joint);
1740
1741
joint->set_enabled(p_enabled);
1742
}
1743
1744
int JoltPhysicsServer3D::joint_get_solver_velocity_iterations(RID p_joint) {
1745
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1746
ERR_FAIL_NULL_V(joint, 0);
1747
1748
return joint->get_solver_velocity_iterations();
1749
}
1750
1751
void JoltPhysicsServer3D::joint_set_solver_velocity_iterations(RID p_joint, int p_value) {
1752
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1753
ERR_FAIL_NULL(joint);
1754
1755
return joint->set_solver_velocity_iterations(p_value);
1756
}
1757
1758
int JoltPhysicsServer3D::joint_get_solver_position_iterations(RID p_joint) {
1759
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1760
ERR_FAIL_NULL_V(joint, 0);
1761
1762
return joint->get_solver_position_iterations();
1763
}
1764
1765
void JoltPhysicsServer3D::joint_set_solver_position_iterations(RID p_joint, int p_value) {
1766
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1767
ERR_FAIL_NULL(joint);
1768
1769
return joint->set_solver_position_iterations(p_value);
1770
}
1771
1772
float JoltPhysicsServer3D::pin_joint_get_applied_force(RID p_joint) {
1773
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1774
ERR_FAIL_NULL_V(joint, 0.0f);
1775
1776
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, 0.0);
1777
JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);
1778
1779
return pin_joint->get_applied_force();
1780
}
1781
1782
double JoltPhysicsServer3D::hinge_joint_get_jolt_param(RID p_joint, HingeJointParamJolt p_param) const {
1783
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1784
ERR_FAIL_NULL_V(joint, 0.0);
1785
1786
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0);
1787
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1788
1789
return hinge_joint->get_jolt_param(p_param);
1790
}
1791
1792
void JoltPhysicsServer3D::hinge_joint_set_jolt_param(RID p_joint, HingeJointParamJolt p_param, double p_value) {
1793
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1794
ERR_FAIL_NULL(joint);
1795
1796
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);
1797
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1798
1799
return hinge_joint->set_jolt_param(p_param, p_value);
1800
}
1801
1802
bool JoltPhysicsServer3D::hinge_joint_get_jolt_flag(RID p_joint, HingeJointFlagJolt p_flag) const {
1803
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1804
ERR_FAIL_NULL_V(joint, false);
1805
1806
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, false);
1807
const JoltHingeJoint3D *hinge_joint = static_cast<const JoltHingeJoint3D *>(joint);
1808
1809
return hinge_joint->get_jolt_flag(p_flag);
1810
}
1811
1812
void JoltPhysicsServer3D::hinge_joint_set_jolt_flag(RID p_joint, HingeJointFlagJolt p_flag, bool p_enabled) {
1813
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1814
ERR_FAIL_NULL(joint);
1815
1816
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);
1817
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1818
1819
return hinge_joint->set_jolt_flag(p_flag, p_enabled);
1820
}
1821
1822
float JoltPhysicsServer3D::hinge_joint_get_applied_force(RID p_joint) {
1823
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1824
ERR_FAIL_NULL_V(joint, 0.0f);
1825
1826
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0f);
1827
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1828
1829
return hinge_joint->get_applied_force();
1830
}
1831
1832
float JoltPhysicsServer3D::hinge_joint_get_applied_torque(RID p_joint) {
1833
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1834
ERR_FAIL_NULL_V(joint, 0.0f);
1835
1836
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0f);
1837
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1838
1839
return hinge_joint->get_applied_torque();
1840
}
1841
1842
double JoltPhysicsServer3D::slider_joint_get_jolt_param(RID p_joint, SliderJointParamJolt p_param) const {
1843
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1844
ERR_FAIL_NULL_V(joint, 0.0);
1845
1846
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0);
1847
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1848
1849
return slider_joint->get_jolt_param(p_param);
1850
}
1851
1852
void JoltPhysicsServer3D::slider_joint_set_jolt_param(RID p_joint, SliderJointParamJolt p_param, double p_value) {
1853
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1854
ERR_FAIL_NULL(joint);
1855
1856
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_SLIDER);
1857
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1858
1859
return slider_joint->set_jolt_param(p_param, p_value);
1860
}
1861
1862
bool JoltPhysicsServer3D::slider_joint_get_jolt_flag(RID p_joint, SliderJointFlagJolt p_flag) const {
1863
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1864
ERR_FAIL_NULL_V(joint, false);
1865
1866
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, false);
1867
const JoltSliderJoint3D *slider_joint = static_cast<const JoltSliderJoint3D *>(joint);
1868
1869
return slider_joint->get_jolt_flag(p_flag);
1870
}
1871
1872
void JoltPhysicsServer3D::slider_joint_set_jolt_flag(RID p_joint, SliderJointFlagJolt p_flag, bool p_enabled) {
1873
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1874
ERR_FAIL_NULL(joint);
1875
1876
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_SLIDER);
1877
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1878
1879
return slider_joint->set_jolt_flag(p_flag, p_enabled);
1880
}
1881
1882
float JoltPhysicsServer3D::slider_joint_get_applied_force(RID p_joint) {
1883
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1884
ERR_FAIL_NULL_V(joint, 0.0f);
1885
1886
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0f);
1887
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1888
1889
return slider_joint->get_applied_force();
1890
}
1891
1892
float JoltPhysicsServer3D::slider_joint_get_applied_torque(RID p_joint) {
1893
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1894
ERR_FAIL_NULL_V(joint, 0.0f);
1895
1896
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0f);
1897
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1898
1899
return slider_joint->get_applied_torque();
1900
}
1901
1902
double JoltPhysicsServer3D::cone_twist_joint_get_jolt_param(RID p_joint, ConeTwistJointParamJolt p_param) const {
1903
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1904
ERR_FAIL_NULL_V(joint, 0.0);
1905
1906
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0);
1907
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1908
1909
return cone_twist_joint->get_jolt_param(p_param);
1910
}
1911
1912
void JoltPhysicsServer3D::cone_twist_joint_set_jolt_param(RID p_joint, ConeTwistJointParamJolt p_param, double p_value) {
1913
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1914
ERR_FAIL_NULL(joint);
1915
1916
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_CONE_TWIST);
1917
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1918
1919
return cone_twist_joint->set_jolt_param(p_param, p_value);
1920
}
1921
1922
bool JoltPhysicsServer3D::cone_twist_joint_get_jolt_flag(RID p_joint, ConeTwistJointFlagJolt p_flag) const {
1923
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1924
ERR_FAIL_NULL_V(joint, false);
1925
1926
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, false);
1927
const JoltConeTwistJoint3D *cone_twist_joint = static_cast<const JoltConeTwistJoint3D *>(joint);
1928
1929
return cone_twist_joint->get_jolt_flag(p_flag);
1930
}
1931
1932
void JoltPhysicsServer3D::cone_twist_joint_set_jolt_flag(RID p_joint, ConeTwistJointFlagJolt p_flag, bool p_enabled) {
1933
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1934
ERR_FAIL_NULL(joint);
1935
1936
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_CONE_TWIST);
1937
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1938
1939
return cone_twist_joint->set_jolt_flag(p_flag, p_enabled);
1940
}
1941
1942
float JoltPhysicsServer3D::cone_twist_joint_get_applied_force(RID p_joint) {
1943
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1944
ERR_FAIL_NULL_V(joint, 0.0f);
1945
1946
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0f);
1947
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1948
1949
return cone_twist_joint->get_applied_force();
1950
}
1951
1952
float JoltPhysicsServer3D::cone_twist_joint_get_applied_torque(RID p_joint) {
1953
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1954
ERR_FAIL_NULL_V(joint, 0.0f);
1955
1956
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0f);
1957
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1958
1959
return cone_twist_joint->get_applied_torque();
1960
}
1961
1962
double JoltPhysicsServer3D::generic_6dof_joint_get_jolt_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParamJolt p_param) const {
1963
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1964
ERR_FAIL_NULL_V(joint, 0.0);
1965
1966
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0);
1967
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
1968
1969
return g6dof_joint->get_jolt_param(p_axis, p_param);
1970
}
1971
1972
void JoltPhysicsServer3D::generic_6dof_joint_set_jolt_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParamJolt p_param, double p_value) {
1973
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1974
ERR_FAIL_NULL(joint);
1975
1976
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);
1977
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
1978
1979
return g6dof_joint->set_jolt_param(p_axis, p_param, p_value);
1980
}
1981
1982
bool JoltPhysicsServer3D::generic_6dof_joint_get_jolt_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlagJolt p_flag) const {
1983
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1984
ERR_FAIL_NULL_V(joint, false);
1985
1986
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, false);
1987
const JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<const JoltGeneric6DOFJoint3D *>(joint);
1988
1989
return g6dof_joint->get_jolt_flag(p_axis, p_flag);
1990
}
1991
1992
void JoltPhysicsServer3D::generic_6dof_joint_set_jolt_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlagJolt p_flag, bool p_enabled) {
1993
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1994
ERR_FAIL_NULL(joint);
1995
1996
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);
1997
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
1998
1999
return g6dof_joint->set_jolt_flag(p_axis, p_flag, p_enabled);
2000
}
2001
2002
float JoltPhysicsServer3D::generic_6dof_joint_get_applied_force(RID p_joint) {
2003
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
2004
ERR_FAIL_NULL_V(joint, 0.0f);
2005
2006
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0f);
2007
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
2008
2009
return g6dof_joint->get_applied_force();
2010
}
2011
2012
float JoltPhysicsServer3D::generic_6dof_joint_get_applied_torque(RID p_joint) {
2013
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
2014
ERR_FAIL_NULL_V(joint, 0.0f);
2015
2016
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0f);
2017
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
2018
2019
return g6dof_joint->get_applied_torque();
2020
}
2021
2022