mesh_data_tool.h 4.7 KB

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