Blender V4.3
BKE_subdiv_foreach.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#include "BLI_sys_types.h"
12
13struct Mesh;
14
15namespace blender::bke::subdiv {
16
17struct ToMeshSettings;
18struct ForeachContext;
19struct Subdiv;
20
21using ForeachTopologyInformationCb = bool (*)(const ForeachContext *context,
22 int num_vertices,
23 int num_edges,
24 int num_loops,
25 int num_faces,
26 const int *subdiv_face_offset);
27
28using ForeachVertexFromCornerCb = void (*)(const ForeachContext *context,
29 void *tls,
30 int ptex_face_index,
31 float u,
32 float v,
33 int coarse_vertex_index,
34 int coarse_face_index,
35 int coarse_corner,
36 int subdiv_vertex_index);
37
38using ForeachVertexFromEdgeCb = void (*)(const ForeachContext *context,
39 void *tls,
40 int ptex_face_index,
41 float u,
42 float v,
43 int coarse_edge_index,
44 int coarse_face_index,
45 int coarse_corner,
46 int subdiv_vertex_index);
47
48using ForeachVertexInnerCb = void (*)(const ForeachContext *context,
49 void *tls,
50 int ptex_face_index,
51 float u,
52 float v,
53 int coarse_face_index,
54 int coarse_corner,
55 int subdiv_vertex_index);
56
57using ForeachEdgeCb = void (*)(const ForeachContext *context,
58 void *tls,
59 int coarse_edge_index,
60 int subdiv_edge_index,
61 bool is_loose,
62 int subdiv_v1,
63 int subdiv_v2);
64
65using ForeachLoopCb = void (*)(const ForeachContext *context,
66 void *tls,
67 int ptex_face_index,
68 float u,
69 float v,
70 int coarse_loop_index,
71 int coarse_face_index,
72 int coarse_corner,
73 int subdiv_loop_index,
74 int subdiv_vertex_index,
75 int subdiv_edge_index);
76
77using ForeachPolygonCb = void (*)(const ForeachContext *context,
78 void *tls,
79 int coarse_face_index,
80 int subdiv_face_index,
81 int start_loop_index,
82 int num_loops);
83
84using ForeachLooseCb = void (*)(const ForeachContext *context,
85 void *tls,
86 int coarse_vertex_index,
87 int subdiv_vertex_index);
88
89using ForeachVertexOfLooseEdgeCb = void (*)(const ForeachContext *context,
90 void *tls,
91 int coarse_edge_index,
92 float u,
93 int subdiv_vertex_index);
94
96 /* Is called when topology information becomes available.
97 * Is only called once.
98 *
99 * NOTE: If this callback returns false, the foreach loop is aborted.
100 */
102 /* These callbacks are called from every ptex which shares "emitting"
103 * vertex or edge.
104 */
107 /* Those callbacks are run once per subdivision vertex, ptex is undefined
108 * as in it will be whatever first ptex face happened to be traversed in
109 * the multi-threaded environment and which shares "emitting" vertex or
110 * edge.
111 */
114 /* Called exactly once, always corresponds to a single ptex face. */
116 /* Called once for each loose vertex. One loose coarse vertex corresponds
117 * to a single subdivision vertex.
118 */
120 /* Called once per vertex created for loose edge. */
122 /* NOTE: If subdivided edge does not come from coarse edge, ORIGINDEX_NONE
123 * will be passed as coarse_edge_index.
124 */
126 /* NOTE: If subdivided loop does not come from coarse loop, ORIGINDEX_NONE
127 * will be passed as coarse_loop_index.
128 */
131
132 /* User-defined pointer, to allow callbacks know something about context the
133 * traversal is happening for.
134 */
136
137 /* Initial value of TLS data. */
139 /* Size of TLS data. */
141 /* Function to free TLS storage. */
142 void (*user_data_tls_free)(void *tls);
143};
144
145/* Invokes callbacks in the order and with values which corresponds to creation
146 * of final subdivided mesh.
147 *
148 * Main goal is to abstract all the traversal routines to give geometry element
149 * indices (for vertices, edges, loops, faces) in the same way as subdivision
150 * modifier will do for a dense mesh.
151 *
152 * Returns true if the whole topology was traversed, without any early exits.
153 *
154 * TODO(sergey): Need to either get rid of subdiv or of coarse_mesh.
155 * The main point here is to be able to get base level topology, which can be
156 * done with either of those. Having both of them is kind of redundant.
157 */
159 const ForeachContext *context,
160 const ToMeshSettings *mesh_settings,
161 const Mesh *coarse_mesh);
162
163} // namespace blender::bke::subdiv
ATTR_WARN_UNUSED_RESULT const BMVert * v
bool foreach_subdiv_geometry(Subdiv *subdiv, const ForeachContext *context, const ToMeshSettings *mesh_settings, const Mesh *coarse_mesh)
bool(*)(const ForeachContext *context, int num_vertices, int num_edges, int num_loops, int num_faces, const int *subdiv_face_offset) ForeachTopologyInformationCb
void(*)(const ForeachContext *context, void *tls, int ptex_face_index, float u, float v, int coarse_face_index, int coarse_corner, int subdiv_vertex_index) ForeachVertexInnerCb
void(*)(const ForeachContext *context, void *tls, int ptex_face_index, float u, float v, int coarse_edge_index, int coarse_face_index, int coarse_corner, int subdiv_vertex_index) ForeachVertexFromEdgeCb
void(*)(const ForeachContext *context, void *tls, int ptex_face_index, float u, float v, int coarse_loop_index, int coarse_face_index, int coarse_corner, int subdiv_loop_index, int subdiv_vertex_index, int subdiv_edge_index) ForeachLoopCb
void(*)(const ForeachContext *context, void *tls, int ptex_face_index, float u, float v, int coarse_vertex_index, int coarse_face_index, int coarse_corner, int subdiv_vertex_index) ForeachVertexFromCornerCb
void(*)(const ForeachContext *context, void *tls, int coarse_edge_index, int subdiv_edge_index, bool is_loose, int subdiv_v1, int subdiv_v2) ForeachEdgeCb
void(*)(const ForeachContext *context, void *tls, int coarse_edge_index, float u, int subdiv_vertex_index) ForeachVertexOfLooseEdgeCb
void(*)(const ForeachContext *context, void *tls, int coarse_vertex_index, int subdiv_vertex_index) ForeachLooseCb
void(*)(const ForeachContext *context, void *tls, int coarse_face_index, int subdiv_face_index, int start_loop_index, int num_loops) ForeachPolygonCb
ForeachTopologyInformationCb topology_info
ForeachVertexOfLooseEdgeCb vertex_of_loose_edge
ForeachVertexFromCornerCb vertex_every_corner