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