physics_server_3d.h 40 KB

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