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