mesh_data_tool.h
1 /*************************************************************************/
2 /* mesh_data_tool.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef MESH_DATA_TOOL_H
30 #define MESH_DATA_TOOL_H
31 
32 #include "scene/resources/mesh.h"
33 
34 class MeshDataTool : public Reference {
35 
36  OBJ_TYPE(MeshDataTool,Reference);
37 
38 
39  int format;
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 
58  int vertex[2];
59  Vector<int> faces;
60  Variant meta;
61  };
62 
63  Vector<Edge> edges;
64 
65  struct Face {
66 
67  int v[3];
68  int edges[3];
69  Variant meta;
70  };
71 
72 
73  Vector<Face> faces;
74 
75  Ref<Material> material;
76 protected:
77 
78  static void _bind_methods();
79 public:
80 
81  void clear();
82  Error create_from_surface(const Ref<Mesh>& p_mesh,int p_surface);
83  Error commit_to_surface(const Ref<Mesh>& p_mesh);
84 
85  int get_format() const;
86 
87  int get_vertex_count() const;
88  int get_edge_count() const;
89  int get_face_count() const;
90 
91  Vector3 get_vertex(int p_idx) const;
92  void set_vertex(int p_idx,const Vector3& p_vertex);
93 
94  Vector3 get_vertex_normal(int p_idx) const;
95  void set_vertex_normal(int p_idx,const Vector3& p_normal);
96 
97  Plane get_vertex_tangent(int p_idx) const;
98  void set_vertex_tangent(int p_idx,const Plane& p_tangent);
99 
100  Vector2 get_vertex_uv(int p_idx) const;
101  void set_vertex_uv(int p_idx,const Vector2& p_uv);
102 
103  Vector2 get_vertex_uv2(int p_idx) const;
104  void set_vertex_uv2(int p_idx,const Vector2& p_uv2);
105 
106  Color get_vertex_color(int p_idx) const;
107  void set_vertex_color(int p_idx,const Color& p_color);
108 
109  Vector<int> get_vertex_bones(int p_idx) const;
110  void set_vertex_bones(int p_idx,const Vector<int>& p_bones);
111 
112  Vector<float> get_vertex_weights(int p_idx) const;
113  void set_vertex_weights(int p_idx,const Vector<float>& p_weights);
114 
115  Variant get_vertex_meta(int p_idx) const;
116  void set_vertex_meta(int p_idx,const Variant& p_meta);
117 
118  Vector<int> get_vertex_edges(int p_idx) const;
119  Vector<int> get_vertex_faces(int p_idx) const;
120 
121  int get_edge_vertex(int p_edge,int p_vertex) const;
122  Vector<int> get_edge_faces(int p_edge) const;
123  Variant get_edge_meta(int p_idx) const;
124  void set_edge_meta(int p_idx,const Variant& p_meta);
125 
126  int get_face_vertex(int p_face,int p_vertex) const;
127  int get_face_edge(int p_face,int p_vertex) const;
128  Variant get_face_meta(int p_face) const;
129  void set_face_meta(int p_face,const Variant& p_meta);
130  Vector3 get_face_normal(int p_face) const;
131 
132  Ref<Material> get_material() const;
133  void set_material(const Ref<Material> &p_material);
134 
135  MeshDataTool();
136 };
137 
138 #endif // MESH_DATA_TOOL_H
Definition: variant.h:74
Definition: color.h:37
Definition: reference.h:40
Definition: mesh_data_tool.h:34
Definition: vector3.h:38
Definition: math_2d.h:65
Definition: plane.h:35