opensubdiv_topology_refiner_capi.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Copyright 2018 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_TOPOLOGY_REFINER_CAPI_H_
  19. #define OPENSUBDIV_TOPOLOGY_REFINER_CAPI_H_
  20. #include <stdint.h> // for bool
  21. #include "opensubdiv_capi_type.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. struct OpenSubdiv_Converter;
  26. struct OpenSubdiv_TopologyRefinerInternal;
  27. // Those settings don't really belong to OpenSubdiv's topology refiner, but
  28. // we are keeping track of them on our side of topology refiner. This is to
  29. // make it possible to ensure we are not trying to abuse same OpenSubdiv's
  30. // topology refiner with different subdivision levels or with different
  31. // adaptive settings.
  32. typedef struct OpenSubdiv_TopologyRefinerSettings {
  33. bool is_adaptive;
  34. int level;
  35. } OpenSubdiv_TopologyRefinerSettings;
  36. typedef struct OpenSubdiv_TopologyRefiner {
  37. // Query subdivision level the refiner is created for.
  38. int (*getSubdivisionLevel)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
  39. bool (*getIsAdaptive)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
  40. // NOTE: All queries are querying base level.
  41. //
  42. // TODO(sergey): Consider making it more obvious in function naming,
  43. // but since it's unlikely (or at least, will be uncommon use) for API
  44. // which queries final geometry, we should be fine with this name for
  45. // now.
  46. //////////////////////////////////////////////////////////////////////////////
  47. // Query basic topology information from base level.
  48. int (*getNumVertices)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
  49. int (*getNumEdges)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
  50. int (*getNumFaces)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
  51. int (*getNumFaceVertices)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
  52. const int face_index);
  53. void (*getFaceVertices)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
  54. const int face_index,
  55. int *face_vertices_indices);
  56. int (*getNumFaceEdges)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
  57. const int face_index);
  58. void (*getFaceEdges)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
  59. const int face_index,
  60. int *face_edges_indices);
  61. void (*getEdgeVertices)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
  62. const int edge_index,
  63. int edge_vertices_indices[2]);
  64. //////////////////////////////////////////////////////////////////////////////
  65. // PTex face geometry queries.
  66. // Ptex face corresponds to OpenSubdiv's internal "patch" and to Blender's
  67. // subdivision grid. The rule commes as:
  68. // - Triangle face consist of 3 ptex faces, ordered in the order of
  69. // face-vertices.
  70. // - Quad face consists of a single ptex face.
  71. // - N-gons (similar to triangle) consists of N ptex faces, ordered same
  72. // way as for triangle.
  73. int (*getNumFacePtexFaces)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
  74. const int face_index);
  75. int (*getNumPtexFaces)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
  76. // Initialize a per-base-face offset measured in ptex face indices.
  77. //
  78. // Basically, face_ptex_offset[base_face_index] is a total number of ptex
  79. // faces created for bases faces [0 .. base_face_index - 1].
  80. //
  81. // The array must contain at least total number of ptex faces elements.
  82. void (*fillFacePtexIndexOffset)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
  83. int *face_ptex_index_offset);
  84. //////////////////////////////////////////////////////////////////////////////
  85. // Face-varying data.
  86. // Number of face-varying channels (or how they are called in Blender layers).
  87. int (*getNumFVarChannels)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
  88. // Get face-varying interpolation type.
  89. OpenSubdiv_FVarLinearInterpolation (*getFVarLinearInterpolation)(
  90. const struct OpenSubdiv_TopologyRefiner *topology_refiner);
  91. // Get total number of face-varying values in a particular channel.
  92. int (*getNumFVarValues)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
  93. const int channel);
  94. // Get face-varying value indices associated with a particular face.
  95. //
  96. // This is an array of indices inside of face-varying array, array elements
  97. // are aligned with face corners (or loops in Blender terminology).
  98. const int *(*getFaceFVarValueIndices)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
  99. const int face_index,
  100. const int channel);
  101. //////////////////////////////////////////////////////////////////////////////
  102. // Internal use.
  103. // Internal storage for the use in this module only.
  104. //
  105. // Tease: Contains actual OpenSubdiv's refiner and (optionally) some other
  106. // data and state needed for an internbal use.
  107. struct OpenSubdiv_TopologyRefinerInternal *internal;
  108. } OpenSubdiv_TopologyRefiner;
  109. // NOTE: Will return NULL in cases of bad topology.
  110. // NOTE: Mesh without faces is considered a bad topology.
  111. OpenSubdiv_TopologyRefiner *openSubdiv_createTopologyRefinerFromConverter(
  112. struct OpenSubdiv_Converter *converter, const OpenSubdiv_TopologyRefinerSettings *settings);
  113. void openSubdiv_deleteTopologyRefiner(OpenSubdiv_TopologyRefiner *topology_refiner);
  114. // Compare given topology refiner with converter. Returns truth if topology
  115. // refiner matches given converter, false otherwise.
  116. //
  117. // This allows users to construct converter (which is supposed to be cheap)
  118. // and compare with existing refiner before going into more computationally
  119. // complicated parts of subdivision process.
  120. bool openSubdiv_topologyRefinerCompareWithConverter(
  121. const OpenSubdiv_TopologyRefiner *topology_refiner,
  122. const struct OpenSubdiv_Converter *converter);
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #endif // OPENSUBDIV_TOPOLOGY_REFINER_CAPI_H_