physics_server_3d.h 40 KB

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