mesh_data_tool.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #pragma once
  31. #include "scene/resources/mesh.h"
  32. class MeshDataTool : public RefCounted {
  33. GDCLASS(MeshDataTool, RefCounted);
  34. uint64_t format = 0;
  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. #ifndef DISABLE_DEPRECATED
  65. Error commit_to_surface_bind_compat_81138(const Ref<ArrayMesh> &p_mesh);
  66. static void _bind_compatibility_methods();
  67. #endif
  68. public:
  69. void clear();
  70. Error create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surface);
  71. Error commit_to_surface(const Ref<ArrayMesh> &p_mesh, uint64_t p_compression_flags = 0);
  72. uint64_t get_format() const;
  73. int get_vertex_count() const;
  74. int get_edge_count() const;
  75. int get_face_count() const;
  76. Vector3 get_vertex(int p_idx) const;
  77. void set_vertex(int p_idx, const Vector3 &p_vertex);
  78. Vector3 get_vertex_normal(int p_idx) const;
  79. void set_vertex_normal(int p_idx, const Vector3 &p_normal);
  80. Plane get_vertex_tangent(int p_idx) const;
  81. void set_vertex_tangent(int p_idx, const Plane &p_tangent);
  82. Vector2 get_vertex_uv(int p_idx) const;
  83. void set_vertex_uv(int p_idx, const Vector2 &p_uv);
  84. Vector2 get_vertex_uv2(int p_idx) const;
  85. void set_vertex_uv2(int p_idx, const Vector2 &p_uv2);
  86. Color get_vertex_color(int p_idx) const;
  87. void set_vertex_color(int p_idx, const Color &p_color);
  88. Vector<int> get_vertex_bones(int p_idx) const;
  89. void set_vertex_bones(int p_idx, const Vector<int> &p_bones);
  90. Vector<float> get_vertex_weights(int p_idx) const;
  91. void set_vertex_weights(int p_idx, const Vector<float> &p_weights);
  92. Variant get_vertex_meta(int p_idx) const;
  93. void set_vertex_meta(int p_idx, const Variant &p_meta);
  94. Vector<int> get_vertex_edges(int p_idx) const;
  95. Vector<int> get_vertex_faces(int p_idx) const;
  96. int get_edge_vertex(int p_edge, int p_vertex) const;
  97. Vector<int> get_edge_faces(int p_edge) const;
  98. Variant get_edge_meta(int p_idx) const;
  99. void set_edge_meta(int p_idx, const Variant &p_meta);
  100. int get_face_vertex(int p_face, int p_vertex) const;
  101. int get_face_edge(int p_face, int p_vertex) const;
  102. Variant get_face_meta(int p_face) const;
  103. void set_face_meta(int p_face, const Variant &p_meta);
  104. Vector3 get_face_normal(int p_face) const;
  105. Ref<Material> get_material() const;
  106. void set_material(const Ref<Material> &p_material);
  107. MeshDataTool();
  108. };