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
10277 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_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, PhysicsServer3DRenderingServerHandler *p_rendering_server_handler) {
989
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
990
ERR_FAIL_NULL(body);
991
992
return body->update_rendering_server(p_rendering_server_handler);
993
}
994
995
void JoltPhysicsServer3D::soft_body_set_space(RID p_body, RID p_space) {
996
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
997
ERR_FAIL_NULL(body);
998
999
JoltSpace3D *space = nullptr;
1000
1001
if (p_space.is_valid()) {
1002
space = space_owner.get_or_null(p_space);
1003
ERR_FAIL_NULL(space);
1004
}
1005
1006
body->set_space(space);
1007
}
1008
1009
RID JoltPhysicsServer3D::soft_body_get_space(RID p_body) const {
1010
const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1011
ERR_FAIL_NULL_V(body, RID());
1012
1013
const JoltSpace3D *space = body->get_space();
1014
1015
if (space == nullptr) {
1016
return RID();
1017
}
1018
1019
return space->get_rid();
1020
}
1021
1022
void JoltPhysicsServer3D::soft_body_set_mesh(RID p_body, RID p_mesh) {
1023
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1024
ERR_FAIL_NULL(body);
1025
1026
body->set_mesh(p_mesh);
1027
}
1028
1029
AABB JoltPhysicsServer3D::soft_body_get_bounds(RID p_body) const {
1030
const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1031
ERR_FAIL_NULL_V(body, AABB());
1032
1033
return body->get_bounds();
1034
}
1035
1036
void JoltPhysicsServer3D::soft_body_set_collision_layer(RID p_body, uint32_t p_layer) {
1037
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1038
ERR_FAIL_NULL(body);
1039
1040
body->set_collision_layer(p_layer);
1041
}
1042
1043
uint32_t JoltPhysicsServer3D::soft_body_get_collision_layer(RID p_body) const {
1044
const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1045
ERR_FAIL_NULL_V(body, 0);
1046
1047
return body->get_collision_layer();
1048
}
1049
1050
void JoltPhysicsServer3D::soft_body_set_collision_mask(RID p_body, uint32_t p_mask) {
1051
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1052
ERR_FAIL_NULL(body);
1053
1054
body->set_collision_mask(p_mask);
1055
}
1056
1057
uint32_t JoltPhysicsServer3D::soft_body_get_collision_mask(RID p_body) const {
1058
const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1059
ERR_FAIL_NULL_V(body, 0);
1060
1061
return body->get_collision_mask();
1062
}
1063
1064
void JoltPhysicsServer3D::soft_body_add_collision_exception(RID p_body, RID p_excepted_body) {
1065
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1066
ERR_FAIL_NULL(body);
1067
1068
body->add_collision_exception(p_excepted_body);
1069
}
1070
1071
void JoltPhysicsServer3D::soft_body_remove_collision_exception(RID p_body, RID p_excepted_body) {
1072
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1073
ERR_FAIL_NULL(body);
1074
1075
body->remove_collision_exception(p_excepted_body);
1076
}
1077
1078
void JoltPhysicsServer3D::soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
1079
const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1080
ERR_FAIL_NULL(body);
1081
1082
for (const RID &exception : body->get_collision_exceptions()) {
1083
p_exceptions->push_back(exception);
1084
}
1085
}
1086
1087
void JoltPhysicsServer3D::soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_value) {
1088
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1089
ERR_FAIL_NULL(body);
1090
1091
body->set_state(p_state, p_value);
1092
}
1093
1094
Variant JoltPhysicsServer3D::soft_body_get_state(RID p_body, BodyState p_state) const {
1095
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1096
ERR_FAIL_NULL_V(body, Variant());
1097
1098
return body->get_state(p_state);
1099
}
1100
1101
void JoltPhysicsServer3D::soft_body_set_transform(RID p_body, const Transform3D &p_transform) {
1102
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1103
ERR_FAIL_NULL(body);
1104
1105
return body->set_transform(p_transform);
1106
}
1107
1108
void JoltPhysicsServer3D::soft_body_set_ray_pickable(RID p_body, bool p_enable) {
1109
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1110
ERR_FAIL_NULL(body);
1111
1112
return body->set_pickable(p_enable);
1113
}
1114
1115
void JoltPhysicsServer3D::soft_body_set_simulation_precision(RID p_body, int p_precision) {
1116
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1117
ERR_FAIL_NULL(body);
1118
1119
return body->set_simulation_precision(p_precision);
1120
}
1121
1122
int JoltPhysicsServer3D::soft_body_get_simulation_precision(RID p_body) const {
1123
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1124
ERR_FAIL_NULL_V(body, 0);
1125
1126
return body->get_simulation_precision();
1127
}
1128
1129
void JoltPhysicsServer3D::soft_body_set_total_mass(RID p_body, real_t p_total_mass) {
1130
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1131
ERR_FAIL_NULL(body);
1132
1133
return body->set_mass((float)p_total_mass);
1134
}
1135
1136
real_t JoltPhysicsServer3D::soft_body_get_total_mass(RID p_body) const {
1137
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1138
ERR_FAIL_NULL_V(body, 0.0);
1139
1140
return (real_t)body->get_mass();
1141
}
1142
1143
void JoltPhysicsServer3D::soft_body_set_linear_stiffness(RID p_body, real_t p_coefficient) {
1144
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1145
ERR_FAIL_NULL(body);
1146
1147
return body->set_stiffness_coefficient((float)p_coefficient);
1148
}
1149
1150
real_t JoltPhysicsServer3D::soft_body_get_linear_stiffness(RID p_body) const {
1151
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1152
ERR_FAIL_NULL_V(body, 0.0);
1153
1154
return (real_t)body->get_stiffness_coefficient();
1155
}
1156
1157
void JoltPhysicsServer3D::soft_body_set_shrinking_factor(RID p_body, real_t p_shrinking_factor) {
1158
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1159
ERR_FAIL_NULL(body);
1160
1161
return body->set_shrinking_factor((float)p_shrinking_factor);
1162
}
1163
1164
real_t JoltPhysicsServer3D::soft_body_get_shrinking_factor(RID p_body) const {
1165
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1166
ERR_FAIL_NULL_V(body, 0.0);
1167
1168
return (real_t)body->get_shrinking_factor();
1169
}
1170
1171
void JoltPhysicsServer3D::soft_body_set_pressure_coefficient(RID p_body, real_t p_coefficient) {
1172
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1173
ERR_FAIL_NULL(body);
1174
1175
return body->set_pressure((float)p_coefficient);
1176
}
1177
1178
real_t JoltPhysicsServer3D::soft_body_get_pressure_coefficient(RID p_body) const {
1179
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1180
ERR_FAIL_NULL_V(body, 0.0);
1181
1182
return (real_t)body->get_pressure();
1183
}
1184
1185
void JoltPhysicsServer3D::soft_body_set_damping_coefficient(RID p_body, real_t p_coefficient) {
1186
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1187
ERR_FAIL_NULL(body);
1188
1189
return body->set_linear_damping((float)p_coefficient);
1190
}
1191
1192
real_t JoltPhysicsServer3D::soft_body_get_damping_coefficient(RID p_body) const {
1193
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1194
ERR_FAIL_NULL_V(body, 0.0);
1195
1196
return (real_t)body->get_linear_damping();
1197
}
1198
1199
void JoltPhysicsServer3D::soft_body_set_drag_coefficient(RID p_body, real_t p_coefficient) {
1200
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1201
ERR_FAIL_NULL(body);
1202
1203
return body->set_drag((float)p_coefficient);
1204
}
1205
1206
real_t JoltPhysicsServer3D::soft_body_get_drag_coefficient(RID p_body) const {
1207
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1208
ERR_FAIL_NULL_V(body, 0.0);
1209
1210
return (real_t)body->get_drag();
1211
}
1212
1213
void JoltPhysicsServer3D::soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) {
1214
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1215
ERR_FAIL_NULL(body);
1216
1217
body->set_vertex_position(p_point_index, p_global_position);
1218
}
1219
1220
Vector3 JoltPhysicsServer3D::soft_body_get_point_global_position(RID p_body, int p_point_index) const {
1221
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1222
ERR_FAIL_NULL_V(body, Vector3());
1223
1224
return body->get_vertex_position(p_point_index);
1225
}
1226
1227
void JoltPhysicsServer3D::soft_body_remove_all_pinned_points(RID p_body) {
1228
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1229
ERR_FAIL_NULL(body);
1230
1231
body->unpin_all_vertices();
1232
}
1233
1234
void JoltPhysicsServer3D::soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) {
1235
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1236
ERR_FAIL_NULL(body);
1237
1238
if (p_pin) {
1239
body->pin_vertex(p_point_index);
1240
} else {
1241
body->unpin_vertex(p_point_index);
1242
}
1243
}
1244
1245
bool JoltPhysicsServer3D::soft_body_is_point_pinned(RID p_body, int p_point_index) const {
1246
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1247
ERR_FAIL_NULL_V(body, false);
1248
1249
return body->is_vertex_pinned(p_point_index);
1250
}
1251
1252
RID JoltPhysicsServer3D::joint_create() {
1253
JoltJoint3D *joint = memnew(JoltJoint3D);
1254
RID rid = joint_owner.make_rid(joint);
1255
joint->set_rid(rid);
1256
return rid;
1257
}
1258
1259
void JoltPhysicsServer3D::joint_clear(RID p_joint) {
1260
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1261
ERR_FAIL_NULL(joint);
1262
1263
if (joint->get_type() != JOINT_TYPE_MAX) {
1264
JoltJoint3D *empty_joint = memnew(JoltJoint3D);
1265
empty_joint->set_rid(joint->get_rid());
1266
1267
memdelete(joint);
1268
joint = nullptr;
1269
1270
joint_owner.replace(p_joint, empty_joint);
1271
}
1272
}
1273
1274
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) {
1275
JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);
1276
ERR_FAIL_NULL(old_joint);
1277
1278
JoltBody3D *body_a = body_owner.get_or_null(p_body_a);
1279
ERR_FAIL_NULL(body_a);
1280
1281
JoltBody3D *body_b = body_owner.get_or_null(p_body_b);
1282
ERR_FAIL_COND(body_a == body_b);
1283
1284
JoltJoint3D *new_joint = memnew(JoltPinJoint3D(*old_joint, body_a, body_b, p_local_a, p_local_b));
1285
1286
memdelete(old_joint);
1287
old_joint = nullptr;
1288
1289
joint_owner.replace(p_joint, new_joint);
1290
}
1291
1292
void JoltPhysicsServer3D::pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) {
1293
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1294
ERR_FAIL_NULL(joint);
1295
1296
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_PIN);
1297
JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);
1298
1299
pin_joint->set_param(p_param, (double)p_value);
1300
}
1301
1302
real_t JoltPhysicsServer3D::pin_joint_get_param(RID p_joint, PinJointParam p_param) const {
1303
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1304
ERR_FAIL_NULL_V(joint, 0.0);
1305
1306
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, 0.0);
1307
const JoltPinJoint3D *pin_joint = static_cast<const JoltPinJoint3D *>(joint);
1308
1309
return (real_t)pin_joint->get_param(p_param);
1310
}
1311
1312
void JoltPhysicsServer3D::pin_joint_set_local_a(RID p_joint, const Vector3 &p_local_a) {
1313
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1314
ERR_FAIL_NULL(joint);
1315
1316
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_PIN);
1317
JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);
1318
1319
pin_joint->set_local_a(p_local_a);
1320
}
1321
1322
Vector3 JoltPhysicsServer3D::pin_joint_get_local_a(RID p_joint) const {
1323
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1324
ERR_FAIL_NULL_V(joint, Vector3());
1325
1326
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, Vector3());
1327
const JoltPinJoint3D *pin_joint = static_cast<const JoltPinJoint3D *>(joint);
1328
1329
return pin_joint->get_local_a();
1330
}
1331
1332
void JoltPhysicsServer3D::pin_joint_set_local_b(RID p_joint, const Vector3 &p_local_b) {
1333
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1334
ERR_FAIL_NULL(joint);
1335
1336
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_PIN);
1337
JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);
1338
1339
pin_joint->set_local_b(p_local_b);
1340
}
1341
1342
Vector3 JoltPhysicsServer3D::pin_joint_get_local_b(RID p_joint) const {
1343
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1344
ERR_FAIL_NULL_V(joint, Vector3());
1345
1346
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, Vector3());
1347
const JoltPinJoint3D *pin_joint = static_cast<const JoltPinJoint3D *>(joint);
1348
1349
return pin_joint->get_local_b();
1350
}
1351
1352
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) {
1353
JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);
1354
ERR_FAIL_NULL(old_joint);
1355
1356
JoltBody3D *body_a = body_owner.get_or_null(p_body_a);
1357
ERR_FAIL_NULL(body_a);
1358
1359
JoltBody3D *body_b = body_owner.get_or_null(p_body_b);
1360
ERR_FAIL_COND(body_a == body_b);
1361
1362
JoltJoint3D *new_joint = memnew(JoltHingeJoint3D(*old_joint, body_a, body_b, p_hinge_a, p_hinge_b));
1363
1364
memdelete(old_joint);
1365
old_joint = nullptr;
1366
1367
joint_owner.replace(p_joint, new_joint);
1368
}
1369
1370
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) {
1371
ERR_FAIL_MSG("Simple hinge joints are not supported when using Jolt Physics.");
1372
}
1373
1374
void JoltPhysicsServer3D::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, real_t p_value) {
1375
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1376
ERR_FAIL_NULL(joint);
1377
1378
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);
1379
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1380
1381
return hinge_joint->set_param(p_param, (double)p_value);
1382
}
1383
1384
real_t JoltPhysicsServer3D::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const {
1385
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1386
ERR_FAIL_NULL_V(joint, 0.0);
1387
1388
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0);
1389
const JoltHingeJoint3D *hinge_joint = static_cast<const JoltHingeJoint3D *>(joint);
1390
1391
return (real_t)hinge_joint->get_param(p_param);
1392
}
1393
1394
void JoltPhysicsServer3D::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_enabled) {
1395
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1396
ERR_FAIL_NULL(joint);
1397
1398
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);
1399
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1400
1401
return hinge_joint->set_flag(p_flag, p_enabled);
1402
}
1403
1404
bool JoltPhysicsServer3D::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const {
1405
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1406
ERR_FAIL_NULL_V(joint, false);
1407
1408
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, false);
1409
const JoltHingeJoint3D *hinge_joint = static_cast<const JoltHingeJoint3D *>(joint);
1410
1411
return hinge_joint->get_flag(p_flag);
1412
}
1413
1414
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) {
1415
JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);
1416
ERR_FAIL_NULL(old_joint);
1417
1418
JoltBody3D *body_a = body_owner.get_or_null(p_body_a);
1419
ERR_FAIL_NULL(body_a);
1420
1421
JoltBody3D *body_b = body_owner.get_or_null(p_body_b);
1422
ERR_FAIL_COND(body_a == body_b);
1423
1424
JoltJoint3D *new_joint = memnew(JoltSliderJoint3D(*old_joint, body_a, body_b, p_local_ref_a, p_local_ref_b));
1425
1426
memdelete(old_joint);
1427
old_joint = nullptr;
1428
1429
joint_owner.replace(p_joint, new_joint);
1430
}
1431
1432
void JoltPhysicsServer3D::slider_joint_set_param(RID p_joint, SliderJointParam p_param, real_t p_value) {
1433
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1434
ERR_FAIL_NULL(joint);
1435
1436
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_SLIDER);
1437
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1438
1439
return slider_joint->set_param(p_param, (real_t)p_value);
1440
}
1441
1442
real_t JoltPhysicsServer3D::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const {
1443
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1444
ERR_FAIL_NULL_V(joint, 0.0);
1445
1446
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0);
1447
const JoltSliderJoint3D *slider_joint = static_cast<const JoltSliderJoint3D *>(joint);
1448
1449
return slider_joint->get_param(p_param);
1450
}
1451
1452
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) {
1453
JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);
1454
ERR_FAIL_NULL(old_joint);
1455
1456
JoltBody3D *body_a = body_owner.get_or_null(p_body_a);
1457
ERR_FAIL_NULL(body_a);
1458
1459
JoltBody3D *body_b = body_owner.get_or_null(p_body_b);
1460
ERR_FAIL_COND(body_a == body_b);
1461
1462
JoltJoint3D *new_joint = memnew(JoltConeTwistJoint3D(*old_joint, body_a, body_b, p_local_ref_a, p_local_ref_b));
1463
1464
memdelete(old_joint);
1465
old_joint = nullptr;
1466
1467
joint_owner.replace(p_joint, new_joint);
1468
}
1469
1470
void JoltPhysicsServer3D::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, real_t p_value) {
1471
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1472
ERR_FAIL_NULL(joint);
1473
1474
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_CONE_TWIST);
1475
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1476
1477
return cone_twist_joint->set_param(p_param, (double)p_value);
1478
}
1479
1480
real_t JoltPhysicsServer3D::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const {
1481
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1482
ERR_FAIL_NULL_V(joint, 0.0);
1483
1484
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0);
1485
const JoltConeTwistJoint3D *cone_twist_joint = static_cast<const JoltConeTwistJoint3D *>(joint);
1486
1487
return (real_t)cone_twist_joint->get_param(p_param);
1488
}
1489
1490
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) {
1491
JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);
1492
ERR_FAIL_NULL(old_joint);
1493
1494
JoltBody3D *body_a = body_owner.get_or_null(p_body_a);
1495
ERR_FAIL_NULL(body_a);
1496
1497
JoltBody3D *body_b = body_owner.get_or_null(p_body_b);
1498
ERR_FAIL_COND(body_a == body_b);
1499
1500
JoltJoint3D *new_joint = memnew(JoltGeneric6DOFJoint3D(*old_joint, body_a, body_b, p_local_ref_a, p_local_ref_b));
1501
1502
memdelete(old_joint);
1503
old_joint = nullptr;
1504
1505
joint_owner.replace(p_joint, new_joint);
1506
}
1507
1508
void JoltPhysicsServer3D::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param, real_t p_value) {
1509
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1510
ERR_FAIL_NULL(joint);
1511
1512
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);
1513
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
1514
1515
return g6dof_joint->set_param(p_axis, p_param, (double)p_value);
1516
}
1517
1518
real_t JoltPhysicsServer3D::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param) const {
1519
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1520
ERR_FAIL_NULL_V(joint, 0.0);
1521
1522
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0);
1523
const JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<const JoltGeneric6DOFJoint3D *>(joint);
1524
1525
return (real_t)g6dof_joint->get_param(p_axis, p_param);
1526
}
1527
1528
void JoltPhysicsServer3D::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag, bool p_enable) {
1529
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1530
ERR_FAIL_NULL(joint);
1531
1532
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);
1533
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
1534
1535
return g6dof_joint->set_flag(p_axis, p_flag, p_enable);
1536
}
1537
1538
bool JoltPhysicsServer3D::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag) const {
1539
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1540
ERR_FAIL_NULL_V(joint, false);
1541
1542
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, false);
1543
const JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<const JoltGeneric6DOFJoint3D *>(joint);
1544
1545
return g6dof_joint->get_flag(p_axis, p_flag);
1546
}
1547
1548
PhysicsServer3D::JointType JoltPhysicsServer3D::joint_get_type(RID p_joint) const {
1549
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1550
ERR_FAIL_NULL_V(joint, JOINT_TYPE_PIN);
1551
1552
return joint->get_type();
1553
}
1554
1555
void JoltPhysicsServer3D::joint_set_solver_priority(RID p_joint, int p_priority) {
1556
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1557
ERR_FAIL_NULL(joint);
1558
1559
joint->set_solver_priority(p_priority);
1560
}
1561
1562
int JoltPhysicsServer3D::joint_get_solver_priority(RID p_joint) const {
1563
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1564
ERR_FAIL_NULL_V(joint, 0);
1565
1566
return joint->get_solver_priority();
1567
}
1568
1569
void JoltPhysicsServer3D::joint_disable_collisions_between_bodies(RID p_joint, bool p_disable) {
1570
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1571
ERR_FAIL_NULL(joint);
1572
1573
joint->set_collision_disabled(p_disable);
1574
}
1575
1576
bool JoltPhysicsServer3D::joint_is_disabled_collisions_between_bodies(RID p_joint) const {
1577
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1578
ERR_FAIL_NULL_V(joint, false);
1579
1580
return joint->is_collision_disabled();
1581
}
1582
1583
void JoltPhysicsServer3D::free(RID p_rid) {
1584
if (JoltShape3D *shape = shape_owner.get_or_null(p_rid)) {
1585
free_shape(shape);
1586
} else if (JoltBody3D *body = body_owner.get_or_null(p_rid)) {
1587
free_body(body);
1588
} else if (JoltJoint3D *joint = joint_owner.get_or_null(p_rid)) {
1589
free_joint(joint);
1590
} else if (JoltArea3D *area = area_owner.get_or_null(p_rid)) {
1591
free_area(area);
1592
} else if (JoltSoftBody3D *soft_body = soft_body_owner.get_or_null(p_rid)) {
1593
free_soft_body(soft_body);
1594
} else if (JoltSpace3D *space = space_owner.get_or_null(p_rid)) {
1595
free_space(space);
1596
} else {
1597
ERR_FAIL_MSG("Failed to free RID: The specified RID has no owner.");
1598
}
1599
}
1600
1601
void JoltPhysicsServer3D::set_active(bool p_active) {
1602
active = p_active;
1603
}
1604
1605
void JoltPhysicsServer3D::init() {
1606
job_system = new JoltJobSystem();
1607
}
1608
1609
void JoltPhysicsServer3D::finish() {
1610
if (job_system != nullptr) {
1611
delete job_system;
1612
job_system = nullptr;
1613
}
1614
}
1615
1616
void JoltPhysicsServer3D::step(real_t p_step) {
1617
if (!active) {
1618
return;
1619
}
1620
1621
for (JoltSpace3D *active_space : active_spaces) {
1622
job_system->pre_step();
1623
1624
active_space->step((float)p_step);
1625
1626
job_system->post_step();
1627
}
1628
}
1629
1630
void JoltPhysicsServer3D::sync() {
1631
doing_sync = true;
1632
}
1633
1634
void JoltPhysicsServer3D::end_sync() {
1635
doing_sync = false;
1636
}
1637
1638
void JoltPhysicsServer3D::flush_queries() {
1639
if (!active) {
1640
return;
1641
}
1642
1643
flushing_queries = true;
1644
1645
for (JoltSpace3D *space : active_spaces) {
1646
space->call_queries();
1647
}
1648
1649
flushing_queries = false;
1650
1651
#ifdef DEBUG_ENABLED
1652
job_system->flush_timings();
1653
#endif
1654
}
1655
1656
bool JoltPhysicsServer3D::is_flushing_queries() const {
1657
return flushing_queries;
1658
}
1659
1660
int JoltPhysicsServer3D::get_process_info(ProcessInfo p_process_info) {
1661
return 0;
1662
}
1663
1664
void JoltPhysicsServer3D::free_space(JoltSpace3D *p_space) {
1665
ERR_FAIL_NULL(p_space);
1666
1667
free_area(p_space->get_default_area());
1668
space_set_active(p_space->get_rid(), false);
1669
space_owner.free(p_space->get_rid());
1670
memdelete(p_space);
1671
}
1672
1673
void JoltPhysicsServer3D::free_area(JoltArea3D *p_area) {
1674
ERR_FAIL_NULL(p_area);
1675
1676
p_area->set_space(nullptr);
1677
area_owner.free(p_area->get_rid());
1678
memdelete(p_area);
1679
}
1680
1681
void JoltPhysicsServer3D::free_body(JoltBody3D *p_body) {
1682
ERR_FAIL_NULL(p_body);
1683
1684
p_body->set_space(nullptr);
1685
body_owner.free(p_body->get_rid());
1686
memdelete(p_body);
1687
}
1688
1689
void JoltPhysicsServer3D::free_soft_body(JoltSoftBody3D *p_body) {
1690
ERR_FAIL_NULL(p_body);
1691
1692
p_body->set_space(nullptr);
1693
soft_body_owner.free(p_body->get_rid());
1694
memdelete(p_body);
1695
}
1696
1697
void JoltPhysicsServer3D::free_shape(JoltShape3D *p_shape) {
1698
ERR_FAIL_NULL(p_shape);
1699
1700
p_shape->remove_self();
1701
shape_owner.free(p_shape->get_rid());
1702
memdelete(p_shape);
1703
}
1704
1705
void JoltPhysicsServer3D::free_joint(JoltJoint3D *p_joint) {
1706
ERR_FAIL_NULL(p_joint);
1707
1708
joint_owner.free(p_joint->get_rid());
1709
memdelete(p_joint);
1710
}
1711
1712
#ifdef DEBUG_ENABLED
1713
1714
void JoltPhysicsServer3D::dump_debug_snapshots(const String &p_dir) {
1715
for (JoltSpace3D *space : active_spaces) {
1716
space->dump_debug_snapshot(p_dir);
1717
}
1718
}
1719
1720
void JoltPhysicsServer3D::space_dump_debug_snapshot(RID p_space, const String &p_dir) {
1721
JoltSpace3D *space = space_owner.get_or_null(p_space);
1722
ERR_FAIL_NULL(space);
1723
1724
space->dump_debug_snapshot(p_dir);
1725
}
1726
1727
#endif
1728
1729
bool JoltPhysicsServer3D::joint_get_enabled(RID p_joint) const {
1730
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1731
ERR_FAIL_NULL_V(joint, false);
1732
1733
return joint->is_enabled();
1734
}
1735
1736
void JoltPhysicsServer3D::joint_set_enabled(RID p_joint, bool p_enabled) {
1737
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1738
ERR_FAIL_NULL(joint);
1739
1740
joint->set_enabled(p_enabled);
1741
}
1742
1743
int JoltPhysicsServer3D::joint_get_solver_velocity_iterations(RID p_joint) {
1744
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1745
ERR_FAIL_NULL_V(joint, 0);
1746
1747
return joint->get_solver_velocity_iterations();
1748
}
1749
1750
void JoltPhysicsServer3D::joint_set_solver_velocity_iterations(RID p_joint, int p_value) {
1751
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1752
ERR_FAIL_NULL(joint);
1753
1754
return joint->set_solver_velocity_iterations(p_value);
1755
}
1756
1757
int JoltPhysicsServer3D::joint_get_solver_position_iterations(RID p_joint) {
1758
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1759
ERR_FAIL_NULL_V(joint, 0);
1760
1761
return joint->get_solver_position_iterations();
1762
}
1763
1764
void JoltPhysicsServer3D::joint_set_solver_position_iterations(RID p_joint, int p_value) {
1765
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1766
ERR_FAIL_NULL(joint);
1767
1768
return joint->set_solver_position_iterations(p_value);
1769
}
1770
1771
float JoltPhysicsServer3D::pin_joint_get_applied_force(RID p_joint) {
1772
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1773
ERR_FAIL_NULL_V(joint, 0.0f);
1774
1775
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, 0.0);
1776
JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);
1777
1778
return pin_joint->get_applied_force();
1779
}
1780
1781
double JoltPhysicsServer3D::hinge_joint_get_jolt_param(RID p_joint, HingeJointParamJolt p_param) const {
1782
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1783
ERR_FAIL_NULL_V(joint, 0.0);
1784
1785
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0);
1786
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1787
1788
return hinge_joint->get_jolt_param(p_param);
1789
}
1790
1791
void JoltPhysicsServer3D::hinge_joint_set_jolt_param(RID p_joint, HingeJointParamJolt p_param, double p_value) {
1792
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1793
ERR_FAIL_NULL(joint);
1794
1795
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);
1796
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1797
1798
return hinge_joint->set_jolt_param(p_param, p_value);
1799
}
1800
1801
bool JoltPhysicsServer3D::hinge_joint_get_jolt_flag(RID p_joint, HingeJointFlagJolt p_flag) const {
1802
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1803
ERR_FAIL_NULL_V(joint, false);
1804
1805
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, false);
1806
const JoltHingeJoint3D *hinge_joint = static_cast<const JoltHingeJoint3D *>(joint);
1807
1808
return hinge_joint->get_jolt_flag(p_flag);
1809
}
1810
1811
void JoltPhysicsServer3D::hinge_joint_set_jolt_flag(RID p_joint, HingeJointFlagJolt p_flag, bool p_enabled) {
1812
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1813
ERR_FAIL_NULL(joint);
1814
1815
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);
1816
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1817
1818
return hinge_joint->set_jolt_flag(p_flag, p_enabled);
1819
}
1820
1821
float JoltPhysicsServer3D::hinge_joint_get_applied_force(RID p_joint) {
1822
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1823
ERR_FAIL_NULL_V(joint, 0.0f);
1824
1825
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0f);
1826
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1827
1828
return hinge_joint->get_applied_force();
1829
}
1830
1831
float JoltPhysicsServer3D::hinge_joint_get_applied_torque(RID p_joint) {
1832
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1833
ERR_FAIL_NULL_V(joint, 0.0f);
1834
1835
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0f);
1836
JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);
1837
1838
return hinge_joint->get_applied_torque();
1839
}
1840
1841
double JoltPhysicsServer3D::slider_joint_get_jolt_param(RID p_joint, SliderJointParamJolt p_param) const {
1842
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1843
ERR_FAIL_NULL_V(joint, 0.0);
1844
1845
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0);
1846
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1847
1848
return slider_joint->get_jolt_param(p_param);
1849
}
1850
1851
void JoltPhysicsServer3D::slider_joint_set_jolt_param(RID p_joint, SliderJointParamJolt p_param, double p_value) {
1852
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1853
ERR_FAIL_NULL(joint);
1854
1855
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_SLIDER);
1856
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1857
1858
return slider_joint->set_jolt_param(p_param, p_value);
1859
}
1860
1861
bool JoltPhysicsServer3D::slider_joint_get_jolt_flag(RID p_joint, SliderJointFlagJolt p_flag) const {
1862
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1863
ERR_FAIL_NULL_V(joint, false);
1864
1865
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, false);
1866
const JoltSliderJoint3D *slider_joint = static_cast<const JoltSliderJoint3D *>(joint);
1867
1868
return slider_joint->get_jolt_flag(p_flag);
1869
}
1870
1871
void JoltPhysicsServer3D::slider_joint_set_jolt_flag(RID p_joint, SliderJointFlagJolt p_flag, bool p_enabled) {
1872
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1873
ERR_FAIL_NULL(joint);
1874
1875
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_SLIDER);
1876
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1877
1878
return slider_joint->set_jolt_flag(p_flag, p_enabled);
1879
}
1880
1881
float JoltPhysicsServer3D::slider_joint_get_applied_force(RID p_joint) {
1882
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1883
ERR_FAIL_NULL_V(joint, 0.0f);
1884
1885
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0f);
1886
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1887
1888
return slider_joint->get_applied_force();
1889
}
1890
1891
float JoltPhysicsServer3D::slider_joint_get_applied_torque(RID p_joint) {
1892
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1893
ERR_FAIL_NULL_V(joint, 0.0f);
1894
1895
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0f);
1896
JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);
1897
1898
return slider_joint->get_applied_torque();
1899
}
1900
1901
double JoltPhysicsServer3D::cone_twist_joint_get_jolt_param(RID p_joint, ConeTwistJointParamJolt p_param) const {
1902
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1903
ERR_FAIL_NULL_V(joint, 0.0);
1904
1905
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0);
1906
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1907
1908
return cone_twist_joint->get_jolt_param(p_param);
1909
}
1910
1911
void JoltPhysicsServer3D::cone_twist_joint_set_jolt_param(RID p_joint, ConeTwistJointParamJolt p_param, double p_value) {
1912
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1913
ERR_FAIL_NULL(joint);
1914
1915
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_CONE_TWIST);
1916
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1917
1918
return cone_twist_joint->set_jolt_param(p_param, p_value);
1919
}
1920
1921
bool JoltPhysicsServer3D::cone_twist_joint_get_jolt_flag(RID p_joint, ConeTwistJointFlagJolt p_flag) const {
1922
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1923
ERR_FAIL_NULL_V(joint, false);
1924
1925
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, false);
1926
const JoltConeTwistJoint3D *cone_twist_joint = static_cast<const JoltConeTwistJoint3D *>(joint);
1927
1928
return cone_twist_joint->get_jolt_flag(p_flag);
1929
}
1930
1931
void JoltPhysicsServer3D::cone_twist_joint_set_jolt_flag(RID p_joint, ConeTwistJointFlagJolt p_flag, bool p_enabled) {
1932
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1933
ERR_FAIL_NULL(joint);
1934
1935
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_CONE_TWIST);
1936
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1937
1938
return cone_twist_joint->set_jolt_flag(p_flag, p_enabled);
1939
}
1940
1941
float JoltPhysicsServer3D::cone_twist_joint_get_applied_force(RID p_joint) {
1942
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1943
ERR_FAIL_NULL_V(joint, 0.0f);
1944
1945
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0f);
1946
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1947
1948
return cone_twist_joint->get_applied_force();
1949
}
1950
1951
float JoltPhysicsServer3D::cone_twist_joint_get_applied_torque(RID p_joint) {
1952
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1953
ERR_FAIL_NULL_V(joint, 0.0f);
1954
1955
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0f);
1956
JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);
1957
1958
return cone_twist_joint->get_applied_torque();
1959
}
1960
1961
double JoltPhysicsServer3D::generic_6dof_joint_get_jolt_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParamJolt p_param) const {
1962
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1963
ERR_FAIL_NULL_V(joint, 0.0);
1964
1965
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0);
1966
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
1967
1968
return g6dof_joint->get_jolt_param(p_axis, p_param);
1969
}
1970
1971
void JoltPhysicsServer3D::generic_6dof_joint_set_jolt_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParamJolt p_param, double p_value) {
1972
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1973
ERR_FAIL_NULL(joint);
1974
1975
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);
1976
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
1977
1978
return g6dof_joint->set_jolt_param(p_axis, p_param, p_value);
1979
}
1980
1981
bool JoltPhysicsServer3D::generic_6dof_joint_get_jolt_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlagJolt p_flag) const {
1982
const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1983
ERR_FAIL_NULL_V(joint, false);
1984
1985
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, false);
1986
const JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<const JoltGeneric6DOFJoint3D *>(joint);
1987
1988
return g6dof_joint->get_jolt_flag(p_axis, p_flag);
1989
}
1990
1991
void JoltPhysicsServer3D::generic_6dof_joint_set_jolt_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlagJolt p_flag, bool p_enabled) {
1992
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
1993
ERR_FAIL_NULL(joint);
1994
1995
ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);
1996
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
1997
1998
return g6dof_joint->set_jolt_flag(p_axis, p_flag, p_enabled);
1999
}
2000
2001
float JoltPhysicsServer3D::generic_6dof_joint_get_applied_force(RID p_joint) {
2002
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
2003
ERR_FAIL_NULL_V(joint, 0.0f);
2004
2005
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0f);
2006
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
2007
2008
return g6dof_joint->get_applied_force();
2009
}
2010
2011
float JoltPhysicsServer3D::generic_6dof_joint_get_applied_torque(RID p_joint) {
2012
JoltJoint3D *joint = joint_owner.get_or_null(p_joint);
2013
ERR_FAIL_NULL_V(joint, 0.0f);
2014
2015
ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0f);
2016
JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);
2017
2018
return g6dof_joint->get_applied_torque();
2019
}
2020
2021