node_3d_editor_gizmos.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /**************************************************************************/
  2. /* node_3d_editor_gizmos.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 NODE_3D_EDITOR_GIZMOS_H
  31. #define NODE_3D_EDITOR_GIZMOS_H
  32. #include "core/templates/hash_map.h"
  33. #include "core/templates/local_vector.h"
  34. #include "scene/3d/camera_3d.h"
  35. #include "scene/3d/node_3d.h"
  36. #include "scene/3d/skeleton_3d.h"
  37. class Timer;
  38. class EditorNode3DGizmoPlugin;
  39. class EditorNode3DGizmo : public Node3DGizmo {
  40. GDCLASS(EditorNode3DGizmo, Node3DGizmo);
  41. struct Instance {
  42. RID instance;
  43. Ref<Mesh> mesh;
  44. Ref<Material> material;
  45. Ref<SkinReference> skin_reference;
  46. bool extra_margin = false;
  47. Transform3D xform;
  48. void create_instance(Node3D *p_base, bool p_hidden = false);
  49. };
  50. bool selected;
  51. Vector<Vector3> collision_segments;
  52. Ref<TriangleMesh> collision_mesh;
  53. Vector<Vector3> handles;
  54. Vector<int> handle_ids;
  55. Vector<Vector3> secondary_handles;
  56. Vector<int> secondary_handle_ids;
  57. real_t selectable_icon_size;
  58. bool billboard_handle;
  59. bool valid;
  60. bool hidden;
  61. Vector<Instance> instances;
  62. Node3D *spatial_node = nullptr;
  63. void _set_node_3d(Node *p_node) { set_node_3d(Object::cast_to<Node3D>(p_node)); }
  64. protected:
  65. static void _bind_methods();
  66. EditorNode3DGizmoPlugin *gizmo_plugin = nullptr;
  67. GDVIRTUAL0(_redraw)
  68. GDVIRTUAL2RC(String, _get_handle_name, int, bool)
  69. GDVIRTUAL2RC(bool, _is_handle_highlighted, int, bool)
  70. GDVIRTUAL2RC(Variant, _get_handle_value, int, bool)
  71. GDVIRTUAL4(_set_handle, int, bool, const Camera3D *, Vector2)
  72. GDVIRTUAL4(_commit_handle, int, bool, Variant, bool)
  73. GDVIRTUAL2RC(int, _subgizmos_intersect_ray, const Camera3D *, Vector2)
  74. GDVIRTUAL2RC(Vector<int>, _subgizmos_intersect_frustum, const Camera3D *, TypedArray<Plane>)
  75. GDVIRTUAL1RC(Transform3D, _get_subgizmo_transform, int)
  76. GDVIRTUAL2(_set_subgizmo_transform, int, Transform3D)
  77. GDVIRTUAL3(_commit_subgizmos, Vector<int>, TypedArray<Transform3D>, bool)
  78. public:
  79. void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1));
  80. void add_vertices(const Vector<Vector3> &p_vertices, const Ref<Material> &p_material, Mesh::PrimitiveType p_primitive_type, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1));
  81. void add_mesh(const Ref<Mesh> &p_mesh, const Ref<Material> &p_material = Ref<Material>(), const Transform3D &p_xform = Transform3D(), const Ref<SkinReference> &p_skin_reference = Ref<SkinReference>());
  82. void add_collision_segments(const Vector<Vector3> &p_lines);
  83. void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh);
  84. void add_unscaled_billboard(const Ref<Material> &p_material, real_t p_scale = 1, const Color &p_modulate = Color(1, 1, 1));
  85. void add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, const Vector<int> &p_ids = Vector<int>(), bool p_billboard = false, bool p_secondary = false);
  86. void add_solid_box(const Ref<Material> &p_material, Vector3 p_size, Vector3 p_position = Vector3(), const Transform3D &p_xform = Transform3D());
  87. virtual bool is_handle_highlighted(int p_id, bool p_secondary) const;
  88. virtual String get_handle_name(int p_id, bool p_secondary) const;
  89. virtual Variant get_handle_value(int p_id, bool p_secondary) const;
  90. virtual void set_handle(int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point);
  91. virtual void commit_handle(int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false);
  92. virtual int subgizmos_intersect_ray(Camera3D *p_camera, const Vector2 &p_point) const;
  93. virtual Vector<int> subgizmos_intersect_frustum(const Camera3D *p_camera, const Vector<Plane> &p_frustum) const;
  94. virtual Transform3D get_subgizmo_transform(int p_id) const;
  95. virtual void set_subgizmo_transform(int p_id, Transform3D p_transform);
  96. virtual void commit_subgizmos(const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel = false);
  97. void set_selected(bool p_selected) { selected = p_selected; }
  98. bool is_selected() const { return selected; }
  99. void set_node_3d(Node3D *p_node);
  100. Node3D *get_node_3d() const { return spatial_node; }
  101. Ref<EditorNode3DGizmoPlugin> get_plugin() const { return gizmo_plugin; }
  102. bool intersect_frustum(const Camera3D *p_camera, const Vector<Plane> &p_frustum);
  103. void handles_intersect_ray(Camera3D *p_camera, const Vector2 &p_point, bool p_shift_pressed, int &r_id, bool &r_secondary);
  104. bool intersect_ray(Camera3D *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal);
  105. bool is_subgizmo_selected(int p_id) const;
  106. Vector<int> get_subgizmo_selection() const;
  107. virtual void clear() override;
  108. virtual void create() override;
  109. virtual void transform() override;
  110. virtual void redraw() override;
  111. virtual void free() override;
  112. virtual bool is_editable() const;
  113. void set_hidden(bool p_hidden);
  114. void set_plugin(EditorNode3DGizmoPlugin *p_plugin);
  115. EditorNode3DGizmo();
  116. ~EditorNode3DGizmo();
  117. };
  118. class EditorNode3DGizmoPlugin : public Resource {
  119. GDCLASS(EditorNode3DGizmoPlugin, Resource);
  120. public:
  121. static const int VISIBLE = 0;
  122. static const int HIDDEN = 1;
  123. static const int ON_TOP = 2;
  124. protected:
  125. int current_state;
  126. List<EditorNode3DGizmo *> current_gizmos;
  127. HashMap<String, Vector<Ref<StandardMaterial3D>>> materials;
  128. static void _bind_methods();
  129. virtual bool has_gizmo(Node3D *p_spatial);
  130. virtual Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial);
  131. GDVIRTUAL1RC(bool, _has_gizmo, Node3D *)
  132. GDVIRTUAL1RC(Ref<EditorNode3DGizmo>, _create_gizmo, Node3D *)
  133. GDVIRTUAL0RC(String, _get_gizmo_name)
  134. GDVIRTUAL0RC(int, _get_priority)
  135. GDVIRTUAL0RC(bool, _can_be_hidden)
  136. GDVIRTUAL0RC(bool, _is_selectable_when_hidden)
  137. GDVIRTUAL1(_redraw, Ref<EditorNode3DGizmo>)
  138. GDVIRTUAL3RC(String, _get_handle_name, Ref<EditorNode3DGizmo>, int, bool)
  139. GDVIRTUAL3RC(bool, _is_handle_highlighted, Ref<EditorNode3DGizmo>, int, bool)
  140. GDVIRTUAL3RC(Variant, _get_handle_value, Ref<EditorNode3DGizmo>, int, bool)
  141. GDVIRTUAL5(_set_handle, Ref<EditorNode3DGizmo>, int, bool, const Camera3D *, Vector2)
  142. GDVIRTUAL5(_commit_handle, Ref<EditorNode3DGizmo>, int, bool, Variant, bool)
  143. GDVIRTUAL3RC(int, _subgizmos_intersect_ray, Ref<EditorNode3DGizmo>, const Camera3D *, Vector2)
  144. GDVIRTUAL3RC(Vector<int>, _subgizmos_intersect_frustum, Ref<EditorNode3DGizmo>, const Camera3D *, TypedArray<Plane>)
  145. GDVIRTUAL2RC(Transform3D, _get_subgizmo_transform, Ref<EditorNode3DGizmo>, int)
  146. GDVIRTUAL3(_set_subgizmo_transform, Ref<EditorNode3DGizmo>, int, Transform3D)
  147. GDVIRTUAL4(_commit_subgizmos, Ref<EditorNode3DGizmo>, Vector<int>, TypedArray<Transform3D>, bool)
  148. public:
  149. void create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false);
  150. void create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1));
  151. void create_handle_material(const String &p_name, bool p_billboard = false, const Ref<Texture2D> &p_texture = nullptr);
  152. void add_material(const String &p_name, Ref<StandardMaterial3D> p_material);
  153. Ref<StandardMaterial3D> get_material(const String &p_name, const Ref<EditorNode3DGizmo> &p_gizmo = Ref<EditorNode3DGizmo>());
  154. virtual String get_gizmo_name() const;
  155. virtual int get_priority() const;
  156. virtual bool can_be_hidden() const;
  157. virtual bool is_selectable_when_hidden() const;
  158. virtual void redraw(EditorNode3DGizmo *p_gizmo);
  159. virtual bool is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const;
  160. virtual String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const;
  161. virtual Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const;
  162. virtual void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point);
  163. virtual void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false);
  164. virtual int subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo, Camera3D *p_camera, const Vector2 &p_point) const;
  165. virtual Vector<int> subgizmos_intersect_frustum(const EditorNode3DGizmo *p_gizmo, const Camera3D *p_camera, const Vector<Plane> &p_frustum) const;
  166. virtual Transform3D get_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id) const;
  167. virtual void set_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id, Transform3D p_transform);
  168. virtual void commit_subgizmos(const EditorNode3DGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel = false);
  169. Ref<EditorNode3DGizmo> get_gizmo(Node3D *p_spatial);
  170. void set_state(int p_state);
  171. int get_state() const;
  172. void unregister_gizmo(EditorNode3DGizmo *p_gizmo);
  173. EditorNode3DGizmoPlugin();
  174. virtual ~EditorNode3DGizmoPlugin();
  175. };
  176. class Light3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  177. GDCLASS(Light3DGizmoPlugin, EditorNode3DGizmoPlugin);
  178. public:
  179. bool has_gizmo(Node3D *p_spatial) override;
  180. String get_gizmo_name() const override;
  181. int get_priority() const override;
  182. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  183. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  184. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  185. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  186. void redraw(EditorNode3DGizmo *p_gizmo) override;
  187. Light3DGizmoPlugin();
  188. };
  189. class AudioStreamPlayer3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  190. GDCLASS(AudioStreamPlayer3DGizmoPlugin, EditorNode3DGizmoPlugin);
  191. public:
  192. bool has_gizmo(Node3D *p_spatial) override;
  193. String get_gizmo_name() const override;
  194. int get_priority() const override;
  195. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  196. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  197. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  198. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  199. void redraw(EditorNode3DGizmo *p_gizmo) override;
  200. AudioStreamPlayer3DGizmoPlugin();
  201. };
  202. class AudioListener3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  203. GDCLASS(AudioListener3DGizmoPlugin, EditorNode3DGizmoPlugin);
  204. public:
  205. bool has_gizmo(Node3D *p_spatial) override;
  206. String get_gizmo_name() const override;
  207. int get_priority() const override;
  208. void redraw(EditorNode3DGizmo *p_gizmo) override;
  209. AudioListener3DGizmoPlugin();
  210. };
  211. class Camera3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  212. GDCLASS(Camera3DGizmoPlugin, EditorNode3DGizmoPlugin);
  213. private:
  214. static Size2i _get_viewport_size(Camera3D *p_camera);
  215. public:
  216. bool has_gizmo(Node3D *p_spatial) override;
  217. String get_gizmo_name() const override;
  218. int get_priority() const override;
  219. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  220. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  221. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  222. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  223. void redraw(EditorNode3DGizmo *p_gizmo) override;
  224. Camera3DGizmoPlugin();
  225. };
  226. class MeshInstance3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  227. GDCLASS(MeshInstance3DGizmoPlugin, EditorNode3DGizmoPlugin);
  228. public:
  229. bool has_gizmo(Node3D *p_spatial) override;
  230. String get_gizmo_name() const override;
  231. int get_priority() const override;
  232. bool can_be_hidden() const override;
  233. void redraw(EditorNode3DGizmo *p_gizmo) override;
  234. MeshInstance3DGizmoPlugin();
  235. };
  236. class OccluderInstance3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  237. GDCLASS(OccluderInstance3DGizmoPlugin, EditorNode3DGizmoPlugin);
  238. public:
  239. bool has_gizmo(Node3D *p_spatial) override;
  240. String get_gizmo_name() const override;
  241. int get_priority() const override;
  242. void redraw(EditorNode3DGizmo *p_gizmo) override;
  243. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  244. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  245. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  246. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  247. OccluderInstance3DGizmoPlugin();
  248. };
  249. class Sprite3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  250. GDCLASS(Sprite3DGizmoPlugin, EditorNode3DGizmoPlugin);
  251. public:
  252. bool has_gizmo(Node3D *p_spatial) override;
  253. String get_gizmo_name() const override;
  254. int get_priority() const override;
  255. bool can_be_hidden() const override;
  256. void redraw(EditorNode3DGizmo *p_gizmo) override;
  257. Sprite3DGizmoPlugin();
  258. };
  259. class Label3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  260. GDCLASS(Label3DGizmoPlugin, EditorNode3DGizmoPlugin);
  261. public:
  262. bool has_gizmo(Node3D *p_spatial) override;
  263. String get_gizmo_name() const override;
  264. int get_priority() const override;
  265. bool can_be_hidden() const override;
  266. void redraw(EditorNode3DGizmo *p_gizmo) override;
  267. Label3DGizmoPlugin();
  268. };
  269. class Marker3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  270. GDCLASS(Marker3DGizmoPlugin, EditorNode3DGizmoPlugin);
  271. Ref<ArrayMesh> pos3d_mesh;
  272. public:
  273. bool has_gizmo(Node3D *p_spatial) override;
  274. String get_gizmo_name() const override;
  275. int get_priority() const override;
  276. void redraw(EditorNode3DGizmo *p_gizmo) override;
  277. Marker3DGizmoPlugin();
  278. };
  279. class PhysicalBone3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  280. GDCLASS(PhysicalBone3DGizmoPlugin, EditorNode3DGizmoPlugin);
  281. public:
  282. bool has_gizmo(Node3D *p_spatial) override;
  283. String get_gizmo_name() const override;
  284. int get_priority() const override;
  285. void redraw(EditorNode3DGizmo *p_gizmo) override;
  286. PhysicalBone3DGizmoPlugin();
  287. };
  288. class RayCast3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  289. GDCLASS(RayCast3DGizmoPlugin, EditorNode3DGizmoPlugin);
  290. public:
  291. bool has_gizmo(Node3D *p_spatial) override;
  292. String get_gizmo_name() const override;
  293. int get_priority() const override;
  294. void redraw(EditorNode3DGizmo *p_gizmo) override;
  295. RayCast3DGizmoPlugin();
  296. };
  297. class ShapeCast3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  298. GDCLASS(ShapeCast3DGizmoPlugin, EditorNode3DGizmoPlugin);
  299. public:
  300. bool has_gizmo(Node3D *p_spatial) override;
  301. String get_gizmo_name() const override;
  302. int get_priority() const override;
  303. void redraw(EditorNode3DGizmo *p_gizmo) override;
  304. ShapeCast3DGizmoPlugin();
  305. };
  306. class SpringArm3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  307. GDCLASS(SpringArm3DGizmoPlugin, EditorNode3DGizmoPlugin);
  308. public:
  309. bool has_gizmo(Node3D *p_spatial) override;
  310. String get_gizmo_name() const override;
  311. int get_priority() const override;
  312. void redraw(EditorNode3DGizmo *p_gizmo) override;
  313. SpringArm3DGizmoPlugin();
  314. };
  315. class VehicleWheel3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  316. GDCLASS(VehicleWheel3DGizmoPlugin, EditorNode3DGizmoPlugin);
  317. public:
  318. bool has_gizmo(Node3D *p_spatial) override;
  319. String get_gizmo_name() const override;
  320. int get_priority() const override;
  321. void redraw(EditorNode3DGizmo *p_gizmo) override;
  322. VehicleWheel3DGizmoPlugin();
  323. };
  324. class SoftBody3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  325. GDCLASS(SoftBody3DGizmoPlugin, EditorNode3DGizmoPlugin);
  326. public:
  327. bool has_gizmo(Node3D *p_spatial) override;
  328. String get_gizmo_name() const override;
  329. int get_priority() const override;
  330. bool is_selectable_when_hidden() const override;
  331. void redraw(EditorNode3DGizmo *p_gizmo) override;
  332. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  333. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  334. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  335. bool is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  336. SoftBody3DGizmoPlugin();
  337. };
  338. class VisibleOnScreenNotifier3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  339. GDCLASS(VisibleOnScreenNotifier3DGizmoPlugin, EditorNode3DGizmoPlugin);
  340. public:
  341. bool has_gizmo(Node3D *p_spatial) override;
  342. String get_gizmo_name() const override;
  343. int get_priority() const override;
  344. void redraw(EditorNode3DGizmo *p_gizmo) override;
  345. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  346. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  347. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  348. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  349. VisibleOnScreenNotifier3DGizmoPlugin();
  350. };
  351. class CPUParticles3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  352. GDCLASS(CPUParticles3DGizmoPlugin, EditorNode3DGizmoPlugin);
  353. public:
  354. bool has_gizmo(Node3D *p_spatial) override;
  355. String get_gizmo_name() const override;
  356. int get_priority() const override;
  357. bool is_selectable_when_hidden() const override;
  358. void redraw(EditorNode3DGizmo *p_gizmo) override;
  359. CPUParticles3DGizmoPlugin();
  360. };
  361. class GPUParticles3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  362. GDCLASS(GPUParticles3DGizmoPlugin, EditorNode3DGizmoPlugin);
  363. public:
  364. bool has_gizmo(Node3D *p_spatial) override;
  365. String get_gizmo_name() const override;
  366. int get_priority() const override;
  367. bool is_selectable_when_hidden() const override;
  368. void redraw(EditorNode3DGizmo *p_gizmo) override;
  369. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  370. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  371. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  372. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  373. GPUParticles3DGizmoPlugin();
  374. };
  375. class GPUParticlesCollision3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  376. GDCLASS(GPUParticlesCollision3DGizmoPlugin, EditorNode3DGizmoPlugin);
  377. public:
  378. bool has_gizmo(Node3D *p_spatial) override;
  379. String get_gizmo_name() const override;
  380. int get_priority() const override;
  381. void redraw(EditorNode3DGizmo *p_gizmo) override;
  382. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  383. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  384. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  385. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  386. GPUParticlesCollision3DGizmoPlugin();
  387. };
  388. class ReflectionProbeGizmoPlugin : public EditorNode3DGizmoPlugin {
  389. GDCLASS(ReflectionProbeGizmoPlugin, EditorNode3DGizmoPlugin);
  390. public:
  391. bool has_gizmo(Node3D *p_spatial) override;
  392. String get_gizmo_name() const override;
  393. int get_priority() const override;
  394. void redraw(EditorNode3DGizmo *p_gizmo) override;
  395. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  396. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  397. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  398. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  399. ReflectionProbeGizmoPlugin();
  400. };
  401. class DecalGizmoPlugin : public EditorNode3DGizmoPlugin {
  402. GDCLASS(DecalGizmoPlugin, EditorNode3DGizmoPlugin);
  403. public:
  404. bool has_gizmo(Node3D *p_spatial) override;
  405. String get_gizmo_name() const override;
  406. int get_priority() const override;
  407. void redraw(EditorNode3DGizmo *p_gizmo) override;
  408. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  409. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  410. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  411. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  412. DecalGizmoPlugin();
  413. };
  414. class VoxelGIGizmoPlugin : public EditorNode3DGizmoPlugin {
  415. GDCLASS(VoxelGIGizmoPlugin, EditorNode3DGizmoPlugin);
  416. public:
  417. bool has_gizmo(Node3D *p_spatial) override;
  418. String get_gizmo_name() const override;
  419. int get_priority() const override;
  420. void redraw(EditorNode3DGizmo *p_gizmo) override;
  421. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  422. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  423. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  424. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  425. VoxelGIGizmoPlugin();
  426. };
  427. class LightmapGIGizmoPlugin : public EditorNode3DGizmoPlugin {
  428. GDCLASS(LightmapGIGizmoPlugin, EditorNode3DGizmoPlugin);
  429. public:
  430. bool has_gizmo(Node3D *p_spatial) override;
  431. String get_gizmo_name() const override;
  432. int get_priority() const override;
  433. void redraw(EditorNode3DGizmo *p_gizmo) override;
  434. LightmapGIGizmoPlugin();
  435. };
  436. class LightmapProbeGizmoPlugin : public EditorNode3DGizmoPlugin {
  437. GDCLASS(LightmapProbeGizmoPlugin, EditorNode3DGizmoPlugin);
  438. public:
  439. bool has_gizmo(Node3D *p_spatial) override;
  440. String get_gizmo_name() const override;
  441. int get_priority() const override;
  442. void redraw(EditorNode3DGizmo *p_gizmo) override;
  443. LightmapProbeGizmoPlugin();
  444. };
  445. class CollisionObject3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  446. GDCLASS(CollisionObject3DGizmoPlugin, EditorNode3DGizmoPlugin);
  447. public:
  448. bool has_gizmo(Node3D *p_spatial) override;
  449. String get_gizmo_name() const override;
  450. int get_priority() const override;
  451. void redraw(EditorNode3DGizmo *p_gizmo) override;
  452. CollisionObject3DGizmoPlugin();
  453. };
  454. class CollisionShape3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  455. GDCLASS(CollisionShape3DGizmoPlugin, EditorNode3DGizmoPlugin);
  456. public:
  457. bool has_gizmo(Node3D *p_spatial) override;
  458. String get_gizmo_name() const override;
  459. int get_priority() const override;
  460. void redraw(EditorNode3DGizmo *p_gizmo) override;
  461. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  462. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  463. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  464. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  465. CollisionShape3DGizmoPlugin();
  466. };
  467. class CollisionPolygon3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  468. GDCLASS(CollisionPolygon3DGizmoPlugin, EditorNode3DGizmoPlugin);
  469. public:
  470. bool has_gizmo(Node3D *p_spatial) override;
  471. String get_gizmo_name() const override;
  472. int get_priority() const override;
  473. void redraw(EditorNode3DGizmo *p_gizmo) override;
  474. CollisionPolygon3DGizmoPlugin();
  475. };
  476. class NavigationRegion3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  477. GDCLASS(NavigationRegion3DGizmoPlugin, EditorNode3DGizmoPlugin);
  478. struct _EdgeKey {
  479. Vector3 from;
  480. Vector3 to;
  481. static uint32_t hash(const _EdgeKey &p_key) {
  482. return HashMapHasherDefault::hash(p_key.from) ^ HashMapHasherDefault::hash(p_key.to);
  483. }
  484. bool operator==(const _EdgeKey &p_with) const {
  485. return HashMapComparatorDefault<Vector3>::compare(from, p_with.from) && HashMapComparatorDefault<Vector3>::compare(to, p_with.to);
  486. }
  487. };
  488. public:
  489. bool has_gizmo(Node3D *p_spatial) override;
  490. String get_gizmo_name() const override;
  491. int get_priority() const override;
  492. void redraw(EditorNode3DGizmo *p_gizmo) override;
  493. NavigationRegion3DGizmoPlugin();
  494. };
  495. class NavigationLink3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  496. GDCLASS(NavigationLink3DGizmoPlugin, EditorNode3DGizmoPlugin);
  497. public:
  498. bool has_gizmo(Node3D *p_spatial) override;
  499. String get_gizmo_name() const override;
  500. int get_priority() const override;
  501. void redraw(EditorNode3DGizmo *p_gizmo) override;
  502. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  503. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  504. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  505. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  506. NavigationLink3DGizmoPlugin();
  507. };
  508. class JointGizmosDrawer {
  509. public:
  510. static Basis look_body(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
  511. static Basis look_body_toward(Vector3::Axis p_axis, const Transform3D &joint_transform, const Transform3D &body_transform);
  512. static Basis look_body_toward_x(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
  513. static Basis look_body_toward_y(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
  514. /// Special function just used for physics joints, it returns a basis constrained toward Joint Z axis
  515. /// with axis X and Y that are looking toward the body and oriented toward up
  516. static Basis look_body_toward_z(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
  517. // Draw circle around p_axis
  518. static void draw_circle(Vector3::Axis p_axis, real_t p_radius, const Transform3D &p_offset, const Basis &p_base, real_t p_limit_lower, real_t p_limit_upper, Vector<Vector3> &r_points, bool p_inverse = false);
  519. static void draw_cone(const Transform3D &p_offset, const Basis &p_base, real_t p_swing, real_t p_twist, Vector<Vector3> &r_points);
  520. };
  521. class Joint3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  522. GDCLASS(Joint3DGizmoPlugin, EditorNode3DGizmoPlugin);
  523. Timer *update_timer = nullptr;
  524. uint64_t update_idx = 0;
  525. void incremental_update_gizmos();
  526. public:
  527. bool has_gizmo(Node3D *p_spatial) override;
  528. String get_gizmo_name() const override;
  529. int get_priority() const override;
  530. void redraw(EditorNode3DGizmo *p_gizmo) override;
  531. static void CreatePinJointGizmo(const Transform3D &p_offset, Vector<Vector3> &r_cursor_points);
  532. static void CreateHingeJointGizmo(const Transform3D &p_offset, const Transform3D &p_trs_joint, const Transform3D &p_trs_body_a, const Transform3D &p_trs_body_b, real_t p_limit_lower, real_t p_limit_upper, bool p_use_limit, Vector<Vector3> &r_common_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
  533. static void CreateSliderJointGizmo(const Transform3D &p_offset, const Transform3D &p_trs_joint, const Transform3D &p_trs_body_a, const Transform3D &p_trs_body_b, real_t p_angular_limit_lower, real_t p_angular_limit_upper, real_t p_linear_limit_lower, real_t p_linear_limit_upper, Vector<Vector3> &r_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
  534. static void CreateConeTwistJointGizmo(const Transform3D &p_offset, const Transform3D &p_trs_joint, const Transform3D &p_trs_body_a, const Transform3D &p_trs_body_b, real_t p_swing, real_t p_twist, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
  535. static void CreateGeneric6DOFJointGizmo(
  536. const Transform3D &p_offset,
  537. const Transform3D &p_trs_joint,
  538. const Transform3D &p_trs_body_a,
  539. const Transform3D &p_trs_body_b,
  540. real_t p_angular_limit_lower_x,
  541. real_t p_angular_limit_upper_x,
  542. real_t p_linear_limit_lower_x,
  543. real_t p_linear_limit_upper_x,
  544. bool p_enable_angular_limit_x,
  545. bool p_enable_linear_limit_x,
  546. real_t p_angular_limit_lower_y,
  547. real_t p_angular_limit_upper_y,
  548. real_t p_linear_limit_lower_y,
  549. real_t p_linear_limit_upper_y,
  550. bool p_enable_angular_limit_y,
  551. bool p_enable_linear_limit_y,
  552. real_t p_angular_limit_lower_z,
  553. real_t p_angular_limit_upper_z,
  554. real_t p_linear_limit_lower_z,
  555. real_t p_linear_limit_upper_z,
  556. bool p_enable_angular_limit_z,
  557. bool p_enable_linear_limit_z,
  558. Vector<Vector3> &r_points,
  559. Vector<Vector3> *r_body_a_points,
  560. Vector<Vector3> *r_body_b_points);
  561. Joint3DGizmoPlugin();
  562. };
  563. class FogVolumeGizmoPlugin : public EditorNode3DGizmoPlugin {
  564. GDCLASS(FogVolumeGizmoPlugin, EditorNode3DGizmoPlugin);
  565. public:
  566. bool has_gizmo(Node3D *p_spatial) override;
  567. String get_gizmo_name() const override;
  568. int get_priority() const override;
  569. void redraw(EditorNode3DGizmo *p_gizmo) override;
  570. String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  571. Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
  572. void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  573. void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  574. FogVolumeGizmoPlugin();
  575. };
  576. #endif // NODE_3D_EDITOR_GIZMOS_H