opensubdiv_converter_capi.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // Copyright 2015 Blender Foundation. All rights reserved.
  2. //
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation; either version 2
  6. // of the License, or (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software Foundation,
  15. // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. //
  17. // Author: Sergey Sharybin
  18. #ifndef OPENSUBDIV_CONVERTER_CAPI_H_
  19. #define OPENSUBDIV_CONVERTER_CAPI_H_
  20. #include <stdint.h> // for bool
  21. #include "opensubdiv_capi_type.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. typedef struct OpenSubdiv_Converter {
  26. OpenSubdiv_SchemeType (*getSchemeType)(const struct OpenSubdiv_Converter *converter);
  27. OpenSubdiv_VtxBoundaryInterpolation (*getVtxBoundaryInterpolation)(
  28. const struct OpenSubdiv_Converter *converter);
  29. OpenSubdiv_FVarLinearInterpolation (*getFVarLinearInterpolation)(
  30. const struct OpenSubdiv_Converter *converter);
  31. // Denotes whether this converter specifies full topology, which includes
  32. // vertices, edges, faces, vertices+edges of a face and edges/faces of a
  33. // vertex.
  34. // Otherwise this converter will only provide number of vertices and faces,
  35. // and vertices of faces. The rest of topology will be created by OpenSubdiv.
  36. //
  37. // NOTE: Even if converter does not provide full topology, it still needs
  38. // to provide number of edges and vertices-of-edge. Those are used to assign
  39. // topology tags.
  40. bool (*specifiesFullTopology)(const struct OpenSubdiv_Converter *converter);
  41. //////////////////////////////////////////////////////////////////////////////
  42. // Global geometry counters.
  43. // Number of faces/edges/vertices in the base mesh.
  44. int (*getNumFaces)(const struct OpenSubdiv_Converter *converter);
  45. int (*getNumEdges)(const struct OpenSubdiv_Converter *converter);
  46. int (*getNumVertices)(const struct OpenSubdiv_Converter *converter);
  47. //////////////////////////////////////////////////////////////////////////////
  48. // Face relationships.
  49. // Number of vertices the face consists of.
  50. int (*getNumFaceVertices)(const struct OpenSubdiv_Converter *converter, const int face_index);
  51. // Array of vertex indices the face consists of.
  52. void (*getFaceVertices)(const struct OpenSubdiv_Converter *converter,
  53. const int face_index,
  54. int *face_vertices);
  55. // Array of edge indices the face consists of.
  56. // Aligned with the vertex indices array, edge i connects face vertex i
  57. // with face index i+1.
  58. void (*getFaceEdges)(const struct OpenSubdiv_Converter *converter,
  59. const int face_index,
  60. int *face_edges);
  61. //////////////////////////////////////////////////////////////////////////////
  62. // Edge relationships.
  63. // Vertices the edge consists of.
  64. void (*getEdgeVertices)(const struct OpenSubdiv_Converter *converter,
  65. const int edge_index,
  66. int edge_vertices[2]);
  67. // Number of faces which are sharing the given edge.
  68. int (*getNumEdgeFaces)(const struct OpenSubdiv_Converter *converter, const int edge_index);
  69. // Array of face indices which are sharing the given edge.
  70. void (*getEdgeFaces)(const struct OpenSubdiv_Converter *converter,
  71. const int edge,
  72. int *edge_faces);
  73. // Edge sharpness (aka crease).
  74. float (*getEdgeSharpness)(const struct OpenSubdiv_Converter *converter, const int edge_index);
  75. //////////////////////////////////////////////////////////////////////////////
  76. // Vertex relationships.
  77. // Number of edges which are adjacent to the given vertex.
  78. int (*getNumVertexEdges)(const struct OpenSubdiv_Converter *converter, const int vertex_index);
  79. // Array fo edge indices which are adjacent to the given vertex.
  80. void (*getVertexEdges)(const struct OpenSubdiv_Converter *converter,
  81. const int vertex_index,
  82. int *vertex_edges);
  83. // Number of faces which are adjacent to the given vertex.
  84. int (*getNumVertexFaces)(const struct OpenSubdiv_Converter *converter, const int vertex_index);
  85. // Array fo face indices which are adjacent to the given vertex.
  86. void (*getVertexFaces)(const struct OpenSubdiv_Converter *converter,
  87. const int vertex_index,
  88. int *vertex_faces);
  89. // Check whether vertex is to be marked as an infinite sharp.
  90. // This is a way to make sharp vertices which are adjacent to a loose edges.
  91. bool (*isInfiniteSharpVertex)(const struct OpenSubdiv_Converter *converter,
  92. const int vertex_index);
  93. // If vertex is not infinitely sharp, this is it's actual sharpness.
  94. float (*getVertexSharpness)(const struct OpenSubdiv_Converter *converter,
  95. const int vertex_index);
  96. //////////////////////////////////////////////////////////////////////////////
  97. // Face-varying data.
  98. /////////////////////////////////////
  99. // UV coordinates.
  100. // Number of UV layers.
  101. int (*getNumUVLayers)(const struct OpenSubdiv_Converter *converter);
  102. // We need some corner connectivity information, which might not be trivial
  103. // to be gathered (might require multiple matching calculations per corver
  104. // query).
  105. // precalc() is called before any corner connectivity or UV coordinate is
  106. // queried from the given layer, allowing converter to calculate and cache
  107. // complex complex-to-calculate information.
  108. // finish() is called after converter is done porting UV layer to OpenSubdiv,
  109. // allowing to free cached data.
  110. void (*precalcUVLayer)(const struct OpenSubdiv_Converter *converter, const int layer_index);
  111. void (*finishUVLayer)(const struct OpenSubdiv_Converter *converter);
  112. // Get number of UV coordinates in the current layer (layer which was
  113. // specified in precalcUVLayer().
  114. int (*getNumUVCoordinates)(const struct OpenSubdiv_Converter *converter);
  115. // For the given face index and its corner (known as loop in Blender)
  116. // get corrsponding UV coordinate index.
  117. int (*getFaceCornerUVIndex)(const struct OpenSubdiv_Converter *converter,
  118. const int face_index,
  119. const int corner_index);
  120. //////////////////////////////////////////////////////////////////////////////
  121. // User data associated with this converter.
  122. void (*freeUserData)(const struct OpenSubdiv_Converter *converter);
  123. void *user_data;
  124. } OpenSubdiv_Converter;
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. #endif /* OPENSUBDIV_CONVERTER_CAPI_H_ */