spatial_editor_gizmos.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /*************************************************************************/
  2. /* spatial_editor_gizmos.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef SPATIAL_EDITOR_GIZMOS_H
  30. #define SPATIAL_EDITOR_GIZMOS_H
  31. #include "tools/editor/plugins/spatial_editor_plugin.h"
  32. #include "scene/3d/light.h"
  33. #include "scene/3d/camera.h"
  34. #include "scene/3d/position_3d.h"
  35. #include "scene/3d/spatial_sample_player.h"
  36. #include "scene/3d/spatial_stream_player.h"
  37. #include "scene/3d/test_cube.h"
  38. #include "scene/3d/mesh_instance.h"
  39. #include "scene/3d/body_shape.h"
  40. #include "scene/3d/room_instance.h"
  41. #include "scene/3d/visibility_notifier.h"
  42. #include "scene/3d/portal.h"
  43. #include "scene/3d/ray_cast.h"
  44. #include "scene/3d/navigation_mesh.h"
  45. #include "scene/3d/car_body.h"
  46. class Camera;
  47. class SpatialGizmoTool : public SpatialEditorGizmo {
  48. OBJ_TYPE(SpatialGizmoTool,SpatialGizmo);
  49. struct Instance{
  50. RID instance;
  51. Ref<Mesh> mesh;
  52. RID skeleton;
  53. bool billboard;
  54. bool unscaled;
  55. bool can_intersect;
  56. bool extra_margin;
  57. Instance() {
  58. billboard=false;
  59. unscaled=false;
  60. can_intersect=false;
  61. extra_margin=false;
  62. }
  63. void create_instance(Spatial *p_base);
  64. };
  65. Vector<Vector3> collision_segments;
  66. Ref<TriangleMesh> collision_mesh;
  67. struct Handle {
  68. Vector3 pos;
  69. bool billboard;
  70. };
  71. Vector<Vector3> handles;
  72. Vector<Vector3> secondary_handles;
  73. bool billboard_handle;
  74. bool valid;
  75. Spatial *base;
  76. Vector<Instance> instances;
  77. Spatial *spatial_node;
  78. protected:
  79. void clear();
  80. void add_lines(const Vector<Vector3> &p_lines,const Ref<Material>& p_material,bool p_billboard=false);
  81. void add_mesh(const Ref<Mesh>& p_mesh,bool p_billboard=false,const RID& p_skeleton=RID());
  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,float p_scale=1);
  85. void add_handles(const Vector<Vector3> &p_handles,bool p_billboard=false,bool p_secondary=false);
  86. void set_spatial_node(Spatial *p_node);
  87. public:
  88. virtual Vector3 get_handle_pos(int p_idx) const;
  89. virtual bool intersect_frustum(const Camera *p_camera,const Vector<Plane> &p_frustum);
  90. virtual bool intersect_ray(const Camera *p_camera,const Point2& p_point, Vector3& r_pos, Vector3& r_normal,int *r_gizmo_handle=NULL,bool p_sec_first=false);
  91. void create();
  92. void transform();
  93. //void redraw();
  94. void free();
  95. SpatialGizmoTool();
  96. ~SpatialGizmoTool();
  97. };
  98. class LightSpatialGizmo : public SpatialGizmoTool {
  99. OBJ_TYPE(LightSpatialGizmo,SpatialGizmoTool);
  100. Light* light;
  101. public:
  102. virtual String get_handle_name(int p_idx) const;
  103. virtual Variant get_handle_value(int p_idx) const;
  104. virtual void set_handle(int p_idx,Camera *p_camera, const Point2& p_point);
  105. virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false);
  106. void redraw();
  107. LightSpatialGizmo(Light* p_light=NULL);
  108. };
  109. class CameraSpatialGizmo : public SpatialGizmoTool {
  110. OBJ_TYPE(CameraSpatialGizmo,SpatialGizmoTool);
  111. Camera* camera;
  112. public:
  113. virtual String get_handle_name(int p_idx) const;
  114. virtual Variant get_handle_value(int p_idx) const;
  115. virtual void set_handle(int p_idx,Camera *p_camera, const Point2& p_point);
  116. virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false);
  117. void redraw();
  118. CameraSpatialGizmo(Camera* p_camera=NULL);
  119. };
  120. class MeshInstanceSpatialGizmo : public SpatialGizmoTool {
  121. OBJ_TYPE(MeshInstanceSpatialGizmo,SpatialGizmoTool);
  122. MeshInstance* mesh;
  123. public:
  124. void redraw();
  125. MeshInstanceSpatialGizmo(MeshInstance* p_mesh=NULL);
  126. };
  127. class Position3DSpatialGizmo : public SpatialGizmoTool {
  128. OBJ_TYPE(Position3DSpatialGizmo,SpatialGizmoTool);
  129. Position3D* p3d;
  130. public:
  131. void redraw();
  132. Position3DSpatialGizmo(Position3D* p_p3d=NULL);
  133. };
  134. class SkeletonSpatialGizmo : public SpatialGizmoTool {
  135. OBJ_TYPE(SkeletonSpatialGizmo,SpatialGizmoTool);
  136. Skeleton* skel;
  137. public:
  138. void redraw();
  139. SkeletonSpatialGizmo(Skeleton* p_skel=NULL);
  140. };
  141. class SpatialPlayerSpatialGizmo : public SpatialGizmoTool {
  142. OBJ_TYPE(SpatialPlayerSpatialGizmo,SpatialGizmoTool);
  143. SpatialPlayer* splayer;
  144. public:
  145. void redraw();
  146. SpatialPlayerSpatialGizmo(SpatialPlayer* p_splayer=NULL);
  147. };
  148. class TestCubeSpatialGizmo : public SpatialGizmoTool {
  149. OBJ_TYPE(TestCubeSpatialGizmo,SpatialGizmoTool);
  150. TestCube* tc;
  151. public:
  152. void redraw();
  153. TestCubeSpatialGizmo(TestCube* p_tc=NULL);
  154. };
  155. class RoomSpatialGizmo : public SpatialGizmoTool {
  156. OBJ_TYPE(RoomSpatialGizmo,SpatialGizmoTool);
  157. struct _EdgeKey {
  158. Vector3 from;
  159. Vector3 to;
  160. bool operator<(const _EdgeKey& p_with) const { return from==p_with.from ? to < p_with.to : from < p_with.from; }
  161. };
  162. Room* room;
  163. public:
  164. void redraw();
  165. RoomSpatialGizmo(Room* p_room=NULL);
  166. };
  167. class PortalSpatialGizmo : public SpatialGizmoTool {
  168. OBJ_TYPE(PortalSpatialGizmo,SpatialGizmoTool);
  169. Portal* portal;
  170. public:
  171. void redraw();
  172. PortalSpatialGizmo(Portal* p_portal=NULL);
  173. };
  174. class VisibilityNotifierGizmo : public SpatialGizmoTool {
  175. OBJ_TYPE(VisibilityNotifierGizmo ,SpatialGizmoTool);
  176. VisibilityNotifier* notifier;
  177. public:
  178. virtual String get_handle_name(int p_idx) const;
  179. virtual Variant get_handle_value(int p_idx) const;
  180. virtual void set_handle(int p_idx,Camera *p_camera, const Point2& p_point);
  181. virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false);
  182. void redraw();
  183. VisibilityNotifierGizmo(VisibilityNotifier* p_notifier=NULL);
  184. };
  185. class CollisionShapeSpatialGizmo : public SpatialGizmoTool {
  186. OBJ_TYPE(CollisionShapeSpatialGizmo,SpatialGizmoTool);
  187. CollisionShape* cs;
  188. public:
  189. virtual String get_handle_name(int p_idx) const;
  190. virtual Variant get_handle_value(int p_idx) const;
  191. virtual void set_handle(int p_idx,Camera *p_camera, const Point2& p_point);
  192. virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false);
  193. void redraw();
  194. CollisionShapeSpatialGizmo(CollisionShape* p_cs=NULL);
  195. };
  196. class RayCastSpatialGizmo : public SpatialGizmoTool {
  197. OBJ_TYPE(RayCastSpatialGizmo,SpatialGizmoTool);
  198. RayCast* raycast;
  199. public:
  200. void redraw();
  201. RayCastSpatialGizmo(RayCast* p_raycast=NULL);
  202. };
  203. class CarWheelSpatialGizmo : public SpatialGizmoTool {
  204. OBJ_TYPE(CarWheelSpatialGizmo,SpatialGizmoTool);
  205. CarWheel* car_wheel;
  206. public:
  207. void redraw();
  208. CarWheelSpatialGizmo(CarWheel* p_car_wheel=NULL);
  209. };
  210. class NavigationMeshSpatialGizmo : public SpatialGizmoTool {
  211. OBJ_TYPE(NavigationMeshSpatialGizmo,SpatialGizmoTool);
  212. struct _EdgeKey {
  213. Vector3 from;
  214. Vector3 to;
  215. bool operator<(const _EdgeKey& p_with) const { return from==p_with.from ? to < p_with.to : from < p_with.from; }
  216. };
  217. NavigationMeshInstance* navmesh;
  218. public:
  219. void redraw();
  220. NavigationMeshSpatialGizmo(NavigationMeshInstance* p_navmesh=NULL);
  221. };
  222. class SpatialEditorGizmos {
  223. public:
  224. Ref<FixedMaterial> create_line_material(const Color& p_base_color);
  225. Ref<FixedMaterial> create_solid_material(const Color& p_base_color);
  226. Ref<FixedMaterial> handle2_material;
  227. Ref<FixedMaterial> handle_material;
  228. Ref<FixedMaterial> light_material;
  229. Ref<FixedMaterial> light_material_omni_icon;
  230. Ref<FixedMaterial> light_material_directional_icon;
  231. Ref<FixedMaterial> camera_material;
  232. Ref<FixedMaterial> skeleton_material;
  233. Ref<FixedMaterial> room_material;
  234. Ref<FixedMaterial> portal_material;
  235. Ref<FixedMaterial> raycast_material;
  236. Ref<FixedMaterial> visibility_notifier_material;
  237. Ref<FixedMaterial> car_wheel_material;
  238. Ref<FixedMaterial> navmesh_edge_material;
  239. Ref<FixedMaterial> navmesh_solid_material;
  240. Ref<FixedMaterial> navmesh_edge_material_disabled;
  241. Ref<FixedMaterial> navmesh_solid_material_disabled;
  242. Ref<FixedMaterial> sample_player_icon;
  243. Ref<FixedMaterial> stream_player_icon;
  244. Ref<FixedMaterial> visibility_notifier_icon;
  245. Ref<FixedMaterial> shape_material;
  246. Ref<Texture> handle_t;
  247. Ref<Mesh> pos3d_mesh;
  248. static SpatialEditorGizmos *singleton;
  249. Ref<TriangleMesh> test_cube_tm;
  250. Ref<SpatialEditorGizmo> get_gizmo(Spatial *p_spatial);
  251. SpatialEditorGizmos();
  252. };
  253. #endif // SPATIAL_EDITOR_GIZMOS_H