physics_server_3d.h 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. /**************************************************************************/
  2. /* physics_server_3d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef PHYSICS_SERVER_3D_H
  31. #define PHYSICS_SERVER_3D_H
  32. #ifndef _3D_DISABLED
  33. #include "core/io/resource.h"
  34. #include "core/object/class_db.h"
  35. #include "core/object/gdvirtual.gen.inc"
  36. #include "core/variant/native_ptr.h"
  37. class PhysicsDirectSpaceState3D;
  38. template <typename T>
  39. class TypedArray;
  40. class PhysicsDirectBodyState3D : public Object {
  41. GDCLASS(PhysicsDirectBodyState3D, Object);
  42. protected:
  43. static void _bind_methods();
  44. public:
  45. virtual Vector3 get_total_gravity() const = 0;
  46. virtual real_t get_total_angular_damp() const = 0;
  47. virtual real_t get_total_linear_damp() const = 0;
  48. virtual Vector3 get_center_of_mass() const = 0;
  49. virtual Vector3 get_center_of_mass_local() const = 0;
  50. virtual Basis get_principal_inertia_axes() const = 0;
  51. virtual real_t get_inverse_mass() const = 0; // get the mass
  52. virtual Vector3 get_inverse_inertia() const = 0; // get density of this body space
  53. virtual Basis get_inverse_inertia_tensor() const = 0; // get density of this body space
  54. virtual void set_linear_velocity(const Vector3 &p_velocity) = 0;
  55. virtual Vector3 get_linear_velocity() const = 0;
  56. virtual void set_angular_velocity(const Vector3 &p_velocity) = 0;
  57. virtual Vector3 get_angular_velocity() const = 0;
  58. virtual void set_transform(const Transform3D &p_transform) = 0;
  59. virtual Transform3D get_transform() const = 0;
  60. virtual Vector3 get_velocity_at_local_position(const Vector3 &p_position) const = 0;
  61. virtual void apply_central_impulse(const Vector3 &p_impulse) = 0;
  62. virtual void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) = 0;
  63. virtual void apply_torque_impulse(const Vector3 &p_impulse) = 0;
  64. virtual void apply_central_force(const Vector3 &p_force) = 0;
  65. virtual void apply_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()) = 0;
  66. virtual void apply_torque(const Vector3 &p_torque) = 0;
  67. virtual void add_constant_central_force(const Vector3 &p_force) = 0;
  68. virtual void add_constant_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()) = 0;
  69. virtual void add_constant_torque(const Vector3 &p_torque) = 0;
  70. virtual void set_constant_force(const Vector3 &p_force) = 0;
  71. virtual Vector3 get_constant_force() const = 0;
  72. virtual void set_constant_torque(const Vector3 &p_torque) = 0;
  73. virtual Vector3 get_constant_torque() const = 0;
  74. virtual void set_sleep_state(bool p_sleep) = 0;
  75. virtual bool is_sleeping() const = 0;
  76. virtual int get_contact_count() const = 0;
  77. virtual Vector3 get_contact_local_position(int p_contact_idx) const = 0;
  78. virtual Vector3 get_contact_local_normal(int p_contact_idx) const = 0;
  79. virtual Vector3 get_contact_impulse(int p_contact_idx) const = 0;
  80. virtual int get_contact_local_shape(int p_contact_idx) const = 0;
  81. virtual Vector3 get_contact_local_velocity_at_position(int p_contact_idx) const = 0;
  82. virtual RID get_contact_collider(int p_contact_idx) const = 0;
  83. virtual Vector3 get_contact_collider_position(int p_contact_idx) const = 0;
  84. virtual ObjectID get_contact_collider_id(int p_contact_idx) const = 0;
  85. virtual Object *get_contact_collider_object(int p_contact_idx) const;
  86. virtual int get_contact_collider_shape(int p_contact_idx) const = 0;
  87. virtual Vector3 get_contact_collider_velocity_at_position(int p_contact_idx) const = 0;
  88. virtual real_t get_step() const = 0;
  89. virtual void integrate_forces();
  90. virtual PhysicsDirectSpaceState3D *get_space_state() = 0;
  91. PhysicsDirectBodyState3D();
  92. };
  93. class PhysicsRayQueryParameters3D;
  94. class PhysicsPointQueryParameters3D;
  95. class PhysicsShapeQueryParameters3D;
  96. class PhysicsDirectSpaceState3D : public Object {
  97. GDCLASS(PhysicsDirectSpaceState3D, Object);
  98. private:
  99. Dictionary _intersect_ray(const Ref<PhysicsRayQueryParameters3D> &p_ray_query);
  100. TypedArray<Dictionary> _intersect_point(const Ref<PhysicsPointQueryParameters3D> &p_point_query, int p_max_results = 32);
  101. TypedArray<Dictionary> _intersect_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results = 32);
  102. Vector<real_t> _cast_motion(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query);
  103. TypedArray<Vector3> _collide_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results = 32);
  104. Dictionary _get_rest_info(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query);
  105. protected:
  106. static void _bind_methods();
  107. public:
  108. struct RayParameters {
  109. Vector3 from;
  110. Vector3 to;
  111. HashSet<RID> exclude;
  112. uint32_t collision_mask = UINT32_MAX;
  113. bool collide_with_bodies = true;
  114. bool collide_with_areas = false;
  115. bool hit_from_inside = false;
  116. bool hit_back_faces = true;
  117. bool pick_ray = false;
  118. };
  119. struct RayResult {
  120. Vector3 position;
  121. Vector3 normal;
  122. RID rid;
  123. ObjectID collider_id;
  124. Object *collider = nullptr;
  125. int shape = 0;
  126. int face_index = -1;
  127. };
  128. virtual bool intersect_ray(const RayParameters &p_parameters, RayResult &r_result) = 0;
  129. struct ShapeResult {
  130. RID rid;
  131. ObjectID collider_id;
  132. Object *collider = nullptr;
  133. int shape = 0;
  134. };
  135. struct PointParameters {
  136. Vector3 position;
  137. HashSet<RID> exclude;
  138. uint32_t collision_mask = UINT32_MAX;
  139. bool collide_with_bodies = true;
  140. bool collide_with_areas = false;
  141. };
  142. virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) = 0;
  143. struct ShapeParameters {
  144. RID shape_rid;
  145. Transform3D transform;
  146. Vector3 motion;
  147. real_t margin = 0.0;
  148. HashSet<RID> exclude;
  149. uint32_t collision_mask = UINT32_MAX;
  150. bool collide_with_bodies = true;
  151. bool collide_with_areas = false;
  152. };
  153. struct ShapeRestInfo {
  154. Vector3 point;
  155. Vector3 normal;
  156. RID rid;
  157. ObjectID collider_id;
  158. int shape = 0;
  159. Vector3 linear_velocity; // Velocity at contact point.
  160. };
  161. virtual int intersect_shape(const ShapeParameters &p_parameters, ShapeResult *r_results, int p_result_max) = 0;
  162. virtual bool cast_motion(const ShapeParameters &p_parameters, real_t &p_closest_safe, real_t &p_closest_unsafe, ShapeRestInfo *r_info = nullptr) = 0;
  163. virtual bool collide_shape(const ShapeParameters &p_parameters, Vector3 *r_results, int p_result_max, int &r_result_count) = 0;
  164. virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) = 0;
  165. virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const = 0;
  166. PhysicsDirectSpaceState3D();
  167. };
  168. class PhysicsServer3DRenderingServerHandler : public Object {
  169. GDCLASS(PhysicsServer3DRenderingServerHandler, Object)
  170. protected:
  171. GDVIRTUAL2(_set_vertex, int, const Vector3 &)
  172. GDVIRTUAL2(_set_normal, int, const Vector3 &)
  173. GDVIRTUAL1(_set_aabb, const AABB &)
  174. static void _bind_methods();
  175. public:
  176. virtual void set_vertex(int p_vertex_id, const Vector3 &p_vertex);
  177. virtual void set_normal(int p_vertex_id, const Vector3 &p_normal);
  178. virtual void set_aabb(const AABB &p_aabb);
  179. virtual ~PhysicsServer3DRenderingServerHandler() {}
  180. };
  181. class PhysicsTestMotionParameters3D;
  182. class PhysicsTestMotionResult3D;
  183. class PhysicsServer3D : public Object {
  184. GDCLASS(PhysicsServer3D, Object);
  185. static PhysicsServer3D *singleton;
  186. virtual bool _body_test_motion(RID p_body, const Ref<PhysicsTestMotionParameters3D> &p_parameters, const Ref<PhysicsTestMotionResult3D> &p_result = Ref<PhysicsTestMotionResult3D>());
  187. protected:
  188. static void _bind_methods();
  189. public:
  190. static PhysicsServer3D *get_singleton();
  191. enum ShapeType {
  192. SHAPE_WORLD_BOUNDARY, ///< plane:"plane"
  193. SHAPE_SEPARATION_RAY, ///< float:"length"
  194. SHAPE_SPHERE, ///< float:"radius"
  195. SHAPE_BOX, ///< vec3:"extents"
  196. SHAPE_CAPSULE, ///< dict( float:"radius", float:"height"):capsule
  197. SHAPE_CYLINDER, ///< dict( float:"radius", float:"height"):cylinder
  198. SHAPE_CONVEX_POLYGON, ///< array of planes:"planes"
  199. SHAPE_CONCAVE_POLYGON, ///< vector3 array:"triangles" , or Dictionary with "indices" (int array) and "triangles" (Vector3 array)
  200. SHAPE_HEIGHTMAP, ///< dict( int:"width", int:"depth",float:"cell_size", float_array:"heights"
  201. SHAPE_SOFT_BODY, ///< Used internally, can't be created from the physics server.
  202. SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_create() with this value will result in an error
  203. };
  204. RID shape_create(ShapeType p_shape);
  205. virtual RID world_boundary_shape_create() = 0;
  206. virtual RID separation_ray_shape_create() = 0;
  207. virtual RID sphere_shape_create() = 0;
  208. virtual RID box_shape_create() = 0;
  209. virtual RID capsule_shape_create() = 0;
  210. virtual RID cylinder_shape_create() = 0;
  211. virtual RID convex_polygon_shape_create() = 0;
  212. virtual RID concave_polygon_shape_create() = 0;
  213. virtual RID heightmap_shape_create() = 0;
  214. virtual RID custom_shape_create() = 0;
  215. virtual void shape_set_data(RID p_shape, const Variant &p_data) = 0;
  216. virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) = 0;
  217. virtual ShapeType shape_get_type(RID p_shape) const = 0;
  218. virtual Variant shape_get_data(RID p_shape) const = 0;
  219. virtual void shape_set_margin(RID p_shape, real_t p_margin) = 0;
  220. virtual real_t shape_get_margin(RID p_shape) const = 0;
  221. virtual real_t shape_get_custom_solver_bias(RID p_shape) const = 0;
  222. /* SPACE API */
  223. virtual RID space_create() = 0;
  224. virtual void space_set_active(RID p_space, bool p_active) = 0;
  225. virtual bool space_is_active(RID p_space) const = 0;
  226. enum SpaceParameter {
  227. SPACE_PARAM_CONTACT_RECYCLE_RADIUS,
  228. SPACE_PARAM_CONTACT_MAX_SEPARATION,
  229. SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION,
  230. SPACE_PARAM_CONTACT_DEFAULT_BIAS,
  231. SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD,
  232. SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD,
  233. SPACE_PARAM_BODY_TIME_TO_SLEEP,
  234. SPACE_PARAM_SOLVER_ITERATIONS,
  235. };
  236. virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0;
  237. virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const = 0;
  238. // this function only works on physics process, errors and returns null otherwise
  239. virtual PhysicsDirectSpaceState3D *space_get_direct_state(RID p_space) = 0;
  240. virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) = 0;
  241. virtual Vector<Vector3> space_get_contacts(RID p_space) const = 0;
  242. virtual int space_get_contact_count(RID p_space) const = 0;
  243. //missing space parameters
  244. /* AREA API */
  245. //missing attenuation? missing better override?
  246. enum AreaParameter {
  247. AREA_PARAM_GRAVITY_OVERRIDE_MODE,
  248. AREA_PARAM_GRAVITY,
  249. AREA_PARAM_GRAVITY_VECTOR,
  250. AREA_PARAM_GRAVITY_IS_POINT,
  251. AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE,
  252. AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE,
  253. AREA_PARAM_LINEAR_DAMP,
  254. AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE,
  255. AREA_PARAM_ANGULAR_DAMP,
  256. AREA_PARAM_PRIORITY,
  257. AREA_PARAM_WIND_FORCE_MAGNITUDE,
  258. AREA_PARAM_WIND_SOURCE,
  259. AREA_PARAM_WIND_DIRECTION,
  260. AREA_PARAM_WIND_ATTENUATION_FACTOR,
  261. };
  262. virtual RID area_create() = 0;
  263. virtual void area_set_space(RID p_area, RID p_space) = 0;
  264. virtual RID area_get_space(RID p_area) const = 0;
  265. enum AreaSpaceOverrideMode {
  266. AREA_SPACE_OVERRIDE_DISABLED,
  267. AREA_SPACE_OVERRIDE_COMBINE,
  268. AREA_SPACE_OVERRIDE_COMBINE_REPLACE,
  269. AREA_SPACE_OVERRIDE_REPLACE,
  270. AREA_SPACE_OVERRIDE_REPLACE_COMBINE
  271. };
  272. virtual void area_add_shape(RID p_area, RID p_shape, const Transform3D &p_transform = Transform3D(), bool p_disabled = false) = 0;
  273. virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) = 0;
  274. virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform3D &p_transform) = 0;
  275. virtual int area_get_shape_count(RID p_area) const = 0;
  276. virtual RID area_get_shape(RID p_area, int p_shape_idx) const = 0;
  277. virtual Transform3D area_get_shape_transform(RID p_area, int p_shape_idx) const = 0;
  278. virtual void area_remove_shape(RID p_area, int p_shape_idx) = 0;
  279. virtual void area_clear_shapes(RID p_area) = 0;
  280. virtual void area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) = 0;
  281. virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id) = 0;
  282. virtual ObjectID area_get_object_instance_id(RID p_area) const = 0;
  283. virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) = 0;
  284. virtual void area_set_transform(RID p_area, const Transform3D &p_transform) = 0;
  285. virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const = 0;
  286. virtual Transform3D area_get_transform(RID p_area) const = 0;
  287. virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) = 0;
  288. virtual uint32_t area_get_collision_layer(RID p_area) const = 0;
  289. virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) = 0;
  290. virtual uint32_t area_get_collision_mask(RID p_area) const = 0;
  291. virtual void area_set_monitorable(RID p_area, bool p_monitorable) = 0;
  292. virtual void area_set_monitor_callback(RID p_area, const Callable &p_callback) = 0;
  293. virtual void area_set_area_monitor_callback(RID p_area, const Callable &p_callback) = 0;
  294. virtual void area_set_ray_pickable(RID p_area, bool p_enable) = 0;
  295. /* BODY API */
  296. //missing ccd?
  297. enum BodyMode {
  298. BODY_MODE_STATIC,
  299. BODY_MODE_KINEMATIC,
  300. BODY_MODE_RIGID,
  301. BODY_MODE_RIGID_LINEAR,
  302. };
  303. enum BodyDampMode {
  304. BODY_DAMP_MODE_COMBINE,
  305. BODY_DAMP_MODE_REPLACE,
  306. };
  307. virtual RID body_create() = 0;
  308. virtual void body_set_space(RID p_body, RID p_space) = 0;
  309. virtual RID body_get_space(RID p_body) const = 0;
  310. virtual void body_set_mode(RID p_body, BodyMode p_mode) = 0;
  311. virtual BodyMode body_get_mode(RID p_body) const = 0;
  312. virtual void body_add_shape(RID p_body, RID p_shape, const Transform3D &p_transform = Transform3D(), bool p_disabled = false) = 0;
  313. virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) = 0;
  314. virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform3D &p_transform) = 0;
  315. virtual int body_get_shape_count(RID p_body) const = 0;
  316. virtual RID body_get_shape(RID p_body, int p_shape_idx) const = 0;
  317. virtual Transform3D body_get_shape_transform(RID p_body, int p_shape_idx) const = 0;
  318. virtual void body_remove_shape(RID p_body, int p_shape_idx) = 0;
  319. virtual void body_clear_shapes(RID p_body) = 0;
  320. virtual void body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) = 0;
  321. virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id) = 0;
  322. virtual ObjectID body_get_object_instance_id(RID p_body) const = 0;
  323. virtual void body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) = 0;
  324. virtual bool body_is_continuous_collision_detection_enabled(RID p_body) const = 0;
  325. virtual void body_set_collision_layer(RID p_body, uint32_t p_layer) = 0;
  326. virtual uint32_t body_get_collision_layer(RID p_body) const = 0;
  327. virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) = 0;
  328. virtual uint32_t body_get_collision_mask(RID p_body) const = 0;
  329. virtual void body_set_collision_priority(RID p_body, real_t p_priority) = 0;
  330. virtual real_t body_get_collision_priority(RID p_body) const = 0;
  331. virtual void body_set_user_flags(RID p_body, uint32_t p_flags) = 0;
  332. virtual uint32_t body_get_user_flags(RID p_body) const = 0;
  333. // common body variables
  334. enum BodyParameter {
  335. BODY_PARAM_BOUNCE,
  336. BODY_PARAM_FRICTION,
  337. BODY_PARAM_MASS, ///< unused for static, always infinite
  338. BODY_PARAM_INERTIA,
  339. BODY_PARAM_CENTER_OF_MASS,
  340. BODY_PARAM_GRAVITY_SCALE,
  341. BODY_PARAM_LINEAR_DAMP_MODE,
  342. BODY_PARAM_ANGULAR_DAMP_MODE,
  343. BODY_PARAM_LINEAR_DAMP,
  344. BODY_PARAM_ANGULAR_DAMP,
  345. BODY_PARAM_MAX,
  346. };
  347. virtual void body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) = 0;
  348. virtual Variant body_get_param(RID p_body, BodyParameter p_param) const = 0;
  349. virtual void body_reset_mass_properties(RID p_body) = 0;
  350. //state
  351. enum BodyState {
  352. BODY_STATE_TRANSFORM,
  353. BODY_STATE_LINEAR_VELOCITY,
  354. BODY_STATE_ANGULAR_VELOCITY,
  355. BODY_STATE_SLEEPING,
  356. BODY_STATE_CAN_SLEEP
  357. };
  358. virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) = 0;
  359. virtual Variant body_get_state(RID p_body, BodyState p_state) const = 0;
  360. virtual void body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) = 0;
  361. virtual void body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) = 0;
  362. virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) = 0;
  363. virtual void body_apply_central_force(RID p_body, const Vector3 &p_force) = 0;
  364. virtual void body_apply_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3()) = 0;
  365. virtual void body_apply_torque(RID p_body, const Vector3 &p_torque) = 0;
  366. virtual void body_add_constant_central_force(RID p_body, const Vector3 &p_force) = 0;
  367. virtual void body_add_constant_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3()) = 0;
  368. virtual void body_add_constant_torque(RID p_body, const Vector3 &p_torque) = 0;
  369. virtual void body_set_constant_force(RID p_body, const Vector3 &p_force) = 0;
  370. virtual Vector3 body_get_constant_force(RID p_body) const = 0;
  371. virtual void body_set_constant_torque(RID p_body, const Vector3 &p_torque) = 0;
  372. virtual Vector3 body_get_constant_torque(RID p_body) const = 0;
  373. virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) = 0;
  374. enum BodyAxis {
  375. BODY_AXIS_LINEAR_X = 1 << 0,
  376. BODY_AXIS_LINEAR_Y = 1 << 1,
  377. BODY_AXIS_LINEAR_Z = 1 << 2,
  378. BODY_AXIS_ANGULAR_X = 1 << 3,
  379. BODY_AXIS_ANGULAR_Y = 1 << 4,
  380. BODY_AXIS_ANGULAR_Z = 1 << 5
  381. };
  382. virtual void body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) = 0;
  383. virtual bool body_is_axis_locked(RID p_body, BodyAxis p_axis) const = 0;
  384. //fix
  385. virtual void body_add_collision_exception(RID p_body, RID p_body_b) = 0;
  386. virtual void body_remove_collision_exception(RID p_body, RID p_body_b) = 0;
  387. virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) = 0;
  388. virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) = 0;
  389. virtual int body_get_max_contacts_reported(RID p_body) const = 0;
  390. //missing remove
  391. virtual void body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) = 0;
  392. virtual real_t body_get_contacts_reported_depth_threshold(RID p_body) const = 0;
  393. virtual void body_set_omit_force_integration(RID p_body, bool p_omit) = 0;
  394. virtual bool body_is_omitting_force_integration(RID p_body) const = 0;
  395. virtual void body_set_state_sync_callback(RID p_body, const Callable &p_callable) = 0;
  396. virtual void body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata = Variant()) = 0;
  397. virtual void body_set_ray_pickable(RID p_body, bool p_enable) = 0;
  398. // this function only works on physics process, errors and returns null otherwise
  399. virtual PhysicsDirectBodyState3D *body_get_direct_state(RID p_body) = 0;
  400. struct MotionParameters {
  401. Transform3D from;
  402. Vector3 motion;
  403. real_t margin = 0.001;
  404. int max_collisions = 1;
  405. bool collide_separation_ray = false;
  406. HashSet<RID> exclude_bodies;
  407. HashSet<ObjectID> exclude_objects;
  408. bool recovery_as_collision = false;
  409. MotionParameters() {}
  410. MotionParameters(const Transform3D &p_from, const Vector3 &p_motion, real_t p_margin = 0.001) :
  411. from(p_from),
  412. motion(p_motion),
  413. margin(p_margin) {}
  414. };
  415. struct MotionCollision {
  416. Vector3 position;
  417. Vector3 normal;
  418. Vector3 collider_velocity;
  419. Vector3 collider_angular_velocity;
  420. real_t depth = 0.0;
  421. int local_shape = 0;
  422. ObjectID collider_id;
  423. RID collider;
  424. int collider_shape = 0;
  425. real_t get_angle(Vector3 p_up_direction) const {
  426. return Math::acos(normal.dot(p_up_direction));
  427. }
  428. };
  429. struct MotionResult {
  430. Vector3 travel;
  431. Vector3 remainder;
  432. real_t collision_depth = 0.0;
  433. real_t collision_safe_fraction = 0.0;
  434. real_t collision_unsafe_fraction = 0.0;
  435. static const int MAX_COLLISIONS = 32;
  436. MotionCollision collisions[MAX_COLLISIONS];
  437. int collision_count = 0;
  438. };
  439. virtual bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) = 0;
  440. /* SOFT BODY */
  441. virtual RID soft_body_create() = 0;
  442. virtual void soft_body_update_rendering_server(RID p_body, PhysicsServer3DRenderingServerHandler *p_rendering_server_handler) = 0;
  443. virtual void soft_body_set_space(RID p_body, RID p_space) = 0;
  444. virtual RID soft_body_get_space(RID p_body) const = 0;
  445. virtual void soft_body_set_mesh(RID p_body, RID p_mesh) = 0;
  446. virtual AABB soft_body_get_bounds(RID p_body) const = 0;
  447. virtual void soft_body_set_collision_layer(RID p_body, uint32_t p_layer) = 0;
  448. virtual uint32_t soft_body_get_collision_layer(RID p_body) const = 0;
  449. virtual void soft_body_set_collision_mask(RID p_body, uint32_t p_mask) = 0;
  450. virtual uint32_t soft_body_get_collision_mask(RID p_body) const = 0;
  451. virtual void soft_body_add_collision_exception(RID p_body, RID p_body_b) = 0;
  452. virtual void soft_body_remove_collision_exception(RID p_body, RID p_body_b) = 0;
  453. virtual void soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) = 0;
  454. virtual void soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) = 0;
  455. virtual Variant soft_body_get_state(RID p_body, BodyState p_state) const = 0;
  456. virtual void soft_body_set_transform(RID p_body, const Transform3D &p_transform) = 0;
  457. virtual void soft_body_set_ray_pickable(RID p_body, bool p_enable) = 0;
  458. virtual void soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) = 0;
  459. virtual int soft_body_get_simulation_precision(RID p_body) const = 0;
  460. virtual void soft_body_set_total_mass(RID p_body, real_t p_total_mass) = 0;
  461. virtual real_t soft_body_get_total_mass(RID p_body) const = 0;
  462. virtual void soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) = 0;
  463. virtual real_t soft_body_get_linear_stiffness(RID p_body) const = 0;
  464. virtual void soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) = 0;
  465. virtual real_t soft_body_get_pressure_coefficient(RID p_body) const = 0;
  466. virtual void soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) = 0;
  467. virtual real_t soft_body_get_damping_coefficient(RID p_body) const = 0;
  468. virtual void soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) = 0;
  469. virtual real_t soft_body_get_drag_coefficient(RID p_body) const = 0;
  470. virtual void soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) = 0;
  471. virtual Vector3 soft_body_get_point_global_position(RID p_body, int p_point_index) const = 0;
  472. virtual void soft_body_remove_all_pinned_points(RID p_body) = 0;
  473. virtual void soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) = 0;
  474. virtual bool soft_body_is_point_pinned(RID p_body, int p_point_index) const = 0;
  475. /* JOINT API */
  476. enum JointType {
  477. JOINT_TYPE_PIN,
  478. JOINT_TYPE_HINGE,
  479. JOINT_TYPE_SLIDER,
  480. JOINT_TYPE_CONE_TWIST,
  481. JOINT_TYPE_6DOF,
  482. JOINT_TYPE_MAX,
  483. };
  484. virtual RID joint_create() = 0;
  485. virtual void joint_clear(RID p_joint) = 0;
  486. virtual JointType joint_get_type(RID p_joint) const = 0;
  487. virtual void joint_set_solver_priority(RID p_joint, int p_priority) = 0;
  488. virtual int joint_get_solver_priority(RID p_joint) const = 0;
  489. virtual void joint_disable_collisions_between_bodies(RID p_joint, bool p_disable) = 0;
  490. virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const = 0;
  491. virtual void joint_make_pin(RID p_joint, RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) = 0;
  492. enum PinJointParam {
  493. PIN_JOINT_BIAS,
  494. PIN_JOINT_DAMPING,
  495. PIN_JOINT_IMPULSE_CLAMP
  496. };
  497. virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) = 0;
  498. virtual real_t pin_joint_get_param(RID p_joint, PinJointParam p_param) const = 0;
  499. virtual void pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) = 0;
  500. virtual Vector3 pin_joint_get_local_a(RID p_joint) const = 0;
  501. virtual void pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) = 0;
  502. virtual Vector3 pin_joint_get_local_b(RID p_joint) const = 0;
  503. enum HingeJointParam {
  504. HINGE_JOINT_BIAS,
  505. HINGE_JOINT_LIMIT_UPPER,
  506. HINGE_JOINT_LIMIT_LOWER,
  507. HINGE_JOINT_LIMIT_BIAS,
  508. HINGE_JOINT_LIMIT_SOFTNESS,
  509. HINGE_JOINT_LIMIT_RELAXATION,
  510. HINGE_JOINT_MOTOR_TARGET_VELOCITY,
  511. HINGE_JOINT_MOTOR_MAX_IMPULSE,
  512. HINGE_JOINT_MAX
  513. };
  514. enum HingeJointFlag {
  515. HINGE_JOINT_FLAG_USE_LIMIT,
  516. HINGE_JOINT_FLAG_ENABLE_MOTOR,
  517. HINGE_JOINT_FLAG_MAX
  518. };
  519. virtual void joint_make_hinge(RID p_joint, RID p_body_A, const Transform3D &p_hinge_A, RID p_body_B, const Transform3D &p_hinge_B) = 0;
  520. virtual void 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) = 0;
  521. virtual void hinge_joint_set_param(RID p_joint, HingeJointParam p_param, real_t p_value) = 0;
  522. virtual real_t hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const = 0;
  523. virtual void hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_enabled) = 0;
  524. virtual bool hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const = 0;
  525. enum SliderJointParam {
  526. SLIDER_JOINT_LINEAR_LIMIT_UPPER,
  527. SLIDER_JOINT_LINEAR_LIMIT_LOWER,
  528. SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS,
  529. SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION,
  530. SLIDER_JOINT_LINEAR_LIMIT_DAMPING,
  531. SLIDER_JOINT_LINEAR_MOTION_SOFTNESS,
  532. SLIDER_JOINT_LINEAR_MOTION_RESTITUTION,
  533. SLIDER_JOINT_LINEAR_MOTION_DAMPING,
  534. SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS,
  535. SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION,
  536. SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING,
  537. SLIDER_JOINT_ANGULAR_LIMIT_UPPER,
  538. SLIDER_JOINT_ANGULAR_LIMIT_LOWER,
  539. SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS,
  540. SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION,
  541. SLIDER_JOINT_ANGULAR_LIMIT_DAMPING,
  542. SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS,
  543. SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION,
  544. SLIDER_JOINT_ANGULAR_MOTION_DAMPING,
  545. SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS,
  546. SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION,
  547. SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING,
  548. SLIDER_JOINT_MAX
  549. };
  550. virtual void joint_make_slider(RID p_joint, RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) = 0; //reference frame is A
  551. virtual void slider_joint_set_param(RID p_joint, SliderJointParam p_param, real_t p_value) = 0;
  552. virtual real_t slider_joint_get_param(RID p_joint, SliderJointParam p_param) const = 0;
  553. enum ConeTwistJointParam {
  554. CONE_TWIST_JOINT_SWING_SPAN,
  555. CONE_TWIST_JOINT_TWIST_SPAN,
  556. CONE_TWIST_JOINT_BIAS,
  557. CONE_TWIST_JOINT_SOFTNESS,
  558. CONE_TWIST_JOINT_RELAXATION,
  559. CONE_TWIST_MAX
  560. };
  561. virtual void joint_make_cone_twist(RID p_joint, RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) = 0; //reference frame is A
  562. virtual void cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, real_t p_value) = 0;
  563. virtual real_t cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const = 0;
  564. enum G6DOFJointAxisParam {
  565. G6DOF_JOINT_LINEAR_LOWER_LIMIT,
  566. G6DOF_JOINT_LINEAR_UPPER_LIMIT,
  567. G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS,
  568. G6DOF_JOINT_LINEAR_RESTITUTION,
  569. G6DOF_JOINT_LINEAR_DAMPING,
  570. G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY,
  571. G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT,
  572. G6DOF_JOINT_LINEAR_SPRING_STIFFNESS,
  573. G6DOF_JOINT_LINEAR_SPRING_DAMPING,
  574. G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT,
  575. G6DOF_JOINT_ANGULAR_LOWER_LIMIT,
  576. G6DOF_JOINT_ANGULAR_UPPER_LIMIT,
  577. G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS,
  578. G6DOF_JOINT_ANGULAR_DAMPING,
  579. G6DOF_JOINT_ANGULAR_RESTITUTION,
  580. G6DOF_JOINT_ANGULAR_FORCE_LIMIT,
  581. G6DOF_JOINT_ANGULAR_ERP,
  582. G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY,
  583. G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT,
  584. G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS,
  585. G6DOF_JOINT_ANGULAR_SPRING_DAMPING,
  586. G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT,
  587. G6DOF_JOINT_MAX
  588. };
  589. enum G6DOFJointAxisFlag {
  590. G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT,
  591. G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT,
  592. G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING,
  593. G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING,
  594. G6DOF_JOINT_FLAG_ENABLE_MOTOR,
  595. G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR,
  596. G6DOF_JOINT_FLAG_MAX
  597. };
  598. virtual void joint_make_generic_6dof(RID p_joint, RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) = 0; //reference frame is A
  599. virtual void generic_6dof_joint_set_param(RID p_joint, Vector3::Axis, G6DOFJointAxisParam p_param, real_t p_value) = 0;
  600. virtual real_t generic_6dof_joint_get_param(RID p_joint, Vector3::Axis, G6DOFJointAxisParam p_param) const = 0;
  601. virtual void generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis, G6DOFJointAxisFlag p_flag, bool p_enable) = 0;
  602. virtual bool generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis, G6DOFJointAxisFlag p_flag) const = 0;
  603. /* QUERY API */
  604. enum AreaBodyStatus {
  605. AREA_BODY_ADDED,
  606. AREA_BODY_REMOVED
  607. };
  608. /* MISC */
  609. virtual void free(RID p_rid) = 0;
  610. virtual void set_active(bool p_active) = 0;
  611. virtual void init() = 0;
  612. virtual void step(real_t p_step) = 0;
  613. virtual void sync() = 0;
  614. virtual void flush_queries() = 0;
  615. virtual void end_sync() = 0;
  616. virtual void finish() = 0;
  617. virtual bool is_flushing_queries() const = 0;
  618. enum ProcessInfo {
  619. INFO_ACTIVE_OBJECTS,
  620. INFO_COLLISION_PAIRS,
  621. INFO_ISLAND_COUNT
  622. };
  623. virtual int get_process_info(ProcessInfo p_info) = 0;
  624. PhysicsServer3D();
  625. ~PhysicsServer3D();
  626. };
  627. class PhysicsRayQueryParameters3D : public RefCounted {
  628. GDCLASS(PhysicsRayQueryParameters3D, RefCounted);
  629. PhysicsDirectSpaceState3D::RayParameters parameters;
  630. protected:
  631. static void _bind_methods();
  632. public:
  633. static Ref<PhysicsRayQueryParameters3D> create(Vector3 p_from, Vector3 p_to, uint32_t p_mask, const TypedArray<RID> &p_exclude);
  634. const PhysicsDirectSpaceState3D::RayParameters &get_parameters() const { return parameters; }
  635. void set_from(const Vector3 &p_from) { parameters.from = p_from; }
  636. const Vector3 &get_from() const { return parameters.from; }
  637. void set_to(const Vector3 &p_to) { parameters.to = p_to; }
  638. const Vector3 &get_to() const { return parameters.to; }
  639. void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
  640. uint32_t get_collision_mask() const { return parameters.collision_mask; }
  641. void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
  642. bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
  643. void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
  644. bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
  645. void set_hit_from_inside(bool p_enable) { parameters.hit_from_inside = p_enable; }
  646. bool is_hit_from_inside_enabled() const { return parameters.hit_from_inside; }
  647. void set_hit_back_faces(bool p_enable) { parameters.hit_back_faces = p_enable; }
  648. bool is_hit_back_faces_enabled() const { return parameters.hit_back_faces; }
  649. void set_exclude(const TypedArray<RID> &p_exclude);
  650. TypedArray<RID> get_exclude() const;
  651. };
  652. class PhysicsPointQueryParameters3D : public RefCounted {
  653. GDCLASS(PhysicsPointQueryParameters3D, RefCounted);
  654. PhysicsDirectSpaceState3D::PointParameters parameters;
  655. protected:
  656. static void _bind_methods();
  657. public:
  658. const PhysicsDirectSpaceState3D::PointParameters &get_parameters() const { return parameters; }
  659. void set_position(const Vector3 &p_position) { parameters.position = p_position; }
  660. const Vector3 &get_position() const { return parameters.position; }
  661. void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
  662. uint32_t get_collision_mask() const { return parameters.collision_mask; }
  663. void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
  664. bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
  665. void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
  666. bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
  667. void set_exclude(const TypedArray<RID> &p_exclude);
  668. TypedArray<RID> get_exclude() const;
  669. };
  670. class PhysicsShapeQueryParameters3D : public RefCounted {
  671. GDCLASS(PhysicsShapeQueryParameters3D, RefCounted);
  672. PhysicsDirectSpaceState3D::ShapeParameters parameters;
  673. Ref<Resource> shape_ref;
  674. protected:
  675. static void _bind_methods();
  676. public:
  677. const PhysicsDirectSpaceState3D::ShapeParameters &get_parameters() const { return parameters; }
  678. void set_shape(const Ref<Resource> &p_shape_ref);
  679. Ref<Resource> get_shape() const { return shape_ref; }
  680. void set_shape_rid(const RID &p_shape);
  681. RID get_shape_rid() const { return parameters.shape_rid; }
  682. void set_transform(const Transform3D &p_transform) { parameters.transform = p_transform; }
  683. const Transform3D &get_transform() const { return parameters.transform; }
  684. void set_motion(const Vector3 &p_motion) { parameters.motion = p_motion; }
  685. const Vector3 &get_motion() const { return parameters.motion; }
  686. void set_margin(real_t p_margin) { parameters.margin = p_margin; }
  687. real_t get_margin() const { return parameters.margin; }
  688. void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
  689. uint32_t get_collision_mask() const { return parameters.collision_mask; }
  690. void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
  691. bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
  692. void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
  693. bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
  694. void set_exclude(const TypedArray<RID> &p_exclude);
  695. TypedArray<RID> get_exclude() const;
  696. };
  697. class PhysicsTestMotionParameters3D : public RefCounted {
  698. GDCLASS(PhysicsTestMotionParameters3D, RefCounted);
  699. PhysicsServer3D::MotionParameters parameters;
  700. protected:
  701. static void _bind_methods();
  702. public:
  703. const PhysicsServer3D::MotionParameters &get_parameters() const { return parameters; }
  704. const Transform3D &get_from() const { return parameters.from; }
  705. void set_from(const Transform3D &p_from) { parameters.from = p_from; }
  706. const Vector3 &get_motion() const { return parameters.motion; }
  707. void set_motion(const Vector3 &p_motion) { parameters.motion = p_motion; }
  708. real_t get_margin() const { return parameters.margin; }
  709. void set_margin(real_t p_margin) { parameters.margin = p_margin; }
  710. int get_max_collisions() const { return parameters.max_collisions; }
  711. void set_max_collisions(int p_max_collisions) { parameters.max_collisions = p_max_collisions; }
  712. bool is_collide_separation_ray_enabled() const { return parameters.collide_separation_ray; }
  713. void set_collide_separation_ray_enabled(bool p_enabled) { parameters.collide_separation_ray = p_enabled; }
  714. TypedArray<RID> get_exclude_bodies() const;
  715. void set_exclude_bodies(const TypedArray<RID> &p_exclude);
  716. TypedArray<uint64_t> get_exclude_objects() const;
  717. void set_exclude_objects(const TypedArray<uint64_t> &p_exclude);
  718. bool is_recovery_as_collision_enabled() const { return parameters.recovery_as_collision; }
  719. void set_recovery_as_collision_enabled(bool p_enabled) { parameters.recovery_as_collision = p_enabled; }
  720. };
  721. class PhysicsTestMotionResult3D : public RefCounted {
  722. GDCLASS(PhysicsTestMotionResult3D, RefCounted);
  723. PhysicsServer3D::MotionResult result;
  724. protected:
  725. static void _bind_methods();
  726. public:
  727. PhysicsServer3D::MotionResult *get_result_ptr() const { return const_cast<PhysicsServer3D::MotionResult *>(&result); }
  728. Vector3 get_travel() const;
  729. Vector3 get_remainder() const;
  730. real_t get_collision_safe_fraction() const;
  731. real_t get_collision_unsafe_fraction() const;
  732. int get_collision_count() const;
  733. Vector3 get_collision_point(int p_collision_index = 0) const;
  734. Vector3 get_collision_normal(int p_collision_index = 0) const;
  735. Vector3 get_collider_velocity(int p_collision_index = 0) const;
  736. ObjectID get_collider_id(int p_collision_index = 0) const;
  737. RID get_collider_rid(int p_collision_index = 0) const;
  738. Object *get_collider(int p_collision_index = 0) const;
  739. int get_collider_shape(int p_collision_index = 0) const;
  740. int get_collision_local_shape(int p_collision_index = 0) const;
  741. real_t get_collision_depth(int p_collision_index = 0) const;
  742. };
  743. class PhysicsServer3DManager : public Object {
  744. GDCLASS(PhysicsServer3DManager, Object);
  745. static PhysicsServer3DManager *singleton;
  746. struct ClassInfo {
  747. String name;
  748. Callable create_callback;
  749. ClassInfo() {}
  750. ClassInfo(String p_name, Callable p_create_callback) :
  751. name(p_name),
  752. create_callback(p_create_callback) {}
  753. ClassInfo(const ClassInfo &p_ci) :
  754. name(p_ci.name),
  755. create_callback(p_ci.create_callback) {}
  756. void operator=(const ClassInfo &p_ci) {
  757. name = p_ci.name;
  758. create_callback = p_ci.create_callback;
  759. }
  760. };
  761. Vector<ClassInfo> physics_servers;
  762. int default_server_id = -1;
  763. int default_server_priority = -1;
  764. void on_servers_changed();
  765. protected:
  766. static void _bind_methods();
  767. public:
  768. static const String setting_property_name;
  769. static PhysicsServer3DManager *get_singleton();
  770. void register_server(const String &p_name, const Callable &p_create_callback);
  771. void set_default_server(const String &p_name, int p_priority = 0);
  772. int find_server_id(const String &p_name);
  773. int get_servers_count();
  774. String get_server_name(int p_id);
  775. PhysicsServer3D *new_default_server();
  776. PhysicsServer3D *new_server(const String &p_name);
  777. PhysicsServer3DManager();
  778. ~PhysicsServer3DManager();
  779. };
  780. VARIANT_ENUM_CAST(PhysicsServer3D::ShapeType);
  781. VARIANT_ENUM_CAST(PhysicsServer3D::SpaceParameter);
  782. VARIANT_ENUM_CAST(PhysicsServer3D::AreaParameter);
  783. VARIANT_ENUM_CAST(PhysicsServer3D::AreaSpaceOverrideMode);
  784. VARIANT_ENUM_CAST(PhysicsServer3D::BodyMode);
  785. VARIANT_ENUM_CAST(PhysicsServer3D::BodyParameter);
  786. VARIANT_ENUM_CAST(PhysicsServer3D::BodyDampMode);
  787. VARIANT_ENUM_CAST(PhysicsServer3D::BodyState);
  788. VARIANT_ENUM_CAST(PhysicsServer3D::BodyAxis);
  789. VARIANT_ENUM_CAST(PhysicsServer3D::PinJointParam);
  790. VARIANT_ENUM_CAST(PhysicsServer3D::JointType);
  791. VARIANT_ENUM_CAST(PhysicsServer3D::HingeJointParam);
  792. VARIANT_ENUM_CAST(PhysicsServer3D::HingeJointFlag);
  793. VARIANT_ENUM_CAST(PhysicsServer3D::SliderJointParam);
  794. VARIANT_ENUM_CAST(PhysicsServer3D::ConeTwistJointParam);
  795. VARIANT_ENUM_CAST(PhysicsServer3D::G6DOFJointAxisParam);
  796. VARIANT_ENUM_CAST(PhysicsServer3D::G6DOFJointAxisFlag);
  797. VARIANT_ENUM_CAST(PhysicsServer3D::AreaBodyStatus);
  798. VARIANT_ENUM_CAST(PhysicsServer3D::ProcessInfo);
  799. #endif // _3D_DISABLED
  800. #endif // PHYSICS_SERVER_3D_H