mesh_library.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*************************************************************************/
  2. /* mesh_library.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 GRID_THEME_H
  31. #define GRID_THEME_H
  32. #include "map.h"
  33. #include "mesh.h"
  34. #include "resource.h"
  35. #include "scene/3d/navigation_mesh.h"
  36. #include "shape.h"
  37. class MeshLibrary : public Resource {
  38. GDCLASS(MeshLibrary, Resource);
  39. RES_BASE_EXTENSION("meshlib");
  40. public:
  41. struct ShapeData {
  42. Ref<Shape> shape;
  43. Transform local_transform;
  44. };
  45. struct Item {
  46. String name;
  47. Ref<Mesh> mesh;
  48. Vector<ShapeData> shapes;
  49. Ref<Texture> preview;
  50. Ref<NavigationMesh> navmesh;
  51. };
  52. Map<int, Item> item_map;
  53. void _set_item_shapes(int p_item, const Array &p_shapes);
  54. Array _get_item_shapes(int p_item) const;
  55. protected:
  56. bool _set(const StringName &p_name, const Variant &p_value);
  57. bool _get(const StringName &p_name, Variant &r_ret) const;
  58. void _get_property_list(List<PropertyInfo> *p_list) const;
  59. static void _bind_methods();
  60. public:
  61. void create_item(int p_item);
  62. void set_item_name(int p_item, const String &p_name);
  63. void set_item_mesh(int p_item, const Ref<Mesh> &p_mesh);
  64. void set_item_navmesh(int p_item, const Ref<NavigationMesh> &p_navmesh);
  65. void set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes);
  66. void set_item_preview(int p_item, const Ref<Texture> &p_preview);
  67. String get_item_name(int p_item) const;
  68. Ref<Mesh> get_item_mesh(int p_item) const;
  69. Ref<NavigationMesh> get_item_navmesh(int p_item) const;
  70. Vector<ShapeData> get_item_shapes(int p_item) const;
  71. Ref<Texture> get_item_preview(int p_item) const;
  72. void remove_item(int p_item);
  73. bool has_item(int p_item) const;
  74. void clear();
  75. int find_item_by_name(const String &p_name) const;
  76. Vector<int> get_item_list() const;
  77. int get_last_unused_item_id() const;
  78. MeshLibrary();
  79. ~MeshLibrary();
  80. };
  81. #endif // CUBE_GRID_THEME_H