mesh_data_tool.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**************************************************************************/
  2. /* mesh_data_tool.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 RefCounted {
  34. GDCLASS(MeshDataTool, RefCounted);
  35. uint64_t format = 0;
  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. #ifndef DISABLE_DEPRECATED
  66. Error commit_to_surface_bind_compat_81138(const Ref<ArrayMesh> &p_mesh);
  67. static void _bind_compatibility_methods();
  68. #endif
  69. public:
  70. void clear();
  71. Error create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surface);
  72. Error commit_to_surface(const Ref<ArrayMesh> &p_mesh, uint64_t p_compression_flags = 0);
  73. uint64_t get_format() const;
  74. int get_vertex_count() const;
  75. int get_edge_count() const;
  76. int get_face_count() const;
  77. Vector3 get_vertex(int p_idx) const;
  78. void set_vertex(int p_idx, const Vector3 &p_vertex);
  79. Vector3 get_vertex_normal(int p_idx) const;
  80. void set_vertex_normal(int p_idx, const Vector3 &p_normal);
  81. Plane get_vertex_tangent(int p_idx) const;
  82. void set_vertex_tangent(int p_idx, const Plane &p_tangent);
  83. Vector2 get_vertex_uv(int p_idx) const;
  84. void set_vertex_uv(int p_idx, const Vector2 &p_uv);
  85. Vector2 get_vertex_uv2(int p_idx) const;
  86. void set_vertex_uv2(int p_idx, const Vector2 &p_uv2);
  87. Color get_vertex_color(int p_idx) const;
  88. void set_vertex_color(int p_idx, const Color &p_color);
  89. Vector<int> get_vertex_bones(int p_idx) const;
  90. void set_vertex_bones(int p_idx, const Vector<int> &p_bones);
  91. Vector<float> get_vertex_weights(int p_idx) const;
  92. void set_vertex_weights(int p_idx, const Vector<float> &p_weights);
  93. Variant get_vertex_meta(int p_idx) const;
  94. void set_vertex_meta(int p_idx, const Variant &p_meta);
  95. Vector<int> get_vertex_edges(int p_idx) const;
  96. Vector<int> get_vertex_faces(int p_idx) const;
  97. int get_edge_vertex(int p_edge, int p_vertex) const;
  98. Vector<int> get_edge_faces(int p_edge) const;
  99. Variant get_edge_meta(int p_idx) const;
  100. void set_edge_meta(int p_idx, const Variant &p_meta);
  101. int get_face_vertex(int p_face, int p_vertex) const;
  102. int get_face_edge(int p_face, int p_vertex) const;
  103. Variant get_face_meta(int p_face) const;
  104. void set_face_meta(int p_face, const Variant &p_meta);
  105. Vector3 get_face_normal(int p_face) const;
  106. Ref<Material> get_material() const;
  107. void set_material(const Ref<Material> &p_material);
  108. MeshDataTool();
  109. };
  110. #endif // MESH_DATA_TOOL_H