Path: blob/master/servers/physics_3d/physics_server_3d.cpp
11322 views
/**************************************************************************/1/* physics_server_3d.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "physics_server_3d.h"3132#include "core/config/project_settings.h"33#include "core/variant/typed_array.h"3435void PhysicsServer3DRenderingServerHandler::set_vertex(int p_vertex_id, const Vector3 &p_vertex) {36GDVIRTUAL_CALL(_set_vertex, p_vertex_id, p_vertex);37}38void PhysicsServer3DRenderingServerHandler::set_normal(int p_vertex_id, const Vector3 &p_normal) {39GDVIRTUAL_CALL(_set_normal, p_vertex_id, p_normal);40}41void PhysicsServer3DRenderingServerHandler::set_aabb(const AABB &p_aabb) {42GDVIRTUAL_CALL(_set_aabb, p_aabb);43}4445void PhysicsServer3DRenderingServerHandler::_bind_methods() {46GDVIRTUAL_BIND(_set_vertex, "vertex_id", "vertex");47GDVIRTUAL_BIND(_set_normal, "vertex_id", "normal");48GDVIRTUAL_BIND(_set_aabb, "aabb");4950ClassDB::bind_method(D_METHOD("set_vertex", "vertex_id", "vertex"), &PhysicsServer3DRenderingServerHandler::set_vertex);51ClassDB::bind_method(D_METHOD("set_normal", "vertex_id", "normal"), &PhysicsServer3DRenderingServerHandler::set_normal);52ClassDB::bind_method(D_METHOD("set_aabb", "aabb"), &PhysicsServer3DRenderingServerHandler::set_aabb);53}5455PhysicsServer3D *PhysicsServer3D::singleton = nullptr;5657void PhysicsDirectBodyState3D::integrate_forces() {58real_t step = get_step();59Vector3 lv = get_linear_velocity();60lv += get_total_gravity() * step;6162Vector3 av = get_angular_velocity();6364real_t linear_damp = 1.0 - step * get_total_linear_damp();6566if (linear_damp < 0) { // reached zero in the given time67linear_damp = 0;68}6970real_t angular_damp = 1.0 - step * get_total_angular_damp();7172if (angular_damp < 0) { // reached zero in the given time73angular_damp = 0;74}7576lv *= linear_damp;77av *= angular_damp;7879set_linear_velocity(lv);80set_angular_velocity(av);81}8283Object *PhysicsDirectBodyState3D::get_contact_collider_object(int p_contact_idx) const {84ObjectID objid = get_contact_collider_id(p_contact_idx);85Object *obj = ObjectDB::get_instance(objid);86return obj;87}8889PhysicsServer3D *PhysicsServer3D::get_singleton() {90return singleton;91}9293void PhysicsDirectBodyState3D::_bind_methods() {94ClassDB::bind_method(D_METHOD("get_total_gravity"), &PhysicsDirectBodyState3D::get_total_gravity);95ClassDB::bind_method(D_METHOD("get_total_linear_damp"), &PhysicsDirectBodyState3D::get_total_linear_damp);96ClassDB::bind_method(D_METHOD("get_total_angular_damp"), &PhysicsDirectBodyState3D::get_total_angular_damp);9798ClassDB::bind_method(D_METHOD("get_center_of_mass"), &PhysicsDirectBodyState3D::get_center_of_mass);99ClassDB::bind_method(D_METHOD("get_center_of_mass_local"), &PhysicsDirectBodyState3D::get_center_of_mass_local);100ClassDB::bind_method(D_METHOD("get_principal_inertia_axes"), &PhysicsDirectBodyState3D::get_principal_inertia_axes);101102ClassDB::bind_method(D_METHOD("get_inverse_mass"), &PhysicsDirectBodyState3D::get_inverse_mass);103ClassDB::bind_method(D_METHOD("get_inverse_inertia"), &PhysicsDirectBodyState3D::get_inverse_inertia);104ClassDB::bind_method(D_METHOD("get_inverse_inertia_tensor"), &PhysicsDirectBodyState3D::get_inverse_inertia_tensor);105106ClassDB::bind_method(D_METHOD("set_linear_velocity", "velocity"), &PhysicsDirectBodyState3D::set_linear_velocity);107ClassDB::bind_method(D_METHOD("get_linear_velocity"), &PhysicsDirectBodyState3D::get_linear_velocity);108109ClassDB::bind_method(D_METHOD("set_angular_velocity", "velocity"), &PhysicsDirectBodyState3D::set_angular_velocity);110ClassDB::bind_method(D_METHOD("get_angular_velocity"), &PhysicsDirectBodyState3D::get_angular_velocity);111112ClassDB::bind_method(D_METHOD("set_transform", "transform"), &PhysicsDirectBodyState3D::set_transform);113ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsDirectBodyState3D::get_transform);114115ClassDB::bind_method(D_METHOD("get_velocity_at_local_position", "local_position"), &PhysicsDirectBodyState3D::get_velocity_at_local_position);116117ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &PhysicsDirectBodyState3D::apply_central_impulse, Vector3());118ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &PhysicsDirectBodyState3D::apply_impulse, Vector3());119ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &PhysicsDirectBodyState3D::apply_torque_impulse);120121ClassDB::bind_method(D_METHOD("apply_central_force", "force"), &PhysicsDirectBodyState3D::apply_central_force, Vector3());122ClassDB::bind_method(D_METHOD("apply_force", "force", "position"), &PhysicsDirectBodyState3D::apply_force, Vector3());123ClassDB::bind_method(D_METHOD("apply_torque", "torque"), &PhysicsDirectBodyState3D::apply_torque);124125ClassDB::bind_method(D_METHOD("add_constant_central_force", "force"), &PhysicsDirectBodyState3D::add_constant_central_force, Vector3());126ClassDB::bind_method(D_METHOD("add_constant_force", "force", "position"), &PhysicsDirectBodyState3D::add_constant_force, Vector3());127ClassDB::bind_method(D_METHOD("add_constant_torque", "torque"), &PhysicsDirectBodyState3D::add_constant_torque);128129ClassDB::bind_method(D_METHOD("set_constant_force", "force"), &PhysicsDirectBodyState3D::set_constant_force);130ClassDB::bind_method(D_METHOD("get_constant_force"), &PhysicsDirectBodyState3D::get_constant_force);131132ClassDB::bind_method(D_METHOD("set_constant_torque", "torque"), &PhysicsDirectBodyState3D::set_constant_torque);133ClassDB::bind_method(D_METHOD("get_constant_torque"), &PhysicsDirectBodyState3D::get_constant_torque);134135ClassDB::bind_method(D_METHOD("set_sleep_state", "enabled"), &PhysicsDirectBodyState3D::set_sleep_state);136ClassDB::bind_method(D_METHOD("is_sleeping"), &PhysicsDirectBodyState3D::is_sleeping);137138ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &PhysicsDirectBodyState3D::set_collision_layer);139ClassDB::bind_method(D_METHOD("get_collision_layer"), &PhysicsDirectBodyState3D::get_collision_layer);140141ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &PhysicsDirectBodyState3D::set_collision_mask);142ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsDirectBodyState3D::get_collision_mask);143144ClassDB::bind_method(D_METHOD("get_contact_count"), &PhysicsDirectBodyState3D::get_contact_count);145146ClassDB::bind_method(D_METHOD("get_contact_local_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_position);147ClassDB::bind_method(D_METHOD("get_contact_local_normal", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_normal);148ClassDB::bind_method(D_METHOD("get_contact_impulse", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_impulse);149ClassDB::bind_method(D_METHOD("get_contact_local_shape", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_shape);150ClassDB::bind_method(D_METHOD("get_contact_local_velocity_at_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_velocity_at_position);151ClassDB::bind_method(D_METHOD("get_contact_collider", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider);152ClassDB::bind_method(D_METHOD("get_contact_collider_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_position);153ClassDB::bind_method(D_METHOD("get_contact_collider_id", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_id);154ClassDB::bind_method(D_METHOD("get_contact_collider_object", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_object);155ClassDB::bind_method(D_METHOD("get_contact_collider_shape", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_shape);156ClassDB::bind_method(D_METHOD("get_contact_collider_velocity_at_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_velocity_at_position);157ClassDB::bind_method(D_METHOD("get_step"), &PhysicsDirectBodyState3D::get_step);158ClassDB::bind_method(D_METHOD("integrate_forces"), &PhysicsDirectBodyState3D::integrate_forces);159ClassDB::bind_method(D_METHOD("get_space_state"), &PhysicsDirectBodyState3D::get_space_state);160161ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "step"), "", "get_step");162ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inverse_mass"), "", "get_inverse_mass");163ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "total_angular_damp"), "", "get_total_angular_damp");164ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "total_linear_damp"), "", "get_total_linear_damp");165ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "inverse_inertia"), "", "get_inverse_inertia");166ADD_PROPERTY(PropertyInfo(Variant::BASIS, "inverse_inertia_tensor"), "", "get_inverse_inertia_tensor");167ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "total_gravity"), "", "get_total_gravity");168ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_of_mass"), "", "get_center_of_mass");169ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_of_mass_local"), "", "get_center_of_mass_local");170ADD_PROPERTY(PropertyInfo(Variant::BASIS, "principal_inertia_axes"), "", "get_principal_inertia_axes");171ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "angular_velocity"), "set_angular_velocity", "get_angular_velocity");172ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "linear_velocity"), "set_linear_velocity", "get_linear_velocity");173ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sleeping"), "set_sleep_state", "is_sleeping");174ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer"), "set_collision_layer", "get_collision_layer");175ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask"), "set_collision_mask", "get_collision_mask");176ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "transform"), "set_transform", "get_transform");177}178179PhysicsDirectBodyState3D::PhysicsDirectBodyState3D() {}180181///////////////////////////////////////////////////////182183void PhysicsRayQueryParameters3D::set_exclude(const TypedArray<RID> &p_exclude) {184parameters.exclude.clear();185for (int i = 0; i < p_exclude.size(); i++) {186parameters.exclude.insert(p_exclude[i]);187}188}189190TypedArray<RID> PhysicsRayQueryParameters3D::get_exclude() const {191TypedArray<RID> ret;192ret.resize(parameters.exclude.size());193int idx = 0;194for (const RID &E : parameters.exclude) {195ret[idx++] = E;196}197return ret;198}199200void PhysicsRayQueryParameters3D::_bind_methods() {201ClassDB::bind_static_method("PhysicsRayQueryParameters3D", D_METHOD("create", "from", "to", "collision_mask", "exclude"), &PhysicsRayQueryParameters3D::create, DEFVAL(UINT32_MAX), DEFVAL(TypedArray<RID>()));202203ClassDB::bind_method(D_METHOD("set_from", "from"), &PhysicsRayQueryParameters3D::set_from);204ClassDB::bind_method(D_METHOD("get_from"), &PhysicsRayQueryParameters3D::get_from);205206ClassDB::bind_method(D_METHOD("set_to", "to"), &PhysicsRayQueryParameters3D::set_to);207ClassDB::bind_method(D_METHOD("get_to"), &PhysicsRayQueryParameters3D::get_to);208209ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &PhysicsRayQueryParameters3D::set_collision_mask);210ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsRayQueryParameters3D::get_collision_mask);211212ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &PhysicsRayQueryParameters3D::set_exclude);213ClassDB::bind_method(D_METHOD("get_exclude"), &PhysicsRayQueryParameters3D::get_exclude);214215ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &PhysicsRayQueryParameters3D::set_collide_with_bodies);216ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &PhysicsRayQueryParameters3D::is_collide_with_bodies_enabled);217218ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsRayQueryParameters3D::set_collide_with_areas);219ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsRayQueryParameters3D::is_collide_with_areas_enabled);220221ClassDB::bind_method(D_METHOD("set_hit_from_inside", "enable"), &PhysicsRayQueryParameters3D::set_hit_from_inside);222ClassDB::bind_method(D_METHOD("is_hit_from_inside_enabled"), &PhysicsRayQueryParameters3D::is_hit_from_inside_enabled);223224ClassDB::bind_method(D_METHOD("set_hit_back_faces", "enable"), &PhysicsRayQueryParameters3D::set_hit_back_faces);225ClassDB::bind_method(D_METHOD("is_hit_back_faces_enabled"), &PhysicsRayQueryParameters3D::is_hit_back_faces_enabled);226227ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "from"), "set_from", "get_from");228ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "to"), "set_to", "get_to");229ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");230ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude", "get_exclude");231ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");232ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");233ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hit_from_inside"), "set_hit_from_inside", "is_hit_from_inside_enabled");234ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hit_back_faces"), "set_hit_back_faces", "is_hit_back_faces_enabled");235}236237///////////////////////////////////////////////////////238239Ref<PhysicsRayQueryParameters3D> PhysicsRayQueryParameters3D::create(Vector3 p_from, Vector3 p_to, uint32_t p_mask, const TypedArray<RID> &p_exclude) {240Ref<PhysicsRayQueryParameters3D> params;241params.instantiate();242params->set_from(p_from);243params->set_to(p_to);244params->set_collision_mask(p_mask);245params->set_exclude(p_exclude);246return params;247}248249void PhysicsPointQueryParameters3D::set_exclude(const TypedArray<RID> &p_exclude) {250parameters.exclude.clear();251for (int i = 0; i < p_exclude.size(); i++) {252parameters.exclude.insert(p_exclude[i]);253}254}255256TypedArray<RID> PhysicsPointQueryParameters3D::get_exclude() const {257TypedArray<RID> ret;258ret.resize(parameters.exclude.size());259int idx = 0;260for (const RID &E : parameters.exclude) {261ret[idx++] = E;262}263return ret;264}265266void PhysicsPointQueryParameters3D::_bind_methods() {267ClassDB::bind_method(D_METHOD("set_position", "position"), &PhysicsPointQueryParameters3D::set_position);268ClassDB::bind_method(D_METHOD("get_position"), &PhysicsPointQueryParameters3D::get_position);269270ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &PhysicsPointQueryParameters3D::set_collision_mask);271ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsPointQueryParameters3D::get_collision_mask);272273ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &PhysicsPointQueryParameters3D::set_exclude);274ClassDB::bind_method(D_METHOD("get_exclude"), &PhysicsPointQueryParameters3D::get_exclude);275276ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &PhysicsPointQueryParameters3D::set_collide_with_bodies);277ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &PhysicsPointQueryParameters3D::is_collide_with_bodies_enabled);278279ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsPointQueryParameters3D::set_collide_with_areas);280ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsPointQueryParameters3D::is_collide_with_areas_enabled);281282ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position"), "set_position", "get_position");283ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");284ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude", "get_exclude");285ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");286ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");287}288289///////////////////////////////////////////////////////290291void PhysicsShapeQueryParameters3D::set_shape(const Ref<Resource> &p_shape_ref) {292ERR_FAIL_COND(p_shape_ref.is_null());293shape_ref = p_shape_ref;294parameters.shape_rid = p_shape_ref->get_rid();295}296297void PhysicsShapeQueryParameters3D::set_shape_rid(const RID &p_shape) {298if (parameters.shape_rid != p_shape) {299shape_ref = Ref<Resource>();300parameters.shape_rid = p_shape;301}302}303304void PhysicsShapeQueryParameters3D::set_exclude(const TypedArray<RID> &p_exclude) {305parameters.exclude.clear();306for (int i = 0; i < p_exclude.size(); i++) {307parameters.exclude.insert(p_exclude[i]);308}309}310311TypedArray<RID> PhysicsShapeQueryParameters3D::get_exclude() const {312TypedArray<RID> ret;313ret.resize(parameters.exclude.size());314int idx = 0;315for (const RID &E : parameters.exclude) {316ret[idx++] = E;317}318return ret;319}320321void PhysicsShapeQueryParameters3D::_bind_methods() {322ClassDB::bind_method(D_METHOD("set_shape", "shape"), &PhysicsShapeQueryParameters3D::set_shape);323ClassDB::bind_method(D_METHOD("get_shape"), &PhysicsShapeQueryParameters3D::get_shape);324325ClassDB::bind_method(D_METHOD("set_shape_rid", "shape"), &PhysicsShapeQueryParameters3D::set_shape_rid);326ClassDB::bind_method(D_METHOD("get_shape_rid"), &PhysicsShapeQueryParameters3D::get_shape_rid);327328ClassDB::bind_method(D_METHOD("set_transform", "transform"), &PhysicsShapeQueryParameters3D::set_transform);329ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsShapeQueryParameters3D::get_transform);330331ClassDB::bind_method(D_METHOD("set_motion", "motion"), &PhysicsShapeQueryParameters3D::set_motion);332ClassDB::bind_method(D_METHOD("get_motion"), &PhysicsShapeQueryParameters3D::get_motion);333334ClassDB::bind_method(D_METHOD("set_margin", "margin"), &PhysicsShapeQueryParameters3D::set_margin);335ClassDB::bind_method(D_METHOD("get_margin"), &PhysicsShapeQueryParameters3D::get_margin);336337ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &PhysicsShapeQueryParameters3D::set_collision_mask);338ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsShapeQueryParameters3D::get_collision_mask);339340ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &PhysicsShapeQueryParameters3D::set_exclude);341ClassDB::bind_method(D_METHOD("get_exclude"), &PhysicsShapeQueryParameters3D::get_exclude);342343ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &PhysicsShapeQueryParameters3D::set_collide_with_bodies);344ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &PhysicsShapeQueryParameters3D::is_collide_with_bodies_enabled);345346ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsShapeQueryParameters3D::set_collide_with_areas);347ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsShapeQueryParameters3D::is_collide_with_areas_enabled);348349ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");350ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude", "get_exclude");351ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0,100,0.01"), "set_margin", "get_margin");352ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "motion"), "set_motion", "get_motion");353ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape3D"), "set_shape", "get_shape");354ADD_PROPERTY(PropertyInfo(Variant::RID, "shape_rid"), "set_shape_rid", "get_shape_rid");355ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "transform"), "set_transform", "get_transform");356ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");357ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");358}359360/////////////////////////////////////361362Dictionary PhysicsDirectSpaceState3D::_intersect_ray(const Ref<PhysicsRayQueryParameters3D> &p_ray_query) {363ERR_FAIL_COND_V(p_ray_query.is_null(), Dictionary());364365RayResult result;366bool res = intersect_ray(p_ray_query->get_parameters(), result);367368if (!res) {369return Dictionary();370}371372Dictionary d;373d["position"] = result.position;374d["normal"] = result.normal;375d["face_index"] = result.face_index;376d["collider_id"] = result.collider_id;377d["collider"] = result.collider;378d["shape"] = result.shape;379d["rid"] = result.rid;380381return d;382}383384TypedArray<Dictionary> PhysicsDirectSpaceState3D::_intersect_point(const Ref<PhysicsPointQueryParameters3D> &p_point_query, int p_max_results) {385ERR_FAIL_COND_V(p_point_query.is_null(), TypedArray<Dictionary>());386387Vector<ShapeResult> ret;388ret.resize(p_max_results);389390int rc = intersect_point(p_point_query->get_parameters(), ret.ptrw(), ret.size());391392if (rc == 0) {393return TypedArray<Dictionary>();394}395396TypedArray<Dictionary> r;397r.resize(rc);398for (int i = 0; i < rc; i++) {399Dictionary d;400d["rid"] = ret[i].rid;401d["collider_id"] = ret[i].collider_id;402d["collider"] = ret[i].collider;403d["shape"] = ret[i].shape;404r[i] = d;405}406return r;407}408409TypedArray<Dictionary> PhysicsDirectSpaceState3D::_intersect_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results) {410ERR_FAIL_COND_V(p_shape_query.is_null(), TypedArray<Dictionary>());411412Vector<ShapeResult> sr;413sr.resize(p_max_results);414int rc = intersect_shape(p_shape_query->get_parameters(), sr.ptrw(), sr.size());415TypedArray<Dictionary> ret;416ret.resize(rc);417for (int i = 0; i < rc; i++) {418Dictionary d;419d["rid"] = sr[i].rid;420d["collider_id"] = sr[i].collider_id;421d["collider"] = sr[i].collider;422d["shape"] = sr[i].shape;423ret[i] = d;424}425426return ret;427}428429Vector<real_t> PhysicsDirectSpaceState3D::_cast_motion(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query) {430ERR_FAIL_COND_V(p_shape_query.is_null(), Vector<real_t>());431432real_t closest_safe = 1.0f, closest_unsafe = 1.0f;433bool res = cast_motion(p_shape_query->get_parameters(), closest_safe, closest_unsafe);434if (!res) {435return Vector<real_t>();436}437Vector<real_t> ret;438ret.resize(2);439ret.write[0] = closest_safe;440ret.write[1] = closest_unsafe;441return ret;442}443444TypedArray<Vector3> PhysicsDirectSpaceState3D::_collide_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results) {445ERR_FAIL_COND_V(p_shape_query.is_null(), TypedArray<Vector3>());446447Vector<Vector3> ret;448ret.resize(p_max_results * 2);449int rc = 0;450bool res = collide_shape(p_shape_query->get_parameters(), ret.ptrw(), p_max_results, rc);451if (!res) {452return TypedArray<Vector3>();453}454TypedArray<Vector3> r;455r.resize(rc * 2);456for (int i = 0; i < rc * 2; i++) {457r[i] = ret[i];458}459return r;460}461462Dictionary PhysicsDirectSpaceState3D::_get_rest_info(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query) {463ERR_FAIL_COND_V(p_shape_query.is_null(), Dictionary());464465ShapeRestInfo sri;466467bool res = rest_info(p_shape_query->get_parameters(), &sri);468Dictionary r;469if (!res) {470return r;471}472473r["point"] = sri.point;474r["normal"] = sri.normal;475r["rid"] = sri.rid;476r["collider_id"] = sri.collider_id;477r["shape"] = sri.shape;478r["linear_velocity"] = sri.linear_velocity;479480return r;481}482483PhysicsDirectSpaceState3D::PhysicsDirectSpaceState3D() {484}485486void PhysicsDirectSpaceState3D::_bind_methods() {487ClassDB::bind_method(D_METHOD("intersect_point", "parameters", "max_results"), &PhysicsDirectSpaceState3D::_intersect_point, DEFVAL(32));488ClassDB::bind_method(D_METHOD("intersect_ray", "parameters"), &PhysicsDirectSpaceState3D::_intersect_ray);489ClassDB::bind_method(D_METHOD("intersect_shape", "parameters", "max_results"), &PhysicsDirectSpaceState3D::_intersect_shape, DEFVAL(32));490ClassDB::bind_method(D_METHOD("cast_motion", "parameters"), &PhysicsDirectSpaceState3D::_cast_motion);491ClassDB::bind_method(D_METHOD("collide_shape", "parameters", "max_results"), &PhysicsDirectSpaceState3D::_collide_shape, DEFVAL(32));492ClassDB::bind_method(D_METHOD("get_rest_info", "parameters"), &PhysicsDirectSpaceState3D::_get_rest_info);493}494495///////////////////////////////496497TypedArray<RID> PhysicsTestMotionParameters3D::get_exclude_bodies() const {498TypedArray<RID> exclude;499exclude.resize(parameters.exclude_bodies.size());500501int body_index = 0;502for (const RID &body : parameters.exclude_bodies) {503exclude[body_index++] = body;504}505506return exclude;507}508509void PhysicsTestMotionParameters3D::set_exclude_bodies(const TypedArray<RID> &p_exclude) {510parameters.exclude_bodies.clear();511for (int i = 0; i < p_exclude.size(); i++) {512parameters.exclude_bodies.insert(p_exclude[i]);513}514}515516TypedArray<uint64_t> PhysicsTestMotionParameters3D::get_exclude_objects() const {517TypedArray<uint64_t> exclude;518exclude.resize(parameters.exclude_objects.size());519520int object_index = 0;521for (const ObjectID &object_id : parameters.exclude_objects) {522exclude[object_index++] = object_id;523}524525return exclude;526}527528void PhysicsTestMotionParameters3D::set_exclude_objects(const TypedArray<uint64_t> &p_exclude) {529parameters.exclude_objects.clear();530for (int i = 0; i < p_exclude.size(); ++i) {531ObjectID object_id = p_exclude[i];532ERR_CONTINUE(object_id.is_null());533parameters.exclude_objects.insert(object_id);534}535}536537void PhysicsTestMotionParameters3D::_bind_methods() {538ClassDB::bind_method(D_METHOD("get_from"), &PhysicsTestMotionParameters3D::get_from);539ClassDB::bind_method(D_METHOD("set_from", "from"), &PhysicsTestMotionParameters3D::set_from);540541ClassDB::bind_method(D_METHOD("get_motion"), &PhysicsTestMotionParameters3D::get_motion);542ClassDB::bind_method(D_METHOD("set_motion", "motion"), &PhysicsTestMotionParameters3D::set_motion);543544ClassDB::bind_method(D_METHOD("get_margin"), &PhysicsTestMotionParameters3D::get_margin);545ClassDB::bind_method(D_METHOD("set_margin", "margin"), &PhysicsTestMotionParameters3D::set_margin);546547ClassDB::bind_method(D_METHOD("get_max_collisions"), &PhysicsTestMotionParameters3D::get_max_collisions);548ClassDB::bind_method(D_METHOD("set_max_collisions", "max_collisions"), &PhysicsTestMotionParameters3D::set_max_collisions);549550ClassDB::bind_method(D_METHOD("is_collide_separation_ray_enabled"), &PhysicsTestMotionParameters3D::is_collide_separation_ray_enabled);551ClassDB::bind_method(D_METHOD("set_collide_separation_ray_enabled", "enabled"), &PhysicsTestMotionParameters3D::set_collide_separation_ray_enabled);552553ClassDB::bind_method(D_METHOD("get_exclude_bodies"), &PhysicsTestMotionParameters3D::get_exclude_bodies);554ClassDB::bind_method(D_METHOD("set_exclude_bodies", "exclude_list"), &PhysicsTestMotionParameters3D::set_exclude_bodies);555556ClassDB::bind_method(D_METHOD("get_exclude_objects"), &PhysicsTestMotionParameters3D::get_exclude_objects);557ClassDB::bind_method(D_METHOD("set_exclude_objects", "exclude_list"), &PhysicsTestMotionParameters3D::set_exclude_objects);558559ClassDB::bind_method(D_METHOD("is_recovery_as_collision_enabled"), &PhysicsTestMotionParameters3D::is_recovery_as_collision_enabled);560ClassDB::bind_method(D_METHOD("set_recovery_as_collision_enabled", "enabled"), &PhysicsTestMotionParameters3D::set_recovery_as_collision_enabled);561562ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "from"), "set_from", "get_from");563ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "motion"), "set_motion", "get_motion");564ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin"), "set_margin", "get_margin");565ADD_PROPERTY(PropertyInfo(Variant::INT, "max_collisions"), "set_max_collisions", "get_max_collisions");566ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_separation_ray"), "set_collide_separation_ray_enabled", "is_collide_separation_ray_enabled");567ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude_bodies", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude_bodies", "get_exclude_bodies");568ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude_objects"), "set_exclude_objects", "get_exclude_objects");569ADD_PROPERTY(PropertyInfo(Variant::BOOL, "recovery_as_collision"), "set_recovery_as_collision_enabled", "is_recovery_as_collision_enabled");570}571572///////////////////////////////573574Vector3 PhysicsTestMotionResult3D::get_travel() const {575return result.travel;576}577578Vector3 PhysicsTestMotionResult3D::get_remainder() const {579return result.remainder;580}581582real_t PhysicsTestMotionResult3D::get_collision_safe_fraction() const {583return result.collision_safe_fraction;584}585586real_t PhysicsTestMotionResult3D::get_collision_unsafe_fraction() const {587return result.collision_unsafe_fraction;588}589590int PhysicsTestMotionResult3D::get_collision_count() const {591return result.collision_count;592}593594Vector3 PhysicsTestMotionResult3D::get_collision_point(int p_collision_index) const {595ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, Vector3());596return result.collisions[p_collision_index].position;597}598599Vector3 PhysicsTestMotionResult3D::get_collision_normal(int p_collision_index) const {600ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, Vector3());601return result.collisions[p_collision_index].normal;602}603604Vector3 PhysicsTestMotionResult3D::get_collider_velocity(int p_collision_index) const {605ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, Vector3());606return result.collisions[p_collision_index].collider_velocity;607}608609ObjectID PhysicsTestMotionResult3D::get_collider_id(int p_collision_index) const {610ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, ObjectID());611return result.collisions[p_collision_index].collider_id;612}613614RID PhysicsTestMotionResult3D::get_collider_rid(int p_collision_index) const {615ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, RID());616return result.collisions[p_collision_index].collider;617}618619Object *PhysicsTestMotionResult3D::get_collider(int p_collision_index) const {620ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, nullptr);621return ObjectDB::get_instance(result.collisions[p_collision_index].collider_id);622}623624int PhysicsTestMotionResult3D::get_collider_shape(int p_collision_index) const {625ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, 0);626return result.collisions[p_collision_index].collider_shape;627}628629int PhysicsTestMotionResult3D::get_collision_local_shape(int p_collision_index) const {630ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, 0);631return result.collisions[p_collision_index].local_shape;632}633634real_t PhysicsTestMotionResult3D::get_collision_depth(int p_collision_index) const {635ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, 0.0);636return result.collisions[p_collision_index].depth;637}638639void PhysicsTestMotionResult3D::_bind_methods() {640ClassDB::bind_method(D_METHOD("get_travel"), &PhysicsTestMotionResult3D::get_travel);641ClassDB::bind_method(D_METHOD("get_remainder"), &PhysicsTestMotionResult3D::get_remainder);642ClassDB::bind_method(D_METHOD("get_collision_safe_fraction"), &PhysicsTestMotionResult3D::get_collision_safe_fraction);643ClassDB::bind_method(D_METHOD("get_collision_unsafe_fraction"), &PhysicsTestMotionResult3D::get_collision_unsafe_fraction);644ClassDB::bind_method(D_METHOD("get_collision_count"), &PhysicsTestMotionResult3D::get_collision_count);645ClassDB::bind_method(D_METHOD("get_collision_point", "collision_index"), &PhysicsTestMotionResult3D::get_collision_point, DEFVAL(0));646ClassDB::bind_method(D_METHOD("get_collision_normal", "collision_index"), &PhysicsTestMotionResult3D::get_collision_normal, DEFVAL(0));647ClassDB::bind_method(D_METHOD("get_collider_velocity", "collision_index"), &PhysicsTestMotionResult3D::get_collider_velocity, DEFVAL(0));648ClassDB::bind_method(D_METHOD("get_collider_id", "collision_index"), &PhysicsTestMotionResult3D::get_collider_id, DEFVAL(0));649ClassDB::bind_method(D_METHOD("get_collider_rid", "collision_index"), &PhysicsTestMotionResult3D::get_collider_rid, DEFVAL(0));650ClassDB::bind_method(D_METHOD("get_collider", "collision_index"), &PhysicsTestMotionResult3D::get_collider, DEFVAL(0));651ClassDB::bind_method(D_METHOD("get_collider_shape", "collision_index"), &PhysicsTestMotionResult3D::get_collider_shape, DEFVAL(0));652ClassDB::bind_method(D_METHOD("get_collision_local_shape", "collision_index"), &PhysicsTestMotionResult3D::get_collision_local_shape, DEFVAL(0));653ClassDB::bind_method(D_METHOD("get_collision_depth", "collision_index"), &PhysicsTestMotionResult3D::get_collision_depth, DEFVAL(0));654}655656///////////////////////////////////////657658bool PhysicsServer3D::_body_test_motion(RID p_body, const Ref<PhysicsTestMotionParameters3D> &p_parameters, const Ref<PhysicsTestMotionResult3D> &p_result) {659ERR_FAIL_COND_V(p_parameters.is_null(), false);660661MotionResult *result_ptr = nullptr;662if (p_result.is_valid()) {663result_ptr = p_result->get_result_ptr();664}665666return body_test_motion(p_body, p_parameters->get_parameters(), result_ptr);667}668669RID PhysicsServer3D::shape_create(ShapeType p_shape) {670switch (p_shape) {671case SHAPE_WORLD_BOUNDARY:672return world_boundary_shape_create();673case SHAPE_SEPARATION_RAY:674return separation_ray_shape_create();675case SHAPE_SPHERE:676return sphere_shape_create();677case SHAPE_BOX:678return box_shape_create();679case SHAPE_CAPSULE:680return capsule_shape_create();681case SHAPE_CYLINDER:682return cylinder_shape_create();683case SHAPE_CONVEX_POLYGON:684return convex_polygon_shape_create();685case SHAPE_CONCAVE_POLYGON:686return concave_polygon_shape_create();687case SHAPE_HEIGHTMAP:688return heightmap_shape_create();689case SHAPE_CUSTOM:690return custom_shape_create();691default:692return RID();693}694}695696void PhysicsServer3D::_bind_methods() {697#ifndef _3D_DISABLED698699ClassDB::bind_method(D_METHOD("world_boundary_shape_create"), &PhysicsServer3D::world_boundary_shape_create);700ClassDB::bind_method(D_METHOD("separation_ray_shape_create"), &PhysicsServer3D::separation_ray_shape_create);701ClassDB::bind_method(D_METHOD("sphere_shape_create"), &PhysicsServer3D::sphere_shape_create);702ClassDB::bind_method(D_METHOD("box_shape_create"), &PhysicsServer3D::box_shape_create);703ClassDB::bind_method(D_METHOD("capsule_shape_create"), &PhysicsServer3D::capsule_shape_create);704ClassDB::bind_method(D_METHOD("cylinder_shape_create"), &PhysicsServer3D::cylinder_shape_create);705ClassDB::bind_method(D_METHOD("convex_polygon_shape_create"), &PhysicsServer3D::convex_polygon_shape_create);706ClassDB::bind_method(D_METHOD("concave_polygon_shape_create"), &PhysicsServer3D::concave_polygon_shape_create);707ClassDB::bind_method(D_METHOD("heightmap_shape_create"), &PhysicsServer3D::heightmap_shape_create);708ClassDB::bind_method(D_METHOD("custom_shape_create"), &PhysicsServer3D::custom_shape_create);709710ClassDB::bind_method(D_METHOD("shape_set_data", "shape", "data"), &PhysicsServer3D::shape_set_data);711ClassDB::bind_method(D_METHOD("shape_set_margin", "shape", "margin"), &PhysicsServer3D::shape_set_margin);712713ClassDB::bind_method(D_METHOD("shape_get_type", "shape"), &PhysicsServer3D::shape_get_type);714ClassDB::bind_method(D_METHOD("shape_get_data", "shape"), &PhysicsServer3D::shape_get_data);715ClassDB::bind_method(D_METHOD("shape_get_margin", "shape"), &PhysicsServer3D::shape_get_margin);716717ClassDB::bind_method(D_METHOD("space_create"), &PhysicsServer3D::space_create);718ClassDB::bind_method(D_METHOD("space_set_active", "space", "active"), &PhysicsServer3D::space_set_active);719ClassDB::bind_method(D_METHOD("space_is_active", "space"), &PhysicsServer3D::space_is_active);720ClassDB::bind_method(D_METHOD("space_set_param", "space", "param", "value"), &PhysicsServer3D::space_set_param);721ClassDB::bind_method(D_METHOD("space_get_param", "space", "param"), &PhysicsServer3D::space_get_param);722ClassDB::bind_method(D_METHOD("space_get_direct_state", "space"), &PhysicsServer3D::space_get_direct_state);723724ClassDB::bind_method(D_METHOD("area_create"), &PhysicsServer3D::area_create);725ClassDB::bind_method(D_METHOD("area_set_space", "area", "space"), &PhysicsServer3D::area_set_space);726ClassDB::bind_method(D_METHOD("area_get_space", "area"), &PhysicsServer3D::area_get_space);727728ClassDB::bind_method(D_METHOD("area_add_shape", "area", "shape", "transform", "disabled"), &PhysicsServer3D::area_add_shape, DEFVAL(Transform3D()), DEFVAL(false));729ClassDB::bind_method(D_METHOD("area_set_shape", "area", "shape_idx", "shape"), &PhysicsServer3D::area_set_shape);730ClassDB::bind_method(D_METHOD("area_set_shape_transform", "area", "shape_idx", "transform"), &PhysicsServer3D::area_set_shape_transform);731ClassDB::bind_method(D_METHOD("area_set_shape_disabled", "area", "shape_idx", "disabled"), &PhysicsServer3D::area_set_shape_disabled);732733ClassDB::bind_method(D_METHOD("area_get_shape_count", "area"), &PhysicsServer3D::area_get_shape_count);734ClassDB::bind_method(D_METHOD("area_get_shape", "area", "shape_idx"), &PhysicsServer3D::area_get_shape);735ClassDB::bind_method(D_METHOD("area_get_shape_transform", "area", "shape_idx"), &PhysicsServer3D::area_get_shape_transform);736737ClassDB::bind_method(D_METHOD("area_remove_shape", "area", "shape_idx"), &PhysicsServer3D::area_remove_shape);738ClassDB::bind_method(D_METHOD("area_clear_shapes", "area"), &PhysicsServer3D::area_clear_shapes);739740ClassDB::bind_method(D_METHOD("area_set_collision_layer", "area", "layer"), &PhysicsServer3D::area_set_collision_layer);741ClassDB::bind_method(D_METHOD("area_get_collision_layer", "area"), &PhysicsServer3D::area_get_collision_layer);742743ClassDB::bind_method(D_METHOD("area_set_collision_mask", "area", "mask"), &PhysicsServer3D::area_set_collision_mask);744ClassDB::bind_method(D_METHOD("area_get_collision_mask", "area"), &PhysicsServer3D::area_get_collision_mask);745746ClassDB::bind_method(D_METHOD("area_set_param", "area", "param", "value"), &PhysicsServer3D::area_set_param);747ClassDB::bind_method(D_METHOD("area_set_transform", "area", "transform"), &PhysicsServer3D::area_set_transform);748749ClassDB::bind_method(D_METHOD("area_get_param", "area", "param"), &PhysicsServer3D::area_get_param);750ClassDB::bind_method(D_METHOD("area_get_transform", "area"), &PhysicsServer3D::area_get_transform);751752ClassDB::bind_method(D_METHOD("area_attach_object_instance_id", "area", "id"), &PhysicsServer3D::area_attach_object_instance_id);753ClassDB::bind_method(D_METHOD("area_get_object_instance_id", "area"), &PhysicsServer3D::area_get_object_instance_id);754755ClassDB::bind_method(D_METHOD("area_set_monitor_callback", "area", "callback"), &PhysicsServer3D::area_set_monitor_callback);756ClassDB::bind_method(D_METHOD("area_set_area_monitor_callback", "area", "callback"), &PhysicsServer3D::area_set_area_monitor_callback);757ClassDB::bind_method(D_METHOD("area_set_monitorable", "area", "monitorable"), &PhysicsServer3D::area_set_monitorable);758759ClassDB::bind_method(D_METHOD("area_set_ray_pickable", "area", "enable"), &PhysicsServer3D::area_set_ray_pickable);760761ClassDB::bind_method(D_METHOD("body_create"), &PhysicsServer3D::body_create);762763ClassDB::bind_method(D_METHOD("body_set_space", "body", "space"), &PhysicsServer3D::body_set_space);764ClassDB::bind_method(D_METHOD("body_get_space", "body"), &PhysicsServer3D::body_get_space);765766ClassDB::bind_method(D_METHOD("body_set_mode", "body", "mode"), &PhysicsServer3D::body_set_mode);767ClassDB::bind_method(D_METHOD("body_get_mode", "body"), &PhysicsServer3D::body_get_mode);768769ClassDB::bind_method(D_METHOD("body_set_collision_layer", "body", "layer"), &PhysicsServer3D::body_set_collision_layer);770ClassDB::bind_method(D_METHOD("body_get_collision_layer", "body"), &PhysicsServer3D::body_get_collision_layer);771772ClassDB::bind_method(D_METHOD("body_set_collision_mask", "body", "mask"), &PhysicsServer3D::body_set_collision_mask);773ClassDB::bind_method(D_METHOD("body_get_collision_mask", "body"), &PhysicsServer3D::body_get_collision_mask);774775ClassDB::bind_method(D_METHOD("body_set_collision_priority", "body", "priority"), &PhysicsServer3D::body_set_collision_priority);776ClassDB::bind_method(D_METHOD("body_get_collision_priority", "body"), &PhysicsServer3D::body_get_collision_priority);777778ClassDB::bind_method(D_METHOD("body_add_shape", "body", "shape", "transform", "disabled"), &PhysicsServer3D::body_add_shape, DEFVAL(Transform3D()), DEFVAL(false));779ClassDB::bind_method(D_METHOD("body_set_shape", "body", "shape_idx", "shape"), &PhysicsServer3D::body_set_shape);780ClassDB::bind_method(D_METHOD("body_set_shape_transform", "body", "shape_idx", "transform"), &PhysicsServer3D::body_set_shape_transform);781ClassDB::bind_method(D_METHOD("body_set_shape_disabled", "body", "shape_idx", "disabled"), &PhysicsServer3D::body_set_shape_disabled);782783ClassDB::bind_method(D_METHOD("body_get_shape_count", "body"), &PhysicsServer3D::body_get_shape_count);784ClassDB::bind_method(D_METHOD("body_get_shape", "body", "shape_idx"), &PhysicsServer3D::body_get_shape);785ClassDB::bind_method(D_METHOD("body_get_shape_transform", "body", "shape_idx"), &PhysicsServer3D::body_get_shape_transform);786787ClassDB::bind_method(D_METHOD("body_remove_shape", "body", "shape_idx"), &PhysicsServer3D::body_remove_shape);788ClassDB::bind_method(D_METHOD("body_clear_shapes", "body"), &PhysicsServer3D::body_clear_shapes);789790ClassDB::bind_method(D_METHOD("body_attach_object_instance_id", "body", "id"), &PhysicsServer3D::body_attach_object_instance_id);791ClassDB::bind_method(D_METHOD("body_get_object_instance_id", "body"), &PhysicsServer3D::body_get_object_instance_id);792793ClassDB::bind_method(D_METHOD("body_set_enable_continuous_collision_detection", "body", "enable"), &PhysicsServer3D::body_set_enable_continuous_collision_detection);794ClassDB::bind_method(D_METHOD("body_is_continuous_collision_detection_enabled", "body"), &PhysicsServer3D::body_is_continuous_collision_detection_enabled);795796ClassDB::bind_method(D_METHOD("body_set_param", "body", "param", "value"), &PhysicsServer3D::body_set_param);797ClassDB::bind_method(D_METHOD("body_get_param", "body", "param"), &PhysicsServer3D::body_get_param);798799ClassDB::bind_method(D_METHOD("body_reset_mass_properties", "body"), &PhysicsServer3D::body_reset_mass_properties);800801ClassDB::bind_method(D_METHOD("body_set_state", "body", "state", "value"), &PhysicsServer3D::body_set_state);802ClassDB::bind_method(D_METHOD("body_get_state", "body", "state"), &PhysicsServer3D::body_get_state);803804ClassDB::bind_method(D_METHOD("body_apply_central_impulse", "body", "impulse"), &PhysicsServer3D::body_apply_central_impulse);805ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "impulse", "position"), &PhysicsServer3D::body_apply_impulse, Vector3());806ClassDB::bind_method(D_METHOD("body_apply_torque_impulse", "body", "impulse"), &PhysicsServer3D::body_apply_torque_impulse);807808ClassDB::bind_method(D_METHOD("body_apply_central_force", "body", "force"), &PhysicsServer3D::body_apply_central_force);809ClassDB::bind_method(D_METHOD("body_apply_force", "body", "force", "position"), &PhysicsServer3D::body_apply_force, Vector3());810ClassDB::bind_method(D_METHOD("body_apply_torque", "body", "torque"), &PhysicsServer3D::body_apply_torque);811812ClassDB::bind_method(D_METHOD("body_add_constant_central_force", "body", "force"), &PhysicsServer3D::body_add_constant_central_force);813ClassDB::bind_method(D_METHOD("body_add_constant_force", "body", "force", "position"), &PhysicsServer3D::body_add_constant_force, Vector3());814ClassDB::bind_method(D_METHOD("body_add_constant_torque", "body", "torque"), &PhysicsServer3D::body_add_constant_torque);815816ClassDB::bind_method(D_METHOD("body_set_constant_force", "body", "force"), &PhysicsServer3D::body_set_constant_force);817ClassDB::bind_method(D_METHOD("body_get_constant_force", "body"), &PhysicsServer3D::body_get_constant_force);818819ClassDB::bind_method(D_METHOD("body_set_constant_torque", "body", "torque"), &PhysicsServer3D::body_set_constant_torque);820ClassDB::bind_method(D_METHOD("body_get_constant_torque", "body"), &PhysicsServer3D::body_get_constant_torque);821822ClassDB::bind_method(D_METHOD("body_set_axis_velocity", "body", "axis_velocity"), &PhysicsServer3D::body_set_axis_velocity);823824ClassDB::bind_method(D_METHOD("body_set_axis_lock", "body", "axis", "lock"), &PhysicsServer3D::body_set_axis_lock);825ClassDB::bind_method(D_METHOD("body_is_axis_locked", "body", "axis"), &PhysicsServer3D::body_is_axis_locked);826827ClassDB::bind_method(D_METHOD("body_add_collision_exception", "body", "excepted_body"), &PhysicsServer3D::body_add_collision_exception);828ClassDB::bind_method(D_METHOD("body_remove_collision_exception", "body", "excepted_body"), &PhysicsServer3D::body_remove_collision_exception);829830ClassDB::bind_method(D_METHOD("body_set_max_contacts_reported", "body", "amount"), &PhysicsServer3D::body_set_max_contacts_reported);831ClassDB::bind_method(D_METHOD("body_get_max_contacts_reported", "body"), &PhysicsServer3D::body_get_max_contacts_reported);832833ClassDB::bind_method(D_METHOD("body_set_omit_force_integration", "body", "enable"), &PhysicsServer3D::body_set_omit_force_integration);834ClassDB::bind_method(D_METHOD("body_is_omitting_force_integration", "body"), &PhysicsServer3D::body_is_omitting_force_integration);835836ClassDB::bind_method(D_METHOD("body_set_state_sync_callback", "body", "callable"), &PhysicsServer3D::body_set_state_sync_callback);837838ClassDB::bind_method(D_METHOD("body_set_force_integration_callback", "body", "callable", "userdata"), &PhysicsServer3D::body_set_force_integration_callback, DEFVAL(Variant()));839840ClassDB::bind_method(D_METHOD("body_set_ray_pickable", "body", "enable"), &PhysicsServer3D::body_set_ray_pickable);841842ClassDB::bind_method(D_METHOD("body_test_motion", "body", "parameters", "result"), &PhysicsServer3D::_body_test_motion, DEFVAL(Variant()));843844ClassDB::bind_method(D_METHOD("body_get_direct_state", "body"), &PhysicsServer3D::body_get_direct_state);845846/* SOFT BODY API */847848ClassDB::bind_method(D_METHOD("soft_body_create"), &PhysicsServer3D::soft_body_create);849850ClassDB::bind_method(D_METHOD("soft_body_update_rendering_server", "body", "rendering_server_handler"), &PhysicsServer3D::soft_body_update_rendering_server);851852ClassDB::bind_method(D_METHOD("soft_body_set_space", "body", "space"), &PhysicsServer3D::soft_body_set_space);853ClassDB::bind_method(D_METHOD("soft_body_get_space", "body"), &PhysicsServer3D::soft_body_get_space);854855ClassDB::bind_method(D_METHOD("soft_body_set_mesh", "body", "mesh"), &PhysicsServer3D::soft_body_set_mesh);856857ClassDB::bind_method(D_METHOD("soft_body_get_bounds", "body"), &PhysicsServer3D::soft_body_get_bounds);858859ClassDB::bind_method(D_METHOD("soft_body_set_collision_layer", "body", "layer"), &PhysicsServer3D::soft_body_set_collision_layer);860ClassDB::bind_method(D_METHOD("soft_body_get_collision_layer", "body"), &PhysicsServer3D::soft_body_get_collision_layer);861862ClassDB::bind_method(D_METHOD("soft_body_set_collision_mask", "body", "mask"), &PhysicsServer3D::soft_body_set_collision_mask);863ClassDB::bind_method(D_METHOD("soft_body_get_collision_mask", "body"), &PhysicsServer3D::soft_body_get_collision_mask);864865ClassDB::bind_method(D_METHOD("soft_body_add_collision_exception", "body", "body_b"), &PhysicsServer3D::soft_body_add_collision_exception);866ClassDB::bind_method(D_METHOD("soft_body_remove_collision_exception", "body", "body_b"), &PhysicsServer3D::soft_body_remove_collision_exception);867868ClassDB::bind_method(D_METHOD("soft_body_set_state", "body", "state", "variant"), &PhysicsServer3D::soft_body_set_state);869ClassDB::bind_method(D_METHOD("soft_body_get_state", "body", "state"), &PhysicsServer3D::soft_body_get_state);870871ClassDB::bind_method(D_METHOD("soft_body_set_transform", "body", "transform"), &PhysicsServer3D::soft_body_set_transform);872873ClassDB::bind_method(D_METHOD("soft_body_set_ray_pickable", "body", "enable"), &PhysicsServer3D::soft_body_set_ray_pickable);874875ClassDB::bind_method(D_METHOD("soft_body_set_simulation_precision", "body", "simulation_precision"), &PhysicsServer3D::soft_body_set_simulation_precision);876ClassDB::bind_method(D_METHOD("soft_body_get_simulation_precision", "body"), &PhysicsServer3D::soft_body_get_simulation_precision);877878ClassDB::bind_method(D_METHOD("soft_body_set_total_mass", "body", "total_mass"), &PhysicsServer3D::soft_body_set_total_mass);879ClassDB::bind_method(D_METHOD("soft_body_get_total_mass", "body"), &PhysicsServer3D::soft_body_get_total_mass);880881ClassDB::bind_method(D_METHOD("soft_body_set_linear_stiffness", "body", "stiffness"), &PhysicsServer3D::soft_body_set_linear_stiffness);882ClassDB::bind_method(D_METHOD("soft_body_get_linear_stiffness", "body"), &PhysicsServer3D::soft_body_get_linear_stiffness);883884ClassDB::bind_method(D_METHOD("soft_body_set_shrinking_factor", "body", "shrinking_factor"), &PhysicsServer3D::soft_body_set_shrinking_factor);885ClassDB::bind_method(D_METHOD("soft_body_get_shrinking_factor", "body"), &PhysicsServer3D::soft_body_get_shrinking_factor);886887ClassDB::bind_method(D_METHOD("soft_body_set_pressure_coefficient", "body", "pressure_coefficient"), &PhysicsServer3D::soft_body_set_pressure_coefficient);888ClassDB::bind_method(D_METHOD("soft_body_get_pressure_coefficient", "body"), &PhysicsServer3D::soft_body_get_pressure_coefficient);889890ClassDB::bind_method(D_METHOD("soft_body_set_damping_coefficient", "body", "damping_coefficient"), &PhysicsServer3D::soft_body_set_damping_coefficient);891ClassDB::bind_method(D_METHOD("soft_body_get_damping_coefficient", "body"), &PhysicsServer3D::soft_body_get_damping_coefficient);892893ClassDB::bind_method(D_METHOD("soft_body_set_drag_coefficient", "body", "drag_coefficient"), &PhysicsServer3D::soft_body_set_drag_coefficient);894ClassDB::bind_method(D_METHOD("soft_body_get_drag_coefficient", "body"), &PhysicsServer3D::soft_body_get_drag_coefficient);895896ClassDB::bind_method(D_METHOD("soft_body_move_point", "body", "point_index", "global_position"), &PhysicsServer3D::soft_body_move_point);897ClassDB::bind_method(D_METHOD("soft_body_get_point_global_position", "body", "point_index"), &PhysicsServer3D::soft_body_get_point_global_position);898899ClassDB::bind_method(D_METHOD("soft_body_remove_all_pinned_points", "body"), &PhysicsServer3D::soft_body_remove_all_pinned_points);900901ClassDB::bind_method(D_METHOD("soft_body_pin_point", "body", "point_index", "pin"), &PhysicsServer3D::soft_body_pin_point);902903ClassDB::bind_method(D_METHOD("soft_body_is_point_pinned", "body", "point_index"), &PhysicsServer3D::soft_body_is_point_pinned);904905ClassDB::bind_method(D_METHOD("soft_body_apply_point_impulse", "body", "point_index", "impulse"), &PhysicsServer3D::soft_body_apply_point_impulse);906ClassDB::bind_method(D_METHOD("soft_body_apply_point_force", "body", "point_index", "force"), &PhysicsServer3D::soft_body_apply_point_force);907ClassDB::bind_method(D_METHOD("soft_body_apply_central_impulse", "body", "impulse"), &PhysicsServer3D::soft_body_apply_central_impulse);908ClassDB::bind_method(D_METHOD("soft_body_apply_central_force", "body", "force"), &PhysicsServer3D::soft_body_apply_central_force);909910/* JOINT API */911912ClassDB::bind_method(D_METHOD("joint_create"), &PhysicsServer3D::joint_create);913ClassDB::bind_method(D_METHOD("joint_clear", "joint"), &PhysicsServer3D::joint_clear);914915BIND_ENUM_CONSTANT(JOINT_TYPE_PIN);916BIND_ENUM_CONSTANT(JOINT_TYPE_HINGE);917BIND_ENUM_CONSTANT(JOINT_TYPE_SLIDER);918BIND_ENUM_CONSTANT(JOINT_TYPE_CONE_TWIST);919BIND_ENUM_CONSTANT(JOINT_TYPE_6DOF);920BIND_ENUM_CONSTANT(JOINT_TYPE_MAX);921922ClassDB::bind_method(D_METHOD("joint_make_pin", "joint", "body_A", "local_A", "body_B", "local_B"), &PhysicsServer3D::joint_make_pin);923ClassDB::bind_method(D_METHOD("pin_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::pin_joint_set_param);924ClassDB::bind_method(D_METHOD("pin_joint_get_param", "joint", "param"), &PhysicsServer3D::pin_joint_get_param);925926ClassDB::bind_method(D_METHOD("pin_joint_set_local_a", "joint", "local_A"), &PhysicsServer3D::pin_joint_set_local_a);927ClassDB::bind_method(D_METHOD("pin_joint_get_local_a", "joint"), &PhysicsServer3D::pin_joint_get_local_a);928929ClassDB::bind_method(D_METHOD("pin_joint_set_local_b", "joint", "local_B"), &PhysicsServer3D::pin_joint_set_local_b);930ClassDB::bind_method(D_METHOD("pin_joint_get_local_b", "joint"), &PhysicsServer3D::pin_joint_get_local_b);931932BIND_ENUM_CONSTANT(PIN_JOINT_BIAS);933BIND_ENUM_CONSTANT(PIN_JOINT_DAMPING);934BIND_ENUM_CONSTANT(PIN_JOINT_IMPULSE_CLAMP);935936BIND_ENUM_CONSTANT(HINGE_JOINT_BIAS);937BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_UPPER);938BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_LOWER);939BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_BIAS);940BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_SOFTNESS);941BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_RELAXATION);942BIND_ENUM_CONSTANT(HINGE_JOINT_MOTOR_TARGET_VELOCITY);943BIND_ENUM_CONSTANT(HINGE_JOINT_MOTOR_MAX_IMPULSE);944945BIND_ENUM_CONSTANT(HINGE_JOINT_FLAG_USE_LIMIT);946BIND_ENUM_CONSTANT(HINGE_JOINT_FLAG_ENABLE_MOTOR);947948ClassDB::bind_method(D_METHOD("joint_make_hinge", "joint", "body_A", "hinge_A", "body_B", "hinge_B"), &PhysicsServer3D::joint_make_hinge);949950ClassDB::bind_method(D_METHOD("hinge_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::hinge_joint_set_param);951ClassDB::bind_method(D_METHOD("hinge_joint_get_param", "joint", "param"), &PhysicsServer3D::hinge_joint_get_param);952953ClassDB::bind_method(D_METHOD("hinge_joint_set_flag", "joint", "flag", "enabled"), &PhysicsServer3D::hinge_joint_set_flag);954ClassDB::bind_method(D_METHOD("hinge_joint_get_flag", "joint", "flag"), &PhysicsServer3D::hinge_joint_get_flag);955956ClassDB::bind_method(D_METHOD("joint_make_slider", "joint", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer3D::joint_make_slider);957958ClassDB::bind_method(D_METHOD("slider_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::slider_joint_set_param);959ClassDB::bind_method(D_METHOD("slider_joint_get_param", "joint", "param"), &PhysicsServer3D::slider_joint_get_param);960961BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_UPPER);962BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_LOWER);963BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS);964BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION);965BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_DAMPING);966BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_SOFTNESS);967BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_RESTITUTION);968BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_DAMPING);969BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS);970BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION);971BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING);972973BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_UPPER);974BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_LOWER);975BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS);976BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION);977BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_DAMPING);978BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS);979BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION);980BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_DAMPING);981BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS);982BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION);983BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING);984BIND_ENUM_CONSTANT(SLIDER_JOINT_MAX);985986ClassDB::bind_method(D_METHOD("joint_make_cone_twist", "joint", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer3D::joint_make_cone_twist);987988ClassDB::bind_method(D_METHOD("cone_twist_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::cone_twist_joint_set_param);989ClassDB::bind_method(D_METHOD("cone_twist_joint_get_param", "joint", "param"), &PhysicsServer3D::cone_twist_joint_get_param);990991BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_SWING_SPAN);992BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_TWIST_SPAN);993BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_BIAS);994BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_SOFTNESS);995BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_RELAXATION);996997BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_LOWER_LIMIT);998BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_UPPER_LIMIT);999BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS);1000BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_RESTITUTION);1001BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_DAMPING);1002BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY);1003BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT);1004BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_SPRING_STIFFNESS);1005BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_SPRING_DAMPING);1006BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT);1007BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LOWER_LIMIT);1008BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_UPPER_LIMIT);1009BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS);1010BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_DAMPING);1011BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_RESTITUTION);1012BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_FORCE_LIMIT);1013BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_ERP);1014BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY);1015BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT);1016BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS);1017BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_SPRING_DAMPING);1018BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT);1019BIND_ENUM_CONSTANT(G6DOF_JOINT_MAX);10201021BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT);1022BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT);1023BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING);1024BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING);1025BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_MOTOR);1026BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR);1027BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_MAX);10281029ClassDB::bind_method(D_METHOD("joint_get_type", "joint"), &PhysicsServer3D::joint_get_type);10301031ClassDB::bind_method(D_METHOD("joint_set_solver_priority", "joint", "priority"), &PhysicsServer3D::joint_set_solver_priority);1032ClassDB::bind_method(D_METHOD("joint_get_solver_priority", "joint"), &PhysicsServer3D::joint_get_solver_priority);10331034ClassDB::bind_method(D_METHOD("joint_disable_collisions_between_bodies", "joint", "disable"), &PhysicsServer3D::joint_disable_collisions_between_bodies);1035ClassDB::bind_method(D_METHOD("joint_is_disabled_collisions_between_bodies", "joint"), &PhysicsServer3D::joint_is_disabled_collisions_between_bodies);10361037ClassDB::bind_method(D_METHOD("joint_make_generic_6dof", "joint", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer3D::joint_make_generic_6dof);10381039ClassDB::bind_method(D_METHOD("generic_6dof_joint_set_param", "joint", "axis", "param", "value"), &PhysicsServer3D::generic_6dof_joint_set_param);1040ClassDB::bind_method(D_METHOD("generic_6dof_joint_get_param", "joint", "axis", "param"), &PhysicsServer3D::generic_6dof_joint_get_param);10411042ClassDB::bind_method(D_METHOD("generic_6dof_joint_set_flag", "joint", "axis", "flag", "enable"), &PhysicsServer3D::generic_6dof_joint_set_flag);1043ClassDB::bind_method(D_METHOD("generic_6dof_joint_get_flag", "joint", "axis", "flag"), &PhysicsServer3D::generic_6dof_joint_get_flag);10441045ClassDB::bind_method(D_METHOD("free_rid", "rid"), &PhysicsServer3D::free_rid);10461047ClassDB::bind_method(D_METHOD("set_active", "active"), &PhysicsServer3D::set_active);10481049ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &PhysicsServer3D::get_process_info);10501051BIND_ENUM_CONSTANT(SHAPE_WORLD_BOUNDARY);1052BIND_ENUM_CONSTANT(SHAPE_SEPARATION_RAY);1053BIND_ENUM_CONSTANT(SHAPE_SPHERE);1054BIND_ENUM_CONSTANT(SHAPE_BOX);1055BIND_ENUM_CONSTANT(SHAPE_CAPSULE);1056BIND_ENUM_CONSTANT(SHAPE_CYLINDER);1057BIND_ENUM_CONSTANT(SHAPE_CONVEX_POLYGON);1058BIND_ENUM_CONSTANT(SHAPE_CONCAVE_POLYGON);1059BIND_ENUM_CONSTANT(SHAPE_HEIGHTMAP);1060BIND_ENUM_CONSTANT(SHAPE_SOFT_BODY);1061BIND_ENUM_CONSTANT(SHAPE_CUSTOM);10621063BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_OVERRIDE_MODE);1064BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY);1065BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_VECTOR);1066BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_IS_POINT);1067BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE);1068BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE);1069BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP);1070BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE);1071BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP);1072BIND_ENUM_CONSTANT(AREA_PARAM_PRIORITY);1073BIND_ENUM_CONSTANT(AREA_PARAM_WIND_FORCE_MAGNITUDE);1074BIND_ENUM_CONSTANT(AREA_PARAM_WIND_SOURCE);1075BIND_ENUM_CONSTANT(AREA_PARAM_WIND_DIRECTION);1076BIND_ENUM_CONSTANT(AREA_PARAM_WIND_ATTENUATION_FACTOR);10771078BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_DISABLED);1079BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE);1080BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE_REPLACE);1081BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE);1082BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE_COMBINE);10831084BIND_ENUM_CONSTANT(BODY_MODE_STATIC);1085BIND_ENUM_CONSTANT(BODY_MODE_KINEMATIC);1086BIND_ENUM_CONSTANT(BODY_MODE_RIGID);1087BIND_ENUM_CONSTANT(BODY_MODE_RIGID_LINEAR);10881089BIND_ENUM_CONSTANT(BODY_PARAM_BOUNCE);1090BIND_ENUM_CONSTANT(BODY_PARAM_FRICTION);1091BIND_ENUM_CONSTANT(BODY_PARAM_MASS);1092BIND_ENUM_CONSTANT(BODY_PARAM_INERTIA);1093BIND_ENUM_CONSTANT(BODY_PARAM_CENTER_OF_MASS);1094BIND_ENUM_CONSTANT(BODY_PARAM_GRAVITY_SCALE);1095BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP_MODE);1096BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP_MODE);1097BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP);1098BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP);1099BIND_ENUM_CONSTANT(BODY_PARAM_MAX);11001101BIND_ENUM_CONSTANT(BODY_DAMP_MODE_COMBINE);1102BIND_ENUM_CONSTANT(BODY_DAMP_MODE_REPLACE);11031104BIND_ENUM_CONSTANT(BODY_STATE_TRANSFORM);1105BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY);1106BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY);1107BIND_ENUM_CONSTANT(BODY_STATE_SLEEPING);1108BIND_ENUM_CONSTANT(BODY_STATE_CAN_SLEEP);11091110BIND_ENUM_CONSTANT(AREA_BODY_ADDED);1111BIND_ENUM_CONSTANT(AREA_BODY_REMOVED);11121113BIND_ENUM_CONSTANT(INFO_ACTIVE_OBJECTS);1114BIND_ENUM_CONSTANT(INFO_COLLISION_PAIRS);1115BIND_ENUM_CONSTANT(INFO_ISLAND_COUNT);11161117BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_RECYCLE_RADIUS);1118BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_SEPARATION);1119BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION);1120BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_DEFAULT_BIAS);1121BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD);1122BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD);1123BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_TIME_TO_SLEEP);1124BIND_ENUM_CONSTANT(SPACE_PARAM_SOLVER_ITERATIONS);11251126BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_X);1127BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Y);1128BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Z);1129BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_X);1130BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_Y);1131BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_Z);11321133#endif1134}11351136PhysicsServer3D::PhysicsServer3D() {1137singleton = this;11381139// World3D physics space1140GLOBAL_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);1141GLOBAL_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));1142GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/default_linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), 0.1);1143GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/default_angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), 0.1);11441145// PhysicsServer3D1146GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/sleep_threshold_linear", PROPERTY_HINT_RANGE, "0,1,0.001,or_greater"), 0.1);1147GLOBAL_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));1148GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/time_before_sleep", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater"), 0.5);1149GLOBAL_DEF(PropertyInfo(Variant::INT, "physics/3d/solver/solver_iterations", PROPERTY_HINT_RANGE, "1,32,1,or_greater"), 16);1150GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_recycle_radius", PROPERTY_HINT_RANGE, "0,0.1,0.001,or_greater"), 0.01);1151GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_max_separation", PROPERTY_HINT_RANGE, "0,0.1,0.001,or_greater"), 0.05);1152GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_max_allowed_penetration", PROPERTY_HINT_RANGE, "0.001,0.1,0.001,or_greater"), 0.01);1153GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/default_contact_bias", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.8);1154}11551156PhysicsServer3D::~PhysicsServer3D() {1157singleton = nullptr;1158}11591160PhysicsServer3DManager *PhysicsServer3DManager::singleton = nullptr;1161const String PhysicsServer3DManager::setting_property_name(PNAME("physics/3d/physics_engine"));11621163void PhysicsServer3DManager::on_servers_changed() {1164String physics_servers2("DEFAULT");1165for (int i = get_servers_count() - 1; 0 <= i; --i) {1166physics_servers2 += "," + get_server_name(i);1167}1168ProjectSettings::get_singleton()->set_custom_property_info(PropertyInfo(Variant::STRING, setting_property_name, PROPERTY_HINT_ENUM, physics_servers2));1169ProjectSettings::get_singleton()->set_restart_if_changed(setting_property_name, true);1170ProjectSettings::get_singleton()->set_as_basic(setting_property_name, true);1171}11721173void PhysicsServer3DManager::_bind_methods() {1174ClassDB::bind_method(D_METHOD("register_server", "name", "create_callback"), &PhysicsServer3DManager::register_server);1175ClassDB::bind_method(D_METHOD("set_default_server", "name", "priority"), &PhysicsServer3DManager::set_default_server);1176}11771178PhysicsServer3DManager *PhysicsServer3DManager::get_singleton() {1179return singleton;1180}11811182void PhysicsServer3DManager::register_server(const String &p_name, const Callable &p_create_callback) {1183//ERR_FAIL_COND(!p_create_callback.is_valid());1184ERR_FAIL_COND(find_server_id(p_name) != -1);1185physics_servers.push_back(ClassInfo(p_name, p_create_callback));1186on_servers_changed();1187}11881189void PhysicsServer3DManager::set_default_server(const String &p_name, int p_priority) {1190const int id = find_server_id(p_name);1191ERR_FAIL_COND(id == -1); // Not found1192if (default_server_priority < p_priority) {1193default_server_id = id;1194default_server_priority = p_priority;1195}1196}11971198int PhysicsServer3DManager::find_server_id(const String &p_name) {1199for (int i = physics_servers.size() - 1; 0 <= i; --i) {1200if (p_name == physics_servers[i].name) {1201return i;1202}1203}1204return -1;1205}12061207int PhysicsServer3DManager::get_servers_count() {1208return physics_servers.size();1209}12101211String PhysicsServer3DManager::get_server_name(int p_id) {1212ERR_FAIL_INDEX_V(p_id, get_servers_count(), "");1213return physics_servers[p_id].name;1214}12151216PhysicsServer3D *PhysicsServer3DManager::new_default_server() {1217if (default_server_id == -1) {1218return nullptr;1219}1220Variant ret;1221Callable::CallError ce;1222physics_servers[default_server_id].create_callback.callp(nullptr, 0, ret, ce);1223ERR_FAIL_COND_V(ce.error != Callable::CallError::CALL_OK, nullptr);1224return Object::cast_to<PhysicsServer3D>(ret.get_validated_object());1225}12261227PhysicsServer3D *PhysicsServer3DManager::new_server(const String &p_name) {1228int id = find_server_id(p_name);1229if (id == -1) {1230return nullptr;1231} else {1232Variant ret;1233Callable::CallError ce;1234physics_servers[id].create_callback.callp(nullptr, 0, ret, ce);1235ERR_FAIL_COND_V(ce.error != Callable::CallError::CALL_OK, nullptr);1236return Object::cast_to<PhysicsServer3D>(ret.get_validated_object());1237}1238}12391240PhysicsServer3DManager::PhysicsServer3DManager() {1241singleton = this;1242}12431244PhysicsServer3DManager::~PhysicsServer3DManager() {1245singleton = nullptr;1246}124712481249