spatial_editor_gizmos.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*************************************************************************/
  2. /* spatial_editor_gizmos.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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 SPATIAL_EDITOR_GIZMOS_H
  31. #define SPATIAL_EDITOR_GIZMOS_H
  32. #include "editor/plugins/spatial_editor_plugin.h"
  33. #include "scene/3d/camera.h"
  34. class Camera;
  35. class LightSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  36. GDCLASS(LightSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  37. public:
  38. bool has_gizmo(Spatial *p_spatial);
  39. String get_name() const;
  40. String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
  41. Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
  42. void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
  43. void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
  44. void redraw(EditorSpatialGizmo *p_gizmo);
  45. LightSpatialGizmoPlugin();
  46. };
  47. class AudioStreamPlayer3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  48. GDCLASS(AudioStreamPlayer3DSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  49. public:
  50. bool has_gizmo(Spatial *p_spatial);
  51. String get_name() const;
  52. String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
  53. Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
  54. void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
  55. void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
  56. void redraw(EditorSpatialGizmo *p_gizmo);
  57. AudioStreamPlayer3DSpatialGizmoPlugin();
  58. };
  59. class CameraSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  60. GDCLASS(CameraSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  61. public:
  62. bool has_gizmo(Spatial *p_spatial);
  63. String get_name() const;
  64. String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
  65. Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
  66. void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
  67. void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
  68. void redraw(EditorSpatialGizmo *p_gizmo);
  69. CameraSpatialGizmoPlugin();
  70. };
  71. class MeshInstanceSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  72. GDCLASS(MeshInstanceSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  73. public:
  74. bool has_gizmo(Spatial *p_spatial);
  75. String get_name() const;
  76. bool can_be_hidden() const;
  77. void redraw(EditorSpatialGizmo *p_gizmo);
  78. MeshInstanceSpatialGizmoPlugin();
  79. };
  80. class Sprite3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  81. GDCLASS(Sprite3DSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  82. public:
  83. bool has_gizmo(Spatial *p_spatial);
  84. String get_name() const;
  85. bool can_be_hidden() const;
  86. void redraw(EditorSpatialGizmo *p_gizmo);
  87. Sprite3DSpatialGizmoPlugin();
  88. };
  89. class Position3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  90. GDCLASS(Position3DSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  91. Ref<ArrayMesh> pos3d_mesh;
  92. Vector<Vector3> cursor_points;
  93. public:
  94. bool has_gizmo(Spatial *p_spatial);
  95. String get_name() const;
  96. void redraw(EditorSpatialGizmo *p_gizmo);
  97. Position3DSpatialGizmoPlugin();
  98. };
  99. class SkeletonSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  100. GDCLASS(SkeletonSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  101. public:
  102. bool has_gizmo(Spatial *p_spatial);
  103. String get_name() const;
  104. void redraw(EditorSpatialGizmo *p_gizmo);
  105. SkeletonSpatialGizmoPlugin();
  106. };
  107. class PhysicalBoneSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  108. GDCLASS(PhysicalBoneSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  109. public:
  110. bool has_gizmo(Spatial *p_spatial);
  111. String get_name() const;
  112. void redraw(EditorSpatialGizmo *p_gizmo);
  113. PhysicalBoneSpatialGizmoPlugin();
  114. };
  115. #if 0
  116. class PortalSpatialGizmo : public EditorSpatialGizmo {
  117. GDCLASS(PortalSpatialGizmo, EditorSpatialGizmo);
  118. Portal *portal;
  119. public:
  120. void redraw();
  121. PortalSpatialGizmo(Portal *p_portal = NULL);
  122. };
  123. #endif
  124. class RayCastSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  125. GDCLASS(RayCastSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  126. public:
  127. bool has_gizmo(Spatial *p_spatial);
  128. String get_name() const;
  129. void redraw(EditorSpatialGizmo *p_gizmo);
  130. RayCastSpatialGizmoPlugin();
  131. };
  132. class SpringArmSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  133. GDCLASS(SpringArmSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  134. public:
  135. bool has_gizmo(Spatial *p_spatial);
  136. String get_name() const;
  137. void redraw(EditorSpatialGizmo *p_gizmo);
  138. SpringArmSpatialGizmoPlugin();
  139. };
  140. class VehicleWheelSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  141. GDCLASS(VehicleWheelSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  142. public:
  143. bool has_gizmo(Spatial *p_spatial);
  144. String get_name() const;
  145. void redraw(EditorSpatialGizmo *p_gizmo);
  146. VehicleWheelSpatialGizmoPlugin();
  147. };
  148. class SoftBodySpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  149. GDCLASS(SoftBodySpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  150. public:
  151. bool has_gizmo(Spatial *p_spatial);
  152. String get_name() const;
  153. bool is_selectable_when_hidden() const;
  154. void redraw(EditorSpatialGizmo *p_gizmo);
  155. String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
  156. Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
  157. void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel);
  158. bool is_gizmo_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int idx) const;
  159. SoftBodySpatialGizmoPlugin();
  160. };
  161. class VisibilityNotifierGizmoPlugin : public EditorSpatialGizmoPlugin {
  162. GDCLASS(VisibilityNotifierGizmoPlugin, EditorSpatialGizmoPlugin);
  163. public:
  164. bool has_gizmo(Spatial *p_spatial);
  165. String get_name() const;
  166. void redraw(EditorSpatialGizmo *p_gizmo);
  167. String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
  168. Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
  169. void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
  170. void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
  171. VisibilityNotifierGizmoPlugin();
  172. };
  173. class ParticlesGizmoPlugin : public EditorSpatialGizmoPlugin {
  174. GDCLASS(ParticlesGizmoPlugin, EditorSpatialGizmoPlugin);
  175. public:
  176. bool has_gizmo(Spatial *p_spatial);
  177. String get_name() const;
  178. bool is_selectable_when_hidden() const;
  179. void redraw(EditorSpatialGizmo *p_gizmo);
  180. String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
  181. Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
  182. void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
  183. void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
  184. ParticlesGizmoPlugin();
  185. };
  186. class ReflectionProbeGizmoPlugin : public EditorSpatialGizmoPlugin {
  187. GDCLASS(ReflectionProbeGizmoPlugin, EditorSpatialGizmoPlugin);
  188. public:
  189. bool has_gizmo(Spatial *p_spatial);
  190. String get_name() const;
  191. void redraw(EditorSpatialGizmo *p_gizmo);
  192. String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
  193. Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
  194. void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
  195. void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
  196. ReflectionProbeGizmoPlugin();
  197. };
  198. class GIProbeGizmoPlugin : public EditorSpatialGizmoPlugin {
  199. GDCLASS(GIProbeGizmoPlugin, EditorSpatialGizmoPlugin);
  200. public:
  201. bool has_gizmo(Spatial *p_spatial);
  202. String get_name() const;
  203. void redraw(EditorSpatialGizmo *p_gizmo);
  204. String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
  205. Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
  206. void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
  207. void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
  208. GIProbeGizmoPlugin();
  209. };
  210. class BakedIndirectLightGizmoPlugin : public EditorSpatialGizmoPlugin {
  211. GDCLASS(BakedIndirectLightGizmoPlugin, EditorSpatialGizmoPlugin);
  212. public:
  213. bool has_gizmo(Spatial *p_spatial);
  214. String get_name() const;
  215. void redraw(EditorSpatialGizmo *p_gizmo);
  216. String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
  217. Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
  218. void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
  219. void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
  220. BakedIndirectLightGizmoPlugin();
  221. };
  222. class CollisionShapeSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  223. GDCLASS(CollisionShapeSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  224. public:
  225. bool has_gizmo(Spatial *p_spatial);
  226. String get_name() const;
  227. void redraw(EditorSpatialGizmo *p_gizmo);
  228. String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
  229. Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
  230. void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
  231. void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
  232. CollisionShapeSpatialGizmoPlugin();
  233. };
  234. class CollisionPolygonSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  235. GDCLASS(CollisionPolygonSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  236. public:
  237. bool has_gizmo(Spatial *p_spatial);
  238. String get_name() const;
  239. void redraw(EditorSpatialGizmo *p_gizmo);
  240. CollisionPolygonSpatialGizmoPlugin();
  241. };
  242. class NavigationMeshSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  243. GDCLASS(NavigationMeshSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  244. struct _EdgeKey {
  245. Vector3 from;
  246. Vector3 to;
  247. bool operator<(const _EdgeKey &p_with) const { return from == p_with.from ? to < p_with.to : from < p_with.from; }
  248. };
  249. public:
  250. bool has_gizmo(Spatial *p_spatial);
  251. String get_name() const;
  252. void redraw(EditorSpatialGizmo *p_gizmo);
  253. NavigationMeshSpatialGizmoPlugin();
  254. };
  255. class JointGizmosDrawer {
  256. public:
  257. static Basis look_body(const Transform &p_joint_transform, const Transform &p_body_transform);
  258. static Basis look_body_toward(Vector3::Axis p_axis, const Transform &joint_transform, const Transform &body_transform);
  259. static Basis look_body_toward_x(const Transform &p_joint_transform, const Transform &p_body_transform);
  260. static Basis look_body_toward_y(const Transform &p_joint_transform, const Transform &p_body_transform);
  261. /// Special function just used for physics joints, it returns a basis constrained toward Joint Z axis
  262. /// with axis X and Y that are looking toward the body and oriented toward up
  263. static Basis look_body_toward_z(const Transform &p_joint_transform, const Transform &p_body_transform);
  264. // Draw circle around p_axis
  265. static void draw_circle(Vector3::Axis p_axis, real_t p_radius, const Transform &p_offset, const Basis &p_base, real_t p_limit_lower, real_t p_limit_upper, Vector<Vector3> &r_points, bool p_inverse = false);
  266. static void draw_cone(const Transform &p_offset, const Basis &p_base, real_t p_swing, real_t p_twist, Vector<Vector3> &r_points);
  267. };
  268. class JointSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
  269. GDCLASS(JointSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
  270. public:
  271. bool has_gizmo(Spatial *p_spatial);
  272. String get_name() const;
  273. void redraw(EditorSpatialGizmo *p_gizmo);
  274. static void CreatePinJointGizmo(const Transform &p_offset, Vector<Vector3> &r_cursor_points);
  275. static void CreateHingeJointGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &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);
  276. static void CreateSliderJointGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &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);
  277. static void CreateConeTwistJointGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_swing, real_t p_twist, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
  278. static void CreateGeneric6DOFJointGizmo(
  279. const Transform &p_offset,
  280. const Transform &p_trs_joint,
  281. const Transform &p_trs_body_a,
  282. const Transform &p_trs_body_b,
  283. real_t p_angular_limit_lower_x,
  284. real_t p_angular_limit_upper_x,
  285. real_t p_linear_limit_lower_x,
  286. real_t p_linear_limit_upper_x,
  287. bool p_enable_angular_limit_x,
  288. bool p_enable_linear_limit_x,
  289. real_t p_angular_limit_lower_y,
  290. real_t p_angular_limit_upper_y,
  291. real_t p_linear_limit_lower_y,
  292. real_t p_linear_limit_upper_y,
  293. bool p_enable_angular_limit_y,
  294. bool p_enable_linear_limit_y,
  295. real_t p_angular_limit_lower_z,
  296. real_t p_angular_limit_upper_z,
  297. real_t p_linear_limit_lower_z,
  298. real_t p_linear_limit_upper_z,
  299. bool p_enable_angular_limit_z,
  300. bool p_enable_linear_limit_z,
  301. Vector<Vector3> &r_points,
  302. Vector<Vector3> *r_body_a_points,
  303. Vector<Vector3> *r_body_b_points);
  304. JointSpatialGizmoPlugin();
  305. };
  306. #endif // SPATIAL_EDITOR_GIZMOS_H