path_3d.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**************************************************************************/
  2. /* path_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. #pragma once
  31. #include "scene/3d/node_3d.h"
  32. #include "scene/resources/curve.h"
  33. class Path3D : public Node3D {
  34. GDCLASS(Path3D, Node3D);
  35. private:
  36. Ref<Curve3D> curve;
  37. RID debug_instance;
  38. Color debug_custom_color;
  39. Ref<ArrayMesh> debug_mesh;
  40. Ref<Material> debug_material;
  41. Callable update_callback; // Used only by CSG currently.
  42. void _update_debug_mesh();
  43. void _update_debug_path_material();
  44. void _curve_changed();
  45. protected:
  46. void _notification(int p_what);
  47. static void _bind_methods();
  48. public:
  49. void set_update_callback(Callable p_callback);
  50. void set_curve(const Ref<Curve3D> &p_curve);
  51. Ref<Curve3D> get_curve() const;
  52. const Color &get_debug_custom_color() const;
  53. void set_debug_custom_color(const Color &p_color);
  54. bool get_debug_show() const;
  55. void set_debug_show(bool p_show);
  56. Ref<StandardMaterial3D> get_debug_material();
  57. Path3D();
  58. ~Path3D();
  59. };
  60. class PathFollow3D : public Node3D {
  61. GDCLASS(PathFollow3D, Node3D);
  62. public:
  63. enum RotationMode {
  64. ROTATION_NONE,
  65. ROTATION_Y,
  66. ROTATION_XY,
  67. ROTATION_XYZ,
  68. ROTATION_ORIENTED
  69. };
  70. private:
  71. Path3D *path = nullptr;
  72. real_t progress = 0.0;
  73. real_t h_offset = 0.0;
  74. real_t v_offset = 0.0;
  75. bool cubic = true;
  76. bool loop = true;
  77. bool tilt_enabled = true;
  78. bool transform_dirty = true;
  79. bool use_model_front = false;
  80. RotationMode rotation_mode = ROTATION_XYZ;
  81. protected:
  82. void _validate_property(PropertyInfo &p_property) const;
  83. void _notification(int p_what);
  84. static void _bind_methods();
  85. public:
  86. void set_progress(real_t p_progress);
  87. real_t get_progress() const;
  88. void set_h_offset(real_t p_h_offset);
  89. real_t get_h_offset() const;
  90. void set_v_offset(real_t p_v_offset);
  91. real_t get_v_offset() const;
  92. void set_progress_ratio(real_t p_ratio);
  93. real_t get_progress_ratio() const;
  94. void set_loop(bool p_loop);
  95. bool has_loop() const;
  96. void set_tilt_enabled(bool p_enabled);
  97. bool is_tilt_enabled() const;
  98. void set_rotation_mode(RotationMode p_rotation_mode);
  99. RotationMode get_rotation_mode() const;
  100. void set_use_model_front(bool p_use_model_front);
  101. bool is_using_model_front() const;
  102. void set_cubic_interpolation_enabled(bool p_enabled);
  103. bool is_cubic_interpolation_enabled() const;
  104. PackedStringArray get_configuration_warnings() const override;
  105. void update_transform();
  106. static Transform3D correct_posture(Transform3D p_transform, PathFollow3D::RotationMode p_rotation_mode);
  107. };
  108. VARIANT_ENUM_CAST(PathFollow3D::RotationMode);