Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/physics_3d/physics_server_3d.cpp
11322 views
1
/**************************************************************************/
2
/* 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 "physics_server_3d.h"
32
33
#include "core/config/project_settings.h"
34
#include "core/variant/typed_array.h"
35
36
void PhysicsServer3DRenderingServerHandler::set_vertex(int p_vertex_id, const Vector3 &p_vertex) {
37
GDVIRTUAL_CALL(_set_vertex, p_vertex_id, p_vertex);
38
}
39
void PhysicsServer3DRenderingServerHandler::set_normal(int p_vertex_id, const Vector3 &p_normal) {
40
GDVIRTUAL_CALL(_set_normal, p_vertex_id, p_normal);
41
}
42
void PhysicsServer3DRenderingServerHandler::set_aabb(const AABB &p_aabb) {
43
GDVIRTUAL_CALL(_set_aabb, p_aabb);
44
}
45
46
void PhysicsServer3DRenderingServerHandler::_bind_methods() {
47
GDVIRTUAL_BIND(_set_vertex, "vertex_id", "vertex");
48
GDVIRTUAL_BIND(_set_normal, "vertex_id", "normal");
49
GDVIRTUAL_BIND(_set_aabb, "aabb");
50
51
ClassDB::bind_method(D_METHOD("set_vertex", "vertex_id", "vertex"), &PhysicsServer3DRenderingServerHandler::set_vertex);
52
ClassDB::bind_method(D_METHOD("set_normal", "vertex_id", "normal"), &PhysicsServer3DRenderingServerHandler::set_normal);
53
ClassDB::bind_method(D_METHOD("set_aabb", "aabb"), &PhysicsServer3DRenderingServerHandler::set_aabb);
54
}
55
56
PhysicsServer3D *PhysicsServer3D::singleton = nullptr;
57
58
void PhysicsDirectBodyState3D::integrate_forces() {
59
real_t step = get_step();
60
Vector3 lv = get_linear_velocity();
61
lv += get_total_gravity() * step;
62
63
Vector3 av = get_angular_velocity();
64
65
real_t linear_damp = 1.0 - step * get_total_linear_damp();
66
67
if (linear_damp < 0) { // reached zero in the given time
68
linear_damp = 0;
69
}
70
71
real_t angular_damp = 1.0 - step * get_total_angular_damp();
72
73
if (angular_damp < 0) { // reached zero in the given time
74
angular_damp = 0;
75
}
76
77
lv *= linear_damp;
78
av *= angular_damp;
79
80
set_linear_velocity(lv);
81
set_angular_velocity(av);
82
}
83
84
Object *PhysicsDirectBodyState3D::get_contact_collider_object(int p_contact_idx) const {
85
ObjectID objid = get_contact_collider_id(p_contact_idx);
86
Object *obj = ObjectDB::get_instance(objid);
87
return obj;
88
}
89
90
PhysicsServer3D *PhysicsServer3D::get_singleton() {
91
return singleton;
92
}
93
94
void PhysicsDirectBodyState3D::_bind_methods() {
95
ClassDB::bind_method(D_METHOD("get_total_gravity"), &PhysicsDirectBodyState3D::get_total_gravity);
96
ClassDB::bind_method(D_METHOD("get_total_linear_damp"), &PhysicsDirectBodyState3D::get_total_linear_damp);
97
ClassDB::bind_method(D_METHOD("get_total_angular_damp"), &PhysicsDirectBodyState3D::get_total_angular_damp);
98
99
ClassDB::bind_method(D_METHOD("get_center_of_mass"), &PhysicsDirectBodyState3D::get_center_of_mass);
100
ClassDB::bind_method(D_METHOD("get_center_of_mass_local"), &PhysicsDirectBodyState3D::get_center_of_mass_local);
101
ClassDB::bind_method(D_METHOD("get_principal_inertia_axes"), &PhysicsDirectBodyState3D::get_principal_inertia_axes);
102
103
ClassDB::bind_method(D_METHOD("get_inverse_mass"), &PhysicsDirectBodyState3D::get_inverse_mass);
104
ClassDB::bind_method(D_METHOD("get_inverse_inertia"), &PhysicsDirectBodyState3D::get_inverse_inertia);
105
ClassDB::bind_method(D_METHOD("get_inverse_inertia_tensor"), &PhysicsDirectBodyState3D::get_inverse_inertia_tensor);
106
107
ClassDB::bind_method(D_METHOD("set_linear_velocity", "velocity"), &PhysicsDirectBodyState3D::set_linear_velocity);
108
ClassDB::bind_method(D_METHOD("get_linear_velocity"), &PhysicsDirectBodyState3D::get_linear_velocity);
109
110
ClassDB::bind_method(D_METHOD("set_angular_velocity", "velocity"), &PhysicsDirectBodyState3D::set_angular_velocity);
111
ClassDB::bind_method(D_METHOD("get_angular_velocity"), &PhysicsDirectBodyState3D::get_angular_velocity);
112
113
ClassDB::bind_method(D_METHOD("set_transform", "transform"), &PhysicsDirectBodyState3D::set_transform);
114
ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsDirectBodyState3D::get_transform);
115
116
ClassDB::bind_method(D_METHOD("get_velocity_at_local_position", "local_position"), &PhysicsDirectBodyState3D::get_velocity_at_local_position);
117
118
ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &PhysicsDirectBodyState3D::apply_central_impulse, Vector3());
119
ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &PhysicsDirectBodyState3D::apply_impulse, Vector3());
120
ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &PhysicsDirectBodyState3D::apply_torque_impulse);
121
122
ClassDB::bind_method(D_METHOD("apply_central_force", "force"), &PhysicsDirectBodyState3D::apply_central_force, Vector3());
123
ClassDB::bind_method(D_METHOD("apply_force", "force", "position"), &PhysicsDirectBodyState3D::apply_force, Vector3());
124
ClassDB::bind_method(D_METHOD("apply_torque", "torque"), &PhysicsDirectBodyState3D::apply_torque);
125
126
ClassDB::bind_method(D_METHOD("add_constant_central_force", "force"), &PhysicsDirectBodyState3D::add_constant_central_force, Vector3());
127
ClassDB::bind_method(D_METHOD("add_constant_force", "force", "position"), &PhysicsDirectBodyState3D::add_constant_force, Vector3());
128
ClassDB::bind_method(D_METHOD("add_constant_torque", "torque"), &PhysicsDirectBodyState3D::add_constant_torque);
129
130
ClassDB::bind_method(D_METHOD("set_constant_force", "force"), &PhysicsDirectBodyState3D::set_constant_force);
131
ClassDB::bind_method(D_METHOD("get_constant_force"), &PhysicsDirectBodyState3D::get_constant_force);
132
133
ClassDB::bind_method(D_METHOD("set_constant_torque", "torque"), &PhysicsDirectBodyState3D::set_constant_torque);
134
ClassDB::bind_method(D_METHOD("get_constant_torque"), &PhysicsDirectBodyState3D::get_constant_torque);
135
136
ClassDB::bind_method(D_METHOD("set_sleep_state", "enabled"), &PhysicsDirectBodyState3D::set_sleep_state);
137
ClassDB::bind_method(D_METHOD("is_sleeping"), &PhysicsDirectBodyState3D::is_sleeping);
138
139
ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &PhysicsDirectBodyState3D::set_collision_layer);
140
ClassDB::bind_method(D_METHOD("get_collision_layer"), &PhysicsDirectBodyState3D::get_collision_layer);
141
142
ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &PhysicsDirectBodyState3D::set_collision_mask);
143
ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsDirectBodyState3D::get_collision_mask);
144
145
ClassDB::bind_method(D_METHOD("get_contact_count"), &PhysicsDirectBodyState3D::get_contact_count);
146
147
ClassDB::bind_method(D_METHOD("get_contact_local_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_position);
148
ClassDB::bind_method(D_METHOD("get_contact_local_normal", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_normal);
149
ClassDB::bind_method(D_METHOD("get_contact_impulse", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_impulse);
150
ClassDB::bind_method(D_METHOD("get_contact_local_shape", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_shape);
151
ClassDB::bind_method(D_METHOD("get_contact_local_velocity_at_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_velocity_at_position);
152
ClassDB::bind_method(D_METHOD("get_contact_collider", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider);
153
ClassDB::bind_method(D_METHOD("get_contact_collider_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_position);
154
ClassDB::bind_method(D_METHOD("get_contact_collider_id", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_id);
155
ClassDB::bind_method(D_METHOD("get_contact_collider_object", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_object);
156
ClassDB::bind_method(D_METHOD("get_contact_collider_shape", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_shape);
157
ClassDB::bind_method(D_METHOD("get_contact_collider_velocity_at_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_velocity_at_position);
158
ClassDB::bind_method(D_METHOD("get_step"), &PhysicsDirectBodyState3D::get_step);
159
ClassDB::bind_method(D_METHOD("integrate_forces"), &PhysicsDirectBodyState3D::integrate_forces);
160
ClassDB::bind_method(D_METHOD("get_space_state"), &PhysicsDirectBodyState3D::get_space_state);
161
162
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "step"), "", "get_step");
163
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inverse_mass"), "", "get_inverse_mass");
164
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "total_angular_damp"), "", "get_total_angular_damp");
165
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "total_linear_damp"), "", "get_total_linear_damp");
166
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "inverse_inertia"), "", "get_inverse_inertia");
167
ADD_PROPERTY(PropertyInfo(Variant::BASIS, "inverse_inertia_tensor"), "", "get_inverse_inertia_tensor");
168
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "total_gravity"), "", "get_total_gravity");
169
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_of_mass"), "", "get_center_of_mass");
170
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_of_mass_local"), "", "get_center_of_mass_local");
171
ADD_PROPERTY(PropertyInfo(Variant::BASIS, "principal_inertia_axes"), "", "get_principal_inertia_axes");
172
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "angular_velocity"), "set_angular_velocity", "get_angular_velocity");
173
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "linear_velocity"), "set_linear_velocity", "get_linear_velocity");
174
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sleeping"), "set_sleep_state", "is_sleeping");
175
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer"), "set_collision_layer", "get_collision_layer");
176
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask"), "set_collision_mask", "get_collision_mask");
177
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "transform"), "set_transform", "get_transform");
178
}
179
180
PhysicsDirectBodyState3D::PhysicsDirectBodyState3D() {}
181
182
///////////////////////////////////////////////////////
183
184
void PhysicsRayQueryParameters3D::set_exclude(const TypedArray<RID> &p_exclude) {
185
parameters.exclude.clear();
186
for (int i = 0; i < p_exclude.size(); i++) {
187
parameters.exclude.insert(p_exclude[i]);
188
}
189
}
190
191
TypedArray<RID> PhysicsRayQueryParameters3D::get_exclude() const {
192
TypedArray<RID> ret;
193
ret.resize(parameters.exclude.size());
194
int idx = 0;
195
for (const RID &E : parameters.exclude) {
196
ret[idx++] = E;
197
}
198
return ret;
199
}
200
201
void PhysicsRayQueryParameters3D::_bind_methods() {
202
ClassDB::bind_static_method("PhysicsRayQueryParameters3D", D_METHOD("create", "from", "to", "collision_mask", "exclude"), &PhysicsRayQueryParameters3D::create, DEFVAL(UINT32_MAX), DEFVAL(TypedArray<RID>()));
203
204
ClassDB::bind_method(D_METHOD("set_from", "from"), &PhysicsRayQueryParameters3D::set_from);
205
ClassDB::bind_method(D_METHOD("get_from"), &PhysicsRayQueryParameters3D::get_from);
206
207
ClassDB::bind_method(D_METHOD("set_to", "to"), &PhysicsRayQueryParameters3D::set_to);
208
ClassDB::bind_method(D_METHOD("get_to"), &PhysicsRayQueryParameters3D::get_to);
209
210
ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &PhysicsRayQueryParameters3D::set_collision_mask);
211
ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsRayQueryParameters3D::get_collision_mask);
212
213
ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &PhysicsRayQueryParameters3D::set_exclude);
214
ClassDB::bind_method(D_METHOD("get_exclude"), &PhysicsRayQueryParameters3D::get_exclude);
215
216
ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &PhysicsRayQueryParameters3D::set_collide_with_bodies);
217
ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &PhysicsRayQueryParameters3D::is_collide_with_bodies_enabled);
218
219
ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsRayQueryParameters3D::set_collide_with_areas);
220
ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsRayQueryParameters3D::is_collide_with_areas_enabled);
221
222
ClassDB::bind_method(D_METHOD("set_hit_from_inside", "enable"), &PhysicsRayQueryParameters3D::set_hit_from_inside);
223
ClassDB::bind_method(D_METHOD("is_hit_from_inside_enabled"), &PhysicsRayQueryParameters3D::is_hit_from_inside_enabled);
224
225
ClassDB::bind_method(D_METHOD("set_hit_back_faces", "enable"), &PhysicsRayQueryParameters3D::set_hit_back_faces);
226
ClassDB::bind_method(D_METHOD("is_hit_back_faces_enabled"), &PhysicsRayQueryParameters3D::is_hit_back_faces_enabled);
227
228
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "from"), "set_from", "get_from");
229
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "to"), "set_to", "get_to");
230
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
231
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude", "get_exclude");
232
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
233
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");
234
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hit_from_inside"), "set_hit_from_inside", "is_hit_from_inside_enabled");
235
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hit_back_faces"), "set_hit_back_faces", "is_hit_back_faces_enabled");
236
}
237
238
///////////////////////////////////////////////////////
239
240
Ref<PhysicsRayQueryParameters3D> PhysicsRayQueryParameters3D::create(Vector3 p_from, Vector3 p_to, uint32_t p_mask, const TypedArray<RID> &p_exclude) {
241
Ref<PhysicsRayQueryParameters3D> params;
242
params.instantiate();
243
params->set_from(p_from);
244
params->set_to(p_to);
245
params->set_collision_mask(p_mask);
246
params->set_exclude(p_exclude);
247
return params;
248
}
249
250
void PhysicsPointQueryParameters3D::set_exclude(const TypedArray<RID> &p_exclude) {
251
parameters.exclude.clear();
252
for (int i = 0; i < p_exclude.size(); i++) {
253
parameters.exclude.insert(p_exclude[i]);
254
}
255
}
256
257
TypedArray<RID> PhysicsPointQueryParameters3D::get_exclude() const {
258
TypedArray<RID> ret;
259
ret.resize(parameters.exclude.size());
260
int idx = 0;
261
for (const RID &E : parameters.exclude) {
262
ret[idx++] = E;
263
}
264
return ret;
265
}
266
267
void PhysicsPointQueryParameters3D::_bind_methods() {
268
ClassDB::bind_method(D_METHOD("set_position", "position"), &PhysicsPointQueryParameters3D::set_position);
269
ClassDB::bind_method(D_METHOD("get_position"), &PhysicsPointQueryParameters3D::get_position);
270
271
ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &PhysicsPointQueryParameters3D::set_collision_mask);
272
ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsPointQueryParameters3D::get_collision_mask);
273
274
ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &PhysicsPointQueryParameters3D::set_exclude);
275
ClassDB::bind_method(D_METHOD("get_exclude"), &PhysicsPointQueryParameters3D::get_exclude);
276
277
ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &PhysicsPointQueryParameters3D::set_collide_with_bodies);
278
ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &PhysicsPointQueryParameters3D::is_collide_with_bodies_enabled);
279
280
ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsPointQueryParameters3D::set_collide_with_areas);
281
ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsPointQueryParameters3D::is_collide_with_areas_enabled);
282
283
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position"), "set_position", "get_position");
284
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
285
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude", "get_exclude");
286
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
287
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");
288
}
289
290
///////////////////////////////////////////////////////
291
292
void PhysicsShapeQueryParameters3D::set_shape(const Ref<Resource> &p_shape_ref) {
293
ERR_FAIL_COND(p_shape_ref.is_null());
294
shape_ref = p_shape_ref;
295
parameters.shape_rid = p_shape_ref->get_rid();
296
}
297
298
void PhysicsShapeQueryParameters3D::set_shape_rid(const RID &p_shape) {
299
if (parameters.shape_rid != p_shape) {
300
shape_ref = Ref<Resource>();
301
parameters.shape_rid = p_shape;
302
}
303
}
304
305
void PhysicsShapeQueryParameters3D::set_exclude(const TypedArray<RID> &p_exclude) {
306
parameters.exclude.clear();
307
for (int i = 0; i < p_exclude.size(); i++) {
308
parameters.exclude.insert(p_exclude[i]);
309
}
310
}
311
312
TypedArray<RID> PhysicsShapeQueryParameters3D::get_exclude() const {
313
TypedArray<RID> ret;
314
ret.resize(parameters.exclude.size());
315
int idx = 0;
316
for (const RID &E : parameters.exclude) {
317
ret[idx++] = E;
318
}
319
return ret;
320
}
321
322
void PhysicsShapeQueryParameters3D::_bind_methods() {
323
ClassDB::bind_method(D_METHOD("set_shape", "shape"), &PhysicsShapeQueryParameters3D::set_shape);
324
ClassDB::bind_method(D_METHOD("get_shape"), &PhysicsShapeQueryParameters3D::get_shape);
325
326
ClassDB::bind_method(D_METHOD("set_shape_rid", "shape"), &PhysicsShapeQueryParameters3D::set_shape_rid);
327
ClassDB::bind_method(D_METHOD("get_shape_rid"), &PhysicsShapeQueryParameters3D::get_shape_rid);
328
329
ClassDB::bind_method(D_METHOD("set_transform", "transform"), &PhysicsShapeQueryParameters3D::set_transform);
330
ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsShapeQueryParameters3D::get_transform);
331
332
ClassDB::bind_method(D_METHOD("set_motion", "motion"), &PhysicsShapeQueryParameters3D::set_motion);
333
ClassDB::bind_method(D_METHOD("get_motion"), &PhysicsShapeQueryParameters3D::get_motion);
334
335
ClassDB::bind_method(D_METHOD("set_margin", "margin"), &PhysicsShapeQueryParameters3D::set_margin);
336
ClassDB::bind_method(D_METHOD("get_margin"), &PhysicsShapeQueryParameters3D::get_margin);
337
338
ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &PhysicsShapeQueryParameters3D::set_collision_mask);
339
ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsShapeQueryParameters3D::get_collision_mask);
340
341
ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &PhysicsShapeQueryParameters3D::set_exclude);
342
ClassDB::bind_method(D_METHOD("get_exclude"), &PhysicsShapeQueryParameters3D::get_exclude);
343
344
ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &PhysicsShapeQueryParameters3D::set_collide_with_bodies);
345
ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &PhysicsShapeQueryParameters3D::is_collide_with_bodies_enabled);
346
347
ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsShapeQueryParameters3D::set_collide_with_areas);
348
ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsShapeQueryParameters3D::is_collide_with_areas_enabled);
349
350
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
351
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude", "get_exclude");
352
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0,100,0.01"), "set_margin", "get_margin");
353
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "motion"), "set_motion", "get_motion");
354
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape3D"), "set_shape", "get_shape");
355
ADD_PROPERTY(PropertyInfo(Variant::RID, "shape_rid"), "set_shape_rid", "get_shape_rid");
356
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "transform"), "set_transform", "get_transform");
357
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
358
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");
359
}
360
361
/////////////////////////////////////
362
363
Dictionary PhysicsDirectSpaceState3D::_intersect_ray(const Ref<PhysicsRayQueryParameters3D> &p_ray_query) {
364
ERR_FAIL_COND_V(p_ray_query.is_null(), Dictionary());
365
366
RayResult result;
367
bool res = intersect_ray(p_ray_query->get_parameters(), result);
368
369
if (!res) {
370
return Dictionary();
371
}
372
373
Dictionary d;
374
d["position"] = result.position;
375
d["normal"] = result.normal;
376
d["face_index"] = result.face_index;
377
d["collider_id"] = result.collider_id;
378
d["collider"] = result.collider;
379
d["shape"] = result.shape;
380
d["rid"] = result.rid;
381
382
return d;
383
}
384
385
TypedArray<Dictionary> PhysicsDirectSpaceState3D::_intersect_point(const Ref<PhysicsPointQueryParameters3D> &p_point_query, int p_max_results) {
386
ERR_FAIL_COND_V(p_point_query.is_null(), TypedArray<Dictionary>());
387
388
Vector<ShapeResult> ret;
389
ret.resize(p_max_results);
390
391
int rc = intersect_point(p_point_query->get_parameters(), ret.ptrw(), ret.size());
392
393
if (rc == 0) {
394
return TypedArray<Dictionary>();
395
}
396
397
TypedArray<Dictionary> r;
398
r.resize(rc);
399
for (int i = 0; i < rc; i++) {
400
Dictionary d;
401
d["rid"] = ret[i].rid;
402
d["collider_id"] = ret[i].collider_id;
403
d["collider"] = ret[i].collider;
404
d["shape"] = ret[i].shape;
405
r[i] = d;
406
}
407
return r;
408
}
409
410
TypedArray<Dictionary> PhysicsDirectSpaceState3D::_intersect_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results) {
411
ERR_FAIL_COND_V(p_shape_query.is_null(), TypedArray<Dictionary>());
412
413
Vector<ShapeResult> sr;
414
sr.resize(p_max_results);
415
int rc = intersect_shape(p_shape_query->get_parameters(), sr.ptrw(), sr.size());
416
TypedArray<Dictionary> ret;
417
ret.resize(rc);
418
for (int i = 0; i < rc; i++) {
419
Dictionary d;
420
d["rid"] = sr[i].rid;
421
d["collider_id"] = sr[i].collider_id;
422
d["collider"] = sr[i].collider;
423
d["shape"] = sr[i].shape;
424
ret[i] = d;
425
}
426
427
return ret;
428
}
429
430
Vector<real_t> PhysicsDirectSpaceState3D::_cast_motion(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query) {
431
ERR_FAIL_COND_V(p_shape_query.is_null(), Vector<real_t>());
432
433
real_t closest_safe = 1.0f, closest_unsafe = 1.0f;
434
bool res = cast_motion(p_shape_query->get_parameters(), closest_safe, closest_unsafe);
435
if (!res) {
436
return Vector<real_t>();
437
}
438
Vector<real_t> ret;
439
ret.resize(2);
440
ret.write[0] = closest_safe;
441
ret.write[1] = closest_unsafe;
442
return ret;
443
}
444
445
TypedArray<Vector3> PhysicsDirectSpaceState3D::_collide_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results) {
446
ERR_FAIL_COND_V(p_shape_query.is_null(), TypedArray<Vector3>());
447
448
Vector<Vector3> ret;
449
ret.resize(p_max_results * 2);
450
int rc = 0;
451
bool res = collide_shape(p_shape_query->get_parameters(), ret.ptrw(), p_max_results, rc);
452
if (!res) {
453
return TypedArray<Vector3>();
454
}
455
TypedArray<Vector3> r;
456
r.resize(rc * 2);
457
for (int i = 0; i < rc * 2; i++) {
458
r[i] = ret[i];
459
}
460
return r;
461
}
462
463
Dictionary PhysicsDirectSpaceState3D::_get_rest_info(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query) {
464
ERR_FAIL_COND_V(p_shape_query.is_null(), Dictionary());
465
466
ShapeRestInfo sri;
467
468
bool res = rest_info(p_shape_query->get_parameters(), &sri);
469
Dictionary r;
470
if (!res) {
471
return r;
472
}
473
474
r["point"] = sri.point;
475
r["normal"] = sri.normal;
476
r["rid"] = sri.rid;
477
r["collider_id"] = sri.collider_id;
478
r["shape"] = sri.shape;
479
r["linear_velocity"] = sri.linear_velocity;
480
481
return r;
482
}
483
484
PhysicsDirectSpaceState3D::PhysicsDirectSpaceState3D() {
485
}
486
487
void PhysicsDirectSpaceState3D::_bind_methods() {
488
ClassDB::bind_method(D_METHOD("intersect_point", "parameters", "max_results"), &PhysicsDirectSpaceState3D::_intersect_point, DEFVAL(32));
489
ClassDB::bind_method(D_METHOD("intersect_ray", "parameters"), &PhysicsDirectSpaceState3D::_intersect_ray);
490
ClassDB::bind_method(D_METHOD("intersect_shape", "parameters", "max_results"), &PhysicsDirectSpaceState3D::_intersect_shape, DEFVAL(32));
491
ClassDB::bind_method(D_METHOD("cast_motion", "parameters"), &PhysicsDirectSpaceState3D::_cast_motion);
492
ClassDB::bind_method(D_METHOD("collide_shape", "parameters", "max_results"), &PhysicsDirectSpaceState3D::_collide_shape, DEFVAL(32));
493
ClassDB::bind_method(D_METHOD("get_rest_info", "parameters"), &PhysicsDirectSpaceState3D::_get_rest_info);
494
}
495
496
///////////////////////////////
497
498
TypedArray<RID> PhysicsTestMotionParameters3D::get_exclude_bodies() const {
499
TypedArray<RID> exclude;
500
exclude.resize(parameters.exclude_bodies.size());
501
502
int body_index = 0;
503
for (const RID &body : parameters.exclude_bodies) {
504
exclude[body_index++] = body;
505
}
506
507
return exclude;
508
}
509
510
void PhysicsTestMotionParameters3D::set_exclude_bodies(const TypedArray<RID> &p_exclude) {
511
parameters.exclude_bodies.clear();
512
for (int i = 0; i < p_exclude.size(); i++) {
513
parameters.exclude_bodies.insert(p_exclude[i]);
514
}
515
}
516
517
TypedArray<uint64_t> PhysicsTestMotionParameters3D::get_exclude_objects() const {
518
TypedArray<uint64_t> exclude;
519
exclude.resize(parameters.exclude_objects.size());
520
521
int object_index = 0;
522
for (const ObjectID &object_id : parameters.exclude_objects) {
523
exclude[object_index++] = object_id;
524
}
525
526
return exclude;
527
}
528
529
void PhysicsTestMotionParameters3D::set_exclude_objects(const TypedArray<uint64_t> &p_exclude) {
530
parameters.exclude_objects.clear();
531
for (int i = 0; i < p_exclude.size(); ++i) {
532
ObjectID object_id = p_exclude[i];
533
ERR_CONTINUE(object_id.is_null());
534
parameters.exclude_objects.insert(object_id);
535
}
536
}
537
538
void PhysicsTestMotionParameters3D::_bind_methods() {
539
ClassDB::bind_method(D_METHOD("get_from"), &PhysicsTestMotionParameters3D::get_from);
540
ClassDB::bind_method(D_METHOD("set_from", "from"), &PhysicsTestMotionParameters3D::set_from);
541
542
ClassDB::bind_method(D_METHOD("get_motion"), &PhysicsTestMotionParameters3D::get_motion);
543
ClassDB::bind_method(D_METHOD("set_motion", "motion"), &PhysicsTestMotionParameters3D::set_motion);
544
545
ClassDB::bind_method(D_METHOD("get_margin"), &PhysicsTestMotionParameters3D::get_margin);
546
ClassDB::bind_method(D_METHOD("set_margin", "margin"), &PhysicsTestMotionParameters3D::set_margin);
547
548
ClassDB::bind_method(D_METHOD("get_max_collisions"), &PhysicsTestMotionParameters3D::get_max_collisions);
549
ClassDB::bind_method(D_METHOD("set_max_collisions", "max_collisions"), &PhysicsTestMotionParameters3D::set_max_collisions);
550
551
ClassDB::bind_method(D_METHOD("is_collide_separation_ray_enabled"), &PhysicsTestMotionParameters3D::is_collide_separation_ray_enabled);
552
ClassDB::bind_method(D_METHOD("set_collide_separation_ray_enabled", "enabled"), &PhysicsTestMotionParameters3D::set_collide_separation_ray_enabled);
553
554
ClassDB::bind_method(D_METHOD("get_exclude_bodies"), &PhysicsTestMotionParameters3D::get_exclude_bodies);
555
ClassDB::bind_method(D_METHOD("set_exclude_bodies", "exclude_list"), &PhysicsTestMotionParameters3D::set_exclude_bodies);
556
557
ClassDB::bind_method(D_METHOD("get_exclude_objects"), &PhysicsTestMotionParameters3D::get_exclude_objects);
558
ClassDB::bind_method(D_METHOD("set_exclude_objects", "exclude_list"), &PhysicsTestMotionParameters3D::set_exclude_objects);
559
560
ClassDB::bind_method(D_METHOD("is_recovery_as_collision_enabled"), &PhysicsTestMotionParameters3D::is_recovery_as_collision_enabled);
561
ClassDB::bind_method(D_METHOD("set_recovery_as_collision_enabled", "enabled"), &PhysicsTestMotionParameters3D::set_recovery_as_collision_enabled);
562
563
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "from"), "set_from", "get_from");
564
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "motion"), "set_motion", "get_motion");
565
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin"), "set_margin", "get_margin");
566
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_collisions"), "set_max_collisions", "get_max_collisions");
567
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_separation_ray"), "set_collide_separation_ray_enabled", "is_collide_separation_ray_enabled");
568
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude_bodies", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude_bodies", "get_exclude_bodies");
569
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude_objects"), "set_exclude_objects", "get_exclude_objects");
570
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "recovery_as_collision"), "set_recovery_as_collision_enabled", "is_recovery_as_collision_enabled");
571
}
572
573
///////////////////////////////
574
575
Vector3 PhysicsTestMotionResult3D::get_travel() const {
576
return result.travel;
577
}
578
579
Vector3 PhysicsTestMotionResult3D::get_remainder() const {
580
return result.remainder;
581
}
582
583
real_t PhysicsTestMotionResult3D::get_collision_safe_fraction() const {
584
return result.collision_safe_fraction;
585
}
586
587
real_t PhysicsTestMotionResult3D::get_collision_unsafe_fraction() const {
588
return result.collision_unsafe_fraction;
589
}
590
591
int PhysicsTestMotionResult3D::get_collision_count() const {
592
return result.collision_count;
593
}
594
595
Vector3 PhysicsTestMotionResult3D::get_collision_point(int p_collision_index) const {
596
ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, Vector3());
597
return result.collisions[p_collision_index].position;
598
}
599
600
Vector3 PhysicsTestMotionResult3D::get_collision_normal(int p_collision_index) const {
601
ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, Vector3());
602
return result.collisions[p_collision_index].normal;
603
}
604
605
Vector3 PhysicsTestMotionResult3D::get_collider_velocity(int p_collision_index) const {
606
ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, Vector3());
607
return result.collisions[p_collision_index].collider_velocity;
608
}
609
610
ObjectID PhysicsTestMotionResult3D::get_collider_id(int p_collision_index) const {
611
ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, ObjectID());
612
return result.collisions[p_collision_index].collider_id;
613
}
614
615
RID PhysicsTestMotionResult3D::get_collider_rid(int p_collision_index) const {
616
ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, RID());
617
return result.collisions[p_collision_index].collider;
618
}
619
620
Object *PhysicsTestMotionResult3D::get_collider(int p_collision_index) const {
621
ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, nullptr);
622
return ObjectDB::get_instance(result.collisions[p_collision_index].collider_id);
623
}
624
625
int PhysicsTestMotionResult3D::get_collider_shape(int p_collision_index) const {
626
ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, 0);
627
return result.collisions[p_collision_index].collider_shape;
628
}
629
630
int PhysicsTestMotionResult3D::get_collision_local_shape(int p_collision_index) const {
631
ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, 0);
632
return result.collisions[p_collision_index].local_shape;
633
}
634
635
real_t PhysicsTestMotionResult3D::get_collision_depth(int p_collision_index) const {
636
ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, 0.0);
637
return result.collisions[p_collision_index].depth;
638
}
639
640
void PhysicsTestMotionResult3D::_bind_methods() {
641
ClassDB::bind_method(D_METHOD("get_travel"), &PhysicsTestMotionResult3D::get_travel);
642
ClassDB::bind_method(D_METHOD("get_remainder"), &PhysicsTestMotionResult3D::get_remainder);
643
ClassDB::bind_method(D_METHOD("get_collision_safe_fraction"), &PhysicsTestMotionResult3D::get_collision_safe_fraction);
644
ClassDB::bind_method(D_METHOD("get_collision_unsafe_fraction"), &PhysicsTestMotionResult3D::get_collision_unsafe_fraction);
645
ClassDB::bind_method(D_METHOD("get_collision_count"), &PhysicsTestMotionResult3D::get_collision_count);
646
ClassDB::bind_method(D_METHOD("get_collision_point", "collision_index"), &PhysicsTestMotionResult3D::get_collision_point, DEFVAL(0));
647
ClassDB::bind_method(D_METHOD("get_collision_normal", "collision_index"), &PhysicsTestMotionResult3D::get_collision_normal, DEFVAL(0));
648
ClassDB::bind_method(D_METHOD("get_collider_velocity", "collision_index"), &PhysicsTestMotionResult3D::get_collider_velocity, DEFVAL(0));
649
ClassDB::bind_method(D_METHOD("get_collider_id", "collision_index"), &PhysicsTestMotionResult3D::get_collider_id, DEFVAL(0));
650
ClassDB::bind_method(D_METHOD("get_collider_rid", "collision_index"), &PhysicsTestMotionResult3D::get_collider_rid, DEFVAL(0));
651
ClassDB::bind_method(D_METHOD("get_collider", "collision_index"), &PhysicsTestMotionResult3D::get_collider, DEFVAL(0));
652
ClassDB::bind_method(D_METHOD("get_collider_shape", "collision_index"), &PhysicsTestMotionResult3D::get_collider_shape, DEFVAL(0));
653
ClassDB::bind_method(D_METHOD("get_collision_local_shape", "collision_index"), &PhysicsTestMotionResult3D::get_collision_local_shape, DEFVAL(0));
654
ClassDB::bind_method(D_METHOD("get_collision_depth", "collision_index"), &PhysicsTestMotionResult3D::get_collision_depth, DEFVAL(0));
655
}
656
657
///////////////////////////////////////
658
659
bool PhysicsServer3D::_body_test_motion(RID p_body, const Ref<PhysicsTestMotionParameters3D> &p_parameters, const Ref<PhysicsTestMotionResult3D> &p_result) {
660
ERR_FAIL_COND_V(p_parameters.is_null(), false);
661
662
MotionResult *result_ptr = nullptr;
663
if (p_result.is_valid()) {
664
result_ptr = p_result->get_result_ptr();
665
}
666
667
return body_test_motion(p_body, p_parameters->get_parameters(), result_ptr);
668
}
669
670
RID PhysicsServer3D::shape_create(ShapeType p_shape) {
671
switch (p_shape) {
672
case SHAPE_WORLD_BOUNDARY:
673
return world_boundary_shape_create();
674
case SHAPE_SEPARATION_RAY:
675
return separation_ray_shape_create();
676
case SHAPE_SPHERE:
677
return sphere_shape_create();
678
case SHAPE_BOX:
679
return box_shape_create();
680
case SHAPE_CAPSULE:
681
return capsule_shape_create();
682
case SHAPE_CYLINDER:
683
return cylinder_shape_create();
684
case SHAPE_CONVEX_POLYGON:
685
return convex_polygon_shape_create();
686
case SHAPE_CONCAVE_POLYGON:
687
return concave_polygon_shape_create();
688
case SHAPE_HEIGHTMAP:
689
return heightmap_shape_create();
690
case SHAPE_CUSTOM:
691
return custom_shape_create();
692
default:
693
return RID();
694
}
695
}
696
697
void PhysicsServer3D::_bind_methods() {
698
#ifndef _3D_DISABLED
699
700
ClassDB::bind_method(D_METHOD("world_boundary_shape_create"), &PhysicsServer3D::world_boundary_shape_create);
701
ClassDB::bind_method(D_METHOD("separation_ray_shape_create"), &PhysicsServer3D::separation_ray_shape_create);
702
ClassDB::bind_method(D_METHOD("sphere_shape_create"), &PhysicsServer3D::sphere_shape_create);
703
ClassDB::bind_method(D_METHOD("box_shape_create"), &PhysicsServer3D::box_shape_create);
704
ClassDB::bind_method(D_METHOD("capsule_shape_create"), &PhysicsServer3D::capsule_shape_create);
705
ClassDB::bind_method(D_METHOD("cylinder_shape_create"), &PhysicsServer3D::cylinder_shape_create);
706
ClassDB::bind_method(D_METHOD("convex_polygon_shape_create"), &PhysicsServer3D::convex_polygon_shape_create);
707
ClassDB::bind_method(D_METHOD("concave_polygon_shape_create"), &PhysicsServer3D::concave_polygon_shape_create);
708
ClassDB::bind_method(D_METHOD("heightmap_shape_create"), &PhysicsServer3D::heightmap_shape_create);
709
ClassDB::bind_method(D_METHOD("custom_shape_create"), &PhysicsServer3D::custom_shape_create);
710
711
ClassDB::bind_method(D_METHOD("shape_set_data", "shape", "data"), &PhysicsServer3D::shape_set_data);
712
ClassDB::bind_method(D_METHOD("shape_set_margin", "shape", "margin"), &PhysicsServer3D::shape_set_margin);
713
714
ClassDB::bind_method(D_METHOD("shape_get_type", "shape"), &PhysicsServer3D::shape_get_type);
715
ClassDB::bind_method(D_METHOD("shape_get_data", "shape"), &PhysicsServer3D::shape_get_data);
716
ClassDB::bind_method(D_METHOD("shape_get_margin", "shape"), &PhysicsServer3D::shape_get_margin);
717
718
ClassDB::bind_method(D_METHOD("space_create"), &PhysicsServer3D::space_create);
719
ClassDB::bind_method(D_METHOD("space_set_active", "space", "active"), &PhysicsServer3D::space_set_active);
720
ClassDB::bind_method(D_METHOD("space_is_active", "space"), &PhysicsServer3D::space_is_active);
721
ClassDB::bind_method(D_METHOD("space_set_param", "space", "param", "value"), &PhysicsServer3D::space_set_param);
722
ClassDB::bind_method(D_METHOD("space_get_param", "space", "param"), &PhysicsServer3D::space_get_param);
723
ClassDB::bind_method(D_METHOD("space_get_direct_state", "space"), &PhysicsServer3D::space_get_direct_state);
724
725
ClassDB::bind_method(D_METHOD("area_create"), &PhysicsServer3D::area_create);
726
ClassDB::bind_method(D_METHOD("area_set_space", "area", "space"), &PhysicsServer3D::area_set_space);
727
ClassDB::bind_method(D_METHOD("area_get_space", "area"), &PhysicsServer3D::area_get_space);
728
729
ClassDB::bind_method(D_METHOD("area_add_shape", "area", "shape", "transform", "disabled"), &PhysicsServer3D::area_add_shape, DEFVAL(Transform3D()), DEFVAL(false));
730
ClassDB::bind_method(D_METHOD("area_set_shape", "area", "shape_idx", "shape"), &PhysicsServer3D::area_set_shape);
731
ClassDB::bind_method(D_METHOD("area_set_shape_transform", "area", "shape_idx", "transform"), &PhysicsServer3D::area_set_shape_transform);
732
ClassDB::bind_method(D_METHOD("area_set_shape_disabled", "area", "shape_idx", "disabled"), &PhysicsServer3D::area_set_shape_disabled);
733
734
ClassDB::bind_method(D_METHOD("area_get_shape_count", "area"), &PhysicsServer3D::area_get_shape_count);
735
ClassDB::bind_method(D_METHOD("area_get_shape", "area", "shape_idx"), &PhysicsServer3D::area_get_shape);
736
ClassDB::bind_method(D_METHOD("area_get_shape_transform", "area", "shape_idx"), &PhysicsServer3D::area_get_shape_transform);
737
738
ClassDB::bind_method(D_METHOD("area_remove_shape", "area", "shape_idx"), &PhysicsServer3D::area_remove_shape);
739
ClassDB::bind_method(D_METHOD("area_clear_shapes", "area"), &PhysicsServer3D::area_clear_shapes);
740
741
ClassDB::bind_method(D_METHOD("area_set_collision_layer", "area", "layer"), &PhysicsServer3D::area_set_collision_layer);
742
ClassDB::bind_method(D_METHOD("area_get_collision_layer", "area"), &PhysicsServer3D::area_get_collision_layer);
743
744
ClassDB::bind_method(D_METHOD("area_set_collision_mask", "area", "mask"), &PhysicsServer3D::area_set_collision_mask);
745
ClassDB::bind_method(D_METHOD("area_get_collision_mask", "area"), &PhysicsServer3D::area_get_collision_mask);
746
747
ClassDB::bind_method(D_METHOD("area_set_param", "area", "param", "value"), &PhysicsServer3D::area_set_param);
748
ClassDB::bind_method(D_METHOD("area_set_transform", "area", "transform"), &PhysicsServer3D::area_set_transform);
749
750
ClassDB::bind_method(D_METHOD("area_get_param", "area", "param"), &PhysicsServer3D::area_get_param);
751
ClassDB::bind_method(D_METHOD("area_get_transform", "area"), &PhysicsServer3D::area_get_transform);
752
753
ClassDB::bind_method(D_METHOD("area_attach_object_instance_id", "area", "id"), &PhysicsServer3D::area_attach_object_instance_id);
754
ClassDB::bind_method(D_METHOD("area_get_object_instance_id", "area"), &PhysicsServer3D::area_get_object_instance_id);
755
756
ClassDB::bind_method(D_METHOD("area_set_monitor_callback", "area", "callback"), &PhysicsServer3D::area_set_monitor_callback);
757
ClassDB::bind_method(D_METHOD("area_set_area_monitor_callback", "area", "callback"), &PhysicsServer3D::area_set_area_monitor_callback);
758
ClassDB::bind_method(D_METHOD("area_set_monitorable", "area", "monitorable"), &PhysicsServer3D::area_set_monitorable);
759
760
ClassDB::bind_method(D_METHOD("area_set_ray_pickable", "area", "enable"), &PhysicsServer3D::area_set_ray_pickable);
761
762
ClassDB::bind_method(D_METHOD("body_create"), &PhysicsServer3D::body_create);
763
764
ClassDB::bind_method(D_METHOD("body_set_space", "body", "space"), &PhysicsServer3D::body_set_space);
765
ClassDB::bind_method(D_METHOD("body_get_space", "body"), &PhysicsServer3D::body_get_space);
766
767
ClassDB::bind_method(D_METHOD("body_set_mode", "body", "mode"), &PhysicsServer3D::body_set_mode);
768
ClassDB::bind_method(D_METHOD("body_get_mode", "body"), &PhysicsServer3D::body_get_mode);
769
770
ClassDB::bind_method(D_METHOD("body_set_collision_layer", "body", "layer"), &PhysicsServer3D::body_set_collision_layer);
771
ClassDB::bind_method(D_METHOD("body_get_collision_layer", "body"), &PhysicsServer3D::body_get_collision_layer);
772
773
ClassDB::bind_method(D_METHOD("body_set_collision_mask", "body", "mask"), &PhysicsServer3D::body_set_collision_mask);
774
ClassDB::bind_method(D_METHOD("body_get_collision_mask", "body"), &PhysicsServer3D::body_get_collision_mask);
775
776
ClassDB::bind_method(D_METHOD("body_set_collision_priority", "body", "priority"), &PhysicsServer3D::body_set_collision_priority);
777
ClassDB::bind_method(D_METHOD("body_get_collision_priority", "body"), &PhysicsServer3D::body_get_collision_priority);
778
779
ClassDB::bind_method(D_METHOD("body_add_shape", "body", "shape", "transform", "disabled"), &PhysicsServer3D::body_add_shape, DEFVAL(Transform3D()), DEFVAL(false));
780
ClassDB::bind_method(D_METHOD("body_set_shape", "body", "shape_idx", "shape"), &PhysicsServer3D::body_set_shape);
781
ClassDB::bind_method(D_METHOD("body_set_shape_transform", "body", "shape_idx", "transform"), &PhysicsServer3D::body_set_shape_transform);
782
ClassDB::bind_method(D_METHOD("body_set_shape_disabled", "body", "shape_idx", "disabled"), &PhysicsServer3D::body_set_shape_disabled);
783
784
ClassDB::bind_method(D_METHOD("body_get_shape_count", "body"), &PhysicsServer3D::body_get_shape_count);
785
ClassDB::bind_method(D_METHOD("body_get_shape", "body", "shape_idx"), &PhysicsServer3D::body_get_shape);
786
ClassDB::bind_method(D_METHOD("body_get_shape_transform", "body", "shape_idx"), &PhysicsServer3D::body_get_shape_transform);
787
788
ClassDB::bind_method(D_METHOD("body_remove_shape", "body", "shape_idx"), &PhysicsServer3D::body_remove_shape);
789
ClassDB::bind_method(D_METHOD("body_clear_shapes", "body"), &PhysicsServer3D::body_clear_shapes);
790
791
ClassDB::bind_method(D_METHOD("body_attach_object_instance_id", "body", "id"), &PhysicsServer3D::body_attach_object_instance_id);
792
ClassDB::bind_method(D_METHOD("body_get_object_instance_id", "body"), &PhysicsServer3D::body_get_object_instance_id);
793
794
ClassDB::bind_method(D_METHOD("body_set_enable_continuous_collision_detection", "body", "enable"), &PhysicsServer3D::body_set_enable_continuous_collision_detection);
795
ClassDB::bind_method(D_METHOD("body_is_continuous_collision_detection_enabled", "body"), &PhysicsServer3D::body_is_continuous_collision_detection_enabled);
796
797
ClassDB::bind_method(D_METHOD("body_set_param", "body", "param", "value"), &PhysicsServer3D::body_set_param);
798
ClassDB::bind_method(D_METHOD("body_get_param", "body", "param"), &PhysicsServer3D::body_get_param);
799
800
ClassDB::bind_method(D_METHOD("body_reset_mass_properties", "body"), &PhysicsServer3D::body_reset_mass_properties);
801
802
ClassDB::bind_method(D_METHOD("body_set_state", "body", "state", "value"), &PhysicsServer3D::body_set_state);
803
ClassDB::bind_method(D_METHOD("body_get_state", "body", "state"), &PhysicsServer3D::body_get_state);
804
805
ClassDB::bind_method(D_METHOD("body_apply_central_impulse", "body", "impulse"), &PhysicsServer3D::body_apply_central_impulse);
806
ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "impulse", "position"), &PhysicsServer3D::body_apply_impulse, Vector3());
807
ClassDB::bind_method(D_METHOD("body_apply_torque_impulse", "body", "impulse"), &PhysicsServer3D::body_apply_torque_impulse);
808
809
ClassDB::bind_method(D_METHOD("body_apply_central_force", "body", "force"), &PhysicsServer3D::body_apply_central_force);
810
ClassDB::bind_method(D_METHOD("body_apply_force", "body", "force", "position"), &PhysicsServer3D::body_apply_force, Vector3());
811
ClassDB::bind_method(D_METHOD("body_apply_torque", "body", "torque"), &PhysicsServer3D::body_apply_torque);
812
813
ClassDB::bind_method(D_METHOD("body_add_constant_central_force", "body", "force"), &PhysicsServer3D::body_add_constant_central_force);
814
ClassDB::bind_method(D_METHOD("body_add_constant_force", "body", "force", "position"), &PhysicsServer3D::body_add_constant_force, Vector3());
815
ClassDB::bind_method(D_METHOD("body_add_constant_torque", "body", "torque"), &PhysicsServer3D::body_add_constant_torque);
816
817
ClassDB::bind_method(D_METHOD("body_set_constant_force", "body", "force"), &PhysicsServer3D::body_set_constant_force);
818
ClassDB::bind_method(D_METHOD("body_get_constant_force", "body"), &PhysicsServer3D::body_get_constant_force);
819
820
ClassDB::bind_method(D_METHOD("body_set_constant_torque", "body", "torque"), &PhysicsServer3D::body_set_constant_torque);
821
ClassDB::bind_method(D_METHOD("body_get_constant_torque", "body"), &PhysicsServer3D::body_get_constant_torque);
822
823
ClassDB::bind_method(D_METHOD("body_set_axis_velocity", "body", "axis_velocity"), &PhysicsServer3D::body_set_axis_velocity);
824
825
ClassDB::bind_method(D_METHOD("body_set_axis_lock", "body", "axis", "lock"), &PhysicsServer3D::body_set_axis_lock);
826
ClassDB::bind_method(D_METHOD("body_is_axis_locked", "body", "axis"), &PhysicsServer3D::body_is_axis_locked);
827
828
ClassDB::bind_method(D_METHOD("body_add_collision_exception", "body", "excepted_body"), &PhysicsServer3D::body_add_collision_exception);
829
ClassDB::bind_method(D_METHOD("body_remove_collision_exception", "body", "excepted_body"), &PhysicsServer3D::body_remove_collision_exception);
830
831
ClassDB::bind_method(D_METHOD("body_set_max_contacts_reported", "body", "amount"), &PhysicsServer3D::body_set_max_contacts_reported);
832
ClassDB::bind_method(D_METHOD("body_get_max_contacts_reported", "body"), &PhysicsServer3D::body_get_max_contacts_reported);
833
834
ClassDB::bind_method(D_METHOD("body_set_omit_force_integration", "body", "enable"), &PhysicsServer3D::body_set_omit_force_integration);
835
ClassDB::bind_method(D_METHOD("body_is_omitting_force_integration", "body"), &PhysicsServer3D::body_is_omitting_force_integration);
836
837
ClassDB::bind_method(D_METHOD("body_set_state_sync_callback", "body", "callable"), &PhysicsServer3D::body_set_state_sync_callback);
838
839
ClassDB::bind_method(D_METHOD("body_set_force_integration_callback", "body", "callable", "userdata"), &PhysicsServer3D::body_set_force_integration_callback, DEFVAL(Variant()));
840
841
ClassDB::bind_method(D_METHOD("body_set_ray_pickable", "body", "enable"), &PhysicsServer3D::body_set_ray_pickable);
842
843
ClassDB::bind_method(D_METHOD("body_test_motion", "body", "parameters", "result"), &PhysicsServer3D::_body_test_motion, DEFVAL(Variant()));
844
845
ClassDB::bind_method(D_METHOD("body_get_direct_state", "body"), &PhysicsServer3D::body_get_direct_state);
846
847
/* SOFT BODY API */
848
849
ClassDB::bind_method(D_METHOD("soft_body_create"), &PhysicsServer3D::soft_body_create);
850
851
ClassDB::bind_method(D_METHOD("soft_body_update_rendering_server", "body", "rendering_server_handler"), &PhysicsServer3D::soft_body_update_rendering_server);
852
853
ClassDB::bind_method(D_METHOD("soft_body_set_space", "body", "space"), &PhysicsServer3D::soft_body_set_space);
854
ClassDB::bind_method(D_METHOD("soft_body_get_space", "body"), &PhysicsServer3D::soft_body_get_space);
855
856
ClassDB::bind_method(D_METHOD("soft_body_set_mesh", "body", "mesh"), &PhysicsServer3D::soft_body_set_mesh);
857
858
ClassDB::bind_method(D_METHOD("soft_body_get_bounds", "body"), &PhysicsServer3D::soft_body_get_bounds);
859
860
ClassDB::bind_method(D_METHOD("soft_body_set_collision_layer", "body", "layer"), &PhysicsServer3D::soft_body_set_collision_layer);
861
ClassDB::bind_method(D_METHOD("soft_body_get_collision_layer", "body"), &PhysicsServer3D::soft_body_get_collision_layer);
862
863
ClassDB::bind_method(D_METHOD("soft_body_set_collision_mask", "body", "mask"), &PhysicsServer3D::soft_body_set_collision_mask);
864
ClassDB::bind_method(D_METHOD("soft_body_get_collision_mask", "body"), &PhysicsServer3D::soft_body_get_collision_mask);
865
866
ClassDB::bind_method(D_METHOD("soft_body_add_collision_exception", "body", "body_b"), &PhysicsServer3D::soft_body_add_collision_exception);
867
ClassDB::bind_method(D_METHOD("soft_body_remove_collision_exception", "body", "body_b"), &PhysicsServer3D::soft_body_remove_collision_exception);
868
869
ClassDB::bind_method(D_METHOD("soft_body_set_state", "body", "state", "variant"), &PhysicsServer3D::soft_body_set_state);
870
ClassDB::bind_method(D_METHOD("soft_body_get_state", "body", "state"), &PhysicsServer3D::soft_body_get_state);
871
872
ClassDB::bind_method(D_METHOD("soft_body_set_transform", "body", "transform"), &PhysicsServer3D::soft_body_set_transform);
873
874
ClassDB::bind_method(D_METHOD("soft_body_set_ray_pickable", "body", "enable"), &PhysicsServer3D::soft_body_set_ray_pickable);
875
876
ClassDB::bind_method(D_METHOD("soft_body_set_simulation_precision", "body", "simulation_precision"), &PhysicsServer3D::soft_body_set_simulation_precision);
877
ClassDB::bind_method(D_METHOD("soft_body_get_simulation_precision", "body"), &PhysicsServer3D::soft_body_get_simulation_precision);
878
879
ClassDB::bind_method(D_METHOD("soft_body_set_total_mass", "body", "total_mass"), &PhysicsServer3D::soft_body_set_total_mass);
880
ClassDB::bind_method(D_METHOD("soft_body_get_total_mass", "body"), &PhysicsServer3D::soft_body_get_total_mass);
881
882
ClassDB::bind_method(D_METHOD("soft_body_set_linear_stiffness", "body", "stiffness"), &PhysicsServer3D::soft_body_set_linear_stiffness);
883
ClassDB::bind_method(D_METHOD("soft_body_get_linear_stiffness", "body"), &PhysicsServer3D::soft_body_get_linear_stiffness);
884
885
ClassDB::bind_method(D_METHOD("soft_body_set_shrinking_factor", "body", "shrinking_factor"), &PhysicsServer3D::soft_body_set_shrinking_factor);
886
ClassDB::bind_method(D_METHOD("soft_body_get_shrinking_factor", "body"), &PhysicsServer3D::soft_body_get_shrinking_factor);
887
888
ClassDB::bind_method(D_METHOD("soft_body_set_pressure_coefficient", "body", "pressure_coefficient"), &PhysicsServer3D::soft_body_set_pressure_coefficient);
889
ClassDB::bind_method(D_METHOD("soft_body_get_pressure_coefficient", "body"), &PhysicsServer3D::soft_body_get_pressure_coefficient);
890
891
ClassDB::bind_method(D_METHOD("soft_body_set_damping_coefficient", "body", "damping_coefficient"), &PhysicsServer3D::soft_body_set_damping_coefficient);
892
ClassDB::bind_method(D_METHOD("soft_body_get_damping_coefficient", "body"), &PhysicsServer3D::soft_body_get_damping_coefficient);
893
894
ClassDB::bind_method(D_METHOD("soft_body_set_drag_coefficient", "body", "drag_coefficient"), &PhysicsServer3D::soft_body_set_drag_coefficient);
895
ClassDB::bind_method(D_METHOD("soft_body_get_drag_coefficient", "body"), &PhysicsServer3D::soft_body_get_drag_coefficient);
896
897
ClassDB::bind_method(D_METHOD("soft_body_move_point", "body", "point_index", "global_position"), &PhysicsServer3D::soft_body_move_point);
898
ClassDB::bind_method(D_METHOD("soft_body_get_point_global_position", "body", "point_index"), &PhysicsServer3D::soft_body_get_point_global_position);
899
900
ClassDB::bind_method(D_METHOD("soft_body_remove_all_pinned_points", "body"), &PhysicsServer3D::soft_body_remove_all_pinned_points);
901
902
ClassDB::bind_method(D_METHOD("soft_body_pin_point", "body", "point_index", "pin"), &PhysicsServer3D::soft_body_pin_point);
903
904
ClassDB::bind_method(D_METHOD("soft_body_is_point_pinned", "body", "point_index"), &PhysicsServer3D::soft_body_is_point_pinned);
905
906
ClassDB::bind_method(D_METHOD("soft_body_apply_point_impulse", "body", "point_index", "impulse"), &PhysicsServer3D::soft_body_apply_point_impulse);
907
ClassDB::bind_method(D_METHOD("soft_body_apply_point_force", "body", "point_index", "force"), &PhysicsServer3D::soft_body_apply_point_force);
908
ClassDB::bind_method(D_METHOD("soft_body_apply_central_impulse", "body", "impulse"), &PhysicsServer3D::soft_body_apply_central_impulse);
909
ClassDB::bind_method(D_METHOD("soft_body_apply_central_force", "body", "force"), &PhysicsServer3D::soft_body_apply_central_force);
910
911
/* JOINT API */
912
913
ClassDB::bind_method(D_METHOD("joint_create"), &PhysicsServer3D::joint_create);
914
ClassDB::bind_method(D_METHOD("joint_clear", "joint"), &PhysicsServer3D::joint_clear);
915
916
BIND_ENUM_CONSTANT(JOINT_TYPE_PIN);
917
BIND_ENUM_CONSTANT(JOINT_TYPE_HINGE);
918
BIND_ENUM_CONSTANT(JOINT_TYPE_SLIDER);
919
BIND_ENUM_CONSTANT(JOINT_TYPE_CONE_TWIST);
920
BIND_ENUM_CONSTANT(JOINT_TYPE_6DOF);
921
BIND_ENUM_CONSTANT(JOINT_TYPE_MAX);
922
923
ClassDB::bind_method(D_METHOD("joint_make_pin", "joint", "body_A", "local_A", "body_B", "local_B"), &PhysicsServer3D::joint_make_pin);
924
ClassDB::bind_method(D_METHOD("pin_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::pin_joint_set_param);
925
ClassDB::bind_method(D_METHOD("pin_joint_get_param", "joint", "param"), &PhysicsServer3D::pin_joint_get_param);
926
927
ClassDB::bind_method(D_METHOD("pin_joint_set_local_a", "joint", "local_A"), &PhysicsServer3D::pin_joint_set_local_a);
928
ClassDB::bind_method(D_METHOD("pin_joint_get_local_a", "joint"), &PhysicsServer3D::pin_joint_get_local_a);
929
930
ClassDB::bind_method(D_METHOD("pin_joint_set_local_b", "joint", "local_B"), &PhysicsServer3D::pin_joint_set_local_b);
931
ClassDB::bind_method(D_METHOD("pin_joint_get_local_b", "joint"), &PhysicsServer3D::pin_joint_get_local_b);
932
933
BIND_ENUM_CONSTANT(PIN_JOINT_BIAS);
934
BIND_ENUM_CONSTANT(PIN_JOINT_DAMPING);
935
BIND_ENUM_CONSTANT(PIN_JOINT_IMPULSE_CLAMP);
936
937
BIND_ENUM_CONSTANT(HINGE_JOINT_BIAS);
938
BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_UPPER);
939
BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_LOWER);
940
BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_BIAS);
941
BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_SOFTNESS);
942
BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_RELAXATION);
943
BIND_ENUM_CONSTANT(HINGE_JOINT_MOTOR_TARGET_VELOCITY);
944
BIND_ENUM_CONSTANT(HINGE_JOINT_MOTOR_MAX_IMPULSE);
945
946
BIND_ENUM_CONSTANT(HINGE_JOINT_FLAG_USE_LIMIT);
947
BIND_ENUM_CONSTANT(HINGE_JOINT_FLAG_ENABLE_MOTOR);
948
949
ClassDB::bind_method(D_METHOD("joint_make_hinge", "joint", "body_A", "hinge_A", "body_B", "hinge_B"), &PhysicsServer3D::joint_make_hinge);
950
951
ClassDB::bind_method(D_METHOD("hinge_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::hinge_joint_set_param);
952
ClassDB::bind_method(D_METHOD("hinge_joint_get_param", "joint", "param"), &PhysicsServer3D::hinge_joint_get_param);
953
954
ClassDB::bind_method(D_METHOD("hinge_joint_set_flag", "joint", "flag", "enabled"), &PhysicsServer3D::hinge_joint_set_flag);
955
ClassDB::bind_method(D_METHOD("hinge_joint_get_flag", "joint", "flag"), &PhysicsServer3D::hinge_joint_get_flag);
956
957
ClassDB::bind_method(D_METHOD("joint_make_slider", "joint", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer3D::joint_make_slider);
958
959
ClassDB::bind_method(D_METHOD("slider_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::slider_joint_set_param);
960
ClassDB::bind_method(D_METHOD("slider_joint_get_param", "joint", "param"), &PhysicsServer3D::slider_joint_get_param);
961
962
BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_UPPER);
963
BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_LOWER);
964
BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS);
965
BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION);
966
BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_DAMPING);
967
BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_SOFTNESS);
968
BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_RESTITUTION);
969
BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_DAMPING);
970
BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS);
971
BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION);
972
BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING);
973
974
BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_UPPER);
975
BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_LOWER);
976
BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS);
977
BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION);
978
BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_DAMPING);
979
BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS);
980
BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION);
981
BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_DAMPING);
982
BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS);
983
BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION);
984
BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING);
985
BIND_ENUM_CONSTANT(SLIDER_JOINT_MAX);
986
987
ClassDB::bind_method(D_METHOD("joint_make_cone_twist", "joint", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer3D::joint_make_cone_twist);
988
989
ClassDB::bind_method(D_METHOD("cone_twist_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::cone_twist_joint_set_param);
990
ClassDB::bind_method(D_METHOD("cone_twist_joint_get_param", "joint", "param"), &PhysicsServer3D::cone_twist_joint_get_param);
991
992
BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_SWING_SPAN);
993
BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_TWIST_SPAN);
994
BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_BIAS);
995
BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_SOFTNESS);
996
BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_RELAXATION);
997
998
BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_LOWER_LIMIT);
999
BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_UPPER_LIMIT);
1000
BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS);
1001
BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_RESTITUTION);
1002
BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_DAMPING);
1003
BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY);
1004
BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT);
1005
BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_SPRING_STIFFNESS);
1006
BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_SPRING_DAMPING);
1007
BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT);
1008
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LOWER_LIMIT);
1009
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_UPPER_LIMIT);
1010
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS);
1011
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_DAMPING);
1012
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_RESTITUTION);
1013
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_FORCE_LIMIT);
1014
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_ERP);
1015
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY);
1016
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT);
1017
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS);
1018
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_SPRING_DAMPING);
1019
BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT);
1020
BIND_ENUM_CONSTANT(G6DOF_JOINT_MAX);
1021
1022
BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT);
1023
BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT);
1024
BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING);
1025
BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING);
1026
BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_MOTOR);
1027
BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR);
1028
BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_MAX);
1029
1030
ClassDB::bind_method(D_METHOD("joint_get_type", "joint"), &PhysicsServer3D::joint_get_type);
1031
1032
ClassDB::bind_method(D_METHOD("joint_set_solver_priority", "joint", "priority"), &PhysicsServer3D::joint_set_solver_priority);
1033
ClassDB::bind_method(D_METHOD("joint_get_solver_priority", "joint"), &PhysicsServer3D::joint_get_solver_priority);
1034
1035
ClassDB::bind_method(D_METHOD("joint_disable_collisions_between_bodies", "joint", "disable"), &PhysicsServer3D::joint_disable_collisions_between_bodies);
1036
ClassDB::bind_method(D_METHOD("joint_is_disabled_collisions_between_bodies", "joint"), &PhysicsServer3D::joint_is_disabled_collisions_between_bodies);
1037
1038
ClassDB::bind_method(D_METHOD("joint_make_generic_6dof", "joint", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer3D::joint_make_generic_6dof);
1039
1040
ClassDB::bind_method(D_METHOD("generic_6dof_joint_set_param", "joint", "axis", "param", "value"), &PhysicsServer3D::generic_6dof_joint_set_param);
1041
ClassDB::bind_method(D_METHOD("generic_6dof_joint_get_param", "joint", "axis", "param"), &PhysicsServer3D::generic_6dof_joint_get_param);
1042
1043
ClassDB::bind_method(D_METHOD("generic_6dof_joint_set_flag", "joint", "axis", "flag", "enable"), &PhysicsServer3D::generic_6dof_joint_set_flag);
1044
ClassDB::bind_method(D_METHOD("generic_6dof_joint_get_flag", "joint", "axis", "flag"), &PhysicsServer3D::generic_6dof_joint_get_flag);
1045
1046
ClassDB::bind_method(D_METHOD("free_rid", "rid"), &PhysicsServer3D::free_rid);
1047
1048
ClassDB::bind_method(D_METHOD("set_active", "active"), &PhysicsServer3D::set_active);
1049
1050
ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &PhysicsServer3D::get_process_info);
1051
1052
BIND_ENUM_CONSTANT(SHAPE_WORLD_BOUNDARY);
1053
BIND_ENUM_CONSTANT(SHAPE_SEPARATION_RAY);
1054
BIND_ENUM_CONSTANT(SHAPE_SPHERE);
1055
BIND_ENUM_CONSTANT(SHAPE_BOX);
1056
BIND_ENUM_CONSTANT(SHAPE_CAPSULE);
1057
BIND_ENUM_CONSTANT(SHAPE_CYLINDER);
1058
BIND_ENUM_CONSTANT(SHAPE_CONVEX_POLYGON);
1059
BIND_ENUM_CONSTANT(SHAPE_CONCAVE_POLYGON);
1060
BIND_ENUM_CONSTANT(SHAPE_HEIGHTMAP);
1061
BIND_ENUM_CONSTANT(SHAPE_SOFT_BODY);
1062
BIND_ENUM_CONSTANT(SHAPE_CUSTOM);
1063
1064
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_OVERRIDE_MODE);
1065
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY);
1066
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_VECTOR);
1067
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_IS_POINT);
1068
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE);
1069
BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE);
1070
BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP);
1071
BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE);
1072
BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP);
1073
BIND_ENUM_CONSTANT(AREA_PARAM_PRIORITY);
1074
BIND_ENUM_CONSTANT(AREA_PARAM_WIND_FORCE_MAGNITUDE);
1075
BIND_ENUM_CONSTANT(AREA_PARAM_WIND_SOURCE);
1076
BIND_ENUM_CONSTANT(AREA_PARAM_WIND_DIRECTION);
1077
BIND_ENUM_CONSTANT(AREA_PARAM_WIND_ATTENUATION_FACTOR);
1078
1079
BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_DISABLED);
1080
BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE);
1081
BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE_REPLACE);
1082
BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE);
1083
BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE_COMBINE);
1084
1085
BIND_ENUM_CONSTANT(BODY_MODE_STATIC);
1086
BIND_ENUM_CONSTANT(BODY_MODE_KINEMATIC);
1087
BIND_ENUM_CONSTANT(BODY_MODE_RIGID);
1088
BIND_ENUM_CONSTANT(BODY_MODE_RIGID_LINEAR);
1089
1090
BIND_ENUM_CONSTANT(BODY_PARAM_BOUNCE);
1091
BIND_ENUM_CONSTANT(BODY_PARAM_FRICTION);
1092
BIND_ENUM_CONSTANT(BODY_PARAM_MASS);
1093
BIND_ENUM_CONSTANT(BODY_PARAM_INERTIA);
1094
BIND_ENUM_CONSTANT(BODY_PARAM_CENTER_OF_MASS);
1095
BIND_ENUM_CONSTANT(BODY_PARAM_GRAVITY_SCALE);
1096
BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP_MODE);
1097
BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP_MODE);
1098
BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP);
1099
BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP);
1100
BIND_ENUM_CONSTANT(BODY_PARAM_MAX);
1101
1102
BIND_ENUM_CONSTANT(BODY_DAMP_MODE_COMBINE);
1103
BIND_ENUM_CONSTANT(BODY_DAMP_MODE_REPLACE);
1104
1105
BIND_ENUM_CONSTANT(BODY_STATE_TRANSFORM);
1106
BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY);
1107
BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY);
1108
BIND_ENUM_CONSTANT(BODY_STATE_SLEEPING);
1109
BIND_ENUM_CONSTANT(BODY_STATE_CAN_SLEEP);
1110
1111
BIND_ENUM_CONSTANT(AREA_BODY_ADDED);
1112
BIND_ENUM_CONSTANT(AREA_BODY_REMOVED);
1113
1114
BIND_ENUM_CONSTANT(INFO_ACTIVE_OBJECTS);
1115
BIND_ENUM_CONSTANT(INFO_COLLISION_PAIRS);
1116
BIND_ENUM_CONSTANT(INFO_ISLAND_COUNT);
1117
1118
BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_RECYCLE_RADIUS);
1119
BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_SEPARATION);
1120
BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION);
1121
BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_DEFAULT_BIAS);
1122
BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD);
1123
BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD);
1124
BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_TIME_TO_SLEEP);
1125
BIND_ENUM_CONSTANT(SPACE_PARAM_SOLVER_ITERATIONS);
1126
1127
BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_X);
1128
BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Y);
1129
BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Z);
1130
BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_X);
1131
BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_Y);
1132
BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_Z);
1133
1134
#endif
1135
}
1136
1137
PhysicsServer3D::PhysicsServer3D() {
1138
singleton = this;
1139
1140
// World3D physics space
1141
GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "physics/3d/default_gravity", PROPERTY_HINT_RANGE, U"-32,32,0.001,or_less,or_greater,suffix:m/s\u00B2"), 9.8);
1142
GLOBAL_DEF_BASIC(PropertyInfo(Variant::VECTOR3, "physics/3d/default_gravity_vector", PROPERTY_HINT_RANGE, "-10,10,0.001,or_less,or_greater"), Vector3(0, -1, 0));
1143
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/default_linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), 0.1);
1144
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/default_angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), 0.1);
1145
1146
// PhysicsServer3D
1147
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/sleep_threshold_linear", PROPERTY_HINT_RANGE, "0,1,0.001,or_greater"), 0.1);
1148
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/sleep_threshold_angular", PROPERTY_HINT_RANGE, "0,90,0.1,radians_as_degrees"), Math::deg_to_rad(8.0));
1149
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/time_before_sleep", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater"), 0.5);
1150
GLOBAL_DEF(PropertyInfo(Variant::INT, "physics/3d/solver/solver_iterations", PROPERTY_HINT_RANGE, "1,32,1,or_greater"), 16);
1151
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_recycle_radius", PROPERTY_HINT_RANGE, "0,0.1,0.001,or_greater"), 0.01);
1152
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_max_separation", PROPERTY_HINT_RANGE, "0,0.1,0.001,or_greater"), 0.05);
1153
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_max_allowed_penetration", PROPERTY_HINT_RANGE, "0.001,0.1,0.001,or_greater"), 0.01);
1154
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/default_contact_bias", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.8);
1155
}
1156
1157
PhysicsServer3D::~PhysicsServer3D() {
1158
singleton = nullptr;
1159
}
1160
1161
PhysicsServer3DManager *PhysicsServer3DManager::singleton = nullptr;
1162
const String PhysicsServer3DManager::setting_property_name(PNAME("physics/3d/physics_engine"));
1163
1164
void PhysicsServer3DManager::on_servers_changed() {
1165
String physics_servers2("DEFAULT");
1166
for (int i = get_servers_count() - 1; 0 <= i; --i) {
1167
physics_servers2 += "," + get_server_name(i);
1168
}
1169
ProjectSettings::get_singleton()->set_custom_property_info(PropertyInfo(Variant::STRING, setting_property_name, PROPERTY_HINT_ENUM, physics_servers2));
1170
ProjectSettings::get_singleton()->set_restart_if_changed(setting_property_name, true);
1171
ProjectSettings::get_singleton()->set_as_basic(setting_property_name, true);
1172
}
1173
1174
void PhysicsServer3DManager::_bind_methods() {
1175
ClassDB::bind_method(D_METHOD("register_server", "name", "create_callback"), &PhysicsServer3DManager::register_server);
1176
ClassDB::bind_method(D_METHOD("set_default_server", "name", "priority"), &PhysicsServer3DManager::set_default_server);
1177
}
1178
1179
PhysicsServer3DManager *PhysicsServer3DManager::get_singleton() {
1180
return singleton;
1181
}
1182
1183
void PhysicsServer3DManager::register_server(const String &p_name, const Callable &p_create_callback) {
1184
//ERR_FAIL_COND(!p_create_callback.is_valid());
1185
ERR_FAIL_COND(find_server_id(p_name) != -1);
1186
physics_servers.push_back(ClassInfo(p_name, p_create_callback));
1187
on_servers_changed();
1188
}
1189
1190
void PhysicsServer3DManager::set_default_server(const String &p_name, int p_priority) {
1191
const int id = find_server_id(p_name);
1192
ERR_FAIL_COND(id == -1); // Not found
1193
if (default_server_priority < p_priority) {
1194
default_server_id = id;
1195
default_server_priority = p_priority;
1196
}
1197
}
1198
1199
int PhysicsServer3DManager::find_server_id(const String &p_name) {
1200
for (int i = physics_servers.size() - 1; 0 <= i; --i) {
1201
if (p_name == physics_servers[i].name) {
1202
return i;
1203
}
1204
}
1205
return -1;
1206
}
1207
1208
int PhysicsServer3DManager::get_servers_count() {
1209
return physics_servers.size();
1210
}
1211
1212
String PhysicsServer3DManager::get_server_name(int p_id) {
1213
ERR_FAIL_INDEX_V(p_id, get_servers_count(), "");
1214
return physics_servers[p_id].name;
1215
}
1216
1217
PhysicsServer3D *PhysicsServer3DManager::new_default_server() {
1218
if (default_server_id == -1) {
1219
return nullptr;
1220
}
1221
Variant ret;
1222
Callable::CallError ce;
1223
physics_servers[default_server_id].create_callback.callp(nullptr, 0, ret, ce);
1224
ERR_FAIL_COND_V(ce.error != Callable::CallError::CALL_OK, nullptr);
1225
return Object::cast_to<PhysicsServer3D>(ret.get_validated_object());
1226
}
1227
1228
PhysicsServer3D *PhysicsServer3DManager::new_server(const String &p_name) {
1229
int id = find_server_id(p_name);
1230
if (id == -1) {
1231
return nullptr;
1232
} else {
1233
Variant ret;
1234
Callable::CallError ce;
1235
physics_servers[id].create_callback.callp(nullptr, 0, ret, ce);
1236
ERR_FAIL_COND_V(ce.error != Callable::CallError::CALL_OK, nullptr);
1237
return Object::cast_to<PhysicsServer3D>(ret.get_validated_object());
1238
}
1239
}
1240
1241
PhysicsServer3DManager::PhysicsServer3DManager() {
1242
singleton = this;
1243
}
1244
1245
PhysicsServer3DManager::~PhysicsServer3DManager() {
1246
singleton = nullptr;
1247
}
1248
1249