occluder_shape.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**************************************************************************/
  2. /* occluder_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 OCCLUDER_SHAPE_H
  31. #define OCCLUDER_SHAPE_H
  32. #include "core/math/plane.h"
  33. #include "core/resource.h"
  34. #include "core/vector.h"
  35. class OccluderShape : public Resource {
  36. GDCLASS(OccluderShape, Resource);
  37. OBJ_SAVE_TYPE(OccluderShape);
  38. RES_BASE_EXTENSION("occ");
  39. RID _shape;
  40. protected:
  41. static void _bind_methods();
  42. RID get_shape() const { return _shape; }
  43. OccluderShape();
  44. public:
  45. virtual RID get_rid() const { return _shape; }
  46. ~OccluderShape();
  47. virtual Transform center_node(const Transform &p_global_xform, const Transform &p_parent_xform, real_t p_snap) = 0;
  48. #ifdef TOOLS_ENABLED
  49. // for editor gizmo
  50. virtual AABB get_fallback_gizmo_aabb() const;
  51. virtual bool requires_uniform_scale() const { return false; }
  52. #endif
  53. };
  54. class OccluderShapeSphere : public OccluderShape {
  55. GDCLASS(OccluderShapeSphere, OccluderShape);
  56. // We bandit a plane to store position / radius
  57. Vector<Plane> _spheres;
  58. const real_t _min_radius = 0.1;
  59. #ifdef TOOLS_ENABLED
  60. AABB _aabb_local;
  61. void _update_aabb();
  62. #endif
  63. protected:
  64. static void _bind_methods();
  65. public:
  66. void set_spheres(const Vector<Plane> &p_spheres);
  67. Vector<Plane> get_spheres() const { return _spheres; }
  68. void set_sphere_position(int p_idx, const Vector3 &p_position);
  69. void set_sphere_radius(int p_idx, real_t p_radius);
  70. void update_shape_to_visual_server();
  71. virtual Transform center_node(const Transform &p_global_xform, const Transform &p_parent_xform, real_t p_snap);
  72. #ifdef TOOLS_ENABLED
  73. virtual AABB get_fallback_gizmo_aabb() const;
  74. virtual bool requires_uniform_scale() const { return false; }
  75. #endif
  76. OccluderShapeSphere();
  77. };
  78. #endif // OCCLUDER_SHAPE_H