surface_tool.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*************************************************************************/
  2. /* surface_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 SURFACE_TOOL_H
  30. #define SURFACE_TOOL_H
  31. #include "scene/resources/mesh.h"
  32. class SurfaceTool : public Reference {
  33. OBJ_TYPE(SurfaceTool, Reference );
  34. public:
  35. struct Vertex {
  36. Vector3 vertex;
  37. Color color;
  38. Vector3 normal; // normal, binormal, tangent
  39. Vector3 binormal;
  40. Vector3 tangent;
  41. Vector2 uv;
  42. Vector2 uv2;
  43. Vector<int> bones;
  44. Vector<float> weights;
  45. bool operator==(const Vertex& p_vertex) const;
  46. Vertex() { }
  47. };
  48. private:
  49. struct VertexHasher {
  50. static _FORCE_INLINE_ uint32_t hash(const Vertex &p_vtx);
  51. };
  52. bool begun;
  53. bool first;
  54. Mesh::PrimitiveType primitive;
  55. int format;
  56. Ref<Material> material;
  57. //arrays
  58. List< Vertex > vertex_array;
  59. List< int > index_array;
  60. Map<int,bool> smooth_groups;
  61. //memory
  62. Color last_color;
  63. Vector3 last_normal;
  64. Vector2 last_uv;
  65. Vector2 last_uv2;
  66. Vector<int> last_bones;
  67. Vector<float> last_weights;
  68. Plane last_tangent;
  69. void _create_list(const Ref<Mesh>& p_existing, int p_surface, List<Vertex> *r_vertex, List<int> *r_index,int &lformat);
  70. protected:
  71. static void _bind_methods();
  72. public:
  73. void begin(Mesh::PrimitiveType p_primitive);
  74. void add_vertex( const Vector3& p_vertex);
  75. void add_color( Color p_color );
  76. void add_normal( const Vector3& p_normal);
  77. void add_tangent( const Plane& p_tangent );
  78. void add_uv( const Vector2& p_uv);
  79. void add_uv2( const Vector2& p_uv);
  80. void add_bones( const Vector<int>& p_indices);
  81. void add_weights( const Vector<float>& p_weights);
  82. void add_smooth_group(bool p_smooth);
  83. void add_index( int p_index);
  84. void index();
  85. void deindex();
  86. void generate_normals();
  87. void generate_tangents();
  88. void add_to_format(int p_flags) { format|=p_flags; }
  89. void set_material(const Ref<Material>& p_material);
  90. void clear();
  91. List< Vertex > &get_vertex_array() { return vertex_array; }
  92. void create_from(const Ref<Mesh>& p_existing, int p_surface);
  93. void append_from(const Ref<Mesh>& p_existing, int p_surface,const Transform& p_xform);
  94. Ref<Mesh> commit(const Ref<Mesh>& p_existing=Ref<Mesh>());
  95. SurfaceTool();
  96. };
  97. #endif