39 return 2 * (resolution - 1) * resolution;
47 return (resolution - 2) * resolution + (resolution - 1) * (resolution - 1);
53 return (resolution - 1) * (resolution - 1);
59 return (poly->
totloop == 4) ? (resolution) : ((resolution >> 1) + 1);
155 const int no_quad_patch_resolution = ((resolution >> 1) + 1);
156 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
157 const int num_inner_vertices_per_quad = (resolution - 2) * (resolution - 2);
158 const int num_inner_vertices_per_noquad_patch = (no_quad_patch_resolution - 2) *
159 (no_quad_patch_resolution - 2);
161 const MLoop *coarse_mloop = coarse_mesh->
mloop;
162 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
166 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
167 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
179 if (num_ptex_faces_per_poly == 1) {
182 4 * num_subdiv_vertices_per_coarse_edge;
187 num_ptex_faces_per_poly * num_inner_vertices_per_noquad_patch;
190 (no_quad_patch_resolution - 2) +
191 num_subdiv_vertices_per_coarse_edge);
192 if (no_quad_patch_resolution >= 3) {
200 for (
int edge_index = 0; edge_index < coarse_mesh->
totedge; edge_index++) {
212 const int resolution_2 = resolution - 2;
213 const int resolution_2_squared = resolution_2 * resolution_2;
214 const int no_quad_patch_resolution = ((resolution >> 1) + 1);
215 const int num_irregular_vertices_per_patch = (no_quad_patch_resolution - 2) *
216 (no_quad_patch_resolution - 1);
217 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
218 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
223 coarse_mesh->
totedge * num_subdiv_vertices_per_coarse_edge;
226 coarse_mesh->
totedge * num_subdiv_edges_per_coarse_edge;
228 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
229 int vertex_offset = 0;
231 int polygon_offset = 0;
232 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
233 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
238 if (num_ptex_faces_per_poly == 1) {
239 vertex_offset += resolution_2_squared;
241 4 * num_subdiv_vertices_per_coarse_edge;
245 vertex_offset += 1 + num_ptex_faces_per_poly * num_irregular_vertices_per_patch;
246 edge_offset += num_ptex_faces_per_poly *
248 (no_quad_patch_resolution - 2) + num_subdiv_vertices_per_coarse_edge);
249 if (no_quad_patch_resolution >= 3) {
250 edge_offset += coarse_poly->
totloop;
298 const MPoly *coarse_poly,
302 const float weights[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
304 const MLoop *coarse_mloop = coarse_mesh->
mloop;
305 const int coarse_poly_index = coarse_poly - coarse_mesh->
mpoly;
313 const int coarse_vertex_index = coarse_loop->
v;
315 const float u = weights[
corner][0];
316 const float v = weights[
corner][1];
325 subdiv_vertex_index);
331 const MPoly *coarse_poly)
340 const MPoly *coarse_poly,
345 const MLoop *coarse_mloop = coarse_mesh->
mloop;
346 const int coarse_poly_index = coarse_poly - coarse_mesh->
mpoly;
354 const int coarse_vertex_index = coarse_loop->
v;
364 subdiv_vertex_index);
370 const MPoly *coarse_poly)
378 const MPoly *coarse_poly)
380 if (coarse_poly->
totloop == 4) {
390 const MPoly *coarse_poly)
398 const MPoly *coarse_poly)
410 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
411 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
412 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
413 if (coarse_poly->
totloop == 4) {
426 const MPoly *coarse_poly,
431 const int resolution_1 = resolution - 1;
432 const float inv_resolution_1 = 1.0f / (
float)resolution_1;
433 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
435 const MEdge *coarse_medge = coarse_mesh->
medge;
436 const MLoop *coarse_mloop = coarse_mesh->
mloop;
437 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
438 const int coarse_poly_index = coarse_poly - coarse_mpoly;
439 const int poly_index = coarse_poly - coarse_mesh->
mpoly;
443 const int coarse_edge_index = coarse_loop->
e;
448 const MEdge *coarse_edge = &coarse_medge[coarse_edge_index];
449 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
451 coarse_edge_index * num_subdiv_vertices_per_coarse_edge;
452 for (
int vertex_index = 0; vertex_index < num_subdiv_vertices_per_coarse_edge;
453 vertex_index++, subdiv_vertex_index++) {
454 float fac = (vertex_index + 1) * inv_resolution_1;
464 v = (
corner == 2) ? 1.0f : 0.0f;
467 u = (
corner == 1) ? 1.0f : 0.0f;
478 subdiv_vertex_index);
485 const MPoly *coarse_poly)
493 const MPoly *coarse_poly,
498 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
499 const int num_vertices_per_ptex_edge = ((resolution >> 1) + 1);
500 const float inv_ptex_resolution_1 = 1.0f / (
float)(num_vertices_per_ptex_edge - 1);
502 const MEdge *coarse_medge = coarse_mesh->
medge;
503 const MLoop *coarse_mloop = coarse_mesh->
mloop;
504 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
505 const int coarse_poly_index = coarse_poly - coarse_mpoly;
506 const int poly_index = coarse_poly - coarse_mesh->
mpoly;
508 int ptex_face_index = ptex_face_start_index;
511 const int coarse_edge_index = coarse_loop->
e;
516 const MEdge *coarse_edge = &coarse_medge[coarse_edge_index];
517 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
519 coarse_edge_index * num_subdiv_vertices_per_coarse_edge;
520 int vertex_delta = 1;
522 subdiv_vertex_index += num_subdiv_vertices_per_coarse_edge - 1;
525 for (
int vertex_index = 1; vertex_index < num_vertices_per_ptex_edge;
526 vertex_index++, subdiv_vertex_index += vertex_delta) {
527 const float u = vertex_index * inv_ptex_resolution_1;
536 subdiv_vertex_index);
539 const int next_ptex_face_index = ptex_face_start_index + next_corner;
540 for (
int vertex_index = 1; vertex_index < num_vertices_per_ptex_edge - 1;
541 vertex_index++, subdiv_vertex_index += vertex_delta) {
542 const float v = 1.0f - vertex_index * inv_ptex_resolution_1;
545 next_ptex_face_index,
551 subdiv_vertex_index);
558 const MPoly *coarse_poly)
566 const MPoly *coarse_poly)
568 if (coarse_poly->
totloop == 4) {
578 const MPoly *coarse_poly)
586 const MPoly *coarse_poly)
598 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
599 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
600 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
601 if (coarse_poly->
totloop == 4) {
614 const MPoly *coarse_poly)
617 const float inv_resolution_1 = 1.0f / (
float)(resolution - 1);
619 const int coarse_poly_index = coarse_poly - coarse_mesh->
mpoly;
623 for (
int y = 1;
y < resolution - 1;
y++) {
624 const float v =
y * inv_resolution_1;
625 for (
int x = 1;
x < resolution - 1;
x++, subdiv_vertex_index++) {
626 const float u =
x * inv_resolution_1;
634 subdiv_vertex_index);
641 const MPoly *coarse_poly)
645 const float inv_ptex_face_resolution_1 = 1.0f / (
float)(ptex_face_resolution - 1);
647 const int coarse_poly_index = coarse_poly - coarse_mesh->
mpoly;
658 subdiv_vertex_index);
659 subdiv_vertex_index++;
661 for (
int y = 1;
y < ptex_face_resolution - 1;
y++) {
662 const float v =
y * inv_ptex_face_resolution_1;
663 for (
int x = 1;
x < ptex_face_resolution;
x++, subdiv_vertex_index++) {
664 const float u =
x * inv_ptex_face_resolution_1;
672 subdiv_vertex_index);
680 const MPoly *coarse_poly)
682 if (coarse_poly->
totloop == 4) {
694 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
695 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
710 const int coarse_edge_index,
711 const int start_subdiv_edge_index,
712 const int start_vertex_index,
713 const int num_edges_per_row)
715 int subdiv_edge_index = start_subdiv_edge_index;
716 int vertex_index = start_vertex_index;
717 for (
int edge_index = 0; edge_index < num_edges_per_row - 1; edge_index++, subdiv_edge_index++) {
718 const int v1 = vertex_index;
719 const int v2 = vertex_index + 1;
724 return subdiv_edge_index;
730 const int coarse_start_edge_index,
731 const int coarse_end_edge_index,
732 const int start_subdiv_edge_index,
733 const int start_vertex_index,
734 const int num_edges_per_row)
736 int subdiv_edge_index = start_subdiv_edge_index;
737 int vertex_index = start_vertex_index;
738 for (
int edge_index = 0; edge_index < num_edges_per_row; edge_index++, subdiv_edge_index++) {
740 if (edge_index == 0) {
741 coarse_edge_index = coarse_start_edge_index;
743 else if (edge_index == num_edges_per_row - 1) {
744 coarse_edge_index = coarse_end_edge_index;
746 const int v1 = vertex_index;
747 const int v2 = vertex_index + num_edges_per_row;
752 return subdiv_edge_index;
775 const MPoly *coarse_poly)
778 const MEdge *coarse_medge = coarse_mesh->
medge;
779 const MLoop *coarse_mloop = coarse_mesh->
mloop;
780 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
781 const int poly_index = coarse_poly - coarse_mpoly;
785 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
789 ctx, tls,
ORIGINDEX_NONE, subdiv_edge_index, start_vertex_index, resolution - 2);
791 for (
int row = 0; row < resolution - 3; row++) {
792 const int start_row_vertex_index = start_vertex_index + row * (resolution - 2);
803 start_row_vertex_index,
814 start_row_vertex_index + resolution - 2,
820 const MEdge *coarse_edge = &coarse_medge[coarse_loop->
e];
822 coarse_loop->
e * num_subdiv_vertices_per_coarse_edge;
823 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
824 int side_start_index = start_vertex_index;
831 side_start_index += resolution - 3;
832 side_stride = resolution - 2;
835 side_start_index += num_subdiv_vertices_per_coarse_edge *
836 num_subdiv_vertices_per_coarse_edge -
841 side_start_index += num_subdiv_vertices_per_coarse_edge *
842 (num_subdiv_vertices_per_coarse_edge - 1);
843 side_stride = -(resolution - 2);
845 for (
int i = 0; i < resolution - 2; i++, subdiv_edge_index++) {
846 const int v1 = (flip) ? (start_edge_vertex + (resolution - i - 3)) : (start_edge_vertex + i);
847 const int v2 = side_start_index + side_stride * i;
856 const MPoly *coarse_poly)
859 const MEdge *coarse_medge = coarse_mesh->
medge;
860 const MLoop *coarse_mloop = coarse_mesh->
mloop;
861 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
862 const int poly_index = coarse_poly - coarse_mpoly;
865 const int ptex_face_inner_resolution = ptex_face_resolution - 2;
866 const int num_inner_vertices_per_ptex = (ptex_face_resolution - 1) * (ptex_face_resolution - 2);
867 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
870 const int start_vertex_index = center_vertex_index + 1;
874 const int start_ptex_face_vertex_index = start_vertex_index +
875 corner * num_inner_vertices_per_ptex;
881 start_ptex_face_vertex_index,
882 ptex_face_inner_resolution + 1);
883 for (
int row = 0; row < ptex_face_inner_resolution - 1; row++) {
884 const int start_row_vertex_index = start_ptex_face_vertex_index +
885 row * (ptex_face_inner_resolution + 1);
891 start_row_vertex_index,
892 ptex_face_inner_resolution + 1);
897 start_row_vertex_index +
898 ptex_face_inner_resolution + 1,
899 ptex_face_inner_resolution + 1);
905 int current_patch_vertex_index = start_vertex_index +
corner * num_inner_vertices_per_ptex +
906 ptex_face_inner_resolution;
907 int next_path_vertex_index = start_vertex_index + next_corner * num_inner_vertices_per_ptex +
908 num_inner_vertices_per_ptex - ptex_face_resolution + 1;
909 for (
int row = 0; row < ptex_face_inner_resolution; row++, subdiv_edge_index++) {
910 const int v1 = current_patch_vertex_index;
911 const int v2 = next_path_vertex_index;
914 current_patch_vertex_index += ptex_face_inner_resolution + 1;
915 next_path_vertex_index += 1;
919 if (ptex_face_resolution >= 3) {
921 const int current_patch_end_vertex_index = start_vertex_index +
922 corner * num_inner_vertices_per_ptex +
923 num_inner_vertices_per_ptex - 1;
924 const int v1 = center_vertex_index;
925 const int v2 = current_patch_end_vertex_index;
935 const MEdge *coarse_edge = &coarse_medge[coarse_loop->
e];
937 coarse_loop->
e * num_subdiv_vertices_per_coarse_edge;
938 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
939 int side_start_index;
940 if (ptex_face_resolution >= 3) {
941 side_start_index = start_vertex_index + num_inner_vertices_per_ptex *
corner;
944 side_start_index = center_vertex_index;
946 for (
int i = 0; i < ptex_face_resolution - 1; i++, subdiv_edge_index++) {
947 const int v1 = (flip) ? (start_edge_vertex + (resolution - i - 3)) :
948 (start_edge_vertex + i);
949 const int v2 = side_start_index + i;
954 if (ptex_face_resolution >= 3) {
955 const MEdge *coarse_edge = &coarse_medge[prev_coarse_loop->
e];
957 prev_coarse_loop->
e * num_subdiv_vertices_per_coarse_edge;
958 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
959 int side_start_index = start_vertex_index + num_inner_vertices_per_ptex *
corner;
960 for (
int i = 0; i < ptex_face_resolution - 2; i++, subdiv_edge_index++) {
961 const int v1 = (flip) ? (start_edge_vertex + (resolution - i - 3)) :
962 (start_edge_vertex + i);
963 const int v2 = side_start_index + (ptex_face_inner_resolution + 1) * i;
968 prev_coarse_loop = coarse_loop;
974 const MPoly *coarse_poly)
976 if (coarse_poly->
totloop == 4) {
987 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
988 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
994 int coarse_edge_index)
997 const MEdge *coarse_medge = coarse_mesh->
medge;
998 const MEdge *coarse_edge = &coarse_medge[coarse_edge_index];
1000 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
1001 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
1005 coarse_edge_index * num_subdiv_edges_per_coarse_edge;
1007 for (
int i = 0; i < num_subdiv_edges_per_coarse_edge - 1; i++, subdiv_edge_index++) {
1008 const int v1 = last_vertex_index;
1010 coarse_edge_index * num_subdiv_vertices_per_coarse_edge + i;
1013 last_vertex_index =
v2;
1015 const int v1 = last_vertex_index;
1029 const int values[4] = {*
a, *
b, *
c, *d};
1030 *
a = values[(0 -
rot + 4) % 4];
1031 *
b = values[(1 -
rot + 4) % 4];
1032 *
c = values[(2 -
rot + 4) % 4];
1033 *d = values[(3 -
rot + 4) % 4];
1038 int subdiv_loop_start_index,
1039 const int ptex_face_index,
1040 const int coarse_poly_index,
1041 const int coarse_corner_index,
1065 coarse_corner_index,
1066 subdiv_loop_start_index + 0,
1076 coarse_corner_index,
1077 subdiv_loop_start_index + 1,
1087 coarse_corner_index,
1088 subdiv_loop_start_index + 2,
1098 coarse_corner_index,
1099 subdiv_loop_start_index + 3,
1109 if (u + du <= 0.5f &&
v + dv <= 0.5f) {
1112 if (u >= 0.5f &&
v + dv <= 0.5f) {
1115 if (u >= 0.5f &&
v >= 0.5f) {
1123 const MPoly *coarse_poly)
1128 const MEdge *coarse_medge = coarse_mesh->
medge;
1129 const MLoop *coarse_mloop = coarse_mesh->
mloop;
1130 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1131 const int coarse_poly_index = coarse_poly - coarse_mpoly;
1133 const int ptex_inner_resolution = ptex_resolution - 2;
1134 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
1135 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
1136 const float inv_ptex_resolution_1 = 1.0f / (
float)(ptex_resolution - 1);
1142 const int start_loop_index = 4 * start_poly_index;
1143 const float du = inv_ptex_resolution_1;
1144 const float dv = inv_ptex_resolution_1;
1146 int subdiv_loop_index = start_loop_index;
1148 for (
int y = 1;
y < ptex_resolution - 2;
y++) {
1149 const float v =
y * inv_ptex_resolution_1;
1150 const int inner_y =
y - 1;
1151 for (
int x = 1;
x < ptex_resolution - 2;
x++, subdiv_loop_index += 4) {
1152 const int inner_x =
x - 1;
1153 const float u =
x * inv_ptex_resolution_1;
1155 const int v0 = start_vertex_index + (inner_y * ptex_inner_resolution + inner_x);
1156 const int v1 = v0 + 1;
1157 const int v2 = v0 + ptex_inner_resolution + 1;
1158 const int v3 = v0 + ptex_inner_resolution;
1160 const int e0 = start_edge_index + (inner_y * (2 * ptex_inner_resolution - 1) + inner_x);
1161 const int e1 = e0 + ptex_inner_resolution;
1162 const int e2 = e0 + (2 * ptex_inner_resolution - 1);
1163 const int e3 = e0 + ptex_inner_resolution - 1;
1190 const MEdge *coarse_edge = &coarse_medge[coarse_loop->
e];
1191 const MEdge *prev_coarse_edge = &coarse_medge[prev_coarse_loop->
e];
1193 coarse_loop->
e * num_subdiv_vertices_per_coarse_edge;
1194 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
1195 int side_start_index = start_vertex_index;
1196 int side_stride = 0;
1199 int e2_offset, e2_stride;
1200 float u,
v, delta_u, delta_v;
1201 if (prev_coarse_loop->
v == prev_coarse_edge->
v1) {
1203 num_subdiv_vertices_per_coarse_edge - 1;
1205 num_subdiv_edges_per_coarse_edge - 1;
1222 side_start_index += resolution - 3;
1223 side_stride = resolution - 2;
1224 e2_offset = 2 * num_subdiv_edges_per_coarse_edge - 4;
1225 e2_stride = 2 * num_subdiv_edges_per_coarse_edge - 3;
1232 side_start_index += num_subdiv_vertices_per_coarse_edge *
1233 num_subdiv_vertices_per_coarse_edge -
1244 side_start_index += num_subdiv_vertices_per_coarse_edge *
1245 (num_subdiv_vertices_per_coarse_edge - 1);
1246 side_stride = -(resolution - 2);
1248 (2 * num_subdiv_edges_per_coarse_edge - 3);
1249 e2_stride = -(2 * num_subdiv_edges_per_coarse_edge - 3);
1255 for (
int i = 0; i < resolution - 2; i++, subdiv_loop_index += 4) {
1258 v1 = start_edge_vertex + (resolution - i - 3);
1261 v1 = start_edge_vertex + i;
1263 const int v2 = side_start_index + side_stride * i;
1267 num_subdiv_edges_per_coarse_edge - i - 1;
1273 corner * num_subdiv_vertices_per_coarse_edge + i;
1278 num_subdiv_vertices_per_coarse_edge +
1279 num_subdiv_vertices_per_coarse_edge - 1;
1282 e2 = start_edge_index + e2_offset + e2_stride * (i - 1);
1285 const float loop_u = u + delta_u * i;
1286 const float loop_v =
v + delta_v * i;
1311 prev_coarse_loop = coarse_loop;
1317 const MPoly *coarse_poly)
1322 const MEdge *coarse_medge = coarse_mesh->
medge;
1323 const MLoop *coarse_mloop = coarse_mesh->
mloop;
1324 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1325 const int coarse_poly_index = coarse_poly - coarse_mpoly;
1327 const int ptex_face_inner_resolution = ptex_face_resolution - 2;
1328 const float inv_ptex_resolution_1 = 1.0f / (
float)(ptex_face_resolution - 1);
1329 const int num_inner_vertices_per_ptex = (ptex_face_resolution - 1) * (ptex_face_resolution - 2);
1331 ptex_face_inner_resolution + 1);
1332 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
1333 const int num_subdiv_edges_per_coarse_edge = resolution - 1;
1337 const int start_vertex_index = center_vertex_index + 1;
1338 const int start_inner_vertex_index = center_vertex_index + 1;
1341 const int start_loop_index = 4 * start_poly_index;
1342 const float du = inv_ptex_resolution_1;
1343 const float dv = inv_ptex_resolution_1;
1345 int subdiv_loop_index = start_loop_index;
1347 const int corner_vertex_index = start_vertex_index +
corner * num_inner_vertices_per_ptex;
1348 const int corner_edge_index = start_edge_index +
corner * num_inner_edges_per_ptex_face;
1349 for (
int y = 1;
y < ptex_face_inner_resolution;
y++) {
1350 const float v =
y * inv_ptex_resolution_1;
1351 const int inner_y =
y - 1;
1352 for (
int x = 1;
x < ptex_face_inner_resolution + 1;
x++, subdiv_loop_index += 4) {
1353 const int inner_x =
x - 1;
1354 const float u =
x * inv_ptex_resolution_1;
1356 const int v0 = corner_vertex_index +
1357 (inner_y * (ptex_face_inner_resolution + 1) + inner_x);
1358 const int v1 = v0 + 1;
1359 const int v2 = v0 + ptex_face_inner_resolution + 2;
1360 const int v3 = v0 + ptex_face_inner_resolution + 1;
1362 const int e0 = corner_edge_index +
1363 (inner_y * (2 * ptex_face_inner_resolution + 1) + inner_x);
1364 const int e1 = e0 + ptex_face_inner_resolution + 1;
1365 const int e2 = e0 + (2 * ptex_face_inner_resolution + 1);
1366 const int e3 = e0 + ptex_face_inner_resolution;
1370 ptex_face_index +
corner,
1391 const int next_corner = (
corner + 1) % coarse_poly->
totloop;
1392 const int corner_edge_index = start_edge_index +
corner * num_inner_edges_per_ptex_face;
1393 const int next_corner_edge_index = start_edge_index +
1394 next_corner * num_inner_edges_per_ptex_face;
1395 int current_patch_vertex_index = start_inner_vertex_index +
1396 corner * num_inner_vertices_per_ptex +
1397 ptex_face_inner_resolution;
1398 int next_path_vertex_index = start_inner_vertex_index +
1399 next_corner * num_inner_vertices_per_ptex +
1400 num_inner_vertices_per_ptex - ptex_face_resolution + 1;
1401 int v0 = current_patch_vertex_index;
1402 int v1 = next_path_vertex_index;
1403 current_patch_vertex_index += ptex_face_inner_resolution + 1;
1404 next_path_vertex_index += 1;
1405 int e0 = start_edge_index + coarse_poly->
totloop * num_inner_edges_per_ptex_face +
1406 corner * (ptex_face_resolution - 2);
1407 int e1 = next_corner_edge_index + num_inner_edges_per_ptex_face - ptex_face_resolution + 2;
1408 int e3 = corner_edge_index + 2 * ptex_face_resolution - 4;
1409 for (
int row = 1; row < ptex_face_inner_resolution; row++, subdiv_loop_index += 4) {
1410 const int v2 = next_path_vertex_index;
1411 const int v3 = current_patch_vertex_index;
1412 const int e2 = e0 + 1;
1413 const float u = row * du;
1414 const float v = 1.0f - dv;
1418 ptex_face_index + next_corner,
1434 current_patch_vertex_index += ptex_face_inner_resolution + 1;
1435 next_path_vertex_index += 1;
1440 e3 += 2 * ptex_face_resolution - 3;
1444 if (ptex_face_resolution >= 3) {
1445 const int start_center_edge_index = start_edge_index + (num_inner_edges_per_ptex_face +
1446 ptex_face_inner_resolution) *
1448 const int start_boundary_edge = start_edge_index +
1449 coarse_poly->
totloop * num_inner_edges_per_ptex_face +
1450 ptex_face_inner_resolution - 1;
1452 prev_corner =
corner,
corner++, subdiv_loop_index += 4) {
1453 const int corner_edge_index = start_edge_index +
corner * num_inner_edges_per_ptex_face;
1454 const int current_patch_end_vertex_index = start_vertex_index +
1455 corner * num_inner_vertices_per_ptex +
1456 num_inner_vertices_per_ptex - 1;
1457 const int prev_current_patch_end_vertex_index = start_vertex_index +
1458 prev_corner * num_inner_vertices_per_ptex +
1459 num_inner_vertices_per_ptex - 1;
1460 const int v0 = center_vertex_index;
1461 const int v1 = prev_current_patch_end_vertex_index;
1462 const int v2 = current_patch_end_vertex_index - 1;
1463 const int v3 = current_patch_end_vertex_index;
1464 const int e0 = start_center_edge_index + prev_corner;
1465 const int e1 = start_boundary_edge + prev_corner * (ptex_face_inner_resolution);
1466 const int e2 = corner_edge_index + num_inner_edges_per_ptex_face - 1;
1467 const int e3 = start_center_edge_index +
corner;
1468 const float u = 1.0f - du;
1469 const float v = 1.0f - dv;
1473 ptex_face_index +
corner,
1496 const MEdge *coarse_edge = &coarse_medge[coarse_loop->
e];
1497 const MEdge *prev_coarse_edge = &coarse_medge[prev_coarse_loop->
e];
1498 const bool flip = (coarse_edge->
v2 == coarse_loop->
v);
1500 coarse_loop->
e * num_subdiv_vertices_per_coarse_edge;
1501 const int corner_vertex_index = start_vertex_index +
corner * num_inner_vertices_per_ptex;
1502 const int corner_edge_index = start_edge_index +
corner * num_inner_edges_per_ptex_face;
1506 if (prev_coarse_loop->
v == prev_coarse_edge->
v1) {
1508 num_subdiv_vertices_per_coarse_edge - 1;
1510 num_subdiv_edges_per_coarse_edge - 1;
1516 for (
int i = 0; i <= ptex_face_inner_resolution; i++, subdiv_loop_index += 4) {
1519 v1 = start_edge_vertex + (resolution - i - 3);
1522 v1 = start_edge_vertex + i;
1525 if (ptex_face_inner_resolution >= 1) {
1526 v2 = corner_vertex_index + i;
1529 v2 = center_vertex_index;
1534 num_subdiv_edges_per_coarse_edge - i - 1;
1539 int e1 = start_edge_index +
corner * (2 * ptex_face_inner_resolution + 1);
1540 if (ptex_face_resolution >= 3) {
1542 (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1546 if (i == 0 && ptex_face_resolution >= 3) {
1547 e2 = start_edge_index +
1549 (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1550 corner * (2 * ptex_face_inner_resolution + 1) + ptex_face_inner_resolution + 1;
1552 else if (i == 0 && ptex_face_resolution < 3) {
1553 e2 = start_edge_index + prev_corner * (2 * ptex_face_inner_resolution + 1);
1556 e2 = corner_edge_index + i - 1;
1558 const float u = du * i;
1559 const float v = 0.0f;
1563 ptex_face_index +
corner,
1584 const bool flip_prev = (prev_coarse_edge->
v2 == coarse_loop->
v);
1585 v0 = corner_vertex_index;
1586 if (prev_coarse_loop->
v == prev_coarse_edge->
v1) {
1588 num_subdiv_vertices_per_coarse_edge - 1;
1593 e3 = start_edge_index +
1594 coarse_poly->
totloop * (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1595 corner * (2 * ptex_face_inner_resolution + 1) + ptex_face_inner_resolution + 1;
1596 for (
int i = 0; i <= ptex_face_inner_resolution - 1; i++, subdiv_loop_index += 4) {
1599 if (i == ptex_face_inner_resolution - 1) {
1600 v1 = start_vertex_index + prev_corner * num_inner_vertices_per_ptex +
1601 ptex_face_inner_resolution;
1602 e1 = start_edge_index +
1604 (num_inner_edges_per_ptex_face + ptex_face_inner_resolution + 1) +
1605 prev_corner * (2 * ptex_face_inner_resolution + 1) + ptex_face_inner_resolution;
1606 e0 = start_edge_index + coarse_poly->
totloop * num_inner_edges_per_ptex_face +
1607 prev_corner * ptex_face_inner_resolution;
1610 v1 = v0 + ptex_face_inner_resolution + 1;
1611 e0 = corner_edge_index + ptex_face_inner_resolution +
1612 i * (2 * ptex_face_inner_resolution + 1);
1615 int v2 = flip_prev ? v3 - 1 : v3 + 1;
1619 num_subdiv_edges_per_coarse_edge - 2 - i;
1625 const float u = 0.0f;
1626 const float v = du * (i + 1);
1630 ptex_face_index +
corner,
1650 prev_coarse_loop = coarse_loop;
1657 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1658 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
1659 if (coarse_poly->
totloop == 4) {
1679 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1680 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
1684 const int num_loops_per_ptex = 4 * num_polys_per_ptex;
1685 const int start_loop_index = 4 * start_poly_index;
1687 int subdiv_polyon_index = start_poly_index;
1688 for (
int ptex_of_poly_index = 0; ptex_of_poly_index < num_ptex_faces_per_poly;
1689 ptex_of_poly_index++) {
1690 for (
int subdiv_poly_index = 0; subdiv_poly_index < num_polys_per_ptex;
1691 subdiv_poly_index++, subdiv_polyon_index++) {
1692 const int loopstart = start_loop_index + (ptex_of_poly_index * num_loops_per_ptex) +
1693 (subdiv_poly_index * 4);
1695 ctx->
foreach_context, tls, poly_index, subdiv_polyon_index, loopstart, 4);
1707 const int coarse_vertex_index,
1717 ctx->
foreach_context, tls->userdata_chunk, coarse_vertex_index, subdiv_vertex_index);
1721 const int coarse_edge_index,
1730 const int resolution_1 = resolution - 1;
1731 const float inv_resolution_1 = 1.0f / (
float)resolution_1;
1732 const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
1734 const MEdge *coarse_edge = &coarse_mesh->
medge[coarse_edge_index];
1740 coarse_edge_index * num_subdiv_vertices_per_coarse_edge;
1742 for (
int i = 0; i < resolution; i++) {
1743 const float u = i * inv_resolution_1;
1744 int subdiv_vertex_index;
1746 subdiv_vertex_index = subdiv_v1_index;
1748 else if (i == resolution - 1) {
1749 subdiv_vertex_index = subdiv_v2_index;
1752 subdiv_vertex_index = subdiv_start_vertex + (i - 1);
1755 ctx->
foreach_context, tls->userdata_chunk, coarse_edge_index, u, subdiv_vertex_index);
1771 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1772 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
1773 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
1782 const MPoly *coarse_mpoly = coarse_mesh->
mpoly;
1783 const MLoop *coarse_mloop = coarse_mesh->
mloop;
1784 for (
int poly_index = 0; poly_index < coarse_mesh->
totpoly; poly_index++) {
1785 const MPoly *coarse_poly = &coarse_mpoly[poly_index];
1811 const bool is_loose_geometry_tags_needed = (foreach_context->
vertex_loose !=
NULL ||
1813 if (is_loose_geometry_tagged && is_loose_geometry_tags_needed) {
1819 const int poly_index,
1838 const int edge_index,
1854 const Mesh *coarse_mesh)
1897 ¶llel_range_settings);
1904 ¶llel_range_settings);
1911 ¶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(* SubdivForeachVertexFromCornerCb)(const struct SubdivForeachContext *context, void *tls, int ptex_face_index, float u, float v, int coarse_vertex_index, int coarse_poly_index, int coarse_corner, int subdiv_vertex_index)
void(* SubdivForeachVertexFromEdgeCb)(const struct SubdivForeachContext *context, void *tls, int ptex_face_index, float u, float v, int coarse_edge_index, int coarse_poly_index, int coarse_corner, int subdiv_vertex_index)
#define BLI_BITMAP_NEW(_num, _alloc_string)
#define BLI_BITMAP_ENABLE(_bitmap, _index)
#define BLI_BITMAP_TEST_BOOL(_bitmap, _index)
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(int start, 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)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
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)