Blender V5.3
subdiv_foreach.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_bitmap.hh"
10#include "BLI_task_c.hh"
11
12#include "BKE_customdata.hh"
13#include "BKE_subdiv.hh"
14#include "BKE_subdiv_foreach.hh"
15#include "BKE_subdiv_mesh.hh"
16
17#include "DNA_mesh_types.h"
18#include "MEM_guardedalloc.h"
19
20#include "atomic_ops.h"
21
22namespace blender::bke::subdiv {
23
24/* -------------------------------------------------------------------- */
27
28/* Number of ptex faces for a given face. */
30{
31 return (face.size() == 4) ? 1 : face.size();
32}
33
34BLI_INLINE int num_edges_per_ptex_face_get(const int resolution)
35{
36 return 2 * (resolution - 1) * resolution;
37}
38
40{
41 if (resolution < 2) {
42 return 0;
43 }
44 return (resolution - 2) * resolution + (resolution - 1) * (resolution - 1);
45}
46
47/* Number of subdivision polygons per ptex face. */
48BLI_INLINE int num_faces_per_ptex_get(const int resolution)
49{
50 return (resolution - 1) * (resolution - 1);
51}
52
53/* Subdivision resolution per given face's ptex faces. */
54BLI_INLINE int ptex_face_resolution_get(const IndexRange face, int resolution)
55{
56 return (face.size() == 4) ? (resolution) : ((resolution >> 1) + 1);
57}
58
60
61/* -------------------------------------------------------------------- */
64
72 /* Callbacks. */
74 /* Counters of geometry in subdivided mesh, initialized as a part of
75 * offsets calculation.
76 */
81 /* Offsets of various geometry in the subdivision mesh arrays. */
87 /* Indexed by coarse face index, indicates offset in subdivided mesh
88 * vertices, edges and polygons arrays, where first element of the face
89 * begins.
90 */
94 /* Indexed by base face index, element indicates total number of ptex faces
95 * created for preceding base faces.
96 */
98 /* Bitmap indicating whether vertex was used already or not.
99 * - During patch evaluation indicates whether coarse vertex was already
100 * evaluated and its position on limit is already known.
101 */
103 /* Bitmap indicating whether edge was used already or not. This includes:
104 * - During context initialization it indicates whether subdivided vertices
105 * for corresponding edge were already calculated or not.
106 * - During patch evaluation it indicates whether vertices along this edge
107 * were already evaluated.
108 */
110};
111
113
114/* -------------------------------------------------------------------- */
117
119{
120 const ForeachContext *foreach_context = ctx->foreach_context;
121 void *tls = nullptr;
122 if (foreach_context->user_data_tls_size != 0) {
123 tls = MEM_new_uninitialized(foreach_context->user_data_tls_size, "tls");
124 memcpy(tls, foreach_context->user_data_tls, foreach_context->user_data_tls_size);
125 }
126 return tls;
127}
128
129static void subdiv_foreach_tls_free(ForeachTaskContext *ctx, void *tls)
130{
131 if (tls == nullptr) {
132 return;
133 }
134 if (ctx->foreach_context != nullptr) {
136 }
137 MEM_delete_void(tls);
138}
139
141
142/* -------------------------------------------------------------------- */
145
146/* NOTE: Expects edge map to be zeroed. */
148{
149 /* Reset counters. */
150 ctx->num_subdiv_vertices = 0;
151 ctx->num_subdiv_edges = 0;
152 ctx->num_subdiv_loops = 0;
153 ctx->num_subdiv_faces = 0;
154 /* Static geometry counters. */
155 const int resolution = ctx->settings->resolution;
156 const int no_quad_patch_resolution = ((resolution >> 1) + 1);
157 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
158 const int num_inner_vertices_per_quad = (resolution - 2) * (resolution - 2);
159 const int num_inner_vertices_per_noquad_patch = (no_quad_patch_resolution - 2) *
160 (no_quad_patch_resolution - 2);
161 const Mesh *coarse_mesh = ctx->coarse_mesh;
162 ctx->num_subdiv_vertices = coarse_mesh->verts_num;
163 ctx->num_subdiv_edges = coarse_mesh->edges_num * (num_subdiv_vertices_per_coarse_edge + 1);
164 /* Calculate extra vertices and edges created by non-loose geometry. */
165 for (int face_index = 0; face_index < coarse_mesh->faces_num; face_index++) {
166 const IndexRange coarse_face = ctx->coarse_faces[face_index];
167 const int num_ptex_faces_per_face = num_ptex_faces_per_face_get(coarse_face);
168 /* Inner vertices of face. */
169 if (num_ptex_faces_per_face == 1) {
170 ctx->num_subdiv_vertices += num_inner_vertices_per_quad;
171 ctx->num_subdiv_edges += num_edges_per_ptex_face_get(resolution - 2) +
172 4 * num_subdiv_vertices_per_coarse_edge;
173 ctx->num_subdiv_faces += num_faces_per_ptex_get(resolution);
174 }
175 else {
176 ctx->num_subdiv_vertices += 1 + num_ptex_faces_per_face * (no_quad_patch_resolution - 2) +
177 num_ptex_faces_per_face * num_inner_vertices_per_noquad_patch;
178 ctx->num_subdiv_edges += num_ptex_faces_per_face *
179 (num_inner_edges_per_ptex_face_get(no_quad_patch_resolution - 1) +
180 (no_quad_patch_resolution - 2) +
181 num_subdiv_vertices_per_coarse_edge);
182 if (no_quad_patch_resolution >= 3) {
183 ctx->num_subdiv_edges += coarse_face.size();
184 }
185 ctx->num_subdiv_faces += num_ptex_faces_per_face *
186 num_faces_per_ptex_get(no_quad_patch_resolution);
187 }
188 }
189
190 /* Add vertices used by outer edges on subdivided faces and loose edges. */
191 ctx->num_subdiv_vertices += num_subdiv_vertices_per_coarse_edge * coarse_mesh->edges_num;
192
193 ctx->num_subdiv_loops = ctx->num_subdiv_faces * 4;
194}
195
197{
198 const Mesh *coarse_mesh = ctx->coarse_mesh;
199 const int resolution = ctx->settings->resolution;
200 const int resolution_2 = resolution - 2;
201 const int resolution_2_squared = resolution_2 * resolution_2;
202 const int no_quad_patch_resolution = ((resolution >> 1) + 1);
203 const int num_irregular_vertices_per_patch = (no_quad_patch_resolution - 2) *
204 (no_quad_patch_resolution - 1);
205 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
206 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
207 /* Constant offsets in arrays. */
208 ctx->vertices_corner_offset = 0;
209 ctx->vertices_edge_offset = coarse_mesh->verts_num;
211 coarse_mesh->edges_num * num_subdiv_vertices_per_coarse_edge;
212 ctx->edge_boundary_offset = 0;
214 coarse_mesh->edges_num * num_subdiv_edges_per_coarse_edge;
215 /* "Indexed" offsets. */
216 int vert_offset = 0;
217 int edge_offset = 0;
218 int face_offset = 0;
219 for (int face_index = 0; face_index < coarse_mesh->faces_num; face_index++) {
220 const IndexRange coarse_face = ctx->coarse_faces[face_index];
221 const int num_ptex_faces_per_face = num_ptex_faces_per_face_get(coarse_face);
222 ctx->subdiv_vert_offset[face_index] = vert_offset;
223 ctx->subdiv_edge_offset[face_index] = edge_offset;
224 ctx->subdiv_face_offset[face_index] = face_offset;
225 if (num_ptex_faces_per_face == 1) {
226 vert_offset += resolution_2_squared;
227 edge_offset += num_edges_per_ptex_face_get(resolution - 2) +
228 4 * num_subdiv_vertices_per_coarse_edge;
229 face_offset += num_faces_per_ptex_get(resolution);
230 }
231 else {
232 vert_offset += 1 + num_ptex_faces_per_face * num_irregular_vertices_per_patch;
233 edge_offset += num_ptex_faces_per_face *
234 (num_inner_edges_per_ptex_face_get(no_quad_patch_resolution - 1) +
235 (no_quad_patch_resolution - 2) + num_subdiv_vertices_per_coarse_edge);
236 if (no_quad_patch_resolution >= 3) {
237 edge_offset += coarse_face.size();
238 }
239 face_offset += num_ptex_faces_per_face * num_faces_per_ptex_get(no_quad_patch_resolution);
240 }
241 }
242 ctx->subdiv_face_offset.last() = face_offset;
243}
244
246{
247 const Mesh *coarse_mesh = ctx->coarse_mesh;
248 /* Allocate maps and offsets. */
249 ctx->coarse_vertices_used_map = BLI_BITMAP_NEW(coarse_mesh->verts_num, "vertices used map");
250 ctx->coarse_edges_used_map = BLI_BITMAP_NEW(coarse_mesh->edges_num, "edges used map");
251 ctx->subdiv_vert_offset.reinitialize(coarse_mesh->faces_num);
252 ctx->subdiv_edge_offset.reinitialize(coarse_mesh->faces_num);
253 /* One extra element for #OffsetIndices encoding. */
254 ctx->subdiv_face_offset.reinitialize(coarse_mesh->faces_num + 1);
255 /* Initialize all offsets. */
257 /* Calculate number of geometry in the result subdivision mesh. */
260}
261
263{
264 MEM_delete(ctx->coarse_vertices_used_map);
265 MEM_delete(ctx->coarse_edges_used_map);
266}
267
269
270/* -------------------------------------------------------------------- */
273
274/* Traversal of corner vertices. They are coming from coarse vertices. */
275
277 void *tls,
278 const int coarse_face_index,
279 ForeachVertFromCornerCb vert_corner,
280 bool check_usage)
281{
282 const float weights[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
283 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
284 const int ptex_face_index = ctx->face_ptex_offset[coarse_face_index];
285 for (int corner = 0; corner < coarse_face.size(); corner++) {
286 const int coarse_vert = ctx->coarse_corner_verts[coarse_face[corner]];
287 if (check_usage && BLI_BITMAP_TEST_AND_SET_ATOMIC(ctx->coarse_vertices_used_map, coarse_vert))
288 {
289 continue;
290 }
291 const int coarse_vert_index = coarse_vert;
292 const int subdiv_vert_index = ctx->vertices_corner_offset + coarse_vert_index;
293 const float u = weights[corner][0];
294 const float v = weights[corner][1];
295 vert_corner(ctx->foreach_context,
296 tls,
297 ptex_face_index,
298 u,
299 v,
300 coarse_vert_index,
301 coarse_face_index,
302 0,
303 subdiv_vert_index);
304 }
305}
306
308 void *tls,
309 const int coarse_face_index)
310{
312 ctx, tls, coarse_face_index, ctx->foreach_context->vert_corner, true);
313}
314
316 void *tls,
317 const int coarse_face_index,
318 ForeachVertFromCornerCb vert_corner,
319 bool check_usage)
320{
321 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
322 int ptex_face_index = ctx->face_ptex_offset[coarse_face_index];
323 for (int corner = 0; corner < coarse_face.size(); corner++, ptex_face_index++) {
324 const int coarse_vert = ctx->coarse_corner_verts[coarse_face[corner]];
325 if (check_usage && BLI_BITMAP_TEST_AND_SET_ATOMIC(ctx->coarse_vertices_used_map, coarse_vert))
326 {
327 continue;
328 }
329 const int coarse_vert_index = coarse_vert;
330 const int subdiv_vert_index = ctx->vertices_corner_offset + coarse_vert_index;
331 vert_corner(ctx->foreach_context,
332 tls,
333 ptex_face_index,
334 0.0f,
335 0.0f,
336 coarse_vert_index,
337 coarse_face_index,
338 corner,
339 subdiv_vert_index);
340 }
341}
342
344 void *tls,
345 const int coarse_face_index)
346{
348 ctx, tls, coarse_face_index, ctx->foreach_context->vert_corner, true);
349}
350
352 void *tls,
353 const int coarse_face_index)
354{
355 if (ctx->coarse_faces[coarse_face_index].size() == 4) {
356 subdiv_foreach_corner_vertices_regular(ctx, tls, coarse_face_index);
357 }
358 else {
359 subdiv_foreach_corner_vertices_special(ctx, tls, coarse_face_index);
360 }
361}
362
364 void *tls,
365 const int coarse_face_index)
366{
368 ctx, tls, coarse_face_index, ctx->foreach_context->vert_every_corner, false);
369}
370
372 void *tls,
373 const int coarse_face_index)
374{
376 ctx, tls, coarse_face_index, ctx->foreach_context->vert_every_corner, false);
377}
378
380{
381 if (ctx->foreach_context->vert_every_corner == nullptr) {
382 return;
383 }
384 const Mesh *coarse_mesh = ctx->coarse_mesh;
385 for (int face_index = 0; face_index < coarse_mesh->faces_num; face_index++) {
386 if (ctx->coarse_faces[face_index].size() == 4) {
388 }
389 else {
391 }
392 }
393}
394
395/* Traverse of edge vertices. They are coming from coarse edges. */
396
398 void *tls,
399 const int coarse_face_index,
400 ForeachVertFromEdgeCb vert_edge,
401 bool check_usage)
402{
403 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
404 const int resolution = ctx->settings->resolution;
405 const int resolution_1 = resolution - 1;
406 const float inv_resolution_1 = 1.0f / float(resolution_1);
407 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
408 const int ptex_face_index = ctx->face_ptex_offset[coarse_face_index];
409 for (int corner = 0; corner < coarse_face.size(); corner++) {
410 const int coarse_vert = ctx->coarse_corner_verts[coarse_face[corner]];
411 const int coarse_edge_index = ctx->coarse_corner_edges[coarse_face[corner]];
412 if (check_usage &&
414 {
415 continue;
416 }
417 const int2 &coarse_edge = ctx->coarse_edges[coarse_edge_index];
418 const bool flip = (coarse_edge[1] == coarse_vert);
419 int subdiv_vert_index = ctx->vertices_edge_offset +
420 coarse_edge_index * num_subdiv_vertices_per_coarse_edge;
421 for (int vert_index = 0; vert_index < num_subdiv_vertices_per_coarse_edge;
422 vert_index++, subdiv_vert_index++)
423 {
424 float fac = (vert_index + 1) * inv_resolution_1;
425 if (flip) {
426 fac = 1.0f - fac;
427 }
428 if (corner >= 2) {
429 fac = 1.0f - fac;
430 }
431 float u, v;
432 if ((corner & 1) == 0) {
433 u = fac;
434 v = (corner == 2) ? 1.0f : 0.0f;
435 }
436 else {
437 u = (corner == 1) ? 1.0f : 0.0f;
438 v = fac;
439 }
440 vert_edge(ctx->foreach_context,
441 tls,
442 ptex_face_index,
443 u,
444 v,
445 coarse_edge_index,
446 coarse_face_index,
447 0,
448 subdiv_vert_index);
449 }
450 }
451}
452
454 void *tls,
455 const int coarse_face_index)
456{
458 ctx, tls, coarse_face_index, ctx->foreach_context->vert_edge, true);
459}
460
462 void *tls,
463 const int coarse_face_index,
464 ForeachVertFromEdgeCb vert_edge,
465 bool check_usage)
466{
467 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
468 const int resolution = ctx->settings->resolution;
469 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
470 const int num_vertices_per_ptex_edge = ((resolution >> 1) + 1);
471 const float inv_ptex_resolution_1 = 1.0f / float(num_vertices_per_ptex_edge - 1);
472 const int ptex_face_start_index = ctx->face_ptex_offset[coarse_face_index];
473 int ptex_face_index = ptex_face_start_index;
474 for (int corner = 0; corner < coarse_face.size(); corner++, ptex_face_index++) {
475 const int coarse_vert = ctx->coarse_corner_verts[coarse_face[corner]];
476 const int coarse_edge_index = ctx->coarse_corner_edges[coarse_face[corner]];
477 if (check_usage &&
479 {
480 continue;
481 }
482 const int2 &coarse_edge = ctx->coarse_edges[coarse_edge_index];
483 const bool flip = (coarse_edge[1] == coarse_vert);
484 int subdiv_vert_index = ctx->vertices_edge_offset +
485 coarse_edge_index * num_subdiv_vertices_per_coarse_edge;
486 int vert_delta = 1;
487 if (flip) {
488 subdiv_vert_index += num_subdiv_vertices_per_coarse_edge - 1;
489 vert_delta = -1;
490 }
491 for (int vert_index = 1; vert_index < num_vertices_per_ptex_edge;
492 vert_index++, subdiv_vert_index += vert_delta)
493 {
494 const float u = vert_index * inv_ptex_resolution_1;
495 vert_edge(ctx->foreach_context,
496 tls,
497 ptex_face_index,
498 u,
499 0.0f,
500 coarse_edge_index,
501 coarse_face_index,
502 corner,
503 subdiv_vert_index);
504 }
505 const int next_corner = (corner + 1) % coarse_face.size();
506 const int next_ptex_face_index = ptex_face_start_index + next_corner;
507 for (int vert_index = 1; vert_index < num_vertices_per_ptex_edge - 1;
508 vert_index++, subdiv_vert_index += vert_delta)
509 {
510 const float v = 1.0f - vert_index * inv_ptex_resolution_1;
511 vert_edge(ctx->foreach_context,
512 tls,
513 next_ptex_face_index,
514 0.0f,
515 v,
516 coarse_edge_index,
517 coarse_face_index,
518 next_corner,
519 subdiv_vert_index);
520 }
521 }
522}
523
525 void *tls,
526 const int coarse_face_index)
527{
529 ctx, tls, coarse_face_index, ctx->foreach_context->vert_edge, true);
530}
531
533 void *tls,
534 const int coarse_face_index)
535{
536 if (ctx->coarse_faces[coarse_face_index].size() == 4) {
537 subdiv_foreach_edge_vertices_regular(ctx, tls, coarse_face_index);
538 }
539 else {
540 subdiv_foreach_edge_vertices_special(ctx, tls, coarse_face_index);
541 }
542}
543
545 void *tls,
546 const int coarse_face_index)
547{
549 ctx, tls, coarse_face_index, ctx->foreach_context->vert_every_edge, false);
550}
551
553 void *tls,
554 const int coarse_face_index)
555{
557 ctx, tls, coarse_face_index, ctx->foreach_context->vert_every_edge, false);
558}
559
561{
562 if (ctx->foreach_context->vert_every_edge == nullptr) {
563 return;
564 }
565 const Mesh *coarse_mesh = ctx->coarse_mesh;
566 for (int face_index = 0; face_index < coarse_mesh->faces_num; face_index++) {
567 if (ctx->coarse_faces[face_index].size() == 4) {
568 subdiv_foreach_every_edge_vertices_regular(ctx, tls, face_index);
569 }
570 else {
571 subdiv_foreach_every_edge_vertices_special(ctx, tls, face_index);
572 }
573 }
574}
575
576/* Traversal of inner vertices, they are coming from ptex patches. */
577
579 void *tls,
580 const int coarse_face_index)
581{
582 const int resolution = ctx->settings->resolution;
583 const float inv_resolution_1 = 1.0f / float(resolution - 1);
584 const int ptex_face_index = ctx->face_ptex_offset[coarse_face_index];
585 const int start_vert_index = ctx->subdiv_vert_offset[coarse_face_index];
586 int subdiv_vert_index = ctx->vertices_inner_offset + start_vert_index;
587 for (int y = 1; y < resolution - 1; y++) {
588 const float v = y * inv_resolution_1;
589 for (int x = 1; x < resolution - 1; x++, subdiv_vert_index++) {
590 const float u = x * inv_resolution_1;
592 tls,
593 ptex_face_index,
594 u,
595 v,
596 coarse_face_index,
597 0,
598 subdiv_vert_index);
599 }
600 }
601}
602
604 void *tls,
605 const int coarse_face_index)
606{
607 const int resolution = ctx->settings->resolution;
608 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
609 const int ptex_face_resolution = ptex_face_resolution_get(coarse_face, resolution);
610 const float inv_ptex_face_resolution_1 = 1.0f / float(ptex_face_resolution - 1);
611 int ptex_face_index = ctx->face_ptex_offset[coarse_face_index];
612 const int start_vert_index = ctx->subdiv_vert_offset[coarse_face_index];
613 int subdiv_vert_index = ctx->vertices_inner_offset + start_vert_index;
615 tls,
616 ptex_face_index,
617 1.0f,
618 1.0f,
619 coarse_face_index,
620 0,
621 subdiv_vert_index);
622 subdiv_vert_index++;
623 for (int corner = 0; corner < coarse_face.size(); corner++, ptex_face_index++) {
624 for (int y = 1; y < ptex_face_resolution - 1; y++) {
625 const float v = y * inv_ptex_face_resolution_1;
626 for (int x = 1; x < ptex_face_resolution; x++, subdiv_vert_index++) {
627 const float u = x * inv_ptex_face_resolution_1;
629 tls,
630 ptex_face_index,
631 u,
632 v,
633 coarse_face_index,
634 corner,
635 subdiv_vert_index);
636 }
637 }
638 }
639}
640
642 void *tls,
643 const int coarse_face_index)
644{
645 if (ctx->coarse_faces[coarse_face_index].size() == 4) {
646 subdiv_foreach_inner_vertices_regular(ctx, tls, coarse_face_index);
647 }
648 else {
649 subdiv_foreach_inner_vertices_special(ctx, tls, coarse_face_index);
650 }
651}
652
653/* Traverse all vertices which are emitted from given coarse face. */
654static void subdiv_foreach_vertices(ForeachTaskContext *ctx, void *tls, const int face_index)
655{
656 if (ctx->foreach_context->vert_inner != nullptr) {
657 subdiv_foreach_inner_vertices(ctx, tls, face_index);
658 }
659}
660
662
663/* -------------------------------------------------------------------- */
666
667/* TODO(sergey): Coarse edge are always NONE, consider getting rid of it. */
669 void *tls,
670 const int coarse_edge_index,
671 const int start_subdiv_edge_index,
672 const int start_vert_index,
673 const int num_edges_per_row)
674{
675 int subdiv_edge_index = start_subdiv_edge_index;
676 int vert_index = start_vert_index;
677 for (int edge_index = 0; edge_index < num_edges_per_row - 1; edge_index++, subdiv_edge_index++) {
678 const int v1 = vert_index;
679 const int v2 = vert_index + 1;
680 ctx->foreach_context->edge(
681 ctx->foreach_context, tls, coarse_edge_index, subdiv_edge_index, false, v1, v2);
682 vert_index += 1;
683 }
684 return subdiv_edge_index;
685}
686
687/* TODO(sergey): Coarse edges are always NONE, consider getting rid of them. */
689 void *tls,
690 const int coarse_start_edge_index,
691 const int coarse_end_edge_index,
692 const int start_subdiv_edge_index,
693 const int start_vert_index,
694 const int num_edges_per_row)
695{
696 int subdiv_edge_index = start_subdiv_edge_index;
697 int vert_index = start_vert_index;
698 for (int edge_index = 0; edge_index < num_edges_per_row; edge_index++, subdiv_edge_index++) {
699 int coarse_edge_index = ORIGINDEX_NONE;
700 if (edge_index == 0) {
701 coarse_edge_index = coarse_start_edge_index;
702 }
703 else if (edge_index == num_edges_per_row - 1) {
704 coarse_edge_index = coarse_end_edge_index;
705 }
706 const int v1 = vert_index;
707 const int v2 = vert_index + num_edges_per_row;
708 ctx->foreach_context->edge(
709 ctx->foreach_context, tls, coarse_edge_index, subdiv_edge_index, false, v1, v2);
710 vert_index += 1;
711 }
712 return subdiv_edge_index;
713}
714
715/* Defines edges between inner vertices of patch, and also edges to the
716 * boundary.
717 */
718
719/* Consider a subdivision of base face at level 1:
720 *
721 * y
722 * ^
723 * | (6) ---- (7) ---- (8)
724 * | | | |
725 * | (3) ---- (4) ---- (5)
726 * | | | |
727 * | (0) ---- (1) ---- (2)
728 * o---------------------------> x
729 *
730 * This is illustrate which parts of geometry is created by code below.
731 */
732
734 void *tls,
735 const int coarse_face_index)
736{
737 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
738 const int resolution = ctx->settings->resolution;
739 const int start_vert_index = ctx->vertices_inner_offset +
740 ctx->subdiv_vert_offset[coarse_face_index];
741 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
742 int subdiv_edge_index = ctx->edge_inner_offset + ctx->subdiv_edge_offset[coarse_face_index];
743 /* Traverse bottom row of edges (0-1, 1-2). */
744 subdiv_edge_index = subdiv_foreach_edges_row(
745 ctx, tls, ORIGINDEX_NONE, subdiv_edge_index, start_vert_index, resolution - 2);
746 /* Traverse remaining edges. */
747 for (int row = 0; row < resolution - 3; row++) {
748 const int start_row_vert_index = start_vert_index + row * (resolution - 2);
749 /* Traverse vertical columns.
750 *
751 * At first iteration it will be edges (0-3. 1-4, 2-5), then it
752 * will be (3-6, 4-7, 5-8) and so on.
753 */
754 subdiv_edge_index = subdiv_foreach_edges_column(ctx,
755 tls,
758 subdiv_edge_index,
759 start_row_vert_index,
760 resolution - 2);
761 /* Create horizontal edge row.
762 *
763 * At first iteration it will be edges (3-4, 4-5), then it will be
764 * (6-7, 7-8) and so on.
765 */
766 subdiv_edge_index = subdiv_foreach_edges_row(ctx,
767 tls,
769 subdiv_edge_index,
770 start_row_vert_index + resolution - 2,
771 resolution - 2);
772 }
773 /* Connect inner part of patch to boundary. */
774 for (int corner = 0; corner < coarse_face.size(); corner++) {
775 const int coarse_vert_index = ctx->coarse_corner_verts[coarse_face[corner]];
776 const int coarse_edge_index = ctx->coarse_corner_edges[coarse_face[corner]];
777 const int2 &coarse_edge = ctx->coarse_edges[coarse_edge_index];
778 const int start_edge_vert = ctx->vertices_edge_offset +
779 coarse_edge_index * num_subdiv_vertices_per_coarse_edge;
780 const bool flip = (coarse_edge[1] == coarse_vert_index);
781 int side_start_index = start_vert_index;
782 int side_stride = 0;
783 /* Calculate starting vertex of corresponding inner part of ptex. */
784 if (corner == 0) {
785 side_stride = 1;
786 }
787 else if (corner == 1) {
788 side_start_index += resolution - 3;
789 side_stride = resolution - 2;
790 }
791 else if (corner == 2) {
792 side_start_index += num_subdiv_vertices_per_coarse_edge *
793 num_subdiv_vertices_per_coarse_edge -
794 1;
795 side_stride = -1;
796 }
797 else if (corner == 3) {
798 side_start_index += num_subdiv_vertices_per_coarse_edge *
799 (num_subdiv_vertices_per_coarse_edge - 1);
800 side_stride = -(resolution - 2);
801 }
802 for (int i = 0; i < resolution - 2; i++, subdiv_edge_index++) {
803 const int v1 = (flip) ? (start_edge_vert + (resolution - i - 3)) : (start_edge_vert + i);
804 const int v2 = side_start_index + side_stride * i;
805 ctx->foreach_context->edge(
806 ctx->foreach_context, tls, ORIGINDEX_NONE, subdiv_edge_index, false, v1, v2);
807 }
808 }
809}
810
812 void *tls,
813 const int coarse_face_index)
814{
815 const int resolution = ctx->settings->resolution;
816 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
817 const int ptex_face_resolution = ptex_face_resolution_get(coarse_face, resolution);
818 const int ptex_face_inner_resolution = ptex_face_resolution - 2;
819 const int num_inner_vertices_per_ptex = (ptex_face_resolution - 1) * (ptex_face_resolution - 2);
820 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
821 const int center_vert_index = ctx->vertices_inner_offset +
822 ctx->subdiv_vert_offset[coarse_face_index];
823 const int start_vert_index = center_vert_index + 1;
824 int subdiv_edge_index = ctx->edge_inner_offset + ctx->subdiv_edge_offset[coarse_face_index];
825 /* Traverse inner ptex edges. */
826 for (int corner = 0; corner < coarse_face.size(); corner++) {
827 const int start_ptex_face_vert_index = start_vert_index + corner * num_inner_vertices_per_ptex;
828 /* Similar steps to regular patch case. */
829 subdiv_edge_index = subdiv_foreach_edges_row(ctx,
830 tls,
832 subdiv_edge_index,
833 start_ptex_face_vert_index,
834 ptex_face_inner_resolution + 1);
835 for (int row = 0; row < ptex_face_inner_resolution - 1; row++) {
836 const int start_row_vert_index = start_ptex_face_vert_index +
837 row * (ptex_face_inner_resolution + 1);
838 subdiv_edge_index = subdiv_foreach_edges_column(ctx,
839 tls,
842 subdiv_edge_index,
843 start_row_vert_index,
844 ptex_face_inner_resolution + 1);
845 subdiv_edge_index = subdiv_foreach_edges_row(ctx,
846 tls,
848 subdiv_edge_index,
849 start_row_vert_index +
850 ptex_face_inner_resolution + 1,
851 ptex_face_inner_resolution + 1);
852 }
853 }
854 /* Create connections between ptex faces. */
855 for (int corner = 0; corner < coarse_face.size(); corner++) {
856 const int next_corner = (corner + 1) % coarse_face.size();
857 int current_patch_vert_index = start_vert_index + corner * num_inner_vertices_per_ptex +
858 ptex_face_inner_resolution;
859 int next_path_vert_index = start_vert_index + next_corner * num_inner_vertices_per_ptex +
860 num_inner_vertices_per_ptex - ptex_face_resolution + 1;
861 for (int row = 0; row < ptex_face_inner_resolution; row++, subdiv_edge_index++) {
862 const int v1 = current_patch_vert_index;
863 const int v2 = next_path_vert_index;
864 ctx->foreach_context->edge(
865 ctx->foreach_context, tls, ORIGINDEX_NONE, subdiv_edge_index, false, v1, v2);
866 current_patch_vert_index += ptex_face_inner_resolution + 1;
867 next_path_vert_index += 1;
868 }
869 }
870 /* Create edges from center. */
871 if (ptex_face_resolution >= 3) {
872 for (int corner = 0; corner < coarse_face.size(); corner++, subdiv_edge_index++) {
873 const int current_patch_end_vert_index = start_vert_index +
874 corner * num_inner_vertices_per_ptex +
875 num_inner_vertices_per_ptex - 1;
876 const int v1 = center_vert_index;
877 const int v2 = current_patch_end_vert_index;
878 ctx->foreach_context->edge(
879 ctx->foreach_context, tls, ORIGINDEX_NONE, subdiv_edge_index, false, v1, v2);
880 }
881 }
882 /* Connect inner path of patch to boundary. */
883 int prev_corner = coarse_face.size() - 1;
884 for (int corner = 0; corner < coarse_face.size(); corner++) {
885 const int coarse_vert = ctx->coarse_corner_verts[coarse_face[corner]];
886 const int coarse_edge_i = ctx->coarse_corner_edges[coarse_face[corner]];
887 const int coarse_prev_edge = ctx->coarse_corner_edges[coarse_face[prev_corner]];
888 {
889 const int2 &coarse_edge = ctx->coarse_edges[coarse_edge_i];
890 const int start_edge_vert = ctx->vertices_edge_offset +
891 coarse_edge_i * num_subdiv_vertices_per_coarse_edge;
892 const bool flip = (coarse_edge[1] == coarse_vert);
893 int side_start_index;
894 if (ptex_face_resolution >= 3) {
895 side_start_index = start_vert_index + num_inner_vertices_per_ptex * corner;
896 }
897 else {
898 side_start_index = center_vert_index;
899 }
900 for (int i = 0; i < ptex_face_resolution - 1; i++, subdiv_edge_index++) {
901 const int v1 = (flip) ? (start_edge_vert + (resolution - i - 3)) : (start_edge_vert + i);
902 const int v2 = side_start_index + i;
903 ctx->foreach_context->edge(
904 ctx->foreach_context, tls, ORIGINDEX_NONE, subdiv_edge_index, false, v1, v2);
905 }
906 }
907 if (ptex_face_resolution >= 3) {
908 const int2 &coarse_edge = ctx->coarse_edges[coarse_prev_edge];
909 const int start_edge_vert = ctx->vertices_edge_offset +
910 coarse_prev_edge * num_subdiv_vertices_per_coarse_edge;
911 const bool flip = (coarse_edge[1] == coarse_vert);
912 int side_start_index = start_vert_index + num_inner_vertices_per_ptex * corner;
913 for (int i = 0; i < ptex_face_resolution - 2; i++, subdiv_edge_index++) {
914 const int v1 = (flip) ? (start_edge_vert + (resolution - i - 3)) : (start_edge_vert + i);
915 const int v2 = side_start_index + (ptex_face_inner_resolution + 1) * i;
916 ctx->foreach_context->edge(
917 ctx->foreach_context, tls, ORIGINDEX_NONE, subdiv_edge_index, false, v1, v2);
918 }
919 }
920 prev_corner = corner;
921 }
922}
923
925 void *tls,
926 const int coarse_face_index)
927{
928 if (ctx->coarse_faces[coarse_face_index].size() == 4) {
929 subdiv_foreach_edges_all_patches_regular(ctx, tls, coarse_face_index);
930 }
931 else {
932 subdiv_foreach_edges_all_patches_special(ctx, tls, coarse_face_index);
933 }
934}
935
936static void subdiv_foreach_edges(ForeachTaskContext *ctx, void *tls, int face_index)
937{
938 subdiv_foreach_edges_all_patches(ctx, tls, face_index);
939}
940
942 void *tls,
943 int coarse_edge_index)
944{
945 const int2 &coarse_edge = ctx->coarse_edges[coarse_edge_index];
946 const int resolution = ctx->settings->resolution;
947 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
948 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
949 const bool is_loose = !BLI_BITMAP_TEST_BOOL(ctx->coarse_edges_used_map, coarse_edge_index);
950
951 int subdiv_edge_index = ctx->edge_boundary_offset +
952 coarse_edge_index * num_subdiv_edges_per_coarse_edge;
953 int last_vert_index = ctx->vertices_corner_offset + coarse_edge[0];
954 for (int i = 0; i < num_subdiv_edges_per_coarse_edge - 1; i++, subdiv_edge_index++) {
955 const int v1 = last_vert_index;
956 const int v2 = ctx->vertices_edge_offset +
957 coarse_edge_index * num_subdiv_vertices_per_coarse_edge + i;
958 ctx->foreach_context->edge(
959 ctx->foreach_context, tls, coarse_edge_index, subdiv_edge_index, is_loose, v1, v2);
960 last_vert_index = v2;
961 }
962 const int v1 = last_vert_index;
963 const int v2 = ctx->vertices_corner_offset + coarse_edge[1];
964 ctx->foreach_context->edge(
965 ctx->foreach_context, tls, coarse_edge_index, subdiv_edge_index, is_loose, v1, v2);
966}
967
969
970/* -------------------------------------------------------------------- */
973
974static void rotate_indices(const int rot, int *a, int *b, int *c, int *d)
975{
976 const int values[4] = {*a, *b, *c, *d};
977 *a = values[(0 - rot + 4) % 4];
978 *b = values[(1 - rot + 4) % 4];
979 *c = values[(2 - rot + 4) % 4];
980 *d = values[(3 - rot + 4) % 4];
981}
982
984 void *tls,
985 int subdiv_loop_start_index,
986 const int ptex_face_index,
987 const int coarse_face_index,
988 const int coarse_corner_index,
989 const int rotation,
990 /*const*/ int v0,
991 /*const*/ int e0,
992 /*const*/ int v1,
993 /*const*/ int e1,
994 /*const*/ int v2,
995 /*const*/ int e2,
996 /*const*/ int v3,
997 /*const*/ int e3,
998 const float u,
999 const float v,
1000 const float du,
1001 const float dv)
1002{
1003 rotate_indices(rotation, &v0, &v1, &v2, &v3);
1004 rotate_indices(rotation, &e0, &e1, &e2, &e3);
1006 tls,
1007 ptex_face_index,
1008 u,
1009 v,
1011 coarse_face_index,
1012 coarse_corner_index,
1013 subdiv_loop_start_index + 0,
1014 v0,
1015 e0);
1017 tls,
1018 ptex_face_index,
1019 u + du,
1020 v,
1022 coarse_face_index,
1023 coarse_corner_index,
1024 subdiv_loop_start_index + 1,
1025 v1,
1026 e1);
1028 tls,
1029 ptex_face_index,
1030 u + du,
1031 v + dv,
1033 coarse_face_index,
1034 coarse_corner_index,
1035 subdiv_loop_start_index + 2,
1036 v2,
1037 e2);
1039 tls,
1040 ptex_face_index,
1041 u,
1042 v + dv,
1044 coarse_face_index,
1045 coarse_corner_index,
1046 subdiv_loop_start_index + 3,
1047 v3,
1048 e3);
1049}
1050
1051static int subdiv_foreach_loops_corner_index(const float u,
1052 const float v,
1053 const float du,
1054 const float dv)
1055{
1056 if (u + du <= 0.5f && v + dv <= 0.5f) {
1057 return 0;
1058 }
1059 if (u >= 0.5f && v + dv <= 0.5f) {
1060 return 1;
1061 }
1062 if (u >= 0.5f && v >= 0.5f) {
1063 return 2;
1064 }
1065 return 3;
1066}
1067
1069 void *tls,
1070 const int coarse_face_index)
1071{
1072 const int resolution = ctx->settings->resolution;
1073 /* Base/coarse mesh information. */
1074 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
1075 const int ptex_resolution = ptex_face_resolution_get(coarse_face, resolution);
1076 const int ptex_inner_resolution = ptex_resolution - 2;
1077 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
1078 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
1079 const float inv_ptex_resolution_1 = 1.0f / float(ptex_resolution - 1);
1080 const int ptex_face_index = ctx->face_ptex_offset[coarse_face_index];
1081 const int start_vert_index = ctx->vertices_inner_offset +
1082 ctx->subdiv_vert_offset[coarse_face_index];
1083 const int start_edge_index = ctx->edge_inner_offset + ctx->subdiv_edge_offset[coarse_face_index];
1084 const int start_face_index = ctx->subdiv_face_offset[coarse_face_index];
1085 const int start_loop_index = 4 * start_face_index;
1086 const float du = inv_ptex_resolution_1;
1087 const float dv = inv_ptex_resolution_1;
1088 /* Hi-poly subdivided mesh. */
1089 int subdiv_loop_index = start_loop_index;
1090 /* Loops for inner part of ptex. */
1091 for (int y = 1; y < ptex_resolution - 2; y++) {
1092 const float v = y * inv_ptex_resolution_1;
1093 const int inner_y = y - 1;
1094 for (int x = 1; x < ptex_resolution - 2; x++, subdiv_loop_index += 4) {
1095 const int inner_x = x - 1;
1096 const float u = x * inv_ptex_resolution_1;
1097 /* Vertex indices ordered counter-clockwise. */
1098 const int v0 = start_vert_index + (inner_y * ptex_inner_resolution + inner_x);
1099 const int v1 = v0 + 1;
1100 const int v2 = v0 + ptex_inner_resolution + 1;
1101 const int v3 = v0 + ptex_inner_resolution;
1102 /* Edge indices ordered counter-clockwise. */
1103 const int e0 = start_edge_index + (inner_y * (2 * ptex_inner_resolution - 1) + inner_x);
1104 const int e1 = e0 + ptex_inner_resolution;
1105 const int e2 = e0 + (2 * ptex_inner_resolution - 1);
1106 const int e3 = e0 + ptex_inner_resolution - 1;
1107
1109 tls,
1110 subdiv_loop_index,
1111 ptex_face_index,
1112 coarse_face_index,
1114 0,
1115 v0,
1116 e0,
1117 v1,
1118 e1,
1119 v2,
1120 e2,
1121 v3,
1122 e3,
1123 u,
1124 v,
1125 du,
1126 dv);
1127 }
1128 }
1129 /* Loops for faces connecting inner ptex part with boundary. */
1130 int prev_corner_index = coarse_face.size() - 1;
1131 for (int corner = 0; corner < coarse_face.size(); corner++) {
1132 const int coarse_vert = ctx->coarse_corner_verts[coarse_face[corner]];
1133 const int coarse_edge_i = ctx->coarse_corner_edges[coarse_face[corner]];
1134 const int coase_prev_vert = ctx->coarse_corner_verts[coarse_face[prev_corner_index]];
1135 const int coarse_prev_edge = ctx->coarse_corner_edges[coarse_face[prev_corner_index]];
1136
1137 const int2 &coarse_edge = ctx->coarse_edges[coarse_edge_i];
1138 const int2 &prev_coarse_edge = ctx->coarse_edges[coarse_prev_edge];
1139 const int start_edge_vert = ctx->vertices_edge_offset +
1140 coarse_edge_i * num_subdiv_vertices_per_coarse_edge;
1141 const bool flip = (coarse_edge[1] == coarse_vert);
1142 int side_start_index = start_vert_index;
1143 int side_stride = 0;
1144 int v0 = ctx->vertices_corner_offset + coarse_vert;
1145 int v3, e3;
1146 int e2_offset, e2_stride;
1147 float u, v, delta_u, delta_v;
1148 if (coase_prev_vert == prev_coarse_edge[0]) {
1149 v3 = ctx->vertices_edge_offset + coarse_prev_edge * num_subdiv_vertices_per_coarse_edge +
1150 num_subdiv_vertices_per_coarse_edge - 1;
1151 e3 = ctx->edge_boundary_offset + coarse_prev_edge * num_subdiv_edges_per_coarse_edge +
1152 num_subdiv_edges_per_coarse_edge - 1;
1153 }
1154 else {
1155 v3 = ctx->vertices_edge_offset + coarse_prev_edge * num_subdiv_vertices_per_coarse_edge;
1156 e3 = ctx->edge_boundary_offset + coarse_prev_edge * num_subdiv_edges_per_coarse_edge;
1157 }
1158 /* Calculate starting vertex of corresponding inner part of ptex. */
1159 if (corner == 0) {
1160 side_stride = 1;
1161 e2_offset = 0;
1162 e2_stride = 1;
1163 u = 0.0f;
1164 v = 0.0f;
1165 delta_u = du;
1166 delta_v = 0.0f;
1167 }
1168 else if (corner == 1) {
1169 side_start_index += resolution - 3;
1170 side_stride = resolution - 2;
1171 e2_offset = 2 * num_subdiv_edges_per_coarse_edge - 4;
1172 e2_stride = 2 * num_subdiv_edges_per_coarse_edge - 3;
1173 u = 1.0f - du;
1174 v = 0;
1175 delta_u = 0.0f;
1176 delta_v = dv;
1177 }
1178 else if (corner == 2) {
1179 side_start_index += num_subdiv_vertices_per_coarse_edge *
1180 num_subdiv_vertices_per_coarse_edge -
1181 1;
1182 side_stride = -1;
1183 e2_offset = num_edges_per_ptex_face_get(resolution - 2) - 1;
1184 e2_stride = -1;
1185 u = 1.0f - du;
1186 v = 1.0f - dv;
1187 delta_u = -du;
1188 delta_v = 0.0f;
1189 }
1190 else if (corner == 3) {
1191 side_start_index += num_subdiv_vertices_per_coarse_edge *
1192 (num_subdiv_vertices_per_coarse_edge - 1);
1193 side_stride = -(resolution - 2);
1194 e2_offset = num_edges_per_ptex_face_get(resolution - 2) -
1195 (2 * num_subdiv_edges_per_coarse_edge - 3);
1196 e2_stride = -(2 * num_subdiv_edges_per_coarse_edge - 3);
1197 u = 0.0f;
1198 v = 1.0f - dv;
1199 delta_u = 0.0f;
1200 delta_v = -dv;
1201 }
1202 for (int i = 0; i < resolution - 2; i++, subdiv_loop_index += 4) {
1203 int v1;
1204 if (flip) {
1205 v1 = start_edge_vert + (resolution - i - 3);
1206 }
1207 else {
1208 v1 = start_edge_vert + i;
1209 }
1210 const int v2 = side_start_index + side_stride * i;
1211 int e0;
1212 if (flip) {
1213 e0 = ctx->edge_boundary_offset + coarse_edge_i * num_subdiv_edges_per_coarse_edge +
1214 num_subdiv_edges_per_coarse_edge - i - 1;
1215 }
1216 else {
1217 e0 = ctx->edge_boundary_offset + coarse_edge_i * num_subdiv_edges_per_coarse_edge + i;
1218 }
1219 int e1 = start_edge_index + num_edges_per_ptex_face_get(resolution - 2) +
1220 corner * num_subdiv_vertices_per_coarse_edge + i;
1221 int e2;
1222 if (i == 0) {
1223 e2 = start_edge_index + num_edges_per_ptex_face_get(resolution - 2) +
1224 ((corner - 1 + coarse_face.size()) % coarse_face.size()) *
1225 num_subdiv_vertices_per_coarse_edge +
1226 num_subdiv_vertices_per_coarse_edge - 1;
1227 }
1228 else {
1229 e2 = start_edge_index + e2_offset + e2_stride * (i - 1);
1230 }
1231
1232 const float loop_u = u + delta_u * i;
1233 const float loop_v = v + delta_v * i;
1234
1236 tls,
1237 subdiv_loop_index,
1238 ptex_face_index,
1239 coarse_face_index,
1240 subdiv_foreach_loops_corner_index(loop_u, loop_v, du, dv),
1241 corner,
1242 v0,
1243 e0,
1244 v1,
1245 e1,
1246 v2,
1247 e2,
1248 v3,
1249 e3,
1250 loop_u,
1251 loop_v,
1252 du,
1253 dv);
1254 v0 = v1;
1255 v3 = v2;
1256 e3 = e1;
1257 }
1258 prev_corner_index = corner;
1259 }
1260}
1261
1263 void *tls,
1264 const int coarse_face_index)
1265{
1266 const int resolution = ctx->settings->resolution;
1267 /* Base/coarse mesh information. */
1268 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
1269 const int ptex_face_resolution = ptex_face_resolution_get(coarse_face, resolution);
1270 const int ptex_face_inner_resolution = ptex_face_resolution - 2;
1271 const float inv_ptex_resolution_1 = 1.0f / float(ptex_face_resolution - 1);
1272 const int num_inner_vertices_per_ptex = (ptex_face_resolution - 1) * (ptex_face_resolution - 2);
1273 const int num_inner_edges_per_ptex_face = num_inner_edges_per_ptex_face_get(
1274 ptex_face_inner_resolution + 1);
1275 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
1276 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
1277 const int ptex_face_index = ctx->face_ptex_offset[coarse_face_index];
1278 const int center_vert_index = ctx->vertices_inner_offset +
1279 ctx->subdiv_vert_offset[coarse_face_index];
1280 const int start_vert_index = center_vert_index + 1;
1281 const int start_inner_vert_index = center_vert_index + 1;
1282 const int start_edge_index = ctx->edge_inner_offset + ctx->subdiv_edge_offset[coarse_face_index];
1283 const int start_face_index = ctx->subdiv_face_offset[coarse_face_index];
1284 const int start_loop_index = 4 * start_face_index;
1285 const float du = inv_ptex_resolution_1;
1286 const float dv = inv_ptex_resolution_1;
1287 /* Hi-poly subdivided mesh. */
1288 int subdiv_loop_index = start_loop_index;
1289 for (int corner = 0; corner < coarse_face.size(); corner++) {
1290 const int corner_vert_index = start_vert_index + corner * num_inner_vertices_per_ptex;
1291 const int corner_edge_index = start_edge_index + corner * num_inner_edges_per_ptex_face;
1292 for (int y = 1; y < ptex_face_inner_resolution; y++) {
1293 const float v = y * inv_ptex_resolution_1;
1294 const int inner_y = y - 1;
1295 for (int x = 1; x < ptex_face_inner_resolution + 1; x++, subdiv_loop_index += 4) {
1296 const int inner_x = x - 1;
1297 const float u = x * inv_ptex_resolution_1;
1298 /* Vertex indices ordered counter-clockwise. */
1299 const int v0 = corner_vert_index + (inner_y * (ptex_face_inner_resolution + 1) + inner_x);
1300 const int v1 = v0 + 1;
1301 const int v2 = v0 + ptex_face_inner_resolution + 2;
1302 const int v3 = v0 + ptex_face_inner_resolution + 1;
1303 /* Edge indices ordered counter-clockwise. */
1304 const int e0 = corner_edge_index +
1305 (inner_y * (2 * ptex_face_inner_resolution + 1) + inner_x);
1306 const int e1 = e0 + ptex_face_inner_resolution + 1;
1307 const int e2 = e0 + (2 * ptex_face_inner_resolution + 1);
1308 const int e3 = e0 + ptex_face_inner_resolution;
1310 tls,
1311 subdiv_loop_index,
1312 ptex_face_index + corner,
1313 coarse_face_index,
1314 corner,
1315 0,
1316 v0,
1317 e0,
1318 v1,
1319 e1,
1320 v2,
1321 e2,
1322 v3,
1323 e3,
1324 u,
1325 v,
1326 du,
1327 dv);
1328 }
1329 }
1330 }
1331 /* Create connections between ptex faces. */
1332 for (int corner = 0; corner < coarse_face.size(); corner++) {
1333 const int next_corner = (corner + 1) % coarse_face.size();
1334 const int corner_edge_index = start_edge_index + corner * num_inner_edges_per_ptex_face;
1335 const int next_corner_edge_index = start_edge_index +
1336 next_corner * num_inner_edges_per_ptex_face;
1337 int current_patch_vert_index = start_inner_vert_index + corner * num_inner_vertices_per_ptex +
1338 ptex_face_inner_resolution;
1339 int next_path_vert_index = start_inner_vert_index + next_corner * num_inner_vertices_per_ptex +
1340 num_inner_vertices_per_ptex - ptex_face_resolution + 1;
1341 int v0 = current_patch_vert_index;
1342 int v1 = next_path_vert_index;
1343 current_patch_vert_index += ptex_face_inner_resolution + 1;
1344 next_path_vert_index += 1;
1345 int e0 = start_edge_index + coarse_face.size() * num_inner_edges_per_ptex_face +
1346 corner * (ptex_face_resolution - 2);
1347 int e1 = next_corner_edge_index + num_inner_edges_per_ptex_face - ptex_face_resolution + 2;
1348 int e3 = corner_edge_index + 2 * ptex_face_resolution - 4;
1349 for (int row = 1; row < ptex_face_inner_resolution; row++, subdiv_loop_index += 4) {
1350 const int v2 = next_path_vert_index;
1351 const int v3 = current_patch_vert_index;
1352 const int e2 = e0 + 1;
1353 const float u = row * du;
1354 const float v = 1.0f - dv;
1356 tls,
1357 subdiv_loop_index,
1358 ptex_face_index + next_corner,
1359 coarse_face_index,
1360 next_corner,
1361 3,
1362 v0,
1363 e0,
1364 v1,
1365 e1,
1366 v2,
1367 e2,
1368 v3,
1369 e3,
1370 u,
1371 v,
1372 du,
1373 dv);
1374 current_patch_vert_index += ptex_face_inner_resolution + 1;
1375 next_path_vert_index += 1;
1376 v0 = v3;
1377 v1 = v2;
1378 e0 = e2;
1379 e1 += 1;
1380 e3 += 2 * ptex_face_resolution - 3;
1381 }
1382 }
1383 /* Create loops from center. */
1384 if (ptex_face_resolution >= 3) {
1385 const int start_center_edge_index = start_edge_index + (num_inner_edges_per_ptex_face +
1386 ptex_face_inner_resolution) *
1387 coarse_face.size();
1388 const int start_boundary_edge = start_edge_index +
1389 coarse_face.size() * num_inner_edges_per_ptex_face +
1390 ptex_face_inner_resolution - 1;
1391 for (int corner = 0, prev_corner = coarse_face.size() - 1; corner < coarse_face.size();
1392 prev_corner = corner, corner++, subdiv_loop_index += 4)
1393 {
1394 const int corner_edge_index = start_edge_index + corner * num_inner_edges_per_ptex_face;
1395 const int current_patch_end_vert_index = start_vert_index +
1396 corner * num_inner_vertices_per_ptex +
1397 num_inner_vertices_per_ptex - 1;
1398 const int prev_current_patch_end_vert_index = start_vert_index +
1399 prev_corner * num_inner_vertices_per_ptex +
1400 num_inner_vertices_per_ptex - 1;
1401 const int v0 = center_vert_index;
1402 const int v1 = prev_current_patch_end_vert_index;
1403 const int v2 = current_patch_end_vert_index - 1;
1404 const int v3 = current_patch_end_vert_index;
1405 const int e0 = start_center_edge_index + prev_corner;
1406 const int e1 = start_boundary_edge + prev_corner * (ptex_face_inner_resolution);
1407 const int e2 = corner_edge_index + num_inner_edges_per_ptex_face - 1;
1408 const int e3 = start_center_edge_index + corner;
1409 const float u = 1.0f - du;
1410 const float v = 1.0f - dv;
1412 tls,
1413 subdiv_loop_index,
1414 ptex_face_index + corner,
1415 coarse_face_index,
1416 corner,
1417 2,
1418 v0,
1419 e0,
1420 v1,
1421 e1,
1422 v2,
1423 e2,
1424 v3,
1425 e3,
1426 u,
1427 v,
1428 du,
1429 dv);
1430 }
1431 }
1432 /* Loops for faces connecting inner ptex part with boundary. */
1433 for (int prev_corner = coarse_face.size() - 1, corner = 0; corner < coarse_face.size();
1434 prev_corner = corner, corner++)
1435 {
1436 const int coarse_vert = ctx->coarse_corner_verts[coarse_face[corner]];
1437 const int coarse_edge_i = ctx->coarse_corner_edges[coarse_face[corner]];
1438 const int coase_prev_vert = ctx->coarse_corner_verts[coarse_face[prev_corner]];
1439 const int coarse_prev_edge = ctx->coarse_corner_edges[coarse_face[prev_corner]];
1440
1441 const int2 &coarse_edge = ctx->coarse_edges[coarse_edge_i];
1442 const int2 &prev_coarse_edge = ctx->coarse_edges[coarse_prev_edge];
1443 const bool flip = (coarse_edge[1] == coarse_vert);
1444 const int start_edge_vert = ctx->vertices_edge_offset +
1445 coarse_edge_i * num_subdiv_vertices_per_coarse_edge;
1446 const int corner_vert_index = start_vert_index + corner * num_inner_vertices_per_ptex;
1447 const int corner_edge_index = start_edge_index + corner * num_inner_edges_per_ptex_face;
1448 /* Create loops for polygons along U axis. */
1449 int v0 = ctx->vertices_corner_offset + coarse_vert;
1450 int v3, e3;
1451 if (coase_prev_vert == prev_coarse_edge[0]) {
1452 v3 = ctx->vertices_edge_offset + coarse_prev_edge * num_subdiv_vertices_per_coarse_edge +
1453 num_subdiv_vertices_per_coarse_edge - 1;
1454 e3 = ctx->edge_boundary_offset + coarse_prev_edge * num_subdiv_edges_per_coarse_edge +
1455 num_subdiv_edges_per_coarse_edge - 1;
1456 }
1457 else {
1458 v3 = ctx->vertices_edge_offset + coarse_prev_edge * num_subdiv_vertices_per_coarse_edge;
1459 e3 = ctx->edge_boundary_offset + coarse_prev_edge * num_subdiv_edges_per_coarse_edge;
1460 }
1461 for (int i = 0; i <= ptex_face_inner_resolution; i++, subdiv_loop_index += 4) {
1462 int v1;
1463 if (flip) {
1464 v1 = start_edge_vert + (resolution - i - 3);
1465 }
1466 else {
1467 v1 = start_edge_vert + i;
1468 }
1469 int v2;
1470 if (ptex_face_inner_resolution >= 1) {
1471 v2 = corner_vert_index + i;
1472 }
1473 else {
1474 v2 = center_vert_index;
1475 }
1476 int e0;
1477 if (flip) {
1478 e0 = ctx->edge_boundary_offset + coarse_edge_i * num_subdiv_edges_per_coarse_edge +
1479 num_subdiv_edges_per_coarse_edge - i - 1;
1480 }
1481 else {
1482 e0 = ctx->edge_boundary_offset + coarse_edge_i * num_subdiv_edges_per_coarse_edge + i;
1483 }
1484 int e1 = start_edge_index + corner * (2 * ptex_face_inner_resolution + 1);
1485 if (ptex_face_resolution >= 3) {
1486 e1 += coarse_face.size() *
1487 (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1488 i;
1489 }
1490 int e2 = 0;
1491 if (i == 0 && ptex_face_resolution >= 3) {
1492 e2 = start_edge_index +
1493 coarse_face.size() *
1494 (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1495 corner * (2 * ptex_face_inner_resolution + 1) + ptex_face_inner_resolution + 1;
1496 }
1497 else if (i == 0 && ptex_face_resolution < 3) {
1498 e2 = start_edge_index + prev_corner * (2 * ptex_face_inner_resolution + 1);
1499 }
1500 else {
1501 e2 = corner_edge_index + i - 1;
1502 }
1503 const float u = du * i;
1504 const float v = 0.0f;
1506 tls,
1507 subdiv_loop_index,
1508 ptex_face_index + corner,
1509 coarse_face_index,
1510 corner,
1511 0,
1512 v0,
1513 e0,
1514 v1,
1515 e1,
1516 v2,
1517 e2,
1518 v3,
1519 e3,
1520 u,
1521 v,
1522 du,
1523 dv);
1524 v0 = v1;
1525 v3 = v2;
1526 e3 = e1;
1527 }
1528 /* Create loops for polygons along V axis. */
1529 const bool flip_prev = (prev_coarse_edge[1] == coarse_vert);
1530 v0 = corner_vert_index;
1531 if (coase_prev_vert == prev_coarse_edge[0]) {
1532 v3 = ctx->vertices_edge_offset + coarse_prev_edge * num_subdiv_vertices_per_coarse_edge +
1533 num_subdiv_vertices_per_coarse_edge - 1;
1534 }
1535 else {
1536 v3 = ctx->vertices_edge_offset + coarse_prev_edge * num_subdiv_vertices_per_coarse_edge;
1537 }
1538 e3 = start_edge_index +
1539 coarse_face.size() * (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1540 corner * (2 * ptex_face_inner_resolution + 1) + ptex_face_inner_resolution + 1;
1541 for (int i = 0; i <= ptex_face_inner_resolution - 1; i++, subdiv_loop_index += 4) {
1542 int v1;
1543 int e0, e1;
1544 if (i == ptex_face_inner_resolution - 1) {
1545 v1 = start_vert_index + prev_corner * num_inner_vertices_per_ptex +
1546 ptex_face_inner_resolution;
1547 e1 = start_edge_index +
1548 coarse_face.size() *
1549 (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1550 prev_corner * (2 * ptex_face_inner_resolution + 1) + ptex_face_inner_resolution;
1551 e0 = start_edge_index + coarse_face.size() * num_inner_edges_per_ptex_face +
1552 prev_corner * ptex_face_inner_resolution;
1553 }
1554 else {
1555 v1 = v0 + ptex_face_inner_resolution + 1;
1556 e0 = corner_edge_index + ptex_face_inner_resolution +
1557 i * (2 * ptex_face_inner_resolution + 1);
1558 e1 = e3 + 1;
1559 }
1560 int v2 = flip_prev ? v3 - 1 : v3 + 1;
1561 int e2;
1562 if (flip_prev) {
1563 e2 = ctx->edge_boundary_offset + coarse_prev_edge * num_subdiv_edges_per_coarse_edge +
1564 num_subdiv_edges_per_coarse_edge - 2 - i;
1565 }
1566 else {
1567 e2 = ctx->edge_boundary_offset + coarse_prev_edge * num_subdiv_edges_per_coarse_edge + 1 +
1568 i;
1569 }
1570 const float u = 0.0f;
1571 const float v = du * (i + 1);
1573 tls,
1574 subdiv_loop_index,
1575 ptex_face_index + corner,
1576 coarse_face_index,
1577 corner,
1578 1,
1579 v0,
1580 e0,
1581 v1,
1582 e1,
1583 v2,
1584 e2,
1585 v3,
1586 e3,
1587 u,
1588 v,
1589 du,
1590 dv);
1591 v0 = v1;
1592 v3 = v2;
1593 e3 = e1;
1594 }
1595 }
1596}
1597
1598static void subdiv_foreach_loops(ForeachTaskContext *ctx, void *tls, int face_index)
1599{
1600 if (ctx->coarse_faces[face_index].size() == 4) {
1601 subdiv_foreach_loops_regular(ctx, tls, face_index);
1602 }
1603 else {
1604 subdiv_foreach_loops_special(ctx, tls, face_index);
1605 }
1606}
1607
1609
1610/* -------------------------------------------------------------------- */
1613
1614static void subdiv_foreach_loose_vertices_task(void *__restrict userdata,
1615 const int coarse_vert_index,
1616 const TaskParallelTLS *__restrict tls)
1617{
1618 ForeachTaskContext *ctx = static_cast<ForeachTaskContext *>(userdata);
1619 if (BLI_BITMAP_TEST_BOOL(ctx->coarse_vertices_used_map, coarse_vert_index)) {
1620 /* Vertex is not loose, was handled when handling polygons. */
1621 return;
1622 }
1623 const int subdiv_vert_index = ctx->vertices_corner_offset + coarse_vert_index;
1625 ctx->foreach_context, tls->userdata_chunk, coarse_vert_index, subdiv_vert_index);
1626}
1627
1628static void subdiv_foreach_vertices_of_loose_edges_task(void *__restrict userdata,
1629 const int coarse_edge_index,
1630 const TaskParallelTLS *__restrict tls)
1631{
1632 ForeachTaskContext *ctx = static_cast<ForeachTaskContext *>(userdata);
1633 if (BLI_BITMAP_TEST_BOOL(ctx->coarse_edges_used_map, coarse_edge_index)) {
1634 /* Vertex is not loose, was handled when handling polygons. */
1635 return;
1636 }
1637 const int resolution = ctx->settings->resolution;
1638 const int resolution_1 = resolution - 1;
1639 const float inv_resolution_1 = 1.0f / float(resolution_1);
1640 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
1641 const int2 &coarse_edge = ctx->coarse_edges[coarse_edge_index];
1642 /* Subdivision vertices which corresponds to edge's v1 and v2. */
1643 const int subdiv_v1_index = ctx->vertices_corner_offset + coarse_edge[0];
1644 const int subdiv_v2_index = ctx->vertices_corner_offset + coarse_edge[1];
1645 /* First subdivided inner vertex of the edge. */
1646 const int subdiv_start_vert = ctx->vertices_edge_offset +
1647 coarse_edge_index * num_subdiv_vertices_per_coarse_edge;
1648 /* Perform interpolation. */
1649 for (int i = 0; i < resolution; i++) {
1650 const float u = i * inv_resolution_1;
1651 int subdiv_vert_index;
1652 if (i == 0) {
1653 subdiv_vert_index = subdiv_v1_index;
1654 }
1655 else if (i == resolution - 1) {
1656 subdiv_vert_index = subdiv_v2_index;
1657 }
1658 else {
1659 subdiv_vert_index = subdiv_start_vert + (i - 1);
1660 }
1662 ctx->foreach_context, tls->userdata_chunk, coarse_edge_index, u, subdiv_vert_index);
1663 }
1664}
1665
1667
1668/* -------------------------------------------------------------------- */
1671
1673{
1674 if (ctx->foreach_context->vert_corner == nullptr) {
1675 return;
1676 }
1677 const Mesh *coarse_mesh = ctx->coarse_mesh;
1678 for (int face_index = 0; face_index < coarse_mesh->faces_num; face_index++) {
1679 subdiv_foreach_corner_vertices(ctx, tls, face_index);
1680 subdiv_foreach_edge_vertices(ctx, tls, face_index);
1681 }
1682}
1683
1685{
1686 for (const int face_index : ctx->coarse_faces.index_range()) {
1687 for (const int corner : ctx->coarse_faces[face_index]) {
1690 }
1691 }
1692}
1693
1695{
1696 /* NOTE: In theory, we can try to skip allocation of TLS here, but in
1697 * practice if the callbacks used here are not specified then TLS will not
1698 * be requested anyway. */
1699 void *tls = subdiv_foreach_tls_alloc(ctx);
1700 /* Passes to average displacement on the corner vertices
1701 * and boundary edges. */
1704 /* Run callbacks which are supposed to be run once per shared geometry. */
1706 subdiv_foreach_tls_free(ctx, tls);
1707
1708 const ForeachContext *foreach_context = ctx->foreach_context;
1709 const bool is_loose_geometry_tagged = (foreach_context->vert_every_edge != nullptr &&
1710 foreach_context->vert_every_corner != nullptr);
1711 const bool is_loose_geometry_tags_needed = (foreach_context->vert_loose != nullptr ||
1712 foreach_context->vert_of_loose_edge != nullptr);
1713 if (is_loose_geometry_tagged && is_loose_geometry_tags_needed) {
1715 }
1716}
1717
1718static void subdiv_foreach_task(void *__restrict userdata,
1719 const int face_index,
1720 const TaskParallelTLS *__restrict tls)
1721{
1722 ForeachTaskContext *ctx = static_cast<ForeachTaskContext *>(userdata);
1723 /* Traverse hi-poly vertex coordinates and normals. */
1724 subdiv_foreach_vertices(ctx, tls->userdata_chunk, face_index);
1725 /* Traverse mesh geometry for the given base poly index. */
1726 if (ctx->foreach_context->edge != nullptr) {
1727 subdiv_foreach_edges(ctx, tls->userdata_chunk, face_index);
1728 }
1729 if (ctx->foreach_context->loop != nullptr) {
1730 subdiv_foreach_loops(ctx, tls->userdata_chunk, face_index);
1731 }
1732}
1733
1734static void subdiv_foreach_boundary_edges_task(void *__restrict userdata,
1735 const int edge_index,
1736 const TaskParallelTLS *__restrict tls)
1737{
1738 ForeachTaskContext *ctx = static_cast<ForeachTaskContext *>(userdata);
1739 subdiv_foreach_boundary_edges(ctx, tls->userdata_chunk, edge_index);
1740}
1741
1742static void subdiv_foreach_free(const void *__restrict userdata, void *__restrict userdata_chunk)
1743{
1744 const ForeachTaskContext *ctx = static_cast<const ForeachTaskContext *>(userdata);
1745 ctx->foreach_context->user_data_tls_free(userdata_chunk);
1746}
1747
1749 const ForeachContext *context,
1750 const ToMeshSettings *mesh_settings,
1751 const Mesh *coarse_mesh)
1752{
1753 ForeachTaskContext ctx = {nullptr};
1754 ctx.coarse_mesh = coarse_mesh;
1755 ctx.coarse_edges = coarse_mesh->edges();
1756 ctx.coarse_faces = coarse_mesh->faces();
1757 ctx.coarse_corner_verts = coarse_mesh->corner_verts();
1758 ctx.coarse_corner_edges = coarse_mesh->corner_edges();
1759 ctx.settings = mesh_settings;
1760 ctx.foreach_context = context;
1762 if (context->topology_info != nullptr) {
1763 /* Skip the last sentinel element so that the callback "sees" offsets of actual faces. */
1764 const Span<int> subdiv_face_offset_no_sentinel = ctx.subdiv_face_offset.as_span().drop_back(1);
1765 if (!context->topology_info(context,
1767 ctx.num_subdiv_edges,
1768 ctx.num_subdiv_loops,
1769 ctx.num_subdiv_faces,
1770 subdiv_face_offset_no_sentinel))
1771 {
1773 return false;
1774 }
1775 }
1776 /* Run all the code which is not supposed to be run from threads. */
1778 /* Threaded traversal of the rest of topology. */
1779 TaskParallelSettings parallel_range_settings;
1780 BLI_parallel_range_settings_defaults(&parallel_range_settings);
1781 parallel_range_settings.userdata_chunk = context->user_data_tls;
1782 parallel_range_settings.userdata_chunk_size = context->user_data_tls_size;
1783 parallel_range_settings.min_iter_per_thread = 1;
1784 if (context->user_data_tls_free != nullptr) {
1785 parallel_range_settings.func_free = subdiv_foreach_free;
1786 }
1787
1788 if (context->faces) {
1789 context->faces(context, OffsetIndices<int>(ctx.subdiv_face_offset));
1790 }
1791
1792 /* TODO(sergey): Possible optimization is to have a single pool and push all
1793 * the tasks into it.
1794 * NOTE: Watch out for callbacks which needs to run for loose geometry as they
1795 * currently are relying on the fact that face/grid callbacks will tag non-
1796 * loose geometry. */
1797
1799 0, coarse_mesh->faces_num, &ctx, subdiv_foreach_task, &parallel_range_settings);
1800 if (context->vert_loose != nullptr) {
1802 coarse_mesh->verts_num,
1803 &ctx,
1805 &parallel_range_settings);
1806 }
1807 if (context->vert_of_loose_edge != nullptr) {
1809 coarse_mesh->edges_num,
1810 &ctx,
1812 &parallel_range_settings);
1813 }
1814 if (context->edge != nullptr) {
1816 coarse_mesh->edges_num,
1817 &ctx,
1819 &parallel_range_settings);
1820 }
1822 return true;
1823}
1824
1826
1827} // namespace blender::bke::subdiv
CustomData interface, see also DNA_customdata_types.h.
#define ORIGINDEX_NONE
#define BLI_BITMAP_NEW(_num, _alloc_string)
Definition BLI_bitmap.hh:39
#define BLI_BITMAP_ENABLE(_bitmap, _index)
Definition BLI_bitmap.hh:80
#define BLI_BITMAP_TEST_BOOL(_bitmap, _index)
Definition BLI_bitmap.hh:73
#define BLI_BITMAP_TEST_AND_SET_ATOMIC(_bitmap, _index)
Definition BLI_bitmap.hh:67
Read Blender memory allocation and freeing.
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
#define BLI_INLINE
Span< T > as_span() const
Definition BLI_array.hh:254
const T & last(const int64_t n=0) const
Definition BLI_array.hh:307
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
constexpr int64_t size() const
#define rot(x, k)
static void subdiv_foreach_free(const void *__restrict userdata, void *__restrict userdata_chunk)
static void subdiv_foreach_ctx_count(ForeachTaskContext *ctx)
static void subdiv_foreach_edges_all_patches_regular(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_single_geometry_vertices(ForeachTaskContext *ctx, void *tls)
static void subdiv_foreach_every_edge_vertices(ForeachTaskContext *ctx, void *tls)
static void subdiv_foreach_boundary_edges_task(void *__restrict userdata, const int edge_index, const TaskParallelTLS *__restrict tls)
BLI_INLINE int num_inner_edges_per_ptex_face_get(const int resolution)
static int subdiv_foreach_edges_row(ForeachTaskContext *ctx, void *tls, const int coarse_edge_index, const int start_subdiv_edge_index, const int start_vert_index, const int num_edges_per_row)
BLI_INLINE int num_edges_per_ptex_face_get(const int resolution)
static void subdiv_foreach_loops_of_face(ForeachTaskContext *ctx, void *tls, int subdiv_loop_start_index, const int ptex_face_index, const int coarse_face_index, const int coarse_corner_index, const int rotation, int v0, int e0, int v1, int e1, int v2, int e2, int v3, int e3, const float u, const float v, const float du, const float dv)
static void subdiv_foreach_corner_vertices_special(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_boundary_edges(ForeachTaskContext *ctx, void *tls, int coarse_edge_index)
static void subdiv_foreach_edges_all_patches(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_ctx_init(Subdiv *subdiv, ForeachTaskContext *ctx)
bool foreach_subdiv_geometry(Subdiv *subdiv, const ForeachContext *context, const ToMeshSettings *mesh_settings, const Mesh *coarse_mesh)
BLI_INLINE int ptex_face_resolution_get(const IndexRange face, int resolution)
static void subdiv_foreach_edges(ForeachTaskContext *ctx, void *tls, int face_index)
static void subdiv_foreach_vertices(ForeachTaskContext *ctx, void *tls, const int face_index)
static void subdiv_foreach_every_edge_vertices_special(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_tls_free(ForeachTaskContext *ctx, void *tls)
static void subdiv_foreach_every_corner_vertices_regular(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static int subdiv_foreach_loops_corner_index(const float u, const float v, const float du, const float dv)
static void subdiv_foreach_edge_vertices(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_edge_vertices_special(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_task(void *__restrict userdata, const int face_index, const TaskParallelTLS *__restrict tls)
static void subdiv_foreach_mark_non_loose_geometry(ForeachTaskContext *ctx)
BLI_INLINE int num_ptex_faces_per_face_get(const IndexRange face)
static void subdiv_foreach_edges_all_patches_special(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void * subdiv_foreach_tls_alloc(ForeachTaskContext *ctx)
static void subdiv_foreach_corner_vertices_regular(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_inner_vertices_regular(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_edge_vertices_special_do(ForeachTaskContext *ctx, void *tls, const int coarse_face_index, ForeachVertFromEdgeCb vert_edge, bool check_usage)
static void subdiv_foreach_every_edge_vertices_regular(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_loops_special(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
void(*)(const ForeachContext *context, void *tls, int ptex_face_index, float u, float v, int coarse_vert_index, int coarse_face_index, int coarse_corner, int subdiv_vert_index) ForeachVertFromCornerCb
static void subdiv_foreach_ctx_free(ForeachTaskContext *ctx)
static void subdiv_foreach_loops_regular(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_ctx_init_offsets(ForeachTaskContext *ctx)
static void subdiv_foreach_edge_vertices_regular(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_edge_vertices_regular_do(ForeachTaskContext *ctx, void *tls, const int coarse_face_index, ForeachVertFromEdgeCb vert_edge, bool check_usage)
static void subdiv_foreach_corner_vertices(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static int subdiv_foreach_edges_column(ForeachTaskContext *ctx, void *tls, const int coarse_start_edge_index, const int coarse_end_edge_index, const int start_subdiv_edge_index, const int start_vert_index, const int num_edges_per_row)
static void rotate_indices(const int rot, int *a, int *b, int *c, int *d)
static void subdiv_foreach_inner_vertices(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_loops(ForeachTaskContext *ctx, void *tls, int face_index)
static void subdiv_foreach_loose_vertices_task(void *__restrict userdata, const int coarse_vert_index, const TaskParallelTLS *__restrict tls)
static void subdiv_foreach_inner_vertices_special(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_every_corner_vertices(ForeachTaskContext *ctx, void *tls)
static void subdiv_foreach_corner_vertices_regular_do(ForeachTaskContext *ctx, void *tls, const int coarse_face_index, ForeachVertFromCornerCb vert_corner, bool check_usage)
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_vert_index) ForeachVertFromEdgeCb
BLI_INLINE int num_faces_per_ptex_get(const int resolution)
static void subdiv_foreach_every_corner_vertices_special(ForeachTaskContext *ctx, void *tls, const int coarse_face_index)
static void subdiv_foreach_corner_vertices_special_do(ForeachTaskContext *ctx, void *tls, const int coarse_face_index, ForeachVertFromCornerCb vert_corner, bool check_usage)
static void subdiv_foreach_single_thread_tasks(ForeachTaskContext *ctx)
Span< int > face_ptex_offset_get(Subdiv *subdiv)
Definition subdiv.cc:216
static void subdiv_foreach_vertices_of_loose_edges_task(void *__restrict userdata, const int coarse_edge_index, const TaskParallelTLS *__restrict tls)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void MEM_delete_void(void *vmemh)
VecBase< int32_t, 2 > int2
unsigned int BLI_bitmap
Definition BLI_bitmap.hh:15
ATTR_WARN_UNUSED_RESULT const BMVert * v2
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
TaskParallelFreeFunc func_free
ForeachVertOfLooseEdgeCb vert_of_loose_edge