gltf_physics_shape.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**************************************************************************/
  2. /* gltf_physics_shape.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_SHAPE_H
  31. #define GLTF_PHYSICS_SHAPE_H
  32. #include "../../gltf_defines.h"
  33. #include "scene/3d/physics/collision_shape_3d.h"
  34. class ImporterMesh;
  35. // GLTFPhysicsShape is an intermediary between Godot's collision shape nodes
  36. // and the OMI_physics_shape extension.
  37. // https://github.com/omigroup/gltf-extensions/tree/main/extensions/2.0/OMI_physics_shape
  38. class GLTFPhysicsShape : public Resource {
  39. GDCLASS(GLTFPhysicsShape, Resource)
  40. protected:
  41. static void _bind_methods();
  42. private:
  43. String shape_type;
  44. Vector3 size = Vector3(1.0, 1.0, 1.0);
  45. real_t radius = 0.5;
  46. real_t height = 2.0;
  47. bool is_trigger = false;
  48. GLTFMeshIndex mesh_index = -1;
  49. Ref<ImporterMesh> importer_mesh = nullptr;
  50. // Internal only, for caching Godot shape resources. Used in `to_resource` and `to_node`.
  51. Ref<Shape3D> _shape_cache = nullptr;
  52. public:
  53. String get_shape_type() const;
  54. void set_shape_type(String p_shape_type);
  55. Vector3 get_size() const;
  56. void set_size(Vector3 p_size);
  57. real_t get_radius() const;
  58. void set_radius(real_t p_radius);
  59. real_t get_height() const;
  60. void set_height(real_t p_height);
  61. bool get_is_trigger() const;
  62. void set_is_trigger(bool p_is_trigger);
  63. GLTFMeshIndex get_mesh_index() const;
  64. void set_mesh_index(GLTFMeshIndex p_mesh_index);
  65. Ref<ImporterMesh> get_importer_mesh() const;
  66. void set_importer_mesh(Ref<ImporterMesh> p_importer_mesh);
  67. static Ref<GLTFPhysicsShape> from_node(const CollisionShape3D *p_shape_node);
  68. CollisionShape3D *to_node(bool p_cache_shapes = false);
  69. static Ref<GLTFPhysicsShape> from_resource(const Ref<Shape3D> &p_shape_resource);
  70. Ref<Shape3D> to_resource(bool p_cache_shapes = false);
  71. static Ref<GLTFPhysicsShape> from_dictionary(const Dictionary p_dictionary);
  72. Dictionary to_dictionary() const;
  73. };
  74. #endif // GLTF_PHYSICS_SHAPE_H