Path: blob/master/modules/jolt_physics/jolt_physics_server_3d.cpp
10277 views
/**************************************************************************/1/* jolt_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 "jolt_physics_server_3d.h"3132#include "joints/jolt_cone_twist_joint_3d.h"33#include "joints/jolt_generic_6dof_joint_3d.h"34#include "joints/jolt_hinge_joint_3d.h"35#include "joints/jolt_joint_3d.h"36#include "joints/jolt_pin_joint_3d.h"37#include "joints/jolt_slider_joint_3d.h"38#include "objects/jolt_area_3d.h"39#include "objects/jolt_body_3d.h"40#include "objects/jolt_soft_body_3d.h"41#include "servers/physics_server_3d_wrap_mt.h"42#include "shapes/jolt_box_shape_3d.h"43#include "shapes/jolt_capsule_shape_3d.h"44#include "shapes/jolt_concave_polygon_shape_3d.h"45#include "shapes/jolt_convex_polygon_shape_3d.h"46#include "shapes/jolt_cylinder_shape_3d.h"47#include "shapes/jolt_height_map_shape_3d.h"48#include "shapes/jolt_separation_ray_shape_3d.h"49#include "shapes/jolt_sphere_shape_3d.h"50#include "shapes/jolt_world_boundary_shape_3d.h"51#include "spaces/jolt_job_system.h"52#include "spaces/jolt_physics_direct_space_state_3d.h"53#include "spaces/jolt_space_3d.h"5455JoltPhysicsServer3D::JoltPhysicsServer3D(bool p_on_separate_thread) :56on_separate_thread(p_on_separate_thread) {57singleton = this;58}5960JoltPhysicsServer3D::~JoltPhysicsServer3D() {61if (singleton == this) {62singleton = nullptr;63}64}6566RID JoltPhysicsServer3D::world_boundary_shape_create() {67JoltShape3D *shape = memnew(JoltWorldBoundaryShape3D);68RID rid = shape_owner.make_rid(shape);69shape->set_rid(rid);70return rid;71}7273RID JoltPhysicsServer3D::separation_ray_shape_create() {74JoltShape3D *shape = memnew(JoltSeparationRayShape3D);75RID rid = shape_owner.make_rid(shape);76shape->set_rid(rid);77return rid;78}7980RID JoltPhysicsServer3D::sphere_shape_create() {81JoltShape3D *shape = memnew(JoltSphereShape3D);82RID rid = shape_owner.make_rid(shape);83shape->set_rid(rid);84return rid;85}8687RID JoltPhysicsServer3D::box_shape_create() {88JoltShape3D *shape = memnew(JoltBoxShape3D);89RID rid = shape_owner.make_rid(shape);90shape->set_rid(rid);91return rid;92}9394RID JoltPhysicsServer3D::capsule_shape_create() {95JoltShape3D *shape = memnew(JoltCapsuleShape3D);96RID rid = shape_owner.make_rid(shape);97shape->set_rid(rid);98return rid;99}100101RID JoltPhysicsServer3D::cylinder_shape_create() {102JoltShape3D *shape = memnew(JoltCylinderShape3D);103RID rid = shape_owner.make_rid(shape);104shape->set_rid(rid);105return rid;106}107108RID JoltPhysicsServer3D::convex_polygon_shape_create() {109JoltShape3D *shape = memnew(JoltConvexPolygonShape3D);110RID rid = shape_owner.make_rid(shape);111shape->set_rid(rid);112return rid;113}114115RID JoltPhysicsServer3D::concave_polygon_shape_create() {116JoltShape3D *shape = memnew(JoltConcavePolygonShape3D);117RID rid = shape_owner.make_rid(shape);118shape->set_rid(rid);119return rid;120}121122RID JoltPhysicsServer3D::heightmap_shape_create() {123JoltShape3D *shape = memnew(JoltHeightMapShape3D);124RID rid = shape_owner.make_rid(shape);125shape->set_rid(rid);126return rid;127}128129RID JoltPhysicsServer3D::custom_shape_create() {130ERR_FAIL_V_MSG(RID(), "Custom shapes are not supported.");131}132133void JoltPhysicsServer3D::shape_set_data(RID p_shape, const Variant &p_data) {134JoltShape3D *shape = shape_owner.get_or_null(p_shape);135ERR_FAIL_NULL(shape);136137shape->set_data(p_data);138}139140Variant JoltPhysicsServer3D::shape_get_data(RID p_shape) const {141const JoltShape3D *shape = shape_owner.get_or_null(p_shape);142ERR_FAIL_NULL_V(shape, Variant());143144return shape->get_data();145}146147void JoltPhysicsServer3D::shape_set_custom_solver_bias(RID p_shape, real_t p_bias) {148JoltShape3D *shape = shape_owner.get_or_null(p_shape);149ERR_FAIL_NULL(shape);150151shape->set_solver_bias((float)p_bias);152}153154PhysicsServer3D::ShapeType JoltPhysicsServer3D::shape_get_type(RID p_shape) const {155const JoltShape3D *shape = shape_owner.get_or_null(p_shape);156ERR_FAIL_NULL_V(shape, SHAPE_CUSTOM);157158return shape->get_type();159}160161void JoltPhysicsServer3D::shape_set_margin(RID p_shape, real_t p_margin) {162JoltShape3D *shape = shape_owner.get_or_null(p_shape);163ERR_FAIL_NULL(shape);164165shape->set_margin((float)p_margin);166}167168real_t JoltPhysicsServer3D::shape_get_margin(RID p_shape) const {169const JoltShape3D *shape = shape_owner.get_or_null(p_shape);170ERR_FAIL_NULL_V(shape, 0.0);171172return (real_t)shape->get_margin();173}174175real_t JoltPhysicsServer3D::shape_get_custom_solver_bias(RID p_shape) const {176const JoltShape3D *shape = shape_owner.get_or_null(p_shape);177ERR_FAIL_NULL_V(shape, 0.0);178179return (real_t)shape->get_solver_bias();180}181182RID JoltPhysicsServer3D::space_create() {183JoltSpace3D *space = memnew(JoltSpace3D(job_system));184RID rid = space_owner.make_rid(space);185space->set_rid(rid);186187const RID default_area_rid = area_create();188JoltArea3D *default_area = area_owner.get_or_null(default_area_rid);189ERR_FAIL_NULL_V(default_area, RID());190space->set_default_area(default_area);191default_area->set_space(space);192193return rid;194}195196void JoltPhysicsServer3D::space_set_active(RID p_space, bool p_active) {197JoltSpace3D *space = space_owner.get_or_null(p_space);198ERR_FAIL_NULL(space);199200if (p_active) {201space->set_active(true);202active_spaces.insert(space);203} else {204space->set_active(false);205active_spaces.erase(space);206}207}208209bool JoltPhysicsServer3D::space_is_active(RID p_space) const {210JoltSpace3D *space = space_owner.get_or_null(p_space);211ERR_FAIL_NULL_V(space, false);212213return active_spaces.has(space);214}215216void JoltPhysicsServer3D::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) {217JoltSpace3D *space = space_owner.get_or_null(p_space);218ERR_FAIL_NULL(space);219220space->set_param(p_param, (double)p_value);221}222223real_t JoltPhysicsServer3D::space_get_param(RID p_space, SpaceParameter p_param) const {224const JoltSpace3D *space = space_owner.get_or_null(p_space);225ERR_FAIL_NULL_V(space, 0.0);226227return (real_t)space->get_param(p_param);228}229230PhysicsDirectSpaceState3D *JoltPhysicsServer3D::space_get_direct_state(RID p_space) {231JoltSpace3D *space = space_owner.get_or_null(p_space);232ERR_FAIL_NULL_V(space, nullptr);233ERR_FAIL_COND_V_MSG((on_separate_thread && !doing_sync) || space->is_stepping(), nullptr, "Space state is inaccessible right now, wait for iteration or physics process notification.");234235return space->get_direct_state();236}237238void JoltPhysicsServer3D::space_set_debug_contacts(RID p_space, int p_max_contacts) {239#ifdef DEBUG_ENABLED240JoltSpace3D *space = space_owner.get_or_null(p_space);241ERR_FAIL_NULL(space);242243space->set_max_debug_contacts(p_max_contacts);244#endif245}246247PackedVector3Array JoltPhysicsServer3D::space_get_contacts(RID p_space) const {248#ifdef DEBUG_ENABLED249JoltSpace3D *space = space_owner.get_or_null(p_space);250ERR_FAIL_NULL_V(space, PackedVector3Array());251252return space->get_debug_contacts();253#else254return PackedVector3Array();255#endif256}257258int JoltPhysicsServer3D::space_get_contact_count(RID p_space) const {259#ifdef DEBUG_ENABLED260JoltSpace3D *space = space_owner.get_or_null(p_space);261ERR_FAIL_NULL_V(space, 0);262263return space->get_debug_contact_count();264#else265return 0;266#endif267}268269RID JoltPhysicsServer3D::area_create() {270JoltArea3D *area = memnew(JoltArea3D);271RID rid = area_owner.make_rid(area);272area->set_rid(rid);273return rid;274}275276void JoltPhysicsServer3D::area_set_space(RID p_area, RID p_space) {277JoltArea3D *area = area_owner.get_or_null(p_area);278ERR_FAIL_NULL(area);279280JoltSpace3D *space = nullptr;281282if (p_space.is_valid()) {283space = space_owner.get_or_null(p_space);284ERR_FAIL_NULL(space);285}286287area->set_space(space);288}289290void JoltPhysicsServer3D::soft_body_apply_point_impulse(RID p_body, int p_point_index, const Vector3 &p_impulse) {291JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);292ERR_FAIL_NULL(body);293294body->apply_vertex_impulse(p_point_index, p_impulse);295}296297void JoltPhysicsServer3D::soft_body_apply_point_force(RID p_body, int p_point_index, const Vector3 &p_force) {298JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);299ERR_FAIL_NULL(body);300301body->apply_vertex_force(p_point_index, p_force);302}303304void JoltPhysicsServer3D::soft_body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {305JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);306ERR_FAIL_NULL(body);307308body->apply_central_impulse(p_impulse);309}310311void JoltPhysicsServer3D::soft_body_apply_central_force(RID p_body, const Vector3 &p_force) {312JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);313ERR_FAIL_NULL(body);314315body->apply_central_force(p_force);316}317318RID JoltPhysicsServer3D::area_get_space(RID p_area) const {319const JoltArea3D *area = area_owner.get_or_null(p_area);320ERR_FAIL_NULL_V(area, RID());321322const JoltSpace3D *space = area->get_space();323324if (space == nullptr) {325return RID();326}327328return space->get_rid();329}330331void JoltPhysicsServer3D::area_add_shape(RID p_area, RID p_shape, const Transform3D &p_transform, bool p_disabled) {332JoltArea3D *area = area_owner.get_or_null(p_area);333ERR_FAIL_NULL(area);334335JoltShape3D *shape = shape_owner.get_or_null(p_shape);336ERR_FAIL_NULL(shape);337338area->add_shape(shape, p_transform, p_disabled);339}340341void JoltPhysicsServer3D::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {342JoltArea3D *area = area_owner.get_or_null(p_area);343ERR_FAIL_NULL(area);344345JoltShape3D *shape = shape_owner.get_or_null(p_shape);346ERR_FAIL_NULL(shape);347348area->set_shape(p_shape_idx, shape);349}350351RID JoltPhysicsServer3D::area_get_shape(RID p_area, int p_shape_idx) const {352const JoltArea3D *area = area_owner.get_or_null(p_area);353ERR_FAIL_NULL_V(area, RID());354355const JoltShape3D *shape = area->get_shape(p_shape_idx);356ERR_FAIL_NULL_V(shape, RID());357358return shape->get_rid();359}360361void JoltPhysicsServer3D::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform3D &p_transform) {362JoltArea3D *area = area_owner.get_or_null(p_area);363ERR_FAIL_NULL(area);364365area->set_shape_transform(p_shape_idx, p_transform);366}367368Transform3D JoltPhysicsServer3D::area_get_shape_transform(RID p_area, int p_shape_idx) const {369const JoltArea3D *area = area_owner.get_or_null(p_area);370ERR_FAIL_NULL_V(area, Transform3D());371372return area->get_shape_transform_scaled(p_shape_idx);373}374375int JoltPhysicsServer3D::area_get_shape_count(RID p_area) const {376const JoltArea3D *area = area_owner.get_or_null(p_area);377ERR_FAIL_NULL_V(area, 0);378379return area->get_shape_count();380}381382void JoltPhysicsServer3D::area_remove_shape(RID p_area, int p_shape_idx) {383JoltArea3D *area = area_owner.get_or_null(p_area);384ERR_FAIL_NULL(area);385386area->remove_shape(p_shape_idx);387}388389void JoltPhysicsServer3D::area_clear_shapes(RID p_area) {390JoltArea3D *area = area_owner.get_or_null(p_area);391ERR_FAIL_NULL(area);392393area->clear_shapes();394}395396void JoltPhysicsServer3D::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) {397JoltArea3D *area = area_owner.get_or_null(p_area);398ERR_FAIL_NULL(area);399400area->set_shape_disabled(p_shape_idx, p_disabled);401}402403void JoltPhysicsServer3D::area_attach_object_instance_id(RID p_area, ObjectID p_id) {404RID area_rid = p_area;405406if (space_owner.owns(area_rid)) {407const JoltSpace3D *space = space_owner.get_or_null(area_rid);408area_rid = space->get_default_area()->get_rid();409}410411JoltArea3D *area = area_owner.get_or_null(area_rid);412ERR_FAIL_NULL(area);413414area->set_instance_id(p_id);415}416417ObjectID JoltPhysicsServer3D::area_get_object_instance_id(RID p_area) const {418RID area_rid = p_area;419420if (space_owner.owns(area_rid)) {421const JoltSpace3D *space = space_owner.get_or_null(area_rid);422area_rid = space->get_default_area()->get_rid();423}424425JoltArea3D *area = area_owner.get_or_null(area_rid);426ERR_FAIL_NULL_V(area, ObjectID());427428return area->get_instance_id();429}430431void JoltPhysicsServer3D::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) {432RID area_rid = p_area;433434if (space_owner.owns(area_rid)) {435const JoltSpace3D *space = space_owner.get_or_null(area_rid);436area_rid = space->get_default_area()->get_rid();437}438439JoltArea3D *area = area_owner.get_or_null(area_rid);440ERR_FAIL_NULL(area);441442area->set_param(p_param, p_value);443}444445Variant JoltPhysicsServer3D::area_get_param(RID p_area, AreaParameter p_param) const {446RID area_rid = p_area;447448if (space_owner.owns(area_rid)) {449const JoltSpace3D *space = space_owner.get_or_null(area_rid);450area_rid = space->get_default_area()->get_rid();451}452453JoltArea3D *area = area_owner.get_or_null(area_rid);454ERR_FAIL_NULL_V(area, Variant());455456return area->get_param(p_param);457}458459void JoltPhysicsServer3D::area_set_transform(RID p_area, const Transform3D &p_transform) {460JoltArea3D *area = area_owner.get_or_null(p_area);461ERR_FAIL_NULL(area);462463return area->set_transform(p_transform);464}465466Transform3D JoltPhysicsServer3D::area_get_transform(RID p_area) const {467const JoltArea3D *area = area_owner.get_or_null(p_area);468ERR_FAIL_NULL_V(area, Transform3D());469470return area->get_transform_scaled();471}472473void JoltPhysicsServer3D::area_set_collision_mask(RID p_area, uint32_t p_mask) {474JoltArea3D *area = area_owner.get_or_null(p_area);475ERR_FAIL_NULL(area);476477area->set_collision_mask(p_mask);478}479480uint32_t JoltPhysicsServer3D::area_get_collision_mask(RID p_area) const {481const JoltArea3D *area = area_owner.get_or_null(p_area);482ERR_FAIL_NULL_V(area, 0);483484return area->get_collision_mask();485}486487void JoltPhysicsServer3D::area_set_collision_layer(RID p_area, uint32_t p_layer) {488JoltArea3D *area = area_owner.get_or_null(p_area);489ERR_FAIL_NULL(area);490491area->set_collision_layer(p_layer);492}493494uint32_t JoltPhysicsServer3D::area_get_collision_layer(RID p_area) const {495const JoltArea3D *area = area_owner.get_or_null(p_area);496ERR_FAIL_NULL_V(area, 0);497498return area->get_collision_layer();499}500501void JoltPhysicsServer3D::area_set_monitorable(RID p_area, bool p_monitorable) {502JoltArea3D *area = area_owner.get_or_null(p_area);503ERR_FAIL_NULL(area);504505area->set_monitorable(p_monitorable);506}507508void JoltPhysicsServer3D::area_set_monitor_callback(RID p_area, const Callable &p_callback) {509JoltArea3D *area = area_owner.get_or_null(p_area);510ERR_FAIL_NULL(area);511512area->set_body_monitor_callback(p_callback);513}514515void JoltPhysicsServer3D::area_set_area_monitor_callback(RID p_area, const Callable &p_callback) {516JoltArea3D *area = area_owner.get_or_null(p_area);517ERR_FAIL_NULL(area);518519area->set_area_monitor_callback(p_callback);520}521522void JoltPhysicsServer3D::area_set_ray_pickable(RID p_area, bool p_enable) {523JoltArea3D *area = area_owner.get_or_null(p_area);524ERR_FAIL_NULL(area);525526area->set_pickable(p_enable);527}528529RID JoltPhysicsServer3D::body_create() {530JoltBody3D *body = memnew(JoltBody3D);531RID rid = body_owner.make_rid(body);532body->set_rid(rid);533return rid;534}535536void JoltPhysicsServer3D::body_set_space(RID p_body, RID p_space) {537JoltBody3D *body = body_owner.get_or_null(p_body);538ERR_FAIL_NULL(body);539540JoltSpace3D *space = nullptr;541542if (p_space.is_valid()) {543space = space_owner.get_or_null(p_space);544ERR_FAIL_NULL(space);545}546547body->set_space(space);548}549550RID JoltPhysicsServer3D::body_get_space(RID p_body) const {551const JoltBody3D *body = body_owner.get_or_null(p_body);552ERR_FAIL_NULL_V(body, RID());553554const JoltSpace3D *space = body->get_space();555556if (space == nullptr) {557return RID();558}559560return space->get_rid();561}562563void JoltPhysicsServer3D::body_set_mode(RID p_body, BodyMode p_mode) {564JoltBody3D *body = body_owner.get_or_null(p_body);565ERR_FAIL_NULL(body);566567body->set_mode(p_mode);568}569570PhysicsServer3D::BodyMode JoltPhysicsServer3D::body_get_mode(RID p_body) const {571const JoltBody3D *body = body_owner.get_or_null(p_body);572ERR_FAIL_NULL_V(body, BODY_MODE_STATIC);573574return body->get_mode();575}576577void JoltPhysicsServer3D::body_add_shape(RID p_body, RID p_shape, const Transform3D &p_transform, bool p_disabled) {578JoltBody3D *body = body_owner.get_or_null(p_body);579ERR_FAIL_NULL(body);580581JoltShape3D *shape = shape_owner.get_or_null(p_shape);582ERR_FAIL_NULL(shape);583584body->add_shape(shape, p_transform, p_disabled);585}586587void JoltPhysicsServer3D::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {588JoltBody3D *body = body_owner.get_or_null(p_body);589ERR_FAIL_NULL(body);590591JoltShape3D *shape = shape_owner.get_or_null(p_shape);592ERR_FAIL_NULL(shape);593594body->set_shape(p_shape_idx, shape);595}596597RID JoltPhysicsServer3D::body_get_shape(RID p_body, int p_shape_idx) const {598const JoltBody3D *body = body_owner.get_or_null(p_body);599ERR_FAIL_NULL_V(body, RID());600601const JoltShape3D *shape = body->get_shape(p_shape_idx);602ERR_FAIL_NULL_V(shape, RID());603604return shape->get_rid();605}606607void JoltPhysicsServer3D::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform3D &p_transform) {608JoltBody3D *body = body_owner.get_or_null(p_body);609ERR_FAIL_NULL(body);610611body->set_shape_transform(p_shape_idx, p_transform);612}613614Transform3D JoltPhysicsServer3D::body_get_shape_transform(RID p_body, int p_shape_idx) const {615const JoltBody3D *body = body_owner.get_or_null(p_body);616ERR_FAIL_NULL_V(body, Transform3D());617618return body->get_shape_transform_scaled(p_shape_idx);619}620621int JoltPhysicsServer3D::body_get_shape_count(RID p_body) const {622const JoltBody3D *body = body_owner.get_or_null(p_body);623ERR_FAIL_NULL_V(body, 0);624625return body->get_shape_count();626}627628void JoltPhysicsServer3D::body_remove_shape(RID p_body, int p_shape_idx) {629JoltBody3D *body = body_owner.get_or_null(p_body);630ERR_FAIL_NULL(body);631632body->remove_shape(p_shape_idx);633}634635void JoltPhysicsServer3D::body_clear_shapes(RID p_body) {636JoltBody3D *body = body_owner.get_or_null(p_body);637ERR_FAIL_NULL(body);638639body->clear_shapes();640}641642void JoltPhysicsServer3D::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) {643JoltBody3D *body = body_owner.get_or_null(p_body);644ERR_FAIL_NULL(body);645646body->set_shape_disabled(p_shape_idx, p_disabled);647}648649void JoltPhysicsServer3D::body_attach_object_instance_id(RID p_body, ObjectID p_id) {650if (JoltBody3D *body = body_owner.get_or_null(p_body)) {651body->set_instance_id(p_id);652} else if (JoltSoftBody3D *soft_body = soft_body_owner.get_or_null(p_body)) {653soft_body->set_instance_id(p_id);654} else {655ERR_FAIL();656}657}658659ObjectID JoltPhysicsServer3D::body_get_object_instance_id(RID p_body) const {660const JoltBody3D *body = body_owner.get_or_null(p_body);661ERR_FAIL_NULL_V(body, ObjectID());662663return body->get_instance_id();664}665666void JoltPhysicsServer3D::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) {667JoltBody3D *body = body_owner.get_or_null(p_body);668ERR_FAIL_NULL(body);669670body->set_ccd_enabled(p_enable);671}672673bool JoltPhysicsServer3D::body_is_continuous_collision_detection_enabled(RID p_body) const {674const JoltBody3D *body = body_owner.get_or_null(p_body);675ERR_FAIL_NULL_V(body, false);676677return body->is_ccd_enabled();678}679680void JoltPhysicsServer3D::body_set_collision_layer(RID p_body, uint32_t p_layer) {681JoltBody3D *body = body_owner.get_or_null(p_body);682ERR_FAIL_NULL(body);683684body->set_collision_layer(p_layer);685}686687uint32_t JoltPhysicsServer3D::body_get_collision_layer(RID p_body) const {688const JoltBody3D *body = body_owner.get_or_null(p_body);689ERR_FAIL_NULL_V(body, 0);690691return body->get_collision_layer();692}693694void JoltPhysicsServer3D::body_set_collision_mask(RID p_body, uint32_t p_mask) {695JoltBody3D *body = body_owner.get_or_null(p_body);696ERR_FAIL_NULL(body);697698body->set_collision_mask(p_mask);699}700701uint32_t JoltPhysicsServer3D::body_get_collision_mask(RID p_body) const {702const JoltBody3D *body = body_owner.get_or_null(p_body);703ERR_FAIL_NULL_V(body, 0);704705return body->get_collision_mask();706}707708void JoltPhysicsServer3D::body_set_collision_priority(RID p_body, real_t p_priority) {709JoltBody3D *body = body_owner.get_or_null(p_body);710ERR_FAIL_NULL(body);711712body->set_collision_priority((float)p_priority);713}714715real_t JoltPhysicsServer3D::body_get_collision_priority(RID p_body) const {716const JoltBody3D *body = body_owner.get_or_null(p_body);717ERR_FAIL_NULL_V(body, 0.0);718719return (real_t)body->get_collision_priority();720}721722void JoltPhysicsServer3D::body_set_user_flags(RID p_body, uint32_t p_flags) {723WARN_PRINT("Body user flags are not supported. Any such value will be ignored.");724}725726uint32_t JoltPhysicsServer3D::body_get_user_flags(RID p_body) const {727return 0;728}729730void JoltPhysicsServer3D::body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) {731JoltBody3D *body = body_owner.get_or_null(p_body);732ERR_FAIL_NULL(body);733734body->set_param(p_param, p_value);735}736737Variant JoltPhysicsServer3D::body_get_param(RID p_body, BodyParameter p_param) const {738const JoltBody3D *body = body_owner.get_or_null(p_body);739ERR_FAIL_NULL_V(body, Variant());740741return body->get_param(p_param);742}743744void JoltPhysicsServer3D::body_reset_mass_properties(RID p_body) {745JoltBody3D *body = body_owner.get_or_null(p_body);746ERR_FAIL_NULL(body);747748body->reset_mass_properties();749}750751void JoltPhysicsServer3D::body_set_state(RID p_body, BodyState p_state, const Variant &p_value) {752JoltBody3D *body = body_owner.get_or_null(p_body);753ERR_FAIL_NULL(body);754755body->set_state(p_state, p_value);756}757758Variant JoltPhysicsServer3D::body_get_state(RID p_body, BodyState p_state) const {759JoltBody3D *body = body_owner.get_or_null(p_body);760ERR_FAIL_NULL_V(body, Variant());761762return body->get_state(p_state);763}764765void JoltPhysicsServer3D::body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {766JoltBody3D *body = body_owner.get_or_null(p_body);767ERR_FAIL_NULL(body);768769return body->apply_central_impulse(p_impulse);770}771772void JoltPhysicsServer3D::body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position) {773JoltBody3D *body = body_owner.get_or_null(p_body);774ERR_FAIL_NULL(body);775776return body->apply_impulse(p_impulse, p_position);777}778779void JoltPhysicsServer3D::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) {780JoltBody3D *body = body_owner.get_or_null(p_body);781ERR_FAIL_NULL(body);782783return body->apply_torque_impulse(p_impulse);784}785786void JoltPhysicsServer3D::body_apply_central_force(RID p_body, const Vector3 &p_force) {787JoltBody3D *body = body_owner.get_or_null(p_body);788ERR_FAIL_NULL(body);789790return body->apply_central_force(p_force);791}792793void JoltPhysicsServer3D::body_apply_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position) {794JoltBody3D *body = body_owner.get_or_null(p_body);795ERR_FAIL_NULL(body);796797return body->apply_force(p_force, p_position);798}799800void JoltPhysicsServer3D::body_apply_torque(RID p_body, const Vector3 &p_torque) {801JoltBody3D *body = body_owner.get_or_null(p_body);802ERR_FAIL_NULL(body);803804return body->apply_torque(p_torque);805}806807void JoltPhysicsServer3D::body_add_constant_central_force(RID p_body, const Vector3 &p_force) {808JoltBody3D *body = body_owner.get_or_null(p_body);809ERR_FAIL_NULL(body);810811body->add_constant_central_force(p_force);812}813814void JoltPhysicsServer3D::body_add_constant_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position) {815JoltBody3D *body = body_owner.get_or_null(p_body);816ERR_FAIL_NULL(body);817818body->add_constant_force(p_force, p_position);819}820821void JoltPhysicsServer3D::body_add_constant_torque(RID p_body, const Vector3 &p_torque) {822JoltBody3D *body = body_owner.get_or_null(p_body);823ERR_FAIL_NULL(body);824825body->add_constant_torque(p_torque);826}827828void JoltPhysicsServer3D::body_set_constant_force(RID p_body, const Vector3 &p_force) {829JoltBody3D *body = body_owner.get_or_null(p_body);830ERR_FAIL_NULL(body);831832body->set_constant_force(p_force);833}834835Vector3 JoltPhysicsServer3D::body_get_constant_force(RID p_body) const {836const JoltBody3D *body = body_owner.get_or_null(p_body);837ERR_FAIL_NULL_V(body, Vector3());838839return body->get_constant_force();840}841842void JoltPhysicsServer3D::body_set_constant_torque(RID p_body, const Vector3 &p_torque) {843JoltBody3D *body = body_owner.get_or_null(p_body);844ERR_FAIL_NULL(body);845846body->set_constant_torque(p_torque);847}848849Vector3 JoltPhysicsServer3D::body_get_constant_torque(RID p_body) const {850const JoltBody3D *body = body_owner.get_or_null(p_body);851ERR_FAIL_NULL_V(body, Vector3());852853return body->get_constant_torque();854}855856void JoltPhysicsServer3D::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) {857JoltBody3D *body = body_owner.get_or_null(p_body);858ERR_FAIL_NULL(body);859860body->set_axis_velocity(p_axis_velocity);861}862863void JoltPhysicsServer3D::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) {864JoltBody3D *body = body_owner.get_or_null(p_body);865ERR_FAIL_NULL(body);866867body->set_axis_lock(p_axis, p_lock);868}869870bool JoltPhysicsServer3D::body_is_axis_locked(RID p_body, BodyAxis p_axis) const {871const JoltBody3D *body = body_owner.get_or_null(p_body);872ERR_FAIL_NULL_V(body, false);873874return body->is_axis_locked(p_axis);875}876877void JoltPhysicsServer3D::body_add_collision_exception(RID p_body, RID p_excepted_body) {878JoltBody3D *body = body_owner.get_or_null(p_body);879ERR_FAIL_NULL(body);880881body->add_collision_exception(p_excepted_body);882}883884void JoltPhysicsServer3D::body_remove_collision_exception(RID p_body, RID p_excepted_body) {885JoltBody3D *body = body_owner.get_or_null(p_body);886ERR_FAIL_NULL(body);887888body->remove_collision_exception(p_excepted_body);889}890891void JoltPhysicsServer3D::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {892const JoltBody3D *body = body_owner.get_or_null(p_body);893ERR_FAIL_NULL(body);894895for (const RID &exception : body->get_collision_exceptions()) {896p_exceptions->push_back(exception);897}898}899900void JoltPhysicsServer3D::body_set_max_contacts_reported(RID p_body, int p_amount) {901JoltBody3D *body = body_owner.get_or_null(p_body);902ERR_FAIL_NULL(body);903904return body->set_max_contacts_reported(p_amount);905}906907int JoltPhysicsServer3D::body_get_max_contacts_reported(RID p_body) const {908const JoltBody3D *body = body_owner.get_or_null(p_body);909ERR_FAIL_NULL_V(body, 0);910911return body->get_max_contacts_reported();912}913914void JoltPhysicsServer3D::body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) {915WARN_PRINT("Per-body contact depth threshold is not supported. Any such value will be ignored.");916}917918real_t JoltPhysicsServer3D::body_get_contacts_reported_depth_threshold(RID p_body) const {919return 0.0;920}921922void JoltPhysicsServer3D::body_set_omit_force_integration(RID p_body, bool p_enable) {923JoltBody3D *body = body_owner.get_or_null(p_body);924ERR_FAIL_NULL(body);925926body->set_custom_integrator(p_enable);927}928929bool JoltPhysicsServer3D::body_is_omitting_force_integration(RID p_body) const {930JoltBody3D *body = body_owner.get_or_null(p_body);931ERR_FAIL_NULL_V(body, false);932933return body->has_custom_integrator();934}935936void JoltPhysicsServer3D::body_set_state_sync_callback(RID p_body, const Callable &p_callable) {937JoltBody3D *body = body_owner.get_or_null(p_body);938ERR_FAIL_NULL(body);939940body->set_state_sync_callback(p_callable);941}942943void JoltPhysicsServer3D::body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_userdata) {944JoltBody3D *body = body_owner.get_or_null(p_body);945ERR_FAIL_NULL(body);946947body->set_custom_integration_callback(p_callable, p_userdata);948}949950void JoltPhysicsServer3D::body_set_ray_pickable(RID p_body, bool p_enable) {951JoltBody3D *body = body_owner.get_or_null(p_body);952ERR_FAIL_NULL(body);953954body->set_pickable(p_enable);955}956957bool JoltPhysicsServer3D::body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result) {958JoltBody3D *body = body_owner.get_or_null(p_body);959ERR_FAIL_NULL_V(body, false);960961JoltSpace3D *space = body->get_space();962ERR_FAIL_NULL_V(space, false);963964return space->get_direct_state()->body_test_motion(*body, p_parameters, r_result);965}966967PhysicsDirectBodyState3D *JoltPhysicsServer3D::body_get_direct_state(RID p_body) {968ERR_FAIL_COND_V_MSG((on_separate_thread && !doing_sync), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification.");969970JoltBody3D *body = body_owner.get_or_null(p_body);971if (unlikely(body == nullptr || body->get_space() == nullptr)) {972return nullptr;973}974975ERR_FAIL_COND_V_MSG(body->get_space()->is_stepping(), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification.");976977return body->get_direct_state();978}979980RID JoltPhysicsServer3D::soft_body_create() {981JoltSoftBody3D *body = memnew(JoltSoftBody3D);982RID rid = soft_body_owner.make_rid(body);983body->set_rid(rid);984return rid;985}986987void JoltPhysicsServer3D::soft_body_update_rendering_server(RID p_body, PhysicsServer3DRenderingServerHandler *p_rendering_server_handler) {988JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);989ERR_FAIL_NULL(body);990991return body->update_rendering_server(p_rendering_server_handler);992}993994void JoltPhysicsServer3D::soft_body_set_space(RID p_body, RID p_space) {995JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);996ERR_FAIL_NULL(body);997998JoltSpace3D *space = nullptr;9991000if (p_space.is_valid()) {1001space = space_owner.get_or_null(p_space);1002ERR_FAIL_NULL(space);1003}10041005body->set_space(space);1006}10071008RID JoltPhysicsServer3D::soft_body_get_space(RID p_body) const {1009const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1010ERR_FAIL_NULL_V(body, RID());10111012const JoltSpace3D *space = body->get_space();10131014if (space == nullptr) {1015return RID();1016}10171018return space->get_rid();1019}10201021void JoltPhysicsServer3D::soft_body_set_mesh(RID p_body, RID p_mesh) {1022JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1023ERR_FAIL_NULL(body);10241025body->set_mesh(p_mesh);1026}10271028AABB JoltPhysicsServer3D::soft_body_get_bounds(RID p_body) const {1029const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1030ERR_FAIL_NULL_V(body, AABB());10311032return body->get_bounds();1033}10341035void JoltPhysicsServer3D::soft_body_set_collision_layer(RID p_body, uint32_t p_layer) {1036JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1037ERR_FAIL_NULL(body);10381039body->set_collision_layer(p_layer);1040}10411042uint32_t JoltPhysicsServer3D::soft_body_get_collision_layer(RID p_body) const {1043const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1044ERR_FAIL_NULL_V(body, 0);10451046return body->get_collision_layer();1047}10481049void JoltPhysicsServer3D::soft_body_set_collision_mask(RID p_body, uint32_t p_mask) {1050JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1051ERR_FAIL_NULL(body);10521053body->set_collision_mask(p_mask);1054}10551056uint32_t JoltPhysicsServer3D::soft_body_get_collision_mask(RID p_body) const {1057const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1058ERR_FAIL_NULL_V(body, 0);10591060return body->get_collision_mask();1061}10621063void JoltPhysicsServer3D::soft_body_add_collision_exception(RID p_body, RID p_excepted_body) {1064JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1065ERR_FAIL_NULL(body);10661067body->add_collision_exception(p_excepted_body);1068}10691070void JoltPhysicsServer3D::soft_body_remove_collision_exception(RID p_body, RID p_excepted_body) {1071JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1072ERR_FAIL_NULL(body);10731074body->remove_collision_exception(p_excepted_body);1075}10761077void JoltPhysicsServer3D::soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {1078const JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1079ERR_FAIL_NULL(body);10801081for (const RID &exception : body->get_collision_exceptions()) {1082p_exceptions->push_back(exception);1083}1084}10851086void JoltPhysicsServer3D::soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_value) {1087JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1088ERR_FAIL_NULL(body);10891090body->set_state(p_state, p_value);1091}10921093Variant JoltPhysicsServer3D::soft_body_get_state(RID p_body, BodyState p_state) const {1094JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1095ERR_FAIL_NULL_V(body, Variant());10961097return body->get_state(p_state);1098}10991100void JoltPhysicsServer3D::soft_body_set_transform(RID p_body, const Transform3D &p_transform) {1101JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1102ERR_FAIL_NULL(body);11031104return body->set_transform(p_transform);1105}11061107void JoltPhysicsServer3D::soft_body_set_ray_pickable(RID p_body, bool p_enable) {1108JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1109ERR_FAIL_NULL(body);11101111return body->set_pickable(p_enable);1112}11131114void JoltPhysicsServer3D::soft_body_set_simulation_precision(RID p_body, int p_precision) {1115JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1116ERR_FAIL_NULL(body);11171118return body->set_simulation_precision(p_precision);1119}11201121int JoltPhysicsServer3D::soft_body_get_simulation_precision(RID p_body) const {1122JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1123ERR_FAIL_NULL_V(body, 0);11241125return body->get_simulation_precision();1126}11271128void JoltPhysicsServer3D::soft_body_set_total_mass(RID p_body, real_t p_total_mass) {1129JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1130ERR_FAIL_NULL(body);11311132return body->set_mass((float)p_total_mass);1133}11341135real_t JoltPhysicsServer3D::soft_body_get_total_mass(RID p_body) const {1136JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1137ERR_FAIL_NULL_V(body, 0.0);11381139return (real_t)body->get_mass();1140}11411142void JoltPhysicsServer3D::soft_body_set_linear_stiffness(RID p_body, real_t p_coefficient) {1143JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1144ERR_FAIL_NULL(body);11451146return body->set_stiffness_coefficient((float)p_coefficient);1147}11481149real_t JoltPhysicsServer3D::soft_body_get_linear_stiffness(RID p_body) const {1150JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1151ERR_FAIL_NULL_V(body, 0.0);11521153return (real_t)body->get_stiffness_coefficient();1154}11551156void JoltPhysicsServer3D::soft_body_set_shrinking_factor(RID p_body, real_t p_shrinking_factor) {1157JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1158ERR_FAIL_NULL(body);11591160return body->set_shrinking_factor((float)p_shrinking_factor);1161}11621163real_t JoltPhysicsServer3D::soft_body_get_shrinking_factor(RID p_body) const {1164JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1165ERR_FAIL_NULL_V(body, 0.0);11661167return (real_t)body->get_shrinking_factor();1168}11691170void JoltPhysicsServer3D::soft_body_set_pressure_coefficient(RID p_body, real_t p_coefficient) {1171JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1172ERR_FAIL_NULL(body);11731174return body->set_pressure((float)p_coefficient);1175}11761177real_t JoltPhysicsServer3D::soft_body_get_pressure_coefficient(RID p_body) const {1178JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1179ERR_FAIL_NULL_V(body, 0.0);11801181return (real_t)body->get_pressure();1182}11831184void JoltPhysicsServer3D::soft_body_set_damping_coefficient(RID p_body, real_t p_coefficient) {1185JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1186ERR_FAIL_NULL(body);11871188return body->set_linear_damping((float)p_coefficient);1189}11901191real_t JoltPhysicsServer3D::soft_body_get_damping_coefficient(RID p_body) const {1192JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1193ERR_FAIL_NULL_V(body, 0.0);11941195return (real_t)body->get_linear_damping();1196}11971198void JoltPhysicsServer3D::soft_body_set_drag_coefficient(RID p_body, real_t p_coefficient) {1199JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1200ERR_FAIL_NULL(body);12011202return body->set_drag((float)p_coefficient);1203}12041205real_t JoltPhysicsServer3D::soft_body_get_drag_coefficient(RID p_body) const {1206JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1207ERR_FAIL_NULL_V(body, 0.0);12081209return (real_t)body->get_drag();1210}12111212void JoltPhysicsServer3D::soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) {1213JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1214ERR_FAIL_NULL(body);12151216body->set_vertex_position(p_point_index, p_global_position);1217}12181219Vector3 JoltPhysicsServer3D::soft_body_get_point_global_position(RID p_body, int p_point_index) const {1220JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1221ERR_FAIL_NULL_V(body, Vector3());12221223return body->get_vertex_position(p_point_index);1224}12251226void JoltPhysicsServer3D::soft_body_remove_all_pinned_points(RID p_body) {1227JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1228ERR_FAIL_NULL(body);12291230body->unpin_all_vertices();1231}12321233void JoltPhysicsServer3D::soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) {1234JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1235ERR_FAIL_NULL(body);12361237if (p_pin) {1238body->pin_vertex(p_point_index);1239} else {1240body->unpin_vertex(p_point_index);1241}1242}12431244bool JoltPhysicsServer3D::soft_body_is_point_pinned(RID p_body, int p_point_index) const {1245JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);1246ERR_FAIL_NULL_V(body, false);12471248return body->is_vertex_pinned(p_point_index);1249}12501251RID JoltPhysicsServer3D::joint_create() {1252JoltJoint3D *joint = memnew(JoltJoint3D);1253RID rid = joint_owner.make_rid(joint);1254joint->set_rid(rid);1255return rid;1256}12571258void JoltPhysicsServer3D::joint_clear(RID p_joint) {1259JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1260ERR_FAIL_NULL(joint);12611262if (joint->get_type() != JOINT_TYPE_MAX) {1263JoltJoint3D *empty_joint = memnew(JoltJoint3D);1264empty_joint->set_rid(joint->get_rid());12651266memdelete(joint);1267joint = nullptr;12681269joint_owner.replace(p_joint, empty_joint);1270}1271}12721273void JoltPhysicsServer3D::joint_make_pin(RID p_joint, RID p_body_a, const Vector3 &p_local_a, RID p_body_b, const Vector3 &p_local_b) {1274JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);1275ERR_FAIL_NULL(old_joint);12761277JoltBody3D *body_a = body_owner.get_or_null(p_body_a);1278ERR_FAIL_NULL(body_a);12791280JoltBody3D *body_b = body_owner.get_or_null(p_body_b);1281ERR_FAIL_COND(body_a == body_b);12821283JoltJoint3D *new_joint = memnew(JoltPinJoint3D(*old_joint, body_a, body_b, p_local_a, p_local_b));12841285memdelete(old_joint);1286old_joint = nullptr;12871288joint_owner.replace(p_joint, new_joint);1289}12901291void JoltPhysicsServer3D::pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) {1292JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1293ERR_FAIL_NULL(joint);12941295ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_PIN);1296JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);12971298pin_joint->set_param(p_param, (double)p_value);1299}13001301real_t JoltPhysicsServer3D::pin_joint_get_param(RID p_joint, PinJointParam p_param) const {1302const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1303ERR_FAIL_NULL_V(joint, 0.0);13041305ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, 0.0);1306const JoltPinJoint3D *pin_joint = static_cast<const JoltPinJoint3D *>(joint);13071308return (real_t)pin_joint->get_param(p_param);1309}13101311void JoltPhysicsServer3D::pin_joint_set_local_a(RID p_joint, const Vector3 &p_local_a) {1312JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1313ERR_FAIL_NULL(joint);13141315ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_PIN);1316JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);13171318pin_joint->set_local_a(p_local_a);1319}13201321Vector3 JoltPhysicsServer3D::pin_joint_get_local_a(RID p_joint) const {1322const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1323ERR_FAIL_NULL_V(joint, Vector3());13241325ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, Vector3());1326const JoltPinJoint3D *pin_joint = static_cast<const JoltPinJoint3D *>(joint);13271328return pin_joint->get_local_a();1329}13301331void JoltPhysicsServer3D::pin_joint_set_local_b(RID p_joint, const Vector3 &p_local_b) {1332JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1333ERR_FAIL_NULL(joint);13341335ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_PIN);1336JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);13371338pin_joint->set_local_b(p_local_b);1339}13401341Vector3 JoltPhysicsServer3D::pin_joint_get_local_b(RID p_joint) const {1342const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1343ERR_FAIL_NULL_V(joint, Vector3());13441345ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, Vector3());1346const JoltPinJoint3D *pin_joint = static_cast<const JoltPinJoint3D *>(joint);13471348return pin_joint->get_local_b();1349}13501351void JoltPhysicsServer3D::joint_make_hinge(RID p_joint, RID p_body_a, const Transform3D &p_hinge_a, RID p_body_b, const Transform3D &p_hinge_b) {1352JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);1353ERR_FAIL_NULL(old_joint);13541355JoltBody3D *body_a = body_owner.get_or_null(p_body_a);1356ERR_FAIL_NULL(body_a);13571358JoltBody3D *body_b = body_owner.get_or_null(p_body_b);1359ERR_FAIL_COND(body_a == body_b);13601361JoltJoint3D *new_joint = memnew(JoltHingeJoint3D(*old_joint, body_a, body_b, p_hinge_a, p_hinge_b));13621363memdelete(old_joint);1364old_joint = nullptr;13651366joint_owner.replace(p_joint, new_joint);1367}13681369void JoltPhysicsServer3D::joint_make_hinge_simple(RID p_joint, RID p_body_a, const Vector3 &p_pivot_a, const Vector3 &p_axis_a, RID p_body_b, const Vector3 &p_pivot_b, const Vector3 &p_axis_b) {1370ERR_FAIL_MSG("Simple hinge joints are not supported when using Jolt Physics.");1371}13721373void JoltPhysicsServer3D::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, real_t p_value) {1374JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1375ERR_FAIL_NULL(joint);13761377ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);1378JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);13791380return hinge_joint->set_param(p_param, (double)p_value);1381}13821383real_t JoltPhysicsServer3D::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const {1384const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1385ERR_FAIL_NULL_V(joint, 0.0);13861387ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0);1388const JoltHingeJoint3D *hinge_joint = static_cast<const JoltHingeJoint3D *>(joint);13891390return (real_t)hinge_joint->get_param(p_param);1391}13921393void JoltPhysicsServer3D::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_enabled) {1394JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1395ERR_FAIL_NULL(joint);13961397ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);1398JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);13991400return hinge_joint->set_flag(p_flag, p_enabled);1401}14021403bool JoltPhysicsServer3D::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const {1404const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1405ERR_FAIL_NULL_V(joint, false);14061407ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, false);1408const JoltHingeJoint3D *hinge_joint = static_cast<const JoltHingeJoint3D *>(joint);14091410return hinge_joint->get_flag(p_flag);1411}14121413void JoltPhysicsServer3D::joint_make_slider(RID p_joint, RID p_body_a, const Transform3D &p_local_ref_a, RID p_body_b, const Transform3D &p_local_ref_b) {1414JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);1415ERR_FAIL_NULL(old_joint);14161417JoltBody3D *body_a = body_owner.get_or_null(p_body_a);1418ERR_FAIL_NULL(body_a);14191420JoltBody3D *body_b = body_owner.get_or_null(p_body_b);1421ERR_FAIL_COND(body_a == body_b);14221423JoltJoint3D *new_joint = memnew(JoltSliderJoint3D(*old_joint, body_a, body_b, p_local_ref_a, p_local_ref_b));14241425memdelete(old_joint);1426old_joint = nullptr;14271428joint_owner.replace(p_joint, new_joint);1429}14301431void JoltPhysicsServer3D::slider_joint_set_param(RID p_joint, SliderJointParam p_param, real_t p_value) {1432JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1433ERR_FAIL_NULL(joint);14341435ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_SLIDER);1436JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);14371438return slider_joint->set_param(p_param, (real_t)p_value);1439}14401441real_t JoltPhysicsServer3D::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const {1442const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1443ERR_FAIL_NULL_V(joint, 0.0);14441445ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0);1446const JoltSliderJoint3D *slider_joint = static_cast<const JoltSliderJoint3D *>(joint);14471448return slider_joint->get_param(p_param);1449}14501451void JoltPhysicsServer3D::joint_make_cone_twist(RID p_joint, RID p_body_a, const Transform3D &p_local_ref_a, RID p_body_b, const Transform3D &p_local_ref_b) {1452JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);1453ERR_FAIL_NULL(old_joint);14541455JoltBody3D *body_a = body_owner.get_or_null(p_body_a);1456ERR_FAIL_NULL(body_a);14571458JoltBody3D *body_b = body_owner.get_or_null(p_body_b);1459ERR_FAIL_COND(body_a == body_b);14601461JoltJoint3D *new_joint = memnew(JoltConeTwistJoint3D(*old_joint, body_a, body_b, p_local_ref_a, p_local_ref_b));14621463memdelete(old_joint);1464old_joint = nullptr;14651466joint_owner.replace(p_joint, new_joint);1467}14681469void JoltPhysicsServer3D::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, real_t p_value) {1470JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1471ERR_FAIL_NULL(joint);14721473ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_CONE_TWIST);1474JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);14751476return cone_twist_joint->set_param(p_param, (double)p_value);1477}14781479real_t JoltPhysicsServer3D::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const {1480const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1481ERR_FAIL_NULL_V(joint, 0.0);14821483ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0);1484const JoltConeTwistJoint3D *cone_twist_joint = static_cast<const JoltConeTwistJoint3D *>(joint);14851486return (real_t)cone_twist_joint->get_param(p_param);1487}14881489void JoltPhysicsServer3D::joint_make_generic_6dof(RID p_joint, RID p_body_a, const Transform3D &p_local_ref_a, RID p_body_b, const Transform3D &p_local_ref_b) {1490JoltJoint3D *old_joint = joint_owner.get_or_null(p_joint);1491ERR_FAIL_NULL(old_joint);14921493JoltBody3D *body_a = body_owner.get_or_null(p_body_a);1494ERR_FAIL_NULL(body_a);14951496JoltBody3D *body_b = body_owner.get_or_null(p_body_b);1497ERR_FAIL_COND(body_a == body_b);14981499JoltJoint3D *new_joint = memnew(JoltGeneric6DOFJoint3D(*old_joint, body_a, body_b, p_local_ref_a, p_local_ref_b));15001501memdelete(old_joint);1502old_joint = nullptr;15031504joint_owner.replace(p_joint, new_joint);1505}15061507void JoltPhysicsServer3D::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param, real_t p_value) {1508JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1509ERR_FAIL_NULL(joint);15101511ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);1512JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);15131514return g6dof_joint->set_param(p_axis, p_param, (double)p_value);1515}15161517real_t JoltPhysicsServer3D::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param) const {1518const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1519ERR_FAIL_NULL_V(joint, 0.0);15201521ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0);1522const JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<const JoltGeneric6DOFJoint3D *>(joint);15231524return (real_t)g6dof_joint->get_param(p_axis, p_param);1525}15261527void JoltPhysicsServer3D::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag, bool p_enable) {1528JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1529ERR_FAIL_NULL(joint);15301531ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);1532JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);15331534return g6dof_joint->set_flag(p_axis, p_flag, p_enable);1535}15361537bool JoltPhysicsServer3D::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag) const {1538const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1539ERR_FAIL_NULL_V(joint, false);15401541ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, false);1542const JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<const JoltGeneric6DOFJoint3D *>(joint);15431544return g6dof_joint->get_flag(p_axis, p_flag);1545}15461547PhysicsServer3D::JointType JoltPhysicsServer3D::joint_get_type(RID p_joint) const {1548const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1549ERR_FAIL_NULL_V(joint, JOINT_TYPE_PIN);15501551return joint->get_type();1552}15531554void JoltPhysicsServer3D::joint_set_solver_priority(RID p_joint, int p_priority) {1555JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1556ERR_FAIL_NULL(joint);15571558joint->set_solver_priority(p_priority);1559}15601561int JoltPhysicsServer3D::joint_get_solver_priority(RID p_joint) const {1562const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1563ERR_FAIL_NULL_V(joint, 0);15641565return joint->get_solver_priority();1566}15671568void JoltPhysicsServer3D::joint_disable_collisions_between_bodies(RID p_joint, bool p_disable) {1569JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1570ERR_FAIL_NULL(joint);15711572joint->set_collision_disabled(p_disable);1573}15741575bool JoltPhysicsServer3D::joint_is_disabled_collisions_between_bodies(RID p_joint) const {1576const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1577ERR_FAIL_NULL_V(joint, false);15781579return joint->is_collision_disabled();1580}15811582void JoltPhysicsServer3D::free(RID p_rid) {1583if (JoltShape3D *shape = shape_owner.get_or_null(p_rid)) {1584free_shape(shape);1585} else if (JoltBody3D *body = body_owner.get_or_null(p_rid)) {1586free_body(body);1587} else if (JoltJoint3D *joint = joint_owner.get_or_null(p_rid)) {1588free_joint(joint);1589} else if (JoltArea3D *area = area_owner.get_or_null(p_rid)) {1590free_area(area);1591} else if (JoltSoftBody3D *soft_body = soft_body_owner.get_or_null(p_rid)) {1592free_soft_body(soft_body);1593} else if (JoltSpace3D *space = space_owner.get_or_null(p_rid)) {1594free_space(space);1595} else {1596ERR_FAIL_MSG("Failed to free RID: The specified RID has no owner.");1597}1598}15991600void JoltPhysicsServer3D::set_active(bool p_active) {1601active = p_active;1602}16031604void JoltPhysicsServer3D::init() {1605job_system = new JoltJobSystem();1606}16071608void JoltPhysicsServer3D::finish() {1609if (job_system != nullptr) {1610delete job_system;1611job_system = nullptr;1612}1613}16141615void JoltPhysicsServer3D::step(real_t p_step) {1616if (!active) {1617return;1618}16191620for (JoltSpace3D *active_space : active_spaces) {1621job_system->pre_step();16221623active_space->step((float)p_step);16241625job_system->post_step();1626}1627}16281629void JoltPhysicsServer3D::sync() {1630doing_sync = true;1631}16321633void JoltPhysicsServer3D::end_sync() {1634doing_sync = false;1635}16361637void JoltPhysicsServer3D::flush_queries() {1638if (!active) {1639return;1640}16411642flushing_queries = true;16431644for (JoltSpace3D *space : active_spaces) {1645space->call_queries();1646}16471648flushing_queries = false;16491650#ifdef DEBUG_ENABLED1651job_system->flush_timings();1652#endif1653}16541655bool JoltPhysicsServer3D::is_flushing_queries() const {1656return flushing_queries;1657}16581659int JoltPhysicsServer3D::get_process_info(ProcessInfo p_process_info) {1660return 0;1661}16621663void JoltPhysicsServer3D::free_space(JoltSpace3D *p_space) {1664ERR_FAIL_NULL(p_space);16651666free_area(p_space->get_default_area());1667space_set_active(p_space->get_rid(), false);1668space_owner.free(p_space->get_rid());1669memdelete(p_space);1670}16711672void JoltPhysicsServer3D::free_area(JoltArea3D *p_area) {1673ERR_FAIL_NULL(p_area);16741675p_area->set_space(nullptr);1676area_owner.free(p_area->get_rid());1677memdelete(p_area);1678}16791680void JoltPhysicsServer3D::free_body(JoltBody3D *p_body) {1681ERR_FAIL_NULL(p_body);16821683p_body->set_space(nullptr);1684body_owner.free(p_body->get_rid());1685memdelete(p_body);1686}16871688void JoltPhysicsServer3D::free_soft_body(JoltSoftBody3D *p_body) {1689ERR_FAIL_NULL(p_body);16901691p_body->set_space(nullptr);1692soft_body_owner.free(p_body->get_rid());1693memdelete(p_body);1694}16951696void JoltPhysicsServer3D::free_shape(JoltShape3D *p_shape) {1697ERR_FAIL_NULL(p_shape);16981699p_shape->remove_self();1700shape_owner.free(p_shape->get_rid());1701memdelete(p_shape);1702}17031704void JoltPhysicsServer3D::free_joint(JoltJoint3D *p_joint) {1705ERR_FAIL_NULL(p_joint);17061707joint_owner.free(p_joint->get_rid());1708memdelete(p_joint);1709}17101711#ifdef DEBUG_ENABLED17121713void JoltPhysicsServer3D::dump_debug_snapshots(const String &p_dir) {1714for (JoltSpace3D *space : active_spaces) {1715space->dump_debug_snapshot(p_dir);1716}1717}17181719void JoltPhysicsServer3D::space_dump_debug_snapshot(RID p_space, const String &p_dir) {1720JoltSpace3D *space = space_owner.get_or_null(p_space);1721ERR_FAIL_NULL(space);17221723space->dump_debug_snapshot(p_dir);1724}17251726#endif17271728bool JoltPhysicsServer3D::joint_get_enabled(RID p_joint) const {1729JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1730ERR_FAIL_NULL_V(joint, false);17311732return joint->is_enabled();1733}17341735void JoltPhysicsServer3D::joint_set_enabled(RID p_joint, bool p_enabled) {1736JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1737ERR_FAIL_NULL(joint);17381739joint->set_enabled(p_enabled);1740}17411742int JoltPhysicsServer3D::joint_get_solver_velocity_iterations(RID p_joint) {1743JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1744ERR_FAIL_NULL_V(joint, 0);17451746return joint->get_solver_velocity_iterations();1747}17481749void JoltPhysicsServer3D::joint_set_solver_velocity_iterations(RID p_joint, int p_value) {1750JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1751ERR_FAIL_NULL(joint);17521753return joint->set_solver_velocity_iterations(p_value);1754}17551756int JoltPhysicsServer3D::joint_get_solver_position_iterations(RID p_joint) {1757JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1758ERR_FAIL_NULL_V(joint, 0);17591760return joint->get_solver_position_iterations();1761}17621763void JoltPhysicsServer3D::joint_set_solver_position_iterations(RID p_joint, int p_value) {1764JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1765ERR_FAIL_NULL(joint);17661767return joint->set_solver_position_iterations(p_value);1768}17691770float JoltPhysicsServer3D::pin_joint_get_applied_force(RID p_joint) {1771JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1772ERR_FAIL_NULL_V(joint, 0.0f);17731774ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_PIN, 0.0);1775JoltPinJoint3D *pin_joint = static_cast<JoltPinJoint3D *>(joint);17761777return pin_joint->get_applied_force();1778}17791780double JoltPhysicsServer3D::hinge_joint_get_jolt_param(RID p_joint, HingeJointParamJolt p_param) const {1781JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1782ERR_FAIL_NULL_V(joint, 0.0);17831784ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0);1785JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);17861787return hinge_joint->get_jolt_param(p_param);1788}17891790void JoltPhysicsServer3D::hinge_joint_set_jolt_param(RID p_joint, HingeJointParamJolt p_param, double p_value) {1791JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1792ERR_FAIL_NULL(joint);17931794ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);1795JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);17961797return hinge_joint->set_jolt_param(p_param, p_value);1798}17991800bool JoltPhysicsServer3D::hinge_joint_get_jolt_flag(RID p_joint, HingeJointFlagJolt p_flag) const {1801const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1802ERR_FAIL_NULL_V(joint, false);18031804ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, false);1805const JoltHingeJoint3D *hinge_joint = static_cast<const JoltHingeJoint3D *>(joint);18061807return hinge_joint->get_jolt_flag(p_flag);1808}18091810void JoltPhysicsServer3D::hinge_joint_set_jolt_flag(RID p_joint, HingeJointFlagJolt p_flag, bool p_enabled) {1811JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1812ERR_FAIL_NULL(joint);18131814ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_HINGE);1815JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);18161817return hinge_joint->set_jolt_flag(p_flag, p_enabled);1818}18191820float JoltPhysicsServer3D::hinge_joint_get_applied_force(RID p_joint) {1821JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1822ERR_FAIL_NULL_V(joint, 0.0f);18231824ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0f);1825JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);18261827return hinge_joint->get_applied_force();1828}18291830float JoltPhysicsServer3D::hinge_joint_get_applied_torque(RID p_joint) {1831JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1832ERR_FAIL_NULL_V(joint, 0.0f);18331834ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_HINGE, 0.0f);1835JoltHingeJoint3D *hinge_joint = static_cast<JoltHingeJoint3D *>(joint);18361837return hinge_joint->get_applied_torque();1838}18391840double JoltPhysicsServer3D::slider_joint_get_jolt_param(RID p_joint, SliderJointParamJolt p_param) const {1841JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1842ERR_FAIL_NULL_V(joint, 0.0);18431844ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0);1845JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);18461847return slider_joint->get_jolt_param(p_param);1848}18491850void JoltPhysicsServer3D::slider_joint_set_jolt_param(RID p_joint, SliderJointParamJolt p_param, double p_value) {1851JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1852ERR_FAIL_NULL(joint);18531854ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_SLIDER);1855JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);18561857return slider_joint->set_jolt_param(p_param, p_value);1858}18591860bool JoltPhysicsServer3D::slider_joint_get_jolt_flag(RID p_joint, SliderJointFlagJolt p_flag) const {1861const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1862ERR_FAIL_NULL_V(joint, false);18631864ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, false);1865const JoltSliderJoint3D *slider_joint = static_cast<const JoltSliderJoint3D *>(joint);18661867return slider_joint->get_jolt_flag(p_flag);1868}18691870void JoltPhysicsServer3D::slider_joint_set_jolt_flag(RID p_joint, SliderJointFlagJolt p_flag, bool p_enabled) {1871JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1872ERR_FAIL_NULL(joint);18731874ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_SLIDER);1875JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);18761877return slider_joint->set_jolt_flag(p_flag, p_enabled);1878}18791880float JoltPhysicsServer3D::slider_joint_get_applied_force(RID p_joint) {1881JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1882ERR_FAIL_NULL_V(joint, 0.0f);18831884ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0f);1885JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);18861887return slider_joint->get_applied_force();1888}18891890float JoltPhysicsServer3D::slider_joint_get_applied_torque(RID p_joint) {1891JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1892ERR_FAIL_NULL_V(joint, 0.0f);18931894ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_SLIDER, 0.0f);1895JoltSliderJoint3D *slider_joint = static_cast<JoltSliderJoint3D *>(joint);18961897return slider_joint->get_applied_torque();1898}18991900double JoltPhysicsServer3D::cone_twist_joint_get_jolt_param(RID p_joint, ConeTwistJointParamJolt p_param) const {1901JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1902ERR_FAIL_NULL_V(joint, 0.0);19031904ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0);1905JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);19061907return cone_twist_joint->get_jolt_param(p_param);1908}19091910void JoltPhysicsServer3D::cone_twist_joint_set_jolt_param(RID p_joint, ConeTwistJointParamJolt p_param, double p_value) {1911JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1912ERR_FAIL_NULL(joint);19131914ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_CONE_TWIST);1915JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);19161917return cone_twist_joint->set_jolt_param(p_param, p_value);1918}19191920bool JoltPhysicsServer3D::cone_twist_joint_get_jolt_flag(RID p_joint, ConeTwistJointFlagJolt p_flag) const {1921const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1922ERR_FAIL_NULL_V(joint, false);19231924ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, false);1925const JoltConeTwistJoint3D *cone_twist_joint = static_cast<const JoltConeTwistJoint3D *>(joint);19261927return cone_twist_joint->get_jolt_flag(p_flag);1928}19291930void JoltPhysicsServer3D::cone_twist_joint_set_jolt_flag(RID p_joint, ConeTwistJointFlagJolt p_flag, bool p_enabled) {1931JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1932ERR_FAIL_NULL(joint);19331934ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_CONE_TWIST);1935JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);19361937return cone_twist_joint->set_jolt_flag(p_flag, p_enabled);1938}19391940float JoltPhysicsServer3D::cone_twist_joint_get_applied_force(RID p_joint) {1941JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1942ERR_FAIL_NULL_V(joint, 0.0f);19431944ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0f);1945JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);19461947return cone_twist_joint->get_applied_force();1948}19491950float JoltPhysicsServer3D::cone_twist_joint_get_applied_torque(RID p_joint) {1951JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1952ERR_FAIL_NULL_V(joint, 0.0f);19531954ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_CONE_TWIST, 0.0f);1955JoltConeTwistJoint3D *cone_twist_joint = static_cast<JoltConeTwistJoint3D *>(joint);19561957return cone_twist_joint->get_applied_torque();1958}19591960double JoltPhysicsServer3D::generic_6dof_joint_get_jolt_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParamJolt p_param) const {1961JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1962ERR_FAIL_NULL_V(joint, 0.0);19631964ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0);1965JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);19661967return g6dof_joint->get_jolt_param(p_axis, p_param);1968}19691970void JoltPhysicsServer3D::generic_6dof_joint_set_jolt_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParamJolt p_param, double p_value) {1971JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1972ERR_FAIL_NULL(joint);19731974ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);1975JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);19761977return g6dof_joint->set_jolt_param(p_axis, p_param, p_value);1978}19791980bool JoltPhysicsServer3D::generic_6dof_joint_get_jolt_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlagJolt p_flag) const {1981const JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1982ERR_FAIL_NULL_V(joint, false);19831984ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, false);1985const JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<const JoltGeneric6DOFJoint3D *>(joint);19861987return g6dof_joint->get_jolt_flag(p_axis, p_flag);1988}19891990void JoltPhysicsServer3D::generic_6dof_joint_set_jolt_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlagJolt p_flag, bool p_enabled) {1991JoltJoint3D *joint = joint_owner.get_or_null(p_joint);1992ERR_FAIL_NULL(joint);19931994ERR_FAIL_COND(joint->get_type() != JOINT_TYPE_6DOF);1995JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);19961997return g6dof_joint->set_jolt_flag(p_axis, p_flag, p_enabled);1998}19992000float JoltPhysicsServer3D::generic_6dof_joint_get_applied_force(RID p_joint) {2001JoltJoint3D *joint = joint_owner.get_or_null(p_joint);2002ERR_FAIL_NULL_V(joint, 0.0f);20032004ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0f);2005JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);20062007return g6dof_joint->get_applied_force();2008}20092010float JoltPhysicsServer3D::generic_6dof_joint_get_applied_torque(RID p_joint) {2011JoltJoint3D *joint = joint_owner.get_or_null(p_joint);2012ERR_FAIL_NULL_V(joint, 0.0f);20132014ERR_FAIL_COND_V(joint->get_type() != JOINT_TYPE_6DOF, 0.0f);2015JoltGeneric6DOFJoint3D *g6dof_joint = static_cast<JoltGeneric6DOFJoint3D *>(joint);20162017return g6dof_joint->get_applied_torque();2018}201920202021