importer_mesh.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**************************************************************************/
  2. /* importer_mesh.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 IMPORTER_MESH_H
  31. #define IMPORTER_MESH_H
  32. #include "core/io/resource.h"
  33. #include "core/templates/local_vector.h"
  34. #include "scene/resources/3d/concave_polygon_shape_3d.h"
  35. #include "scene/resources/3d/convex_polygon_shape_3d.h"
  36. #include "scene/resources/mesh.h"
  37. #include "scene/resources/navigation_mesh.h"
  38. #include <cstdint>
  39. // The following classes are used by importers instead of ArrayMesh and MeshInstance3D
  40. // so the data is not registered (hence, quality loss), importing happens faster and
  41. // its easier to modify before saving
  42. class ImporterMesh : public Resource {
  43. GDCLASS(ImporterMesh, Resource)
  44. struct Surface {
  45. Mesh::PrimitiveType primitive;
  46. Array arrays;
  47. struct BlendShape {
  48. Array arrays;
  49. };
  50. Vector<BlendShape> blend_shape_data;
  51. struct LOD {
  52. Vector<int> indices;
  53. float distance = 0.0f;
  54. };
  55. Vector<LOD> lods;
  56. Ref<Material> material;
  57. String name;
  58. uint64_t flags = 0;
  59. struct LODComparator {
  60. _FORCE_INLINE_ bool operator()(const LOD &l, const LOD &r) const {
  61. return l.distance < r.distance;
  62. }
  63. };
  64. void split_normals(const LocalVector<int> &p_indices, const LocalVector<Vector3> &p_normals);
  65. static void _split_normals(Array &r_arrays, const LocalVector<int> &p_indices, const LocalVector<Vector3> &p_normals);
  66. };
  67. Vector<Surface> surfaces;
  68. Vector<String> blend_shapes;
  69. Mesh::BlendShapeMode blend_shape_mode = Mesh::BLEND_SHAPE_MODE_NORMALIZED;
  70. Ref<ArrayMesh> mesh;
  71. Ref<ImporterMesh> shadow_mesh;
  72. Size2i lightmap_size_hint;
  73. protected:
  74. void _set_data(const Dictionary &p_data);
  75. Dictionary _get_data() const;
  76. static void _bind_methods();
  77. public:
  78. void add_blend_shape(const String &p_name);
  79. int get_blend_shape_count() const;
  80. String get_blend_shape_name(int p_blend_shape) const;
  81. void add_surface(Mesh::PrimitiveType p_primitive, const Array &p_arrays, const TypedArray<Array> &p_blend_shapes = Array(), const Dictionary &p_lods = Dictionary(), const Ref<Material> &p_material = Ref<Material>(), const String &p_name = String(), const uint64_t p_flags = 0);
  82. int get_surface_count() const;
  83. void set_blend_shape_mode(Mesh::BlendShapeMode p_blend_shape_mode);
  84. Mesh::BlendShapeMode get_blend_shape_mode() const;
  85. Mesh::PrimitiveType get_surface_primitive_type(int p_surface);
  86. String get_surface_name(int p_surface) const;
  87. void set_surface_name(int p_surface, const String &p_name);
  88. Array get_surface_arrays(int p_surface) const;
  89. Array get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const;
  90. int get_surface_lod_count(int p_surface) const;
  91. Vector<int> get_surface_lod_indices(int p_surface, int p_lod) const;
  92. float get_surface_lod_size(int p_surface, int p_lod) const;
  93. Ref<Material> get_surface_material(int p_surface) const;
  94. uint64_t get_surface_format(int p_surface) const;
  95. void set_surface_material(int p_surface, const Ref<Material> &p_material);
  96. void generate_lods(float p_normal_merge_angle, float p_normal_split_angle, Array p_skin_pose_transform_array);
  97. void create_shadow_mesh();
  98. Ref<ImporterMesh> get_shadow_mesh() const;
  99. Vector<Face3> get_faces() const;
  100. Vector<Ref<Shape3D>> convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const;
  101. Ref<ConvexPolygonShape3D> create_convex_shape(bool p_clean = true, bool p_simplify = false) const;
  102. Ref<ConcavePolygonShape3D> create_trimesh_shape() const;
  103. Ref<NavigationMesh> create_navigation_mesh();
  104. Error lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector<uint8_t> &p_src_cache, Vector<uint8_t> &r_dst_cache);
  105. void set_lightmap_size_hint(const Size2i &p_size);
  106. Size2i get_lightmap_size_hint() const;
  107. bool has_mesh() const;
  108. Ref<ArrayMesh> get_mesh(const Ref<ArrayMesh> &p_base = Ref<ArrayMesh>());
  109. void clear();
  110. };
  111. #endif // IMPORTER_MESH_H