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