55 return 2 * (resolution - 1) * resolution;
63 return (resolution - 2) * resolution + (resolution - 1) * (resolution - 1);
69 return (resolution - 1) * (resolution - 1);
75 return (poly->
totloop == 4) ? (resolution) : ((resolution >> 1) + 1);
171 const int no_quad_patch_resolution = ((resolution >> 1) + 1);
172 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
173 const int num_inner_vertices_per_quad = (resolution - 2) * (resolution - 2);
174 const int num_inner_vertices_per_noquad_patch = (no_quad_patch_resolution - 2) *
175 (no_quad_patch_resolution - 2);
177 const MLoop *coarse_mloop = coarse_mesh->
mloop;
178 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
182 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
183 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
195 if (num_ptex_faces_per_poly == 1) {
198 4 * num_subdiv_vertices_per_coarse_edge;
203 num_ptex_faces_per_poly * num_inner_vertices_per_noquad_patch;
206 (no_quad_patch_resolution - 2) +
207 num_subdiv_vertices_per_coarse_edge);
208 if (no_quad_patch_resolution >= 3) {
216 for (
int edge_index = 0; edge_index < coarse_mesh->
totedge; edge_index++) {
228 const int resolution_2 = resolution - 2;
229 const int resolution_2_squared = resolution_2 * resolution_2;
230 const int no_quad_patch_resolution = ((resolution >> 1) + 1);
231 const int num_irregular_vertices_per_patch = (no_quad_patch_resolution - 2) *
232 (no_quad_patch_resolution - 1);
233 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
234 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
239 coarse_mesh->
totedge * num_subdiv_vertices_per_coarse_edge;
242 coarse_mesh->
totedge * num_subdiv_edges_per_coarse_edge;
244 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
245 int vertex_offset = 0;
247 int polygon_offset = 0;
248 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
249 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
254 if (num_ptex_faces_per_poly == 1) {
255 vertex_offset += resolution_2_squared;
257 4 * num_subdiv_vertices_per_coarse_edge;
261 vertex_offset += 1 + num_ptex_faces_per_poly * num_irregular_vertices_per_patch;
262 edge_offset += num_ptex_faces_per_poly *
264 (no_quad_patch_resolution - 2) + num_subdiv_vertices_per_coarse_edge);
265 if (no_quad_patch_resolution >= 3) {
266 edge_offset += coarse_poly->
totloop;
314 const MPoly *coarse_poly,
318 const float weights[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
320 const MLoop *coarse_mloop = coarse_mesh->
mloop;
321 const int coarse_poly_index = coarse_poly - coarse_mesh->
mpoly;
329 const int coarse_vertex_index = coarse_loop->
v;
331 const float u = weights[
corner][0];
332 const float v = weights[
corner][1];
341 subdiv_vertex_index);
347 const MPoly *coarse_poly)
356 const MPoly *coarse_poly,
361 const MLoop *coarse_mloop = coarse_mesh->
mloop;
362 const int coarse_poly_index = coarse_poly - coarse_mesh->
mpoly;
370 const int coarse_vertex_index = coarse_loop->
v;
380 subdiv_vertex_index);
386 const MPoly *coarse_poly)
394 const MPoly *coarse_poly)
396 if (coarse_poly->
totloop == 4) {
406 const MPoly *coarse_poly)
414 const MPoly *coarse_poly)
426 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
427 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
428 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
429 if (coarse_poly->
totloop == 4) {
442 const MPoly *coarse_poly,
447 const int resolution_1 = resolution - 1;
448 const float inv_resolution_1 = 1.0f / (
float)resolution_1;
449 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
451 const MEdge *coarse_medge = coarse_mesh->
medge;
452 const MLoop *coarse_mloop = coarse_mesh->
mloop;
453 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
454 const int coarse_poly_index = coarse_poly - coarse_mpoly;
455 const int poly_index = coarse_poly - coarse_mesh->
mpoly;
459 const int coarse_edge_index = coarse_loop->
e;
464 const MEdge *coarse_edge = &coarse_medge[coarse_edge_index];
465 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
467 coarse_edge_index * num_subdiv_vertices_per_coarse_edge;
468 for (
int vertex_index = 0; vertex_index < num_subdiv_vertices_per_coarse_edge;
469 vertex_index++, subdiv_vertex_index++) {
470 float fac = (vertex_index + 1) * inv_resolution_1;
480 v = (
corner == 2) ? 1.0f : 0.0f;
483 u = (
corner == 1) ? 1.0f : 0.0f;
494 subdiv_vertex_index);
501 const MPoly *coarse_poly)
509 const MPoly *coarse_poly,
514 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
515 const int num_vertices_per_ptex_edge = ((resolution >> 1) + 1);
516 const float inv_ptex_resolution_1 = 1.0f / (
float)(num_vertices_per_ptex_edge - 1);
518 const MEdge *coarse_medge = coarse_mesh->
medge;
519 const MLoop *coarse_mloop = coarse_mesh->
mloop;
520 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
521 const int coarse_poly_index = coarse_poly - coarse_mpoly;
522 const int poly_index = coarse_poly - coarse_mesh->
mpoly;
524 int ptex_face_index = ptex_face_start_index;
527 const int coarse_edge_index = coarse_loop->
e;
532 const MEdge *coarse_edge = &coarse_medge[coarse_edge_index];
533 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
535 coarse_edge_index * num_subdiv_vertices_per_coarse_edge;
536 int vertex_delta = 1;
538 subdiv_vertex_index += num_subdiv_vertices_per_coarse_edge - 1;
541 for (
int vertex_index = 1; vertex_index < num_vertices_per_ptex_edge;
542 vertex_index++, subdiv_vertex_index += vertex_delta) {
543 const float u = vertex_index * inv_ptex_resolution_1;
552 subdiv_vertex_index);
555 const int next_ptex_face_index = ptex_face_start_index + next_corner;
556 for (
int vertex_index = 1; vertex_index < num_vertices_per_ptex_edge - 1;
557 vertex_index++, subdiv_vertex_index += vertex_delta) {
558 const float v = 1.0f - vertex_index * inv_ptex_resolution_1;
561 next_ptex_face_index,
567 subdiv_vertex_index);
574 const MPoly *coarse_poly)
582 const MPoly *coarse_poly)
584 if (coarse_poly->
totloop == 4) {
594 const MPoly *coarse_poly)
602 const MPoly *coarse_poly)
614 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
615 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
616 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
617 if (coarse_poly->
totloop == 4) {
630 const MPoly *coarse_poly)
633 const float inv_resolution_1 = 1.0f / (
float)(resolution - 1);
635 const int coarse_poly_index = coarse_poly - coarse_mesh->
mpoly;
639 for (
int y = 1;
y < resolution - 1;
y++) {
640 const float v =
y * inv_resolution_1;
641 for (
int x = 1;
x < resolution - 1;
x++, subdiv_vertex_index++) {
642 const float u =
x * inv_resolution_1;
650 subdiv_vertex_index);
657 const MPoly *coarse_poly)
661 const float inv_ptex_face_resolution_1 = 1.0f / (
float)(ptex_face_resolution - 1);
663 const int coarse_poly_index = coarse_poly - coarse_mesh->
mpoly;
674 subdiv_vertex_index);
675 subdiv_vertex_index++;
677 for (
int y = 1;
y < ptex_face_resolution - 1;
y++) {
678 const float v =
y * inv_ptex_face_resolution_1;
679 for (
int x = 1;
x < ptex_face_resolution;
x++, subdiv_vertex_index++) {
680 const float u =
x * inv_ptex_face_resolution_1;
688 subdiv_vertex_index);
696 const MPoly *coarse_poly)
698 if (coarse_poly->
totloop == 4) {
710 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
711 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
726 const int coarse_edge_index,
727 const int start_subdiv_edge_index,
728 const int start_vertex_index,
729 const int num_edges_per_row)
731 int subdiv_edge_index = start_subdiv_edge_index;
732 int vertex_index = start_vertex_index;
733 for (
int edge_index = 0; edge_index < num_edges_per_row - 1; edge_index++, subdiv_edge_index++) {
734 const int v1 = vertex_index;
735 const int v2 = vertex_index + 1;
740 return subdiv_edge_index;
746 const int coarse_start_edge_index,
747 const int coarse_end_edge_index,
748 const int start_subdiv_edge_index,
749 const int start_vertex_index,
750 const int num_edges_per_row)
752 int subdiv_edge_index = start_subdiv_edge_index;
753 int vertex_index = start_vertex_index;
754 for (
int edge_index = 0; edge_index < num_edges_per_row; edge_index++, subdiv_edge_index++) {
756 if (edge_index == 0) {
757 coarse_edge_index = coarse_start_edge_index;
759 else if (edge_index == num_edges_per_row - 1) {
760 coarse_edge_index = coarse_end_edge_index;
762 const int v1 = vertex_index;
763 const int v2 = vertex_index + num_edges_per_row;
768 return subdiv_edge_index;
791 const MPoly *coarse_poly)
794 const MEdge *coarse_medge = coarse_mesh->
medge;
795 const MLoop *coarse_mloop = coarse_mesh->
mloop;
796 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
797 const int poly_index = coarse_poly - coarse_mpoly;
801 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
805 ctx, tls,
ORIGINDEX_NONE, subdiv_edge_index, start_vertex_index, resolution - 2);
807 for (
int row = 0; row < resolution - 3; row++) {
808 const int start_row_vertex_index = start_vertex_index + row * (resolution - 2);
819 start_row_vertex_index,
830 start_row_vertex_index + resolution - 2,
836 const MEdge *coarse_edge = &coarse_medge[coarse_loop->
e];
838 coarse_loop->
e * num_subdiv_vertices_per_coarse_edge;
839 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
840 int side_start_index = start_vertex_index;
847 side_start_index += resolution - 3;
848 side_stride = resolution - 2;
851 side_start_index += num_subdiv_vertices_per_coarse_edge *
852 num_subdiv_vertices_per_coarse_edge -
857 side_start_index += num_subdiv_vertices_per_coarse_edge *
858 (num_subdiv_vertices_per_coarse_edge - 1);
859 side_stride = -(resolution - 2);
861 for (
int i = 0; i < resolution - 2; i++, subdiv_edge_index++) {
862 const int v1 = (flip) ? (start_edge_vertex + (resolution - i - 3)) : (start_edge_vertex + i);
863 const int v2 = side_start_index + side_stride * i;
872 const MPoly *coarse_poly)
875 const MEdge *coarse_medge = coarse_mesh->
medge;
876 const MLoop *coarse_mloop = coarse_mesh->
mloop;
877 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
878 const int poly_index = coarse_poly - coarse_mpoly;
881 const int ptex_face_inner_resolution = ptex_face_resolution - 2;
882 const int num_inner_vertices_per_ptex = (ptex_face_resolution - 1) * (ptex_face_resolution - 2);
883 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
886 const int start_vertex_index = center_vertex_index + 1;
890 const int start_ptex_face_vertex_index = start_vertex_index +
891 corner * num_inner_vertices_per_ptex;
897 start_ptex_face_vertex_index,
898 ptex_face_inner_resolution + 1);
899 for (
int row = 0; row < ptex_face_inner_resolution - 1; row++) {
900 const int start_row_vertex_index = start_ptex_face_vertex_index +
901 row * (ptex_face_inner_resolution + 1);
907 start_row_vertex_index,
908 ptex_face_inner_resolution + 1);
913 start_row_vertex_index +
914 ptex_face_inner_resolution + 1,
915 ptex_face_inner_resolution + 1);
921 int current_patch_vertex_index = start_vertex_index +
corner * num_inner_vertices_per_ptex +
922 ptex_face_inner_resolution;
923 int next_path_vertex_index = start_vertex_index + next_corner * num_inner_vertices_per_ptex +
924 num_inner_vertices_per_ptex - ptex_face_resolution + 1;
925 for (
int row = 0; row < ptex_face_inner_resolution; row++, subdiv_edge_index++) {
926 const int v1 = current_patch_vertex_index;
927 const int v2 = next_path_vertex_index;
930 current_patch_vertex_index += ptex_face_inner_resolution + 1;
931 next_path_vertex_index += 1;
935 if (ptex_face_resolution >= 3) {
937 const int current_patch_end_vertex_index = start_vertex_index +
938 corner * num_inner_vertices_per_ptex +
939 num_inner_vertices_per_ptex - 1;
940 const int v1 = center_vertex_index;
941 const int v2 = current_patch_end_vertex_index;
951 const MEdge *coarse_edge = &coarse_medge[coarse_loop->
e];
953 coarse_loop->
e * num_subdiv_vertices_per_coarse_edge;
954 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
955 int side_start_index;
956 if (ptex_face_resolution >= 3) {
957 side_start_index = start_vertex_index + num_inner_vertices_per_ptex *
corner;
960 side_start_index = center_vertex_index;
962 for (
int i = 0; i < ptex_face_resolution - 1; i++, subdiv_edge_index++) {
963 const int v1 = (flip) ? (start_edge_vertex + (resolution - i - 3)) :
964 (start_edge_vertex + i);
965 const int v2 = side_start_index + i;
970 if (ptex_face_resolution >= 3) {
971 const MEdge *coarse_edge = &coarse_medge[prev_coarse_loop->
e];
973 prev_coarse_loop->
e * num_subdiv_vertices_per_coarse_edge;
974 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
975 int side_start_index = start_vertex_index + num_inner_vertices_per_ptex *
corner;
976 for (
int i = 0; i < ptex_face_resolution - 2; i++, subdiv_edge_index++) {
977 const int v1 = (flip) ? (start_edge_vertex + (resolution - i - 3)) :
978 (start_edge_vertex + i);
979 const int v2 = side_start_index + (ptex_face_inner_resolution + 1) * i;
984 prev_coarse_loop = coarse_loop;
990 const MPoly *coarse_poly)
992 if (coarse_poly->
totloop == 4) {
1003 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1004 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
1010 int coarse_edge_index)
1013 const MEdge *coarse_medge = coarse_mesh->
medge;
1014 const MEdge *coarse_edge = &coarse_medge[coarse_edge_index];
1016 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
1017 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
1019 coarse_edge_index * num_subdiv_edges_per_coarse_edge;
1021 for (
int i = 0; i < num_subdiv_edges_per_coarse_edge - 1; i++, subdiv_edge_index++) {
1022 const int v1 = last_vertex_index;
1024 coarse_edge_index * num_subdiv_vertices_per_coarse_edge + i;
1027 last_vertex_index =
v2;
1029 const int v1 = last_vertex_index;
1043 const int values[4] = {*
a, *b, *
c, *d};
1044 *
a = values[(0 -
rot + 4) % 4];
1045 *b = values[(1 -
rot + 4) % 4];
1046 *
c = values[(2 -
rot + 4) % 4];
1047 *d = values[(3 -
rot + 4) % 4];
1052 int subdiv_loop_start_index,
1053 const int ptex_face_index,
1054 const int coarse_poly_index,
1055 const int coarse_corner_index,
1079 coarse_corner_index,
1080 subdiv_loop_start_index + 0,
1090 coarse_corner_index,
1091 subdiv_loop_start_index + 1,
1101 coarse_corner_index,
1102 subdiv_loop_start_index + 2,
1112 coarse_corner_index,
1113 subdiv_loop_start_index + 3,
1123 if (u + du <= 0.5f &&
v + dv <= 0.5f) {
1126 if (u >= 0.5f &&
v + dv <= 0.5f) {
1129 if (u >= 0.5f &&
v >= 0.5f) {
1137 const MPoly *coarse_poly)
1142 const MEdge *coarse_medge = coarse_mesh->
medge;
1143 const MLoop *coarse_mloop = coarse_mesh->
mloop;
1144 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1145 const int coarse_poly_index = coarse_poly - coarse_mpoly;
1147 const int ptex_inner_resolution = ptex_resolution - 2;
1148 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
1149 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
1150 const float inv_ptex_resolution_1 = 1.0f / (
float)(ptex_resolution - 1);
1156 const int start_loop_index = 4 * start_poly_index;
1157 const float du = inv_ptex_resolution_1;
1158 const float dv = inv_ptex_resolution_1;
1160 int subdiv_loop_index = start_loop_index;
1162 for (
int y = 1;
y < ptex_resolution - 2;
y++) {
1163 const float v =
y * inv_ptex_resolution_1;
1164 const int inner_y =
y - 1;
1165 for (
int x = 1;
x < ptex_resolution - 2;
x++, subdiv_loop_index += 4) {
1166 const int inner_x =
x - 1;
1167 const float u =
x * inv_ptex_resolution_1;
1169 const int v0 = start_vertex_index + (inner_y * ptex_inner_resolution + inner_x);
1170 const int v1 = v0 + 1;
1171 const int v2 = v0 + ptex_inner_resolution + 1;
1172 const int v3 = v0 + ptex_inner_resolution;
1174 const int e0 = start_edge_index + (inner_y * (2 * ptex_inner_resolution - 1) + inner_x);
1175 const int e1 = e0 + ptex_inner_resolution;
1176 const int e2 = e0 + (2 * ptex_inner_resolution - 1);
1177 const int e3 = e0 + ptex_inner_resolution - 1;
1204 const MEdge *coarse_edge = &coarse_medge[coarse_loop->
e];
1205 const MEdge *prev_coarse_edge = &coarse_medge[prev_coarse_loop->
e];
1207 coarse_loop->
e * num_subdiv_vertices_per_coarse_edge;
1208 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
1209 int side_start_index = start_vertex_index;
1210 int side_stride = 0;
1213 int e2_offset, e2_stride;
1214 float u,
v, delta_u, delta_v;
1215 if (prev_coarse_loop->
v == prev_coarse_edge->
v1) {
1217 num_subdiv_vertices_per_coarse_edge - 1;
1219 num_subdiv_edges_per_coarse_edge - 1;
1236 side_start_index += resolution - 3;
1237 side_stride = resolution - 2;
1238 e2_offset = 2 * num_subdiv_edges_per_coarse_edge - 4;
1239 e2_stride = 2 * num_subdiv_edges_per_coarse_edge - 3;
1246 side_start_index += num_subdiv_vertices_per_coarse_edge *
1247 num_subdiv_vertices_per_coarse_edge -
1258 side_start_index += num_subdiv_vertices_per_coarse_edge *
1259 (num_subdiv_vertices_per_coarse_edge - 1);
1260 side_stride = -(resolution - 2);
1262 (2 * num_subdiv_edges_per_coarse_edge - 3);
1263 e2_stride = -(2 * num_subdiv_edges_per_coarse_edge - 3);
1269 for (
int i = 0; i < resolution - 2; i++, subdiv_loop_index += 4) {
1272 v1 = start_edge_vertex + (resolution - i - 3);
1275 v1 = start_edge_vertex + i;
1277 const int v2 = side_start_index + side_stride * i;
1281 num_subdiv_edges_per_coarse_edge - i - 1;
1287 corner * num_subdiv_vertices_per_coarse_edge + i;
1292 num_subdiv_vertices_per_coarse_edge +
1293 num_subdiv_vertices_per_coarse_edge - 1;
1296 e2 = start_edge_index + e2_offset + e2_stride * (i - 1);
1299 const float loop_u = u + delta_u * i;
1300 const float loop_v =
v + delta_v * i;
1325 prev_coarse_loop = coarse_loop;
1331 const MPoly *coarse_poly)
1336 const MEdge *coarse_medge = coarse_mesh->
medge;
1337 const MLoop *coarse_mloop = coarse_mesh->
mloop;
1338 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1339 const int coarse_poly_index = coarse_poly - coarse_mpoly;
1341 const int ptex_face_inner_resolution = ptex_face_resolution - 2;
1342 const float inv_ptex_resolution_1 = 1.0f / (
float)(ptex_face_resolution - 1);
1343 const int num_inner_vertices_per_ptex = (ptex_face_resolution - 1) * (ptex_face_resolution - 2);
1345 ptex_face_inner_resolution + 1);
1346 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
1347 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
1351 const int start_vertex_index = center_vertex_index + 1;
1352 const int start_inner_vertex_index = center_vertex_index + 1;
1355 const int start_loop_index = 4 * start_poly_index;
1356 const float du = inv_ptex_resolution_1;
1357 const float dv = inv_ptex_resolution_1;
1359 int subdiv_loop_index = start_loop_index;
1361 const int corner_vertex_index = start_vertex_index +
corner * num_inner_vertices_per_ptex;
1362 const int corner_edge_index = start_edge_index +
corner * num_inner_edges_per_ptex_face;
1363 for (
int y = 1;
y < ptex_face_inner_resolution;
y++) {
1364 const float v =
y * inv_ptex_resolution_1;
1365 const int inner_y =
y - 1;
1366 for (
int x = 1;
x < ptex_face_inner_resolution + 1;
x++, subdiv_loop_index += 4) {
1367 const int inner_x =
x - 1;
1368 const float u =
x * inv_ptex_resolution_1;
1370 const int v0 = corner_vertex_index +
1371 (inner_y * (ptex_face_inner_resolution + 1) + inner_x);
1372 const int v1 = v0 + 1;
1373 const int v2 = v0 + ptex_face_inner_resolution + 2;
1374 const int v3 = v0 + ptex_face_inner_resolution + 1;
1376 const int e0 = corner_edge_index +
1377 (inner_y * (2 * ptex_face_inner_resolution + 1) + inner_x);
1378 const int e1 = e0 + ptex_face_inner_resolution + 1;
1379 const int e2 = e0 + (2 * ptex_face_inner_resolution + 1);
1380 const int e3 = e0 + ptex_face_inner_resolution;
1384 ptex_face_index +
corner,
1405 const int next_corner = (
corner + 1) % coarse_poly->
totloop;
1406 const int corner_edge_index = start_edge_index +
corner * num_inner_edges_per_ptex_face;
1407 const int next_corner_edge_index = start_edge_index +
1408 next_corner * num_inner_edges_per_ptex_face;
1409 int current_patch_vertex_index = start_inner_vertex_index +
1410 corner * num_inner_vertices_per_ptex +
1411 ptex_face_inner_resolution;
1412 int next_path_vertex_index = start_inner_vertex_index +
1413 next_corner * num_inner_vertices_per_ptex +
1414 num_inner_vertices_per_ptex - ptex_face_resolution + 1;
1415 int v0 = current_patch_vertex_index;
1416 int v1 = next_path_vertex_index;
1417 current_patch_vertex_index += ptex_face_inner_resolution + 1;
1418 next_path_vertex_index += 1;
1419 int e0 = start_edge_index + coarse_poly->
totloop * num_inner_edges_per_ptex_face +
1420 corner * (ptex_face_resolution - 2);
1421 int e1 = next_corner_edge_index + num_inner_edges_per_ptex_face - ptex_face_resolution + 2;
1422 int e3 = corner_edge_index + 2 * ptex_face_resolution - 4;
1423 for (
int row = 1; row < ptex_face_inner_resolution; row++, subdiv_loop_index += 4) {
1424 const int v2 = next_path_vertex_index;
1425 const int v3 = current_patch_vertex_index;
1426 const int e2 = e0 + 1;
1427 const float u = row * du;
1428 const float v = 1.0f - dv;
1432 ptex_face_index + next_corner,
1448 current_patch_vertex_index += ptex_face_inner_resolution + 1;
1449 next_path_vertex_index += 1;
1454 e3 += 2 * ptex_face_resolution - 3;
1458 if (ptex_face_resolution >= 3) {
1459 const int start_center_edge_index = start_edge_index + (num_inner_edges_per_ptex_face +
1460 ptex_face_inner_resolution) *
1462 const int start_boundary_edge = start_edge_index +
1463 coarse_poly->
totloop * num_inner_edges_per_ptex_face +
1464 ptex_face_inner_resolution - 1;
1466 prev_corner =
corner,
corner++, subdiv_loop_index += 4) {
1467 const int corner_edge_index = start_edge_index +
corner * num_inner_edges_per_ptex_face;
1468 const int current_patch_end_vertex_index = start_vertex_index +
1469 corner * num_inner_vertices_per_ptex +
1470 num_inner_vertices_per_ptex - 1;
1471 const int prev_current_patch_end_vertex_index = start_vertex_index +
1472 prev_corner * num_inner_vertices_per_ptex +
1473 num_inner_vertices_per_ptex - 1;
1474 const int v0 = center_vertex_index;
1475 const int v1 = prev_current_patch_end_vertex_index;
1476 const int v2 = current_patch_end_vertex_index - 1;
1477 const int v3 = current_patch_end_vertex_index;
1478 const int e0 = start_center_edge_index + prev_corner;
1479 const int e1 = start_boundary_edge + prev_corner * (ptex_face_inner_resolution);
1480 const int e2 = corner_edge_index + num_inner_edges_per_ptex_face - 1;
1481 const int e3 = start_center_edge_index +
corner;
1482 const float u = 1.0f - du;
1483 const float v = 1.0f - dv;
1487 ptex_face_index +
corner,
1510 const MEdge *coarse_edge = &coarse_medge[coarse_loop->
e];
1511 const MEdge *prev_coarse_edge = &coarse_medge[prev_coarse_loop->
e];
1512 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
1514 coarse_loop->
e * num_subdiv_vertices_per_coarse_edge;
1515 const int corner_vertex_index = start_vertex_index +
corner * num_inner_vertices_per_ptex;
1516 const int corner_edge_index = start_edge_index +
corner * num_inner_edges_per_ptex_face;
1520 if (prev_coarse_loop->
v == prev_coarse_edge->
v1) {
1522 num_subdiv_vertices_per_coarse_edge - 1;
1524 num_subdiv_edges_per_coarse_edge - 1;
1530 for (
int i = 0; i <= ptex_face_inner_resolution; i++, subdiv_loop_index += 4) {
1533 v1 = start_edge_vertex + (resolution - i - 3);
1536 v1 = start_edge_vertex + i;
1539 if (ptex_face_inner_resolution >= 1) {
1540 v2 = corner_vertex_index + i;
1543 v2 = center_vertex_index;
1548 num_subdiv_edges_per_coarse_edge - i - 1;
1553 int e1 = start_edge_index +
corner * (2 * ptex_face_inner_resolution + 1);
1554 if (ptex_face_resolution >= 3) {
1556 (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1560 if (i == 0 && ptex_face_resolution >= 3) {
1561 e2 = start_edge_index +
1563 (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1564 corner * (2 * ptex_face_inner_resolution + 1) + ptex_face_inner_resolution + 1;
1566 else if (i == 0 && ptex_face_resolution < 3) {
1567 e2 = start_edge_index + prev_corner * (2 * ptex_face_inner_resolution + 1);
1570 e2 = corner_edge_index + i - 1;
1572 const float u = du * i;
1573 const float v = 0.0f;
1577 ptex_face_index +
corner,
1598 const bool flip_prev = (prev_coarse_edge->
v2 == coarse_loop->
v);
1599 v0 = corner_vertex_index;
1600 if (prev_coarse_loop->
v == prev_coarse_edge->
v1) {
1602 num_subdiv_vertices_per_coarse_edge - 1;
1607 e3 = start_edge_index +
1608 coarse_poly->
totloop * (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1609 corner * (2 * ptex_face_inner_resolution + 1) + ptex_face_inner_resolution + 1;
1610 for (
int i = 0; i <= ptex_face_inner_resolution - 1; i++, subdiv_loop_index += 4) {
1613 if (i == ptex_face_inner_resolution - 1) {
1614 v1 = start_vertex_index + prev_corner * num_inner_vertices_per_ptex +
1615 ptex_face_inner_resolution;
1616 e1 = start_edge_index +
1618 (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1619 prev_corner * (2 * ptex_face_inner_resolution + 1) + ptex_face_inner_resolution;
1620 e0 = start_edge_index + coarse_poly->
totloop * num_inner_edges_per_ptex_face +
1621 prev_corner * ptex_face_inner_resolution;
1624 v1 = v0 + ptex_face_inner_resolution + 1;
1625 e0 = corner_edge_index + ptex_face_inner_resolution +
1626 i * (2 * ptex_face_inner_resolution + 1);
1629 int v2 = flip_prev ? v3 - 1 : v3 + 1;
1633 num_subdiv_edges_per_coarse_edge - 2 - i;
1639 const float u = 0.0f;
1640 const float v = du * (i + 1);
1644 ptex_face_index +
corner,
1664 prev_coarse_loop = coarse_loop;
1671 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1672 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
1673 if (coarse_poly->
totloop == 4) {
1693 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1694 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
1698 const int num_loops_per_ptex = 4 * num_polys_per_ptex;
1699 const int start_loop_index = 4 * start_poly_index;
1701 int subdiv_polyon_index = start_poly_index;
1702 for (
int ptex_of_poly_index = 0; ptex_of_poly_index < num_ptex_faces_per_poly;
1703 ptex_of_poly_index++) {
1704 for (
int subdiv_poly_index = 0; subdiv_poly_index < num_polys_per_ptex;
1705 subdiv_poly_index++, subdiv_polyon_index++) {
1706 const int loopstart = start_loop_index + (ptex_of_poly_index * num_loops_per_ptex) +
1707 (subdiv_poly_index * 4);
1709 ctx->
foreach_context, tls, poly_index, subdiv_polyon_index, loopstart, 4);
1721 const int coarse_vertex_index,
1731 ctx->
foreach_context, tls->userdata_chunk, coarse_vertex_index, subdiv_vertex_index);
1735 const int coarse_edge_index,
1744 const int resolution_1 = resolution - 1;
1745 const float inv_resolution_1 = 1.0f / (
float)resolution_1;
1746 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
1748 const MEdge *coarse_edge = &coarse_mesh->
medge[coarse_edge_index];
1754 coarse_edge_index * num_subdiv_vertices_per_coarse_edge;
1756 for (
int i = 0; i < resolution; i++) {
1757 const float u = i * inv_resolution_1;
1758 int subdiv_vertex_index;
1760 subdiv_vertex_index = subdiv_v1_index;
1762 else if (i == resolution - 1) {
1763 subdiv_vertex_index = subdiv_v2_index;
1766 subdiv_vertex_index = subdiv_start_vertex + (i - 1);
1769 ctx->
foreach_context, tls->userdata_chunk, coarse_edge_index, u, subdiv_vertex_index);
1785 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1786 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
1787 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
1796 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1797 const MLoop *coarse_mloop = coarse_mesh->
mloop;
1798 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
1799 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
1825 const bool is_loose_geometry_tags_needed = (foreach_context->
vertex_loose !=
NULL ||
1827 if (is_loose_geometry_tagged && is_loose_geometry_tags_needed) {
1833 const int poly_index,
1852 const int edge_index,
1868 const Mesh *coarse_mesh)
1910 ¶llel_range_settings);
1917 ¶llel_range_settings);
1924 ¶llel_range_settings);
typedef float(TangentPoint)[2]
CustomData interface, see also DNA_customdata_types.h.
int * BKE_subdiv_face_ptex_offset_get(Subdiv *subdiv)
void(* SubdivForeachVertexFromEdgeCb)(const struct SubdivForeachContext *context, void *tls, const int ptex_face_index, const float u, const float v, const int coarse_edge_index, const int coarse_poly_index, const int coarse_corner, const int subdiv_vertex_index)
void(* SubdivForeachVertexFromCornerCb)(const struct SubdivForeachContext *context, void *tls, const int ptex_face_index, const float u, const float v, const int coarse_vertex_index, const int coarse_poly_index, const int coarse_corner, const int subdiv_vertex_index)
#define BLI_BITMAP_ENABLE(_bitmap, _index)
#define BLI_BITMAP_TEST_BOOL(_bitmap, _index)
#define BLI_BITMAP_NEW(_tot, _alloc_string)
void BLI_bitmap_set_all(BLI_bitmap *bitmap, bool set, size_t bits)
#define BLI_BITMAP_TEST_AND_SET_ATOMIC(_bitmap, _index)
void BLI_task_parallel_range(const int start, const int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
Read Guarded memory(de)allocation.
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
struct SELECTID_Context context
SubdivForeachVertexFromEdgeCb vertex_every_edge
SubdivForeachPolygonCb poly
size_t user_data_tls_size
SubdivForeachLooseCb vertex_loose
SubdivForeachVertexInnerCb vertex_inner
SubdivForeachVertexOfLooseEdgeCb vertex_of_loose_edge
void(* user_data_tls_free)(void *tls)
SubdivForeachVertexFromEdgeCb vertex_edge
SubdivForeachVertexFromCornerCb vertex_corner
SubdivForeachVertexFromCornerCb vertex_every_corner
int vertices_inner_offset
int * subdiv_vertex_offset
BLI_bitmap * coarse_edges_used_map
BLI_bitmap * coarse_vertices_used_map
const SubdivToMeshSettings * settings
const SubdivForeachContext * foreach_context
int * subdiv_polygon_offset
int vertices_corner_offset
TaskParallelFreeFunc func_free
size_t userdata_chunk_size
static void subdiv_foreach_edge_vertices(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static int subdiv_foreach_edges_row(SubdivForeachTaskContext *ctx, void *tls, const int coarse_edge_index, const int start_subdiv_edge_index, const int start_vertex_index, const int num_edges_per_row)
static void subdiv_foreach_inner_vertices_special(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_edge_vertices_special_do(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly, SubdivForeachVertexFromEdgeCb vertex_edge, bool check_usage)
static void subdiv_foreach_edge_vertices_special(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_ctx_free(SubdivForeachTaskContext *ctx)
static void subdiv_foreach_task(void *__restrict userdata, const int poly_index, const TaskParallelTLS *__restrict tls)
static void subdiv_foreach_single_geometry_vertices(SubdivForeachTaskContext *ctx, void *tls)
static void subdiv_foreach_loops_of_poly(SubdivForeachTaskContext *ctx, void *tls, int subdiv_loop_start_index, const int ptex_face_index, const int coarse_poly_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_every_edge_vertices_special(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_corner_vertices_regular_do(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly, SubdivForeachVertexFromCornerCb vertex_corner, bool check_usage)
static void subdiv_foreach_vertices_of_loose_edges_task(void *__restrict userdata, const int coarse_edge_index, const TaskParallelTLS *__restrict tls)
BLI_INLINE int num_polys_per_ptex_get(const int resolution)
static int subdiv_foreach_loops_corner_index(const float u, const float v, const float du, const float dv)
struct SubdivForeachTaskContext SubdivForeachTaskContext
static void subdiv_foreach_every_corner_vertices_special(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_inner_vertices(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_every_edge_vertices(SubdivForeachTaskContext *ctx, void *tls)
static void subdiv_foreach_vertices(SubdivForeachTaskContext *ctx, void *tls, const int poly_index)
static void subdiv_foreach_ctx_init_offsets(SubdivForeachTaskContext *ctx)
static void subdiv_foreach_edges_all_patches_special(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_corner_vertices_special_do(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly, SubdivForeachVertexFromCornerCb vertex_corner, bool check_usage)
static void subdiv_foreach_free(const void *__restrict userdata, void *__restrict userdata_chunk)
static void subdiv_foreach_corner_vertices_special(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_corner_vertices(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_ctx_count(SubdivForeachTaskContext *ctx)
static void subdiv_foreach_every_corner_vertices(SubdivForeachTaskContext *ctx, void *tls)
static void subdiv_foreach_loops(SubdivForeachTaskContext *ctx, void *tls, int poly_index)
static void rotate_indices(const int rot, int *a, int *b, int *c, int *d)
static void subdiv_foreach_edge_vertices_regular_do(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly, SubdivForeachVertexFromEdgeCb vertex_edge, bool check_usage)
bool BKE_subdiv_foreach_subdiv_geometry(Subdiv *subdiv, const SubdivForeachContext *context, const SubdivToMeshSettings *mesh_settings, const Mesh *coarse_mesh)
static void subdiv_foreach_boundary_edges_task(void *__restrict userdata, const int edge_index, const TaskParallelTLS *__restrict tls)
static void subdiv_foreach_boundary_edges(SubdivForeachTaskContext *ctx, void *tls, int coarse_edge_index)
static void subdiv_foreach_every_corner_vertices_regular(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_edge_vertices_regular(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_loose_vertices_task(void *__restrict userdata, const int coarse_vertex_index, const TaskParallelTLS *__restrict tls)
static void subdiv_foreach_tls_free(SubdivForeachTaskContext *ctx, void *tls)
BLI_INLINE int ptex_face_resolution_get(const MPoly *poly, int resolution)
static void subdiv_foreach_polys(SubdivForeachTaskContext *ctx, void *tls, int poly_index)
static void subdiv_foreach_inner_vertices_regular(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_edges_all_patches(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_every_edge_vertices_regular(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_single_thread_tasks(SubdivForeachTaskContext *ctx)
static void subdiv_foreach_ctx_init(Subdiv *subdiv, SubdivForeachTaskContext *ctx)
BLI_INLINE int num_edges_per_ptex_face_get(const int resolution)
static void subdiv_foreach_loops_regular(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_edges_all_patches_regular(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void subdiv_foreach_loops_special(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
BLI_INLINE int num_ptex_faces_per_poly_get(const MPoly *poly)
static void subdiv_foreach_corner_vertices_regular(SubdivForeachTaskContext *ctx, void *tls, const MPoly *coarse_poly)
static void * subdiv_foreach_tls_alloc(SubdivForeachTaskContext *ctx)
static int subdiv_foreach_edges_column(SubdivForeachTaskContext *ctx, void *tls, const int coarse_start_edge_index, const int coarse_end_edge_index, const int start_subdiv_edge_index, const int start_vertex_index, const int num_edges_per_row)
BLI_INLINE int num_inner_edges_per_ptex_face_get(const int resolution)
static void subdiv_foreach_edges(SubdivForeachTaskContext *ctx, void *tls, int poly_index)
static void subdiv_foreach_mark_non_loose_geometry(SubdivForeachTaskContext *ctx)