1 | /**************************************************************************/ |
2 | /* mesh_data_tool.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 MESH_DATA_TOOL_H |
32 | #define MESH_DATA_TOOL_H |
33 | |
34 | #include "scene/resources/mesh.h" |
35 | |
36 | class MeshDataTool : public RefCounted { |
37 | GDCLASS(MeshDataTool, RefCounted); |
38 | |
39 | int format = 0; |
40 | struct Vertex { |
41 | Vector3 vertex; |
42 | Color color; |
43 | Vector3 normal; // normal, binormal, tangent |
44 | Plane tangent; |
45 | Vector2 uv; |
46 | Vector2 uv2; |
47 | Vector<int> bones; |
48 | Vector<float> weights; |
49 | Vector<int> edges; |
50 | Vector<int> faces; |
51 | Variant meta; |
52 | }; |
53 | |
54 | Vector<Vertex> vertices; |
55 | |
56 | struct Edge { |
57 | int vertex[2] = {}; |
58 | Vector<int> faces; |
59 | Variant meta; |
60 | }; |
61 | |
62 | Vector<Edge> edges; |
63 | |
64 | struct Face { |
65 | int v[3] = {}; |
66 | int edges[3] = {}; |
67 | Variant meta; |
68 | }; |
69 | |
70 | Vector<Face> faces; |
71 | |
72 | Ref<Material> material; |
73 | |
74 | protected: |
75 | static void _bind_methods(); |
76 | |
77 | public: |
78 | void clear(); |
79 | Error create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surface); |
80 | Error commit_to_surface(const Ref<ArrayMesh> &p_mesh); |
81 | |
82 | int get_format() const; |
83 | |
84 | int get_vertex_count() const; |
85 | int get_edge_count() const; |
86 | int get_face_count() const; |
87 | |
88 | Vector3 get_vertex(int p_idx) const; |
89 | void set_vertex(int p_idx, const Vector3 &p_vertex); |
90 | |
91 | Vector3 get_vertex_normal(int p_idx) const; |
92 | void set_vertex_normal(int p_idx, const Vector3 &p_normal); |
93 | |
94 | Plane get_vertex_tangent(int p_idx) const; |
95 | void set_vertex_tangent(int p_idx, const Plane &p_tangent); |
96 | |
97 | Vector2 get_vertex_uv(int p_idx) const; |
98 | void set_vertex_uv(int p_idx, const Vector2 &p_uv); |
99 | |
100 | Vector2 get_vertex_uv2(int p_idx) const; |
101 | void set_vertex_uv2(int p_idx, const Vector2 &p_uv2); |
102 | |
103 | Color get_vertex_color(int p_idx) const; |
104 | void set_vertex_color(int p_idx, const Color &p_color); |
105 | |
106 | Vector<int> get_vertex_bones(int p_idx) const; |
107 | void set_vertex_bones(int p_idx, const Vector<int> &p_bones); |
108 | |
109 | Vector<float> get_vertex_weights(int p_idx) const; |
110 | void set_vertex_weights(int p_idx, const Vector<float> &p_weights); |
111 | |
112 | Variant get_vertex_meta(int p_idx) const; |
113 | void set_vertex_meta(int p_idx, const Variant &p_meta); |
114 | |
115 | Vector<int> get_vertex_edges(int p_idx) const; |
116 | Vector<int> get_vertex_faces(int p_idx) const; |
117 | |
118 | int get_edge_vertex(int p_edge, int p_vertex) const; |
119 | Vector<int> get_edge_faces(int p_edge) const; |
120 | Variant get_edge_meta(int p_idx) const; |
121 | void set_edge_meta(int p_idx, const Variant &p_meta); |
122 | |
123 | int get_face_vertex(int p_face, int p_vertex) const; |
124 | int get_face_edge(int p_face, int p_vertex) const; |
125 | Variant get_face_meta(int p_face) const; |
126 | void set_face_meta(int p_face, const Variant &p_meta); |
127 | Vector3 get_face_normal(int p_face) const; |
128 | |
129 | Ref<Material> get_material() const; |
130 | void set_material(const Ref<Material> &p_material); |
131 | |
132 | MeshDataTool(); |
133 | }; |
134 | |
135 | #endif // MESH_DATA_TOOL_H |
136 | |