mesh_data_tool.h 4.6 KB

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