mesh.h
1 /*************************************************************************/
2 /* mesh.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_H
30 #define MESH_H
31 
32 #include "servers/visual_server.h"
33 #include "scene/resources/material.h"
34 #include "scene/resources/shape.h"
35 #include "resource.h"
36 #include "triangle_mesh.h"
40 class Mesh : public Resource {
41 
42  OBJ_TYPE( Mesh, Resource );
43  RES_BASE_EXTENSION("msh");
44 
45 public:
46 
47  enum {
48 
49  NO_INDEX_ARRAY=VisualServer::NO_INDEX_ARRAY,
50  ARRAY_WEIGHTS_SIZE=VisualServer::ARRAY_WEIGHTS_SIZE
51  };
52 
53  enum ArrayType {
54 
55  ARRAY_VERTEX=VisualServer::ARRAY_VERTEX,
56  ARRAY_NORMAL=VisualServer::ARRAY_NORMAL,
57  ARRAY_TANGENT=VisualServer::ARRAY_TANGENT,
58  ARRAY_COLOR=VisualServer::ARRAY_COLOR,
59  ARRAY_TEX_UV=VisualServer::ARRAY_TEX_UV,
60  ARRAY_TEX_UV2=VisualServer::ARRAY_TEX_UV2,
61  ARRAY_BONES=VisualServer::ARRAY_BONES,
62  ARRAY_WEIGHTS=VisualServer::ARRAY_WEIGHTS,
63  ARRAY_INDEX=VisualServer::ARRAY_INDEX,
64  ARRAY_MAX=VisualServer::ARRAY_MAX
65 
66  };
67 
68  enum ArrayFormat {
69  /* ARRAY FORMAT FLAGS */
70  ARRAY_FORMAT_VERTEX=1<<ARRAY_VERTEX, // mandatory
71  ARRAY_FORMAT_NORMAL=1<<ARRAY_NORMAL,
72  ARRAY_FORMAT_TANGENT=1<<ARRAY_TANGENT,
73  ARRAY_FORMAT_COLOR=1<<ARRAY_COLOR,
74  ARRAY_FORMAT_TEX_UV=1<<ARRAY_TEX_UV,
75  ARRAY_FORMAT_TEX_UV2=1<<ARRAY_TEX_UV2,
76  ARRAY_FORMAT_BONES=1<<ARRAY_BONES,
77  ARRAY_FORMAT_WEIGHTS=1<<ARRAY_WEIGHTS,
78  ARRAY_FORMAT_INDEX=1<<ARRAY_INDEX,
79 
80  };
81 
82  enum PrimitiveType {
83  PRIMITIVE_POINTS=VisualServer::PRIMITIVE_POINTS,
84  PRIMITIVE_LINES=VisualServer::PRIMITIVE_LINES,
85  PRIMITIVE_LINE_STRIP=VisualServer::PRIMITIVE_LINE_STRIP,
86  PRIMITIVE_LINE_LOOP=VisualServer::PRIMITIVE_LINE_LOOP,
87  PRIMITIVE_TRIANGLES=VisualServer::PRIMITIVE_TRIANGLES,
88  PRIMITIVE_TRIANGLE_STRIP=VisualServer::PRIMITIVE_TRIANGLE_STRIP,
89  PRIMITIVE_TRIANGLE_FAN=VisualServer::PRIMITIVE_TRIANGLE_FAN,
90  };
91 
92  enum MorphTargetMode {
93 
94  MORPH_MODE_NORMALIZED=VS::MORPH_MODE_NORMALIZED,
95  MORPH_MODE_RELATIVE=VS::MORPH_MODE_RELATIVE,
96  };
97 
98 private:
99  struct Surface {
100  String name;
101  AABB aabb;
102  bool alphasort;
103  Ref<Material> material;
104  };
105  Vector<Surface> surfaces;
106  RID mesh;
107  AABB aabb;
108  MorphTargetMode morph_target_mode;
109  Vector<StringName> morph_targets;
110  AABB custom_aabb;
111 
112  mutable Ref<TriangleMesh> triangle_mesh;
113 
114 
115  void _recompute_aabb();
116 protected:
117 
118  bool _set(const StringName& p_name, const Variant& p_value);
119  bool _get(const StringName& p_name,Variant &r_ret) const;
120  void _get_property_list( List<PropertyInfo> *p_list) const;
121 
122  static void _bind_methods();
123 
124 public:
125 
126  void add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alphasort=false);
127  Array surface_get_arrays(int p_surface) const;
128  virtual Array surface_get_morph_arrays(int p_surface) const;
129 
130  void add_custom_surface(const Variant& p_data); //only recognized by driver
131 
132  void add_morph_target(const StringName& p_name);
133  int get_morph_target_count() const;
134  StringName get_morph_target_name(int p_index) const;
135  void clear_morph_targets();
136 
137  void set_morph_target_mode(MorphTargetMode p_mode);
138  MorphTargetMode get_morph_target_mode() const;
139 
140  int get_surface_count() const;
141  void surface_remove(int p_idx);
142 
143  void surface_set_custom_aabb(int p_surface,const AABB& p_aabb); //only recognized by driver
144 
145 
146  int surface_get_array_len(int p_idx) const;
147  int surface_get_array_index_len(int p_idx) const;
148  uint32_t surface_get_format(int p_idx) const;
149  PrimitiveType surface_get_primitive_type(int p_idx) const;
150  bool surface_is_alpha_sorting_enabled(int p_idx) const;
151 
152  void surface_set_material(int p_idx, const Ref<Material>& p_material);
153  Ref<Material> surface_get_material(int p_idx) const;
154 
155  void surface_set_name(int p_idx, const String& p_name);
156  String surface_get_name(int p_idx) const;
157 
158  void add_surface_from_mesh_data(const Geometry::MeshData& p_mesh_data);
159 
160  void set_custom_aabb(const AABB& p_custom);
161  AABB get_custom_aabb() const;
162 
163  AABB get_aabb() const;
164  virtual RID get_rid() const;
165 
166  Ref<Shape> create_trimesh_shape() const;
167  Ref<Shape> create_convex_shape() const;
168 
169  Ref<Mesh> create_outline(float p_margin) const;
170 
171  void center_geometry();
172  void regen_normalmaps();
173 
174  DVector<Face3> get_faces() const;
175  Ref<TriangleMesh> generate_triangle_mesh() const;
176  Mesh();
177 
178  ~Mesh();
179 
180 };
181 
182 VARIANT_ENUM_CAST( Mesh::ArrayType );
183 VARIANT_ENUM_CAST( Mesh::PrimitiveType );
184 VARIANT_ENUM_CAST( Mesh::MorphTargetMode );
185 
186 #endif
Definition: mesh.h:40
Definition: array.h:38
Definition: variant.h:74
Definition: aabb.h:43
Definition: string_db.h:48
Definition: geometry.h:816
Definition: resource.h:89
Definition: rid.h:47
Definition: ustring.h:64