mesh_library.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**************************************************************************/
  2. /* mesh_library.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 MESH_LIBRARY_H
  31. #define MESH_LIBRARY_H
  32. #include "core/io/resource.h"
  33. #include "core/templates/rb_map.h"
  34. #include "scene/resources/mesh.h"
  35. #include "scene/resources/navigation_mesh.h"
  36. #include "servers/rendering_server.h"
  37. #include "shape_3d.h"
  38. class MeshLibrary : public Resource {
  39. GDCLASS(MeshLibrary, Resource);
  40. RES_BASE_EXTENSION("meshlib");
  41. public:
  42. struct ShapeData {
  43. Ref<Shape3D> shape;
  44. Transform3D local_transform;
  45. };
  46. struct Item {
  47. String name;
  48. Ref<Mesh> mesh;
  49. Transform3D mesh_transform;
  50. RS::ShadowCastingSetting mesh_cast_shadow = RS::ShadowCastingSetting::SHADOW_CASTING_SETTING_ON;
  51. Vector<ShapeData> shapes;
  52. Ref<Texture2D> preview;
  53. Ref<NavigationMesh> navigation_mesh;
  54. Transform3D navigation_mesh_transform;
  55. uint32_t navigation_layers = 1;
  56. };
  57. RBMap<int, Item> item_map;
  58. void _set_item_shapes(int p_item, const Array &p_shapes);
  59. Array _get_item_shapes(int p_item) const;
  60. protected:
  61. bool _set(const StringName &p_name, const Variant &p_value);
  62. bool _get(const StringName &p_name, Variant &r_ret) const;
  63. void _get_property_list(List<PropertyInfo> *p_list) const;
  64. virtual void reset_state() override;
  65. static void _bind_methods();
  66. public:
  67. void create_item(int p_item);
  68. void set_item_name(int p_item, const String &p_name);
  69. void set_item_mesh(int p_item, const Ref<Mesh> &p_mesh);
  70. void set_item_mesh_transform(int p_item, const Transform3D &p_transform);
  71. void set_item_mesh_cast_shadow(int p_item, RS::ShadowCastingSetting p_shadow_casting_setting);
  72. void set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh);
  73. void set_item_navigation_mesh_transform(int p_item, const Transform3D &p_transform);
  74. void set_item_navigation_layers(int p_item, uint32_t p_navigation_layers);
  75. void set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes);
  76. void set_item_preview(int p_item, const Ref<Texture2D> &p_preview);
  77. String get_item_name(int p_item) const;
  78. Ref<Mesh> get_item_mesh(int p_item) const;
  79. Transform3D get_item_mesh_transform(int p_item) const;
  80. RS::ShadowCastingSetting get_item_mesh_cast_shadow(int p_item) const;
  81. Ref<NavigationMesh> get_item_navigation_mesh(int p_item) const;
  82. Transform3D get_item_navigation_mesh_transform(int p_item) const;
  83. uint32_t get_item_navigation_layers(int p_item) const;
  84. Vector<ShapeData> get_item_shapes(int p_item) const;
  85. Ref<Texture2D> get_item_preview(int p_item) const;
  86. void remove_item(int p_item);
  87. bool has_item(int p_item) const;
  88. void clear();
  89. int find_item_by_name(const String &p_name) const;
  90. Vector<int> get_item_list() const;
  91. int get_last_unused_item_id() const;
  92. MeshLibrary();
  93. ~MeshLibrary();
  94. };
  95. #endif // MESH_LIBRARY_H