gltf_physics_body.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**************************************************************************/
  2. /* gltf_physics_body.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 GLTF_PHYSICS_BODY_H
  31. #define GLTF_PHYSICS_BODY_H
  32. #include "scene/3d/physics/physics_body_3d.h"
  33. // GLTFPhysicsBody is an intermediary between Godot's physics body nodes
  34. // and the OMI_physics_body extension.
  35. // https://github.com/omigroup/gltf-extensions/tree/main/extensions/2.0/OMI_physics_body
  36. class GLTFPhysicsBody : public Resource {
  37. GDCLASS(GLTFPhysicsBody, Resource)
  38. public:
  39. // These values map to Godot's physics body types.
  40. // When importing, the body type will be set to the closest match, and
  41. // user code can change this to make Godot generate a different node type.
  42. // When exporting, this will be squashed down to one of "static",
  43. // "kinematic", or "dynamic" motion types, or the "trigger" property.
  44. enum class PhysicsBodyType {
  45. STATIC,
  46. ANIMATABLE,
  47. CHARACTER,
  48. RIGID,
  49. VEHICLE,
  50. TRIGGER,
  51. };
  52. protected:
  53. static void _bind_methods();
  54. private:
  55. PhysicsBodyType body_type = PhysicsBodyType::RIGID;
  56. real_t mass = 1.0;
  57. Vector3 linear_velocity;
  58. Vector3 angular_velocity;
  59. Vector3 center_of_mass;
  60. Vector3 inertia_diagonal;
  61. Quaternion inertia_orientation;
  62. public:
  63. String get_body_type() const;
  64. void set_body_type(String p_body_type);
  65. PhysicsBodyType get_physics_body_type() const;
  66. void set_physics_body_type(PhysicsBodyType p_body_type);
  67. real_t get_mass() const;
  68. void set_mass(real_t p_mass);
  69. Vector3 get_linear_velocity() const;
  70. void set_linear_velocity(Vector3 p_linear_velocity);
  71. Vector3 get_angular_velocity() const;
  72. void set_angular_velocity(Vector3 p_angular_velocity);
  73. Vector3 get_center_of_mass() const;
  74. void set_center_of_mass(const Vector3 &p_center_of_mass);
  75. Vector3 get_inertia_diagonal() const;
  76. void set_inertia_diagonal(const Vector3 &p_inertia_diagonal);
  77. Quaternion get_inertia_orientation() const;
  78. void set_inertia_orientation(const Quaternion &p_inertia_orientation);
  79. #ifndef DISABLE_DEPRECATED
  80. Basis get_inertia_tensor() const;
  81. void set_inertia_tensor(Basis p_inertia_tensor);
  82. #endif // DISABLE_DEPRECATED
  83. static Ref<GLTFPhysicsBody> from_node(const CollisionObject3D *p_body_node);
  84. CollisionObject3D *to_node() const;
  85. static Ref<GLTFPhysicsBody> from_dictionary(const Dictionary p_dictionary);
  86. Dictionary to_dictionary() const;
  87. };
  88. #endif // GLTF_PHYSICS_BODY_H