BKE_cdderivedmesh.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2006 Blender Foundation.
  19. * All rights reserved.
  20. *
  21. * The Original Code is: all of this file.
  22. *
  23. * Contributor(s): Ben Batt <benbatt@gmail.com>
  24. *
  25. * ***** END GPL LICENSE BLOCK *****
  26. */
  27. /** \file BKE_cdderivedmesh.h
  28. * \ingroup bke
  29. * \section aboutcdderivedmesh CDDerivedMesh interface
  30. * CDDerivedMesh (CD = Custom Data) is a DerivedMesh backend which stores
  31. * mesh elements (vertices, edges and faces) as layers of custom element data.
  32. */
  33. #ifndef __BKE_CDDERIVEDMESH_H__
  34. #define __BKE_CDDERIVEDMESH_H__
  35. #include "BKE_DerivedMesh.h"
  36. struct DerivedMesh;
  37. struct BMEditMesh;
  38. struct Mesh;
  39. struct MLoopNorSpaceArray;
  40. struct Object;
  41. /* creates a new CDDerivedMesh */
  42. struct DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces,
  43. int numLoops, int numPolys);
  44. /* creates a CDDerivedMesh from the given Mesh, this will reference the
  45. * original data in Mesh, but it is safe to apply vertex coordinates or
  46. * calculate normals as those functions will automatically create new
  47. * data to not overwrite the original */
  48. struct DerivedMesh *CDDM_from_mesh(struct Mesh *mesh);
  49. struct DerivedMesh *CDDM_from_bmesh(struct BMesh *bm, const bool use_mdisps);
  50. /* creates a CDDerivedMesh from the given BMEditMesh */
  51. DerivedMesh *CDDM_from_editbmesh(struct BMEditMesh *em, const bool use_mdisps, const bool use_tessface);
  52. /* merge verts */
  53. /* Enum for merge_mode of CDDM_merge_verts.
  54. * Refer to cdderivedmesh.c for details. */
  55. enum {
  56. CDDM_MERGE_VERTS_DUMP_IF_MAPPED,
  57. CDDM_MERGE_VERTS_DUMP_IF_EQUAL,
  58. };
  59. DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int tot_vtargetmap, const int merge_mode);
  60. /* creates a CDDerivedMesh from the given curve object */
  61. struct DerivedMesh *CDDM_from_curve(struct Object *ob);
  62. /* creates a CDDerivedMesh from the given curve object and specified dispbase */
  63. /* useful for OrcoDM creation for curves with constructive modifiers */
  64. DerivedMesh *CDDM_from_curve_displist(struct Object *ob, struct ListBase *dispbase);
  65. /* Copies the given DerivedMesh with verts, faces & edges stored as
  66. * custom element data.
  67. */
  68. struct DerivedMesh *CDDM_copy(struct DerivedMesh *dm);
  69. struct DerivedMesh *CDDM_copy_from_tessface(struct DerivedMesh *dm);
  70. struct DerivedMesh *CDDM_copy_with_tessface(struct DerivedMesh *dm);
  71. /* creates a CDDerivedMesh with the same layer stack configuration as the
  72. * given DerivedMesh and containing the requested numbers of elements.
  73. * elements are initialized to all zeros
  74. */
  75. struct DerivedMesh *CDDM_from_template_ex(
  76. struct DerivedMesh *source,
  77. int numVerts, int numEdges, int numFaces,
  78. int numLoops, int numPolys,
  79. CustomDataMask mask);
  80. struct DerivedMesh *CDDM_from_template(
  81. struct DerivedMesh *source,
  82. int numVerts, int numEdges, int numFaces,
  83. int numLoops, int numPolys);
  84. /* converts mfaces to mpolys. note things may break if there are not valid
  85. * medges surrounding each mface.
  86. */
  87. void CDDM_tessfaces_to_faces(struct DerivedMesh *dm);
  88. /* applies vertex coordinates or normals to a CDDerivedMesh. if the MVert
  89. * layer is a referenced layer, it will be duplicate to not overwrite the
  90. * original
  91. */
  92. void CDDM_apply_vert_coords(struct DerivedMesh *cddm, float (*vertCoords)[3]);
  93. void CDDM_apply_vert_normals(struct DerivedMesh *cddm, short (*vertNormals)[3]);
  94. /* recalculates vertex and face normals for a CDDerivedMesh
  95. */
  96. void CDDM_calc_normals_mapping_ex(struct DerivedMesh *dm, const bool only_face_normals);
  97. void CDDM_calc_normals_mapping(struct DerivedMesh *dm);
  98. void CDDM_calc_normals(struct DerivedMesh *dm);
  99. void CDDM_calc_normals_tessface(struct DerivedMesh *dm);
  100. void CDDM_calc_loop_normals(struct DerivedMesh *dm, const bool use_split_normals, const float split_angle);
  101. void CDDM_calc_loop_normals_spacearr(struct DerivedMesh *dm, const bool use_split_normals, const float split_angle,
  102. struct MLoopNorSpaceArray *r_lnors_spacearr);
  103. /* calculates edges for a CDDerivedMesh (from face data)
  104. * this completely replaces the current edge data in the DerivedMesh
  105. * builds edges from the tessellated face data.
  106. */
  107. void CDDM_calc_edges_tessface(struct DerivedMesh *dm);
  108. /* same as CDDM_calc_edges_tessface only makes edges from ngon faces instead of tessellation
  109. * faces*/
  110. void CDDM_calc_edges(struct DerivedMesh *dm);
  111. /* reconstitute face triangulation */
  112. void CDDM_recalc_tessellation(struct DerivedMesh *dm);
  113. void CDDM_recalc_tessellation_ex(struct DerivedMesh *dm, const bool do_face_nor_cpy);
  114. void CDDM_recalc_looptri(struct DerivedMesh *dm);
  115. /* lowers the number of vertices/edges/faces in a CDDerivedMesh
  116. * the layer data stays the same size
  117. */
  118. void CDDM_lower_num_verts(struct DerivedMesh *dm, int numVerts);
  119. void CDDM_lower_num_edges(struct DerivedMesh *dm, int numEdges);
  120. void CDDM_lower_num_loops(struct DerivedMesh *dm, int numLoops);
  121. void CDDM_lower_num_polys(struct DerivedMesh *dm, int numPolys);
  122. void CDDM_lower_num_tessfaces(DerivedMesh *dm, int numTessFaces);
  123. /* vertex/edge/face access functions
  124. * should always succeed if index is within bounds
  125. * note these return pointers - any change modifies the internals of the mesh
  126. */
  127. struct MVert *CDDM_get_vert(struct DerivedMesh *dm, int index);
  128. struct MEdge *CDDM_get_edge(struct DerivedMesh *dm, int index);
  129. struct MFace *CDDM_get_tessface(struct DerivedMesh *dm, int index);
  130. struct MLoop *CDDM_get_loop(struct DerivedMesh *dm, int index);
  131. struct MPoly *CDDM_get_poly(struct DerivedMesh *dm, int index);
  132. /* vertex/edge/face array access functions - return the array holding the
  133. * desired data
  134. * should always succeed
  135. * note these return pointers - any change modifies the internals of the mesh
  136. */
  137. struct MVert *CDDM_get_verts(struct DerivedMesh *dm);
  138. struct MEdge *CDDM_get_edges(struct DerivedMesh *dm);
  139. struct MFace *CDDM_get_tessfaces(struct DerivedMesh *dm);
  140. struct MLoop *CDDM_get_loops(struct DerivedMesh *dm);
  141. struct MPoly *CDDM_get_polys(struct DerivedMesh *dm);
  142. /* Assigns news m*** layers to the cddm. Note that you must handle
  143. * freeing the old ones yourself. Also you must ensure dm->num****Data
  144. * is correct.*/
  145. void CDDM_set_mvert(struct DerivedMesh *dm, struct MVert *mvert);
  146. void CDDM_set_medge(struct DerivedMesh *dm, struct MEdge *medge);
  147. void CDDM_set_mface(struct DerivedMesh *dm, struct MFace *mface);
  148. void CDDM_set_mloop(struct DerivedMesh *dm, struct MLoop *mloop);
  149. void CDDM_set_mpoly(struct DerivedMesh *dm, struct MPoly *mpoly);
  150. #endif