mesh.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*************************************************************************/
  2. /* mesh.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 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. #include "servers/visual_server.h"
  32. #include "scene/resources/material.h"
  33. #include "scene/resources/shape.h"
  34. #include "resource.h"
  35. #include "triangle_mesh.h"
  36. /**
  37. @author Juan Linietsky <[email protected]>
  38. */
  39. class Mesh : public Resource {
  40. OBJ_TYPE( Mesh, Resource );
  41. RES_BASE_EXTENSION("msh");
  42. public:
  43. enum {
  44. NO_INDEX_ARRAY=VisualServer::NO_INDEX_ARRAY,
  45. ARRAY_WEIGHTS_SIZE=VisualServer::ARRAY_WEIGHTS_SIZE
  46. };
  47. enum ArrayType {
  48. ARRAY_VERTEX=VisualServer::ARRAY_VERTEX,
  49. ARRAY_NORMAL=VisualServer::ARRAY_NORMAL,
  50. ARRAY_TANGENT=VisualServer::ARRAY_TANGENT,
  51. ARRAY_COLOR=VisualServer::ARRAY_COLOR,
  52. ARRAY_TEX_UV=VisualServer::ARRAY_TEX_UV,
  53. ARRAY_TEX_UV2=VisualServer::ARRAY_TEX_UV2,
  54. ARRAY_BONES=VisualServer::ARRAY_BONES,
  55. ARRAY_WEIGHTS=VisualServer::ARRAY_WEIGHTS,
  56. ARRAY_INDEX=VisualServer::ARRAY_INDEX,
  57. ARRAY_MAX=VisualServer::ARRAY_MAX
  58. };
  59. enum ArrayFormat {
  60. /* ARRAY FORMAT FLAGS */
  61. ARRAY_FORMAT_VERTEX=1<<ARRAY_VERTEX, // mandatory
  62. ARRAY_FORMAT_NORMAL=1<<ARRAY_NORMAL,
  63. ARRAY_FORMAT_TANGENT=1<<ARRAY_TANGENT,
  64. ARRAY_FORMAT_COLOR=1<<ARRAY_COLOR,
  65. ARRAY_FORMAT_TEX_UV=1<<ARRAY_TEX_UV,
  66. ARRAY_FORMAT_TEX_UV2=1<<ARRAY_TEX_UV2,
  67. ARRAY_FORMAT_BONES=1<<ARRAY_BONES,
  68. ARRAY_FORMAT_WEIGHTS=1<<ARRAY_WEIGHTS,
  69. ARRAY_FORMAT_INDEX=1<<ARRAY_INDEX,
  70. };
  71. enum PrimitiveType {
  72. PRIMITIVE_POINTS=VisualServer::PRIMITIVE_POINTS,
  73. PRIMITIVE_LINES=VisualServer::PRIMITIVE_LINES,
  74. PRIMITIVE_LINE_STRIP=VisualServer::PRIMITIVE_LINE_STRIP,
  75. PRIMITIVE_LINE_LOOP=VisualServer::PRIMITIVE_LINE_LOOP,
  76. PRIMITIVE_TRIANGLES=VisualServer::PRIMITIVE_TRIANGLES,
  77. PRIMITIVE_TRIANGLE_STRIP=VisualServer::PRIMITIVE_TRIANGLE_STRIP,
  78. PRIMITIVE_TRIANGLE_FAN=VisualServer::PRIMITIVE_TRIANGLE_FAN,
  79. };
  80. enum MorphTargetMode {
  81. MORPH_MODE_NORMALIZED=VS::MORPH_MODE_NORMALIZED,
  82. MORPH_MODE_RELATIVE=VS::MORPH_MODE_RELATIVE,
  83. };
  84. private:
  85. struct Surface {
  86. String name;
  87. AABB aabb;
  88. bool alphasort;
  89. Ref<Material> material;
  90. };
  91. Vector<Surface> surfaces;
  92. RID mesh;
  93. AABB aabb;
  94. MorphTargetMode morph_target_mode;
  95. Vector<StringName> morph_targets;
  96. AABB custom_aabb;
  97. mutable Ref<TriangleMesh> triangle_mesh;
  98. void _recompute_aabb();
  99. protected:
  100. bool _set(const StringName& p_name, const Variant& p_value);
  101. bool _get(const StringName& p_name,Variant &r_ret) const;
  102. void _get_property_list( List<PropertyInfo> *p_list) const;
  103. static void _bind_methods();
  104. public:
  105. void add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alphasort=false);
  106. Array surface_get_arrays(int p_surface) const;
  107. virtual Array surface_get_morph_arrays(int p_surface) const;
  108. void add_custom_surface(const Variant& p_data); //only recognized by driver
  109. void add_morph_target(const StringName& p_name);
  110. int get_morph_target_count() const;
  111. StringName get_morph_target_name(int p_index) const;
  112. void clear_morph_targets();
  113. void set_morph_target_mode(MorphTargetMode p_mode);
  114. MorphTargetMode get_morph_target_mode() const;
  115. int get_surface_count() const;
  116. void surface_remove(int p_idx);
  117. void surface_set_custom_aabb(int p_surface,const AABB& p_aabb); //only recognized by driver
  118. int surface_get_array_len(int p_idx) const;
  119. int surface_get_array_index_len(int p_idx) const;
  120. uint32_t surface_get_format(int p_idx) const;
  121. PrimitiveType surface_get_primitive_type(int p_idx) const;
  122. bool surface_is_alpha_sorting_enabled(int p_idx) const;
  123. void surface_set_material(int p_idx, const Ref<Material>& p_material);
  124. Ref<Material> surface_get_material(int p_idx) const;
  125. void surface_set_name(int p_idx, const String& p_name);
  126. String surface_get_name(int p_idx) const;
  127. void add_surface_from_mesh_data(const Geometry::MeshData& p_mesh_data);
  128. void set_custom_aabb(const AABB& p_custom);
  129. AABB get_custom_aabb() const;
  130. AABB get_aabb() const;
  131. virtual RID get_rid() const;
  132. Ref<Shape> create_trimesh_shape() const;
  133. Ref<Shape> create_convex_shape() const;
  134. void center_geometry();
  135. DVector<Face3> get_faces() const;
  136. Ref<TriangleMesh> generate_triangle_mesh() const;
  137. Mesh();
  138. ~Mesh();
  139. };
  140. VARIANT_ENUM_CAST( Mesh::ArrayType );
  141. VARIANT_ENUM_CAST( Mesh::PrimitiveType );
  142. VARIANT_ENUM_CAST( Mesh::MorphTargetMode );
  143. #endif