spatial_editor_gizmos.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. #include "scene/3d/vehicle_body.h"
  47. class Camera;
  48. class SpatialGizmoTool : public SpatialEditorGizmo {
  49. OBJ_TYPE(SpatialGizmoTool,SpatialGizmo);
  50. struct Instance{
  51. RID instance;
  52. Ref<Mesh> mesh;
  53. RID skeleton;
  54. bool billboard;
  55. bool unscaled;
  56. bool can_intersect;
  57. bool extra_margin;
  58. Instance() {
  59. billboard=false;
  60. unscaled=false;
  61. can_intersect=false;
  62. extra_margin=false;
  63. }
  64. void create_instance(Spatial *p_base);
  65. };
  66. Vector<Vector3> collision_segments;
  67. Ref<TriangleMesh> collision_mesh;
  68. struct Handle {
  69. Vector3 pos;
  70. bool billboard;
  71. };
  72. Vector<Vector3> handles;
  73. Vector<Vector3> secondary_handles;
  74. bool billboard_handle;
  75. bool valid;
  76. Spatial *base;
  77. Vector<Instance> instances;
  78. Spatial *spatial_node;
  79. protected:
  80. void clear();
  81. void add_lines(const Vector<Vector3> &p_lines,const Ref<Material>& p_material,bool p_billboard=false);
  82. void add_mesh(const Ref<Mesh>& p_mesh,bool p_billboard=false,const RID& p_skeleton=RID());
  83. void add_collision_segments(const Vector<Vector3> &p_lines);
  84. void add_collision_triangles(const Ref<TriangleMesh>& p_tmesh);
  85. void add_unscaled_billboard(const Ref<Material>& p_material,float p_scale=1);
  86. void add_handles(const Vector<Vector3> &p_handles,bool p_billboard=false,bool p_secondary=false);
  87. void set_spatial_node(Spatial *p_node);
  88. public:
  89. virtual Vector3 get_handle_pos(int p_idx) const;
  90. virtual bool intersect_frustum(const Camera *p_camera,const Vector<Plane> &p_frustum);
  91. 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);
  92. void create();
  93. void transform();
  94. //void redraw();
  95. void free();
  96. SpatialGizmoTool();
  97. ~SpatialGizmoTool();
  98. };
  99. class LightSpatialGizmo : public SpatialGizmoTool {
  100. OBJ_TYPE(LightSpatialGizmo,SpatialGizmoTool);
  101. Light* light;
  102. public:
  103. virtual String get_handle_name(int p_idx) const;
  104. virtual Variant get_handle_value(int p_idx) const;
  105. virtual void set_handle(int p_idx,Camera *p_camera, const Point2& p_point);
  106. virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false);
  107. void redraw();
  108. LightSpatialGizmo(Light* p_light=NULL);
  109. };
  110. class CameraSpatialGizmo : public SpatialGizmoTool {
  111. OBJ_TYPE(CameraSpatialGizmo,SpatialGizmoTool);
  112. Camera* camera;
  113. public:
  114. virtual String get_handle_name(int p_idx) const;
  115. virtual Variant get_handle_value(int p_idx) const;
  116. virtual void set_handle(int p_idx,Camera *p_camera, const Point2& p_point);
  117. virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false);
  118. void redraw();
  119. CameraSpatialGizmo(Camera* p_camera=NULL);
  120. };
  121. class MeshInstanceSpatialGizmo : public SpatialGizmoTool {
  122. OBJ_TYPE(MeshInstanceSpatialGizmo,SpatialGizmoTool);
  123. MeshInstance* mesh;
  124. public:
  125. void redraw();
  126. MeshInstanceSpatialGizmo(MeshInstance* p_mesh=NULL);
  127. };
  128. class Position3DSpatialGizmo : public SpatialGizmoTool {
  129. OBJ_TYPE(Position3DSpatialGizmo,SpatialGizmoTool);
  130. Position3D* p3d;
  131. public:
  132. void redraw();
  133. Position3DSpatialGizmo(Position3D* p_p3d=NULL);
  134. };
  135. class SkeletonSpatialGizmo : public SpatialGizmoTool {
  136. OBJ_TYPE(SkeletonSpatialGizmo,SpatialGizmoTool);
  137. Skeleton* skel;
  138. public:
  139. void redraw();
  140. SkeletonSpatialGizmo(Skeleton* p_skel=NULL);
  141. };
  142. class SpatialPlayerSpatialGizmo : public SpatialGizmoTool {
  143. OBJ_TYPE(SpatialPlayerSpatialGizmo,SpatialGizmoTool);
  144. SpatialPlayer* splayer;
  145. public:
  146. void redraw();
  147. SpatialPlayerSpatialGizmo(SpatialPlayer* p_splayer=NULL);
  148. };
  149. class TestCubeSpatialGizmo : public SpatialGizmoTool {
  150. OBJ_TYPE(TestCubeSpatialGizmo,SpatialGizmoTool);
  151. TestCube* tc;
  152. public:
  153. void redraw();
  154. TestCubeSpatialGizmo(TestCube* p_tc=NULL);
  155. };
  156. class RoomSpatialGizmo : public SpatialGizmoTool {
  157. OBJ_TYPE(RoomSpatialGizmo,SpatialGizmoTool);
  158. struct _EdgeKey {
  159. Vector3 from;
  160. Vector3 to;
  161. bool operator<(const _EdgeKey& p_with) const { return from==p_with.from ? to < p_with.to : from < p_with.from; }
  162. };
  163. Room* room;
  164. public:
  165. void redraw();
  166. RoomSpatialGizmo(Room* p_room=NULL);
  167. };
  168. class PortalSpatialGizmo : public SpatialGizmoTool {
  169. OBJ_TYPE(PortalSpatialGizmo,SpatialGizmoTool);
  170. Portal* portal;
  171. public:
  172. void redraw();
  173. PortalSpatialGizmo(Portal* p_portal=NULL);
  174. };
  175. class VisibilityNotifierGizmo : public SpatialGizmoTool {
  176. OBJ_TYPE(VisibilityNotifierGizmo ,SpatialGizmoTool);
  177. VisibilityNotifier* notifier;
  178. public:
  179. virtual String get_handle_name(int p_idx) const;
  180. virtual Variant get_handle_value(int p_idx) const;
  181. virtual void set_handle(int p_idx,Camera *p_camera, const Point2& p_point);
  182. virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false);
  183. void redraw();
  184. VisibilityNotifierGizmo(VisibilityNotifier* p_notifier=NULL);
  185. };
  186. class CollisionShapeSpatialGizmo : public SpatialGizmoTool {
  187. OBJ_TYPE(CollisionShapeSpatialGizmo,SpatialGizmoTool);
  188. CollisionShape* cs;
  189. public:
  190. virtual String get_handle_name(int p_idx) const;
  191. virtual Variant get_handle_value(int p_idx) const;
  192. virtual void set_handle(int p_idx,Camera *p_camera, const Point2& p_point);
  193. virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false);
  194. void redraw();
  195. CollisionShapeSpatialGizmo(CollisionShape* p_cs=NULL);
  196. };
  197. class RayCastSpatialGizmo : public SpatialGizmoTool {
  198. OBJ_TYPE(RayCastSpatialGizmo,SpatialGizmoTool);
  199. RayCast* raycast;
  200. public:
  201. void redraw();
  202. RayCastSpatialGizmo(RayCast* p_raycast=NULL);
  203. };
  204. class CarWheelSpatialGizmo : public SpatialGizmoTool {
  205. OBJ_TYPE(CarWheelSpatialGizmo,SpatialGizmoTool);
  206. CarWheel* car_wheel;
  207. public:
  208. void redraw();
  209. CarWheelSpatialGizmo(CarWheel* p_car_wheel=NULL);
  210. };
  211. class VehicleWheelSpatialGizmo : public SpatialGizmoTool {
  212. OBJ_TYPE(VehicleWheelSpatialGizmo,SpatialGizmoTool);
  213. VehicleWheel* car_wheel;
  214. public:
  215. void redraw();
  216. VehicleWheelSpatialGizmo(VehicleWheel* p_car_wheel=NULL);
  217. };
  218. class NavigationMeshSpatialGizmo : public SpatialGizmoTool {
  219. OBJ_TYPE(NavigationMeshSpatialGizmo,SpatialGizmoTool);
  220. struct _EdgeKey {
  221. Vector3 from;
  222. Vector3 to;
  223. bool operator<(const _EdgeKey& p_with) const { return from==p_with.from ? to < p_with.to : from < p_with.from; }
  224. };
  225. NavigationMeshInstance* navmesh;
  226. public:
  227. void redraw();
  228. NavigationMeshSpatialGizmo(NavigationMeshInstance* p_navmesh=NULL);
  229. };
  230. class SpatialEditorGizmos {
  231. public:
  232. Ref<FixedMaterial> create_line_material(const Color& p_base_color);
  233. Ref<FixedMaterial> create_solid_material(const Color& p_base_color);
  234. Ref<FixedMaterial> handle2_material;
  235. Ref<FixedMaterial> handle_material;
  236. Ref<FixedMaterial> light_material;
  237. Ref<FixedMaterial> light_material_omni_icon;
  238. Ref<FixedMaterial> light_material_directional_icon;
  239. Ref<FixedMaterial> camera_material;
  240. Ref<FixedMaterial> skeleton_material;
  241. Ref<FixedMaterial> room_material;
  242. Ref<FixedMaterial> portal_material;
  243. Ref<FixedMaterial> raycast_material;
  244. Ref<FixedMaterial> visibility_notifier_material;
  245. Ref<FixedMaterial> car_wheel_material;
  246. Ref<FixedMaterial> navmesh_edge_material;
  247. Ref<FixedMaterial> navmesh_solid_material;
  248. Ref<FixedMaterial> navmesh_edge_material_disabled;
  249. Ref<FixedMaterial> navmesh_solid_material_disabled;
  250. Ref<FixedMaterial> sample_player_icon;
  251. Ref<FixedMaterial> stream_player_icon;
  252. Ref<FixedMaterial> visibility_notifier_icon;
  253. Ref<FixedMaterial> shape_material;
  254. Ref<Texture> handle_t;
  255. Ref<Mesh> pos3d_mesh;
  256. static SpatialEditorGizmos *singleton;
  257. Ref<TriangleMesh> test_cube_tm;
  258. Ref<SpatialEditorGizmo> get_gizmo(Spatial *p_spatial);
  259. SpatialEditorGizmos();
  260. };
  261. #endif // SPATIAL_EDITOR_GIZMOS_H