forked from blender/blender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opensubdiv_topology_refiner_capi.h
157 lines (132 loc) · 7.01 KB
/
opensubdiv_topology_refiner_capi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2018 Blender Foundation. All rights reserved.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// Author: Sergey Sharybin
#ifndef OPENSUBDIV_TOPOLOGY_REFINER_CAPI_H_
#define OPENSUBDIV_TOPOLOGY_REFINER_CAPI_H_
#include <stdint.h> // for bool
#include "opensubdiv_capi_type.h"
#ifdef __cplusplus
extern "C" {
#endif
struct OpenSubdiv_Converter;
struct OpenSubdiv_TopologyRefinerImpl;
// Those settings don't really belong to OpenSubdiv's topology refiner, but
// we are keeping track of them on our side of topology refiner. This is to
// make it possible to ensure we are not trying to abuse same OpenSubdiv's
// topology refiner with different subdivision levels or with different
// adaptive settings.
typedef struct OpenSubdiv_TopologyRefinerSettings {
bool is_adaptive;
int level;
} OpenSubdiv_TopologyRefinerSettings;
// C-style wrapper around actual topology refiner.
//
// The only purpose is to allow C-only code to access C++ implementation of the
// topology refiner.
typedef struct OpenSubdiv_TopologyRefiner {
// Query subdivision level the refiner is created for.
int (*getSubdivisionLevel)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
bool (*getIsAdaptive)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
// NOTE: All queries are querying base level.
//
// TODO(sergey): Consider making it more obvious in function naming,
// but since it's unlikely (or at least, will be uncommon use) for API
// which queries final geometry, we should be fine with this name for
// now.
//////////////////////////////////////////////////////////////////////////////
// Query basic topology information from base level.
int (*getNumVertices)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
int (*getNumEdges)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
int (*getNumFaces)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
int (*getNumFaceVertices)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
const int face_index);
void (*getFaceVertices)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
const int face_index,
int *face_vertices_indices);
int (*getNumFaceEdges)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
const int face_index);
void (*getFaceEdges)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
const int face_index,
int *face_edges_indices);
void (*getEdgeVertices)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
const int edge_index,
int edge_vertices_indices[2]);
int (*getNumVertexEdges)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
const int vertex_index);
void (*getVertexEdges)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
const int vertex_index,
int *vertex_edges_indices);
//////////////////////////////////////////////////////////////////////////////
// PTex face geometry queries.
// Ptex face corresponds to OpenSubdiv's internal "patch" and to Blender's
// subdivision grid. The rule commes as:
// - Triangle face consist of 3 ptex faces, ordered in the order of
// face-vertices.
// - Quad face consists of a single ptex face.
// - N-gons (similar to triangle) consists of N ptex faces, ordered same
// way as for triangle.
int (*getNumFacePtexFaces)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
const int face_index);
int (*getNumPtexFaces)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
// Initialize a per-base-face offset measured in ptex face indices.
//
// Basically, face_ptex_offset[base_face_index] is a total number of ptex
// faces created for bases faces [0 .. base_face_index - 1].
//
// The array must contain at least total number of ptex faces elements.
void (*fillFacePtexIndexOffset)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
int *face_ptex_index_offset);
//////////////////////////////////////////////////////////////////////////////
// Face-varying data.
// Number of face-varying channels (or how they are called in Blender layers).
int (*getNumFVarChannels)(const struct OpenSubdiv_TopologyRefiner *topology_refiner);
// Get face-varying interpolation type.
OpenSubdiv_FVarLinearInterpolation (*getFVarLinearInterpolation)(
const struct OpenSubdiv_TopologyRefiner *topology_refiner);
// Get total number of face-varying values in a particular channel.
int (*getNumFVarValues)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
const int channel);
// Get face-varying value indices associated with a particular face.
//
// This is an array of indices inside of face-varying array, array elements
// are aligned with face corners (or loops in Blender terminology).
const int *(*getFaceFVarValueIndices)(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
const int face_index,
const int channel);
//////////////////////////////////////////////////////////////////////////////
// Internal use.
// Implementation of the topology refiner.
struct OpenSubdiv_TopologyRefinerImpl *impl;
} OpenSubdiv_TopologyRefiner;
// NOTE: Will return NULL in cases of bad topology.
// NOTE: Mesh without faces is considered a bad topology.
OpenSubdiv_TopologyRefiner *openSubdiv_createTopologyRefinerFromConverter(
struct OpenSubdiv_Converter *converter, const OpenSubdiv_TopologyRefinerSettings *settings);
void openSubdiv_deleteTopologyRefiner(OpenSubdiv_TopologyRefiner *topology_refiner);
// Compare given topology refiner with converter. Returns truth if topology
// refiner matches given converter, false otherwise.
//
// This allows users to construct converter (which is supposed to be cheap)
// and compare with existing refiner before going into more computationally
// complicated parts of subdivision process.
bool openSubdiv_topologyRefinerCompareWithConverter(
const OpenSubdiv_TopologyRefiner *topology_refiner,
const struct OpenSubdiv_Converter *converter);
#ifdef __cplusplus
}
#endif
#endif // OPENSUBDIV_TOPOLOGY_REFINER_CAPI_H_