1 // Copyright 2015 Blender Foundation. All rights reserved.
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.
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.
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.
17 // Author: Sergey Sharybin
19 #ifndef OPENSUBDIV_CONVERTER_CAPI_H_
20 #define OPENSUBDIV_CONVERTER_CAPI_H_
22 #include <stdint.h> // for bool
24 #include "opensubdiv_capi_type.h"
30 typedef struct OpenSubdiv_Converter {
31 OpenSubdiv_SchemeType (*getSchemeType)(
32 const struct OpenSubdiv_Converter* converter);
34 OpenSubdiv_VtxBoundaryInterpolation (*getVtxBoundaryInterpolation)(
35 const struct OpenSubdiv_Converter* converter);
36 OpenSubdiv_FVarLinearInterpolation (*getFVarLinearInterpolation)(
37 const struct OpenSubdiv_Converter* converter);
39 // Denotes whether this converter specifies full topology, which includes
40 // vertices, edges, faces, vertices+edges of a face and edges/faces of a
42 // Otherwise this converter will only provide number of vertices and faces,
43 // and vertices of faces. The rest of topology will be created by OpenSubdiv.
45 // NOTE: Even if converter does not provide full topology, it still needs
46 // to provide number of edges and vertices-of-edge. Those are used to assign
48 bool (*specifiesFullTopology)(const struct OpenSubdiv_Converter* converter);
50 //////////////////////////////////////////////////////////////////////////////
51 // Global geometry counters.
53 // Number of faces/edges/vertices in the base mesh.
54 int (*getNumFaces)(const struct OpenSubdiv_Converter* converter);
55 int (*getNumEdges)(const struct OpenSubdiv_Converter* converter);
56 int (*getNumVertices)(const struct OpenSubdiv_Converter* converter);
58 //////////////////////////////////////////////////////////////////////////////
59 // Face relationships.
61 // Number of vertices the face consists of.
62 int (*getNumFaceVertices)(const struct OpenSubdiv_Converter* converter,
63 const int face_index);
64 // Array of vertex indices the face consists of.
65 void (*getFaceVertices)(const struct OpenSubdiv_Converter* converter,
68 // Array of edge indices the face consists of.
69 // Aligned with the vertex indices array, edge i connects face vertex i
70 // with face index i+1.
71 void (*getFaceEdges)(const struct OpenSubdiv_Converter *converter,
75 //////////////////////////////////////////////////////////////////////////////
76 // Edge relationships.
78 // Vertices the edge consists of.
79 void (*getEdgeVertices)(const struct OpenSubdiv_Converter* converter,
81 int edge_vertices[2]);
82 // Number of faces which are sharing the given edge.
83 int (*getNumEdgeFaces)(const struct OpenSubdiv_Converter* converter,
84 const int edge_index);
85 // Array of face indices which are sharing the given edge.
86 void (*getEdgeFaces)(const struct OpenSubdiv_Converter* converter,
89 // Edge sharpness (aka crease).
90 float (*getEdgeSharpness)(const struct OpenSubdiv_Converter* converter,
91 const int edge_index);
93 //////////////////////////////////////////////////////////////////////////////
94 // Vertex relationships.
96 // Number of edges which are adjacent to the given vertex.
97 int (*getNumVertexEdges)(const struct OpenSubdiv_Converter* converter,
98 const int vertex_index);
99 // Array fo edge indices which are adjacent to the given vertex.
100 void (*getVertexEdges)(const struct OpenSubdiv_Converter* converter,
101 const int vertex_index,
103 // Number of faces which are adjacent to the given vertex.
104 int (*getNumVertexFaces)(const struct OpenSubdiv_Converter* converter,
105 const int vertex_index);
106 // Array fo face indices which are adjacent to the given vertex.
107 void (*getVertexFaces)(const struct OpenSubdiv_Converter* converter,
108 const int vertex_index,
111 // Check whether vertex is to be marked as an infinite sharp.
112 // This is a way to make sharp vertices which are adjacent to a loose edges.
113 bool (*isInfiniteSharpVertex)(const struct OpenSubdiv_Converter* converter,
114 const int vertex_index);
116 // If vertex is not infinitely sharp, this is it's actual sharpness.
117 float (*getVertexSharpness)(const struct OpenSubdiv_Converter* converter,
118 const int vertex_index);
120 //////////////////////////////////////////////////////////////////////////////
121 // Face-varying data.
123 /////////////////////////////////////
126 // Number of UV layers.
127 int (*getNumUVLayers)(const struct OpenSubdiv_Converter* converter);
129 // We need some corner connectivity information, which might not be trivial
130 // to be gathered (might require multiple matching calculations per corver
132 // precalc() is called before any corner connectivity or UV coordinate is
133 // queried from the given layer, allowing converter to calculate and cache
134 // complex complex-to-calculate information.
135 // finish() is called after converter is done porting UV layer to OpenSubdiv,
136 // allowing to free cached data.
137 void (*precalcUVLayer)(const struct OpenSubdiv_Converter* converter,
138 const int layer_index);
139 void (*finishUVLayer)(const struct OpenSubdiv_Converter* converter);
141 // Get number of UV coordinates in the current layer (layer which was
142 // specified in precalcUVLayer().
143 int (*getNumUVCoordinates)(const struct OpenSubdiv_Converter* converter);
144 // For the given face index and its corner (known as loop in Blender)
145 // get corrsponding UV coordinate index.
146 int (*getFaceCornerUVIndex)(const struct OpenSubdiv_Converter* converter,
147 const int face_index,
148 const int corner_index);
150 //////////////////////////////////////////////////////////////////////////////
151 // User data associated with this converter.
153 void (*freeUserData)(const struct OpenSubdiv_Converter* converter);
155 } OpenSubdiv_Converter;
161 #endif /* OPENSUBDIV_CONVERTER_CAPI_H_ */