48#ifdef BEVEL_DEBUG_TIME
52#define BEVEL_EPSILON_D 1e-6
53#define BEVEL_EPSILON 1e-6f
54#define BEVEL_EPSILON_SQ 1e-12f
55#define BEVEL_EPSILON_BIG 1e-4f
56#define BEVEL_EPSILON_BIG_SQ 1e-8f
57#define BEVEL_EPSILON_ANG DEG2RADF(2.0f)
58#define BEVEL_SMALL_ANG DEG2RADF(10.0f)
60#define BEVEL_SMALL_ANG_DOT (1.0f - cosf(BEVEL_SMALL_ANG))
62#define BEVEL_EPSILON_ANG_DOT (1.0f - cosf(BEVEL_EPSILON_ANG))
63#define BEVEL_MAX_ADJUST_PCT 10.0f
64#define BEVEL_MAX_AUTO_ADJUST_PCT 300.0f
65#define BEVEL_MATCH_SPEC_WEIGHT 0.2
158#define PRO_SQUARE_R 1e4f
159#define PRO_CIRCLE_R 2.0f
160#define PRO_LINE_R 1.0f
161#define PRO_SQUARE_IN_R 0.0f
440[[maybe_unused]]
static void ensure_indices(
BMesh *
bm)
448 fmt::print(
"({},{},{})",
v[0],
v[1],
v[2]);
452[[maybe_unused]]
static int vi(
const BMVert *
v)
458[[maybe_unused]]
static int ei(
const BMEdge *
e)
464[[maybe_unused]]
static int fi(
const BMFace *f)
470[[maybe_unused]]
static const char *mesh_kind_name(
MeshKind kind)
489[[maybe_unused]]
static void dump_profile(
const Profile &prof)
491 fmt::print(
" Profile: super_r={} height={} special_params={}\n",
494 prof.special_params);
495 fmt::print(
" start=");
497 fmt::print(
" middle=");
502 fmt::print(
" plane_no=");
504 fmt::print(
" plane_co=");
506 fmt::print(
" proj_dir=");
513[[maybe_unused]]
static void dump_edge_half(
const EdgeHalf &eh,
const int index)
516 " EdgeHalf[{}]: e={} fprev={} fnext={}", index, ei(eh.e), fi(eh.fprev), fi(eh.fnext));
517 fmt::println(
" offset_l={} offset_r={} offset_l_spec={} offset_r_spec={}",
522 fmt::println(
" is_bev={} is_rev={} is_seam={} visited_rpo={}",
527 fmt::println(
" leftv={} rightv={}",
528 eh.leftv ? eh.leftv->index : -1,
529 eh.rightv ? eh.rightv->index : -1);
534[[maybe_unused]]
static void dump_bound_vert(
const BoundVert &bndv)
536 fmt::print(
" BoundVert[{}]: co=", bndv.index);
539 fmt::println(
" efirst={} elast={} eon={} ebev={}",
540 bndv.efirst ? ei(bndv.efirst->e) : -1,
541 bndv.elast ? ei(bndv.elast->e) : -1,
542 bndv.eon ? ei(bndv.eon->e) : -1,
543 bndv.ebev ? ei(bndv.ebev->e) : -1);
545 " sinratio={} any_seam={} visited={}", bndv.sinratio, bndv.any_seam, bndv.visited);
546 fmt::println(
" is_arc_start={} is_patch_start={} is_profile_start={}",
549 bndv.is_profile_start);
550 fmt::println(
" seam_len={} sharp_len={}", bndv.seam_len, bndv.sharp_len);
551 dump_profile(bndv.profile);
555[[maybe_unused]]
static void dump_vmesh(
const VMesh &vm)
558 " VMesh: count={} seg={} mesh_kind={}", vm.count, vm.seg, mesh_kind_name(vm.mesh_kind));
559 if (vm.boundstart ==
nullptr) {
560 fmt::println(
" (no boundverts)");
564 const BoundVert *bndv = vm.boundstart;
566 dump_bound_vert(*bndv);
568 }
while (bndv != vm.boundstart);
571 if (vm.mesh !=
nullptr) {
572 const int n = vm.count;
573 const int ns = vm.seg;
574 const int ns2 = ns / 2;
576 VMesh *vmp =
const_cast<VMesh *
>(&vm);
577 fmt::println(
" NewVerts (i, j, k) for 0<=i<{} 0<=j<={} 0<=k<{}:", n, ns2, ns);
578 for (
int i = 0; i < n; i++) {
579 for (
int j = 0; j <= ns2; j++) {
580 fmt::print(
" ({},{}): ", i, j);
581 for (
int k = 0; k < ns; k++) {
582 const int nj = ns / 2 + 1;
583 const int nk = ns + 1;
584 const NewVert *nv = &vmp->mesh[i * nj * nk + j * nk + k];
585 fmt::print(
"({},({:.3f},{:.3f},{:.3f})) ",
599[[maybe_unused]]
static void dump_bev_vert(
const BevVert &bv)
601 fmt::println(
"BevVert: v={} edgecount={} selcount={} wirecount={}",
606 fmt::println(
" offset={} any_seam={} visited={}", bv.offset, bv.any_seam, bv.visited);
609 fmt::println(
" edges ({}):", bv.edgecount);
610 for (
int i = 0; i < bv.edgecount; i++) {
611 dump_edge_half(bv.edges[i], i);
615 if (bv.wirecount > 0) {
616 fmt::print(
" wire_edges:");
617 for (
int i = 0; i < bv.wirecount; i++) {
619 fmt::print(
"\n[{}] ", i);
621 fmt::print(
"{} ", ei(bv.wire_edges[i]));
628 dump_vmesh(*bv.vmesh);
631 fmt::println(
" (no vmesh)");
646[[maybe_unused]]
static void dump_edge_polygons(
const BevVert &bv)
648 const VMesh *vm = bv.vmesh;
652 const int ns = vm->seg;
653 VMesh *vmp =
const_cast<VMesh *
>(vm);
656 fmt::println(
" Edge polygons for bv={}:", vi(bv.v));
658 for (
int eidx = 0; eidx < bv.edgecount; eidx++) {
659 const EdgeHalf &eh = bv.edges[eidx];
660 if (!eh.is_bev || !eh.leftv) {
663 const int i = eh.leftv->index;
664 fmt::println(
" EdgeHalf[{}] e={} i={}:", eidx, ei(eh.e), i);
666 for (
int k = 0; k < ns; k++) {
668 const int nj = ns / 2 + 1;
669 const int nk = ns + 1;
670 const NewVert *nv_a = &vmp->mesh[i * nj * nk + 0 * nk + k];
671 const NewVert *nv_b = &vmp->mesh[i * nj * nk + 0 * nk + (k + 1)];
672 BMVert *va = nv_a->v;
673 BMVert *vb = nv_b->v;
680 fmt::println(
" k={} va={} vb={}: no edge found", k, vi(va), vi(vb));
685 BMFace *f_edge =
nullptr;
692 if (f != eh.fprev && f != eh.fnext) {
697 }
while (
l != l_start);
701 f_edge = bme->l ? bme->l->f :
nullptr;
704 fmt::println(
" k={} va={} vb={}: no face found", k, vi(va), vi(vb));
708 fmt::print(
" k={} face={} corners:", k, fi(f_edge));
712 fmt::print(
" [v={} e={}]", vi(l_dump->v), ei(l_dump->e));
723[[maybe_unused]]
static void dump_rebuilt_face(BMFace *f)
726 fmt::println(
" dump_rebuilt_face: face is null");
729 fmt::print(
" Rebuilt face={} ({} verts):", fi(f), f->len);
733 fmt::print(
" [v={} e={} co=({:.3f},{:.3f},{:.3f})]",
751#define BM_ELEM_LONG_TAG (1 << 6)
808 const float direction_dot =
dot_v3v3(d1, d2);
856 int nj = (vm->
seg / 2) + 1;
857 int nk = vm->
seg + 1;
859 return &vm->
mesh[i * nk * nj + j * nk + k];
881 for (
int i = 0; i < bv->
edgecount; i++) {
882 if (bv->
edges[i].
e == bme) {
883 return &bv->
edges[i];
892 return bp->
vert_hash.lookup_default(bmv,
nullptr);
918 *r_bvother =
nullptr;
927 if (from_e ==
nullptr) {
935 }
while ((
e =
e->next) != from_e);
983 if (frep_arr && frep_arr[0]) {
1019 if (!uv_vert_buckets) {
1033 bool is_bucket_found =
false;
1049 bool is_orig_uv_verts_connected =
false;
1051 for (
UVVertBucket &orig_uv_vert_bucket : orig_uv_vert_buckets) {
1052 if (orig_uv_vert_bucket.contains(orig_l) && orig_uv_vert_bucket.contains(orig_l2)) {
1053 is_orig_uv_verts_connected =
true;
1066 for (
UVVertBucket &uv_vert_bucket : *uv_vert_buckets) {
1067 if (uv_vert_bucket.contains(l2)) {
1068 uv_vert_bucket.add(
l);
1069 is_bucket_found =
true;
1074 if (is_bucket_found) {
1078 if (!is_bucket_found) {
1098 for (
int i = 0; i < num_uv_layers; ++i) {
1105 bool is_overlap_found =
false;
1107 for (
BMLoop *l2 : uv_vert_bucket) {
1110 uv_vert_bucket.add(
l);
1111 is_overlap_found =
true;
1115 if (is_overlap_found) {
1119 if (!is_overlap_found) {
1142 for (
int i = 0; i < num_uv_layers; ++i) {
1146 int num_uv_verts = uv_vert_bucket.size();
1147 if (num_uv_verts <= 1) {
1150 float uv[2] = {0.0f, 0.0f};
1151 for (
BMLoop *
l : uv_vert_bucket) {
1155 mul_v2_fl(uv, 1.0f /
float(num_uv_verts));
1156 for (
BMLoop *
l : uv_vert_bucket) {
1178 frep =
v->ebev->fprev;
1179 if (
v->efirst->fprev != frep) {
1180 frep2 =
v->efirst->fprev;
1183 else if (
v->efirst) {
1184 frep =
v->efirst->fprev;
1186 if (
v->elast->fnext != frep) {
1187 frep2 =
v->elast->fnext;
1189 else if (
v->efirst->fnext != frep) {
1190 frep2 =
v->efirst->fnext;
1192 else if (
v->elast->fprev != frep) {
1193 frep2 =
v->efirst->fprev;
1196 else if (
v->efirst->fnext) {
1197 frep =
v->efirst->fnext;
1198 if (
v->elast->fnext != frep) {
1199 frep2 =
v->elast->fnext;
1202 else if (
v->elast->fprev) {
1203 frep =
v->elast->fprev;
1206 else if (
v->prev->elast) {
1207 frep =
v->prev->elast->fnext;
1208 if (
v->next->efirst) {
1210 frep2 =
v->next->efirst->fprev;
1213 frep =
v->next->efirst->fprev;
1253 if (facerep || (face_arr && face_arr[0])) {
1264 interp_f = face_arr[i];
1271 if (snap_edge_arr) {
1272 bme = snap_edge_arr[i];
1299 f->
mat_nr = short(mat_nr);
1315 static_cast<char *
>(l1->
head.
data) + offset,
1316 static_cast<char *
>(l2->
head.
data) + offset);
1335 if (lef1->
f == f2) {
1336 std::swap(lef1, lef2);
1338 if (lef1->
f != f1 || lef2->
f != f2) {
1352 BLI_assert(lv1f1->
v == v1 && lv1f1->
f == f1 && lv2f1->
v ==
v2 && lv2f1->
f == f1 &&
1353 lv1f2->
v == v1 && lv1f2->
f == f2 && lv2f2->
v ==
v2 && lv2f2->
f == f2);
1376 BMLoop *l_first =
nullptr;
1380 if (l_first ==
nullptr) {
1406 for (
int f = 0; f < totface; f++) {
1407 if (face_component[f] == c1) {
1408 face_component[f] = c2;
1410 else if (face_component[f] == c2) {
1411 face_component[f] = c1;
1460 int *face_component =
static_cast<int *
>(
1470 for (f = 0; f < totface; f++) {
1471 face_component[f] = -1;
1472 in_stack[f] =
false;
1474 int current_component = -1;
1475 for (f = 0; f < totface; f++) {
1476 if (face_component[f] == -1 && !in_stack[f]) {
1478 current_component++;
1482 while (stack_top >= 0) {
1483 BMFace *bmf = stack[stack_top];
1486 in_stack[bmf_index] =
false;
1487 if (face_component[bmf_index] != -1) {
1490 face_component[bmf_index] = current_component;
1501 if (bmf_other != bmf) {
1503 if (face_component[bmf_other_index] != -1 || in_stack[bmf_other_index]) {
1509 stack[stack_top] = bmf_other;
1510 in_stack[bmf_other_index] =
true;
1519 MEM_delete(in_stack);
1523 if (current_component <= 0) {
1526 BMFace *top_face =
nullptr;
1527 float top_face_z = -1e30f;
1528 int top_face_component = -1;
1529 BMFace *bot_face =
nullptr;
1530 float bot_face_z = 1e30f;
1531 int bot_face_component = -1;
1532 for (f = 0; f < totface; f++) {
1537 if (fz > top_face_z) {
1540 top_face_component = face_component[f];
1542 if (fz < bot_face_z) {
1545 bot_face_component = face_component[f];
1548 BLI_assert(top_face !=
nullptr && bot_face !=
nullptr);
1551 if (bot_face_component != top_face_component) {
1552 if (bot_face_component == 0) {
1554 bot_face_component = top_face_component;
1574#define VEC_VALUE_LEN 6
1580 for (
int f = 0; f < nfaces; f++) {
1582 if (bmf ==
nullptr) {
1583 still_viable[f] =
false;
1586 still_viable[f] =
true;
1589 int value_index = 0;
1601 value_vecs[f][value_index++] = cent[2];
1602 value_vecs[f][value_index++] = cent[0];
1603 value_vecs[f][value_index++] = cent[1];
1611 for (
int value_index = 0; num_viable > 1 && value_index <
VEC_VALUE_LEN; value_index++) {
1612 for (
int f = 0; f < nfaces; f++) {
1613 if (!still_viable[f] || f == best_f) {
1620 if (value_vecs[f][value_index] < value_vecs[best_f][value_index]) {
1623 for (
int i = f - 1; i >= 0; i--) {
1624 if (still_viable[i]) {
1625 still_viable[i] =
false;
1630 else if (value_vecs[f][value_index] > value_vecs[best_f][value_index]) {
1631 still_viable[f] =
false;
1639 return face[best_f];
1661 float *l1 =
e->
e->
v1->
co;
1668 *ret_closer_v =
e->
e->
v1;
1672 *ret_closer_v =
e->
e->
v2;
1683 float dir1[3], dir2[3];
1702 else if (e2->
fprev) {
1720 float dir1[3], dir2[3], dirco[3], no[3];
1748 float dir1[3], dir2[3],
cross[3];
1751 if (e1->
v1 == e2->
v1) {
1756 else if (e1->
v1 == e2->
v2) {
1761 else if (e1->
v2 == e2->
v1) {
1766 else if (e1->
v2 == e2->
v2) {
1807 float d0, d3, d4, d5;
1813 bool no_offsets = f1 ==
nullptr || f2 ==
nullptr;
1830 d0 = d3 = d4 = d5 = bp->
offset;
1892 float dir1[3], dir2[3];
1896 float dir1n[3], dir2p[3];
1897 if (edges_between) {
1910 float norm_perp1[3];
1928 for (
EdgeHalf *eloop = e1; eloop != e2; eloop = eloop->
next) {
1929 if (eloop->fnext !=
nullptr) {
1947 d = d /
cosf(ang / 2.0f);
1967 float norm_v1[3], norm_v2[3];
1972 else if (!edges_between) {
1997 float norm_perp2[3];
2003 float off1a[3], off1b[3], off2a[3], off2b[3];
2020 if (isect_kind == 0) {
2038 if (isect_kind == 2) {
2073#define BEVEL_GOOD_ANGLE 0.1f
2086 float dir1[3], dir2[3];
2117 float sinang =
sinf(ang);
2157 bool retval =
false;
2162 float meet1[3], meet2[3];
2184 *r_sinratio = (ang1 == 0.0f) ? 1.0f :
sinf(ang2) /
sinf(ang1);
2192 *r_sinratio = (ang1 == 0.0f) ? 1.0f :
sinf(ang2) /
sinf(ang1);
2196 else if (ok1 && !ok2) {
2199 else if (!ok1 && ok2) {
2217 float dir[3], no[3];
2247 const float co_a[3],
2248 const float co_b[3],
2253#ifdef BEVEL_ASSERT_PROJECT
2264 bool do_linear_interp =
true;
2268 float start[3], end[3];
2272 do_linear_interp =
false;
2301 if (
e->prev->is_bev &&
e->next->is_bev && bv->
selcount >= 3) {
2303 float d3[3], d4[3], co4[3], meetco[3], isect2[3];
2313 do_linear_interp =
true;
2320 if (isect_kind != 0) {
2326 do_linear_interp =
true;
2339 do_linear_interp =
true;
2356 do_linear_interp =
false;
2366 do_linear_interp =
false;
2369 if (do_linear_interp) {
2402 float no[3], no2[3], no3[3];
2434 float d1[3], d2[3], no[3];
2442 float no2[3], no3[3];
2447 if (l1 != 0.0f && (l2 != 0.0f || l3 != 0.0f)) {
2475 return lb->
next == la ? 1 : -1;
2500 const float vmid[3],
2504 float vb_vmid[3], va_vmid[3];
2516 float vo[3], vd[3], vddir[3];
2557 const float va[3],
const float vb[3],
const float vc[3],
const float vd[3],
float r_mat[4][4])
2598 return pow((1.0 -
pow(
x, r)), (1.0 / r));
2600 return 1.0 -
pow((1.0 -
pow(1.0 -
x, r)), (1.0 / r));
2624 if (nseg == bp->
seg) {
2642 const float map[4][4],
2644 const bool reversed,
2646 const double *xvals,
2647 const double *yvals,
2651 for (
int k = 0; k <= ns; k++) {
2661 const float p[3] = {
2662 reversed ?
float(yvals[ns - k]) :
float(xvals[k]),
2663 reversed ?
float(xvals[ns - k]) :
float(yvals[k]),
2674 float *prof_co_k = r_prof_co + 3 * k;
2708 if (pro->
prof_co ==
nullptr) {
2709 pro->
prof_co =
static_cast<float *
>(
2732 float bottom_corner[3] = {0.0f, 0.0f, 0.0f};
2734 float top_corner[3] = {1.0f, 1.0f, 0.0f};
2770 float a =
max_ff(0.0f, co[0]);
2771 float b =
max_ff(0.0f, co[1]);
2772 float c =
max_ff(0.0f, co[2]);
2784 float dx = 1.0f -
x;
2785 float dy = 1.0f -
y;
2788 y = midline ? 1.0f :
y;
2792 x = midline ? 1.0f :
x;
2799 y = midline ? 0.0f :
y;
2803 x = midline ? 0.0f :
x;
2808 float rinv = 1.0f / r;
2817 y =
powf(1.0f / (1.0f +
powf(c /
b, r)), rinv);
2832#define BEV_EXTEND_EDGE_DATA_CHECK(eh, flag) BM_elem_flag_test(eh->e, flag)
2848#define HASNOT_SEAMSHARP(eh, flag) \
2849 ((flag == BM_ELEM_SEAM && !BM_elem_flag_test(eh->e, BM_ELEM_SEAM)) || \
2850 (flag == BM_ELEM_SMOOTH && BM_elem_flag_test(eh->e, BM_ELEM_SMOOTH)))
2886 e->rightv->seam_len = flag_count;
2889 e->rightv->sharp_len = flag_count;
2892 }
while (
e != efirst);
2917 int idx_end = bcur->
index + extend_len;
2918 for (
int i = bcur->
index; i < idx_end; i++) {
2921 for (
int k = 1; k < vm->
seg; k++) {
2927 while (
e->v1 !=
v2 &&
e->v2 !=
v2) {
2940 while (
e->v1 != v3 &&
e->v2 != v3) {
2955 }
while (bcur != start);
2988 if (lother !=
l && fother) {
3023 if (cd_clnors_offset == -1) {
3031 if (cd_clnors_offset == -1) {
3037 if (cd_clnors_offset == -1) {
3059 float *pnorm =
nullptr;
3070 pnorm = lprev->
f->
no;
3073 pnorm = lnext->
f->
no;
3079 else if (fkind ==
F_VERT) {
3083 else if (fprevkind ==
F_RECON) {
3084 pnorm = lprev->
f->
no;
3086 else if (fnextkind ==
F_RECON) {
3087 pnorm = lnext->
f->
no;
3090 BMLoop *lprevprev, *lnextnext;
3092 estep = lprev->
prev->
e;
3096 lprevprev =
nullptr;
3103 lnextnext =
nullptr;
3108 pnorm = lprevprev->
f->
no;
3124 if (pnorm ==
norm) {
3141 if (cd_prop_int_idx == -1) {
3153 bool do_set_strength =
true;
3173 do_set_strength =
false;
3175 if (do_set_strength) {
3177 *strength_ptr = strength;
3188 v->any_seam =
false;
3190 v->any_seam |=
e->is_seam;
3191 if (
e ==
v->elast) {
3209 if (
e->fprev &&
e->fnext) {
3232 bool miter_profile =
false;
3233 bool reverse_profile =
false;
3258 v->efirst =
v->elast =
e;
3259 e->leftv =
e->rightv =
v;
3264 }
while ((
e =
e->next) != efirst);
3274 if (vm->
count == 2) {
3277 else if (bp->
seg == 1) {
3294 const bool construct)
3305 const float *no =
e->fprev ?
e->fprev->
no : (
e->fnext ?
e->fnext->
no :
nullptr);
3315 no =
e->fnext ?
e->fnext->
no : (
e->fprev ?
e->fprev->
no :
nullptr);
3330 e->next->leftv =
e->next->rightv = bndv;
3354 e->prev->leftv =
e->prev->rightv = bndv;
3370 e->leftv =
e->rightv = bndv;
3371 e->prev->rightv = bndv;
3381 for (
e =
e->next;
e->next != efirst;
e =
e->next) {
3386 e->leftv =
e->rightv = bndv;
3408 else if (vm->
count == 3) {
3409 bool use_tri_fan =
true;
3413 float profile_plane[4];
3417 use_tri_fan =
false;
3454 float co1[3], edge_dir[3], line_p[3];
3458 float d = bp->
offset / (bp->
seg / 2.0f);
3483 if (
v->is_arc_start) {
3487 float edge_dir[3], co[3];
3504 }
while (
v != vstart);
3567 int not_in_plane = 0;
3583 if (in_plane == 0 && not_in_plane == 0) {
3586 else if (not_in_plane > 0) {
3622 e3->leftv = e3->rightv =
v;
3660 if (
e->next == e2) {
3661 v2->efirst =
nullptr;
3662 v2->elast =
nullptr;
3665 v2->efirst =
e->next;
3667 e3->leftv = e3->rightv =
v2;
3675 if (
e->next == e2) {
3679 int between = in_plane + not_in_plane;
3680 int bet2 = between / 2;
3681 bool betodd = (between % 2) == 1;
3688 e3->profile_index = 0;
3690 else if (betodd && i == bet2) {
3691 e3->profile_index = bp->
seg / 2;
3694 e3->profile_index = bp->
seg;
3732 }
while (
e != efirst);
3744 if (vm->
count == 2) {
3747 else if (efirst->
seg == 1) {
3764static void print_adjust_stats(BoundVert *vstart)
3766 printf(
"\nSolution analysis\n");
3767 double even_residual2 = 0.0;
3768 double spec_residual2 = 0.0;
3769 double max_even_r = 0.0;
3770 double max_even_r_pct = 0.0;
3771 double max_spec_r = 0.0;
3772 double max_spec_r_pct = 0.0;
3773 printf(
"width matching\n");
3774 BoundVert *v = vstart;
3776 if (v->adjchain !=
nullptr) {
3777 EdgeHalf *eright = v->efirst;
3778 EdgeHalf *eleft = v->adjchain->elast;
3779 double delta =
fabs(eright->offset_r - eleft->offset_l);
3780 double delta_pct = 100.0 * delta / eright->offset_r_spec;
3781 printf(
"e%d r(%f) vs l(%f): abs(delta)=%f, delta_pct=%f\n",
3787 even_residual2 += delta * delta;
3788 if (delta > max_even_r) {
3791 if (delta_pct > max_even_r_pct) {
3792 max_even_r_pct = delta_pct;
3796 }
while (v && v != vstart);
3798 printf(
"spec matching\n");
3801 if (
v->adjchain !=
nullptr) {
3802 EdgeHalf *eright =
v->efirst;
3803 EdgeHalf *eleft =
v->adjchain->elast;
3804 double delta = eright->offset_r - eright->offset_r_spec;
3805 double delta_pct = 100.0 * delta / eright->offset_r_spec;
3806 printf(
"e%d r(%f) vs r spec(%f): delta=%f, delta_pct=%f\n",
3809 eright->offset_r_spec,
3812 spec_residual2 += delta * delta;
3813 delta =
fabs(delta);
3814 delta_pct =
fabs(delta_pct);
3815 if (delta > max_spec_r) {
3818 if (delta_pct > max_spec_r_pct) {
3819 max_spec_r_pct = delta_pct;
3822 delta = eleft->offset_l - eleft->offset_l_spec;
3823 delta_pct = 100.0 * delta / eright->offset_l_spec;
3824 printf(
"e%d l(%f) vs l spec(%f): delta=%f, delta_pct=%f\n",
3827 eleft->offset_l_spec,
3830 spec_residual2 += delta * delta;
3831 delta =
fabs(delta);
3832 delta_pct =
fabs(delta_pct);
3833 if (delta > max_spec_r) {
3836 if (delta_pct > max_spec_r_pct) {
3837 max_spec_r_pct = delta_pct;
3841 }
while (v && v != vstart);
3843 printf(
"Analysis Result:\n");
3844 printf(
"even residual2 = %f, spec residual2 = %f\n", even_residual2, spec_residual2);
3845 printf(
"max even delta = %f, max as percent of spec = %f\n", max_even_r, max_even_r_pct);
3846 printf(
"max spec delta = %f, max as percent of spec = %f\n", max_spec_r, max_spec_r_pct);
3850#ifdef FAST_ADJUST_CODE
3859static bool adjust_the_cycle_or_chain_fast(BoundVert *vstart,
int np,
bool iscycle)
3864 BoundVert *
v = vstart;
3865 float spec_sum = 0.0f;
3869 if (iscycle ||
v->adjchain !=
nullptr) {
3870 spec_sum +=
v->efirst->offset_r;
3873 spec_sum +=
v->elast->offset_l;
3877 }
while (v && v != vstart);
3879 float gprod = 1.00f;
3880 float gprod_sum = 1.0f;
3881 for (i = np - 1; i > 0; i--) {
3896 if (gprod_sum == 0.0f) {
3901 float p = spec_sum / gprod_sum;
3907 if (iscycle ||
v->adjchain !=
nullptr) {
3908 EdgeHalf *eright =
v->efirst;
3909 EdgeHalf *eleft =
v->elast;
3910 eright->offset_r = g_prod[(i + 1) % np] * p;
3911 if (iscycle || v != vstart) {
3912 eleft->offset_l =
v->sinratio * eright->offset_r;
3917 EdgeHalf *eleft =
v->elast;
3918 eleft->offset_l = p;
3922 }
while (v && v != vstart);
3955 if ((*r_bv)->selcount == 1) {
3960 if ((*r_bv)->selcount == 2) {
3964 new_edge = new_edge->
next;
3965 }
while (!new_edge->
is_bev);
3972 float dir_start_edge[3];
3973 if (start_edge->
e->
v1 == (*r_bv)->v) {
3983 float second_best_dot = 0.0f, best_dot = 0.0f;
3985 while (new_edge != start_edge) {
3987 new_edge = new_edge->
next;
3991 float dir_new_edge[3];
3992 if (new_edge->
e->
v2 == (*r_bv)->v) {
4001 float new_dot =
dot_v3v3(dir_new_edge, dir_start_edge);
4002 if (new_dot > best_dot) {
4003 second_best_dot = best_dot;
4005 next_edge = new_edge;
4007 else if (new_dot > second_best_dot) {
4008 second_best_dot = new_dot;
4011 new_edge = new_edge->
next;
4042 for (
int i = 0; i < 2; i++) {
4043 EdgeHalf *edgehalf = start_edgehalf;
4045 bool toward_bv = (i == 0);
4062 toward_bv = !toward_bv;
4082 printf(
"\nadjust the %s (with eigen)\n", iscycle ?
"cycle" :
"chain");
4093 }
while (
v &&
v != vstart);
4095 printf(
" -> %d parms\n", np);
4098#ifdef FAST_ADJUST_CODE
4099 if (adjust_the_cycle_or_chain_fast(vstart, np, iscycle)) {
4104 int nrows = iscycle ? 3 * np : 3 * np - 3;
4112 EdgeHalf *eleft, *eright, *enextleft;
4115 if (iscycle || i < np - 1) {
4118 enextleft =
v->adjchain->elast;
4121 if (iscycle ||
v != vstart) {
4122 printf(
" dependent: e%d->offset_l = %f * p%d\n",
4143 int row = iscycle ? np + 2 * i : np - 1 + 2 * i;
4147 printf(
"b[%d]=%f * %f, for e%d->offset_r\n",
4158 solver, row, (i == np - 1) ? 0 : i + 1, weight *
v->adjchain->sinratio);
4161 printf(
"b[%d]=%f * %f, for e%d->offset_l\n",
4179 }
while (
v &&
v != vstart);
4185 for (i = 0; i < np; i++) {
4195 if (iscycle || i < np - 1) {
4202 if (iscycle ||
v != vstart) {
4219 }
while (
v &&
v != vstart);
4222 print_adjust_stats(vstart);
4273 v = vchainstart = vchainend = vanchor;
4275 bool iscycle =
false;
4277 while (
v->eon && !
v->visited && !iscycle) {
4288 v->adjchain = vnext;
4292 if (vnext != vchainstart) {
4302 v->adjchain =
nullptr;
4317 vchainstart = vnext;
4319 }
while (!
v->visited &&
v->eon);
4320 if (chainlen >= 3 && !vchainstart->
eon && !vchainend->
eon) {
4357 float dir1[3], dir3[3];
4416 BLI_assert(0 <= i && i <= n && 0 <= j && j <= ns && 0 <= k && k <= ns);
4418 if (!odd && j == ns2 && k == ns2) {
4421 if (j <= ns2 - 1 + odd && k <= ns2) {
4425 return mesh_vert(vm, (i + n - 1) % n, k, ns - j);
4427 return mesh_vert(vm, (i + 1) % n, ns - k, j);
4432 int ns2 = vm->
seg / 2;
4433 if (vm->
seg % 2 == 1) {
4434 return (j <= ns2 && k <= ns2);
4437 return ((j < ns2 && k <= ns2) || (j == ns2 && k == ns2 && i == 0));
4446 for (
int i = 0; i < n; i++) {
4447 for (
int j = 0; j <= ns2; j++) {
4448 for (
int k = 0; k <= ns; k++) {
4465 int ns2 = vm->
seg / 2;
4468 for (
int i = 0; i < n; i++) {
4495 return 0.065247584f;
4501 return 0.401983447f;
4504 return 0.523423277f;
4506 double k =
cos(
M_PI /
double(n));
4510 double k4 = k2 * k2;
4511 double k6 = k4 * k2;
4512 double y =
pow(
M_SQRT3 *
sqrt(64.0 * k6 - 144.0 * k4 + 135.0 * k2 - 27.0) + 9.0 * k, 1.0 / 3.0);
4513 double x = 0.480749856769136 *
y - (0.231120424783545 * (12.0 * k2 - 9.0)) /
y;
4514 return (k *
x + 2.0 * k2 - 1.0) / (
x *
x * (k *
x + 1.0));
4525 for (
int k = 0; k < ns; k++) {
4527 frac[k + 1] = total;
4530 for (
int k = 1; k <= ns; k++) {
4542 float co[3], nextco[3];
4547 for (
int k = 0; k < ns; k++) {
4550 frac[k + 1] = total;
4554 for (
int k = 1; k <= ns; k++) {
4568 for (
int i = 0; i < n; i++) {
4569 if (f <=
frac[i + 1]) {
4570 float rest = f -
frac[i];
4575 *r_rest = rest / (
frac[i + 1] -
frac[i]);
4577 if (i == n - 1 && *r_rest == 1.0f) {
4594 int n_bndv = vm_in->
count;
4595 int ns_in = vm_in->
seg;
4596 int nseg2 = nseg / 2;
4608 for (
int i = 0; i < n_bndv; i++) {
4611 for (
int j = 0; j <= nseg2 - 1 + odd; j++) {
4612 for (
int k = 0; k <= nseg2; k++) {
4614 float fraction = new_frac[k];
4618 fraction = prev_new_frac[nseg - j];
4619 int k_in_prev =
interp_range(prev_frac, ns_in, fraction, &restkprev);
4620 int j_in = ns_in - k_in_prev;
4621 float restj = -restkprev;
4627 restj = 1.0f + restj;
4635 int j0inc = (restj <
BEVEL_EPSILON || j_in == ns_in) ? 0 : 1;
4636 int k0inc = (restk <
BEVEL_EPSILON || k_in == ns_in) ? 0 : 1;
4648 memcpy(prev_frac,
frac,
sizeof(
float) * (ns_in + 1));
4649 memcpy(prev_new_frac, new_frac,
sizeof(
float) * (nseg + 1));
4668 int n_boundary = vm_in->
count;
4669 int ns_in = vm_in->
seg;
4670 int ns_in2 = ns_in / 2;
4672 int ns_out = 2 * ns_in;
4676 for (
int i = 0; i < n_boundary; i++) {
4678 for (
int k = 1; k < ns_in; k++) {
4683 float co1[3], co2[3], acc[3];
4697 for (
int i = 0; i < n_boundary; i++) {
4698 for (
int k = 1; k < ns_out; k += 2) {
4703 float co1[3], co2[3], acc[3];
4719 for (
int i = 0; i < n_boundary; i++) {
4720 for (
int k = 0; k < ns_in; k++) {
4731 for (
int i = 0; i < n_boundary; i++) {
4732 for (
int j = 0; j < ns_in2; j++) {
4733 for (
int k = 0; k < ns_in2; k++) {
4746 for (
int i = 0; i < n_boundary; i++) {
4747 for (
int j = 0; j < ns_in2; j++) {
4748 for (
int k = 1; k <= ns_in2; k++) {
4761 for (
int i = 0; i < n_boundary; i++) {
4762 for (
int j = 1; j < ns_in2; j++) {
4763 for (
int k = 0; k < ns_in2; k++) {
4776 float gamma = 0.25f;
4777 float beta = -gamma;
4778 for (
int i = 0; i < n_boundary; i++) {
4779 for (
int j = 1; j < ns_in2; j++) {
4780 for (
int k = 1; k <= ns_in2; k++) {
4781 float co1[3], co2[3];
4809 float co1[3], co2[3];
4812 for (
int i = 0; i < n_boundary; i++) {
4818 mul_v3_fl(co, 1.0f /
float(n_boundary));
4821 for (
int i = 0; i < n_boundary; i++) {
4827 for (
int i = 0; i < n_boundary; i++) {
4828 int inext = (i + 1) % n_boundary;
4829 for (
int k = 0; k <= ns_out; k++) {
4832 if (k >= ns_in && k < ns_out) {
4848 for (
int i = 0; i < 3; i++) {
4849 float co[3] = {0.0f, 0.0f, 0.0f};
4853 for (
int i = 0; i < 3; i++) {
4854 for (
int j = 0; j <= ns2; j++) {
4855 for (
int k = 0; k <= ns2; k++) {
4861 co[(i + 1) % 3] =
float(k) * 2.0f /
float(nseg);
4862 co[(i + 2) % 3] =
float(j) * 2.0f /
float(nseg);
4883 for (
int i = 0; i < 3; i++) {
4884 float co[3] = {0.0f, 0.0f, 0.0f};
4896 for (
int i = 0; i < 3; i++) {
4897 for (
int k = 0; k <= ns2; k++) {
4899 co[i] = 1.0f -
float(k) *
b;
4900 co[(i + 1) % 3] = 0.0f;
4901 co[(i + 2) % 3] = 0.0f;
4903 co[(i + 1) % 3] = 1.0f -
float(k) *
b;
4904 co[(i + 2) % 3] = 0.0f;
4936 for (
int i = 0; i < 3; i++) {
4937 float co[3] = {0.0f, 0.0f, 0.0f};
4942 for (
int i = 0; i < 3; i++) {
4946 coc[(i + 1) % 3] = 1.0f;
4947 coc[(i + 2) % 3] = 0.0f;
4972 else if (r < 0.75f) {
4981 while (vm1->
seg < nseg) {
4984 if (vm1->
seg != nseg) {
4990 for (
int i = 0; i < 3; i++) {
4991 for (
int j = 0; j <= ns2; j++) {
4992 for (
int k = 0; k <= nseg; k++) {
5017 float totang = 0.0f;
5018 for (
int i = 0; i < bv->
edgecount; i++) {
5021 float absang =
fabsf(ang);
5025 else if (absang >= 3.0f *
float(
M_PI_4)) {
5040 (angdiff >
float(
M_PI_4)))
5054 float co0[3], co1[3], co2[3];
5066 for (
int i = 0; i < 3; i++) {
5067 for (
int j = 0; j <= ns2; j++) {
5068 for (
int k = 0; k <= ns; k++) {
5099 float boundverts_center[3] = {0.0f, 0.0f, 0.0f};
5100 for (
int i = 0; i < n_bndv; i++) {
5107 mul_v3_fl(boundverts_center, 1.0f /
float(n_bndv));
5113 float original_vertex[3], negative_fullest[3];
5115 sub_v3_v3v3(negative_fullest, boundverts_center, original_vertex);
5116 add_v3_v3(negative_fullest, boundverts_center);
5120 float center_direction[3];
5121 sub_v3_v3v3(center_direction, original_vertex, boundverts_center);
5140 }
while (vm1->
seg < nseg);
5141 if (vm1->
seg != nseg) {
5164 float edir[3], plane[4];
5168 float start_plane[3], end_plane[3], middle_plane[3];
5173 float m[4][4], minv[4][4];
5205 int half_ns = ns / 2;
5206 int ipipe1 = vpipe->
index;
5209 for (
int i = 0; i < n_bndv; i++) {
5210 for (
int j = 1; j <= half_ns; j++) {
5211 for (
int k = 0; k <= half_ns; k++) {
5218 float *profile_point_pipe1, *profile_point_pipe2, f;
5219 if (
ELEM(i, ipipe1, ipipe2)) {
5220 if (n_bndv == 3 && i == ipipe1) {
5223 profile_point_pipe2 =
mesh_vert(vm, i, 0, ring)->
co;
5224 profile_point_pipe1 =
mesh_vert(vm, i, ring, 0)->
co;
5226 f = ((k < j) ?
min_ff(j, k) : ((2.0f * ring) - j)) / (2.0f * ring);
5231 profile_point_pipe2 =
mesh_vert(vm, (i == ipipe1) ? ipipe2 : ipipe1, 0, ns - k)->
co;
5238 profile_point_pipe2 =
mesh_vert(vm, i, j, ns)->
co;
5248 bool even = (ns % 2) == 0;
5249 bool midline = even && k == half_ns &&
5250 ((i == 0 && j == half_ns) ||
ELEM(i, ipipe1, ipipe2));
5270 if (
e->v1 ==
v ||
e->v2 ==
v) {
5271 if (*r_e1 ==
nullptr) {
5274 else if (*r_e2 ==
nullptr) {
5316 r_internal[n_internal++] =
v;
5317 if (n_internal == 3) {
5322 for (
int i = n_internal; i < 3; i++) {
5323 r_internal[i] =
nullptr;
5341 float axis_mat[3][3];
5351 float *co =
v->nv.v->
co;
5352 if (
ELEM(
v, unsnapped[0], unsnapped[1], unsnapped[2])) {
5356 float snap1[3], snap2[3];
5361 if (d1_sq <= d2_sq) {
5408 BMFace *any_bmf =
nullptr;
5414 for (
int i = 0; i < bv->
edgecount; i++) {
5415 if (!bv->
edges[i].
is_bev && !consider_all_faces) {
5420 BMFace *ftwo[2] = {bmf1, bmf2};
5422 if (bmf !=
nullptr) {
5423 if (any_bmf ==
nullptr) {
5426 bool already_there =
false;
5427 for (
int j = fcount - 1; j >= 0; j--) {
5428 if (fchoices[j] == bmf) {
5429 already_there =
true;
5433 if (!already_there) {
5439 fchoices[fcount++] = bmf;
5456 int ns2 = vm->
seg / 2;
5458 BMEdge *frep_e1, *frep_e2;
5467 frep_e1 = frep_e2 =
nullptr;
5475 if (
ELEM(
v, frep_unsnapped[0], frep_unsnapped[1], frep_unsnapped[2])) {
5489 bp,
bm, vv.
data(), vv.
size(), vf.
data(), frep, ve.
data(), bv->
v,
nullptr, mat_nr,
true);
5507 for (
int i = 0; i < n; i++) {
5508 for (
int k = 1; k < ns; k++) {
5510 if (i > 0 && k <= ns2) {
5513 else if (i == n - 1 && k > ns2) {
5522 for (
int i = 0; i < n; i++) {
5560 float ns2inv = 1.0f /
float(ns2);
5562 int clstride = 3 * (ns2 + 1);
5569 for (
int i = 0; i < n_bndv; i++) {
5599 float dir1[3], dir2[3], co1[3], co2[3];
5605 float meet1[3], meet2[3];
5630 float *on_edge_cur = centerline + clstride * i;
5631 int iprev = (i == 0) ? n_bndv - 1 : i - 1;
5632 float *on_edge_prev = centerline + clstride * iprev;
5656 for (
int i = 0; i < n_bndv; i++) {
5658 float *on_edge_cur = centerline + clstride * i;
5660 float co1[3], co2[3];
5665 float meet1[3], meet2[3];
5691 float co1[3], co2[3];
5694 for (
int i = 0; i < n_bndv; i++) {
5703 finalfrac = 0.5f /
sinf(ang);
5704 finalfrac = std::min(finalfrac, 0.8f);
5709 ns2inv = 1.0f / (ns2 + finalfrac);
5712 float *p = centerline + clstride * i;
5715 for (
int j = 1; j <= ns2; j++) {
5724 for (
int i = 0; i < n_bndv; i++) {
5726 copy_v3_v3(co2, centerline + clstride * (i == 0 ? n_bndv - 1 : i - 1));
5727 for (
int j = 0; j < ns2 + odd; j++) {
5731 for (
int k = 1; k <= ns2; k++) {
5743 for (
int i = 0; i < n_bndv; i++) {
5744 int im1 = (i == 0) ? n_bndv - 1 : i - 1;
5745 for (
int j = 1; j < ns2 + odd; j++) {
5746 for (
int k = 1; k <= ns2; k++) {
5747 float meet1[3], meet2[3];
5749 centerline + clstride * im1 + 3 * k,
5751 centerline + clstride * i + 3 * j,
5758 centerline + clstride * im1 + 3 * k,
5761 else if (ikind == 1) {
5774 MEM_delete(centerline);
5785 const bool *frep_beats_next)
5787 int previ = (i + n_bndv - 1) % n_bndv;
5788 int nexti = (i + 1) % n_bndv;
5790 if (frep_beats_next[previ] && bndv_rep_faces[previ] == center_frep) {
5793 if (!frep_beats_next[i] && bndv_rep_faces[nexti] == center_frep) {
5835 const bool *frep_beats_next,
5838 BLI_assert(0 <= i && i < n_bndv && 0 <= j && j < ns2 && 0 <= k && k <= ns2);
5839 for (
int corner = 0; corner < 4; corner++) {
5840 r_snap_edges[corner] =
nullptr;
5844 int previ = (i + n_bndv - 1) % n_bndv;
5846 int jj = corner < 2 ? j : j + 1;
5847 int kk =
ELEM(corner, 0, 3) ? k : k + 1;
5848 if (jj < ns2 && kk < ns2) {
5851 else if (jj < ns2 && kk == ns2) {
5853 if (!frep_beats_next[i]) {
5854 r_snap_edges[corner] = enext;
5857 else if (jj < ns2 && kk == ns2 + 1) {
5859 if (frep_beats_next[i]) {
5860 r_snap_edges[corner] = enext;
5863 else if (jj == ns2 && kk < ns2) {
5865 if (frep_beats_next[previ]) {
5866 r_snap_edges[corner] = eprev;
5869 else if (jj == ns2 && kk == ns2) {
5872 i, n_bndv, eprev, enext, bndv_rep_faces, center_frep, frep_beats_next);
5874 else if (jj == ns2 && kk == ns2 + 1) {
5876 int nexti = (i + 1) % n_bndv;
5878 nexti, n_bndv, enext, enextnext, bndv_rep_faces, center_frep, frep_beats_next);
5922 for (
int i = 0; i < n_bndv; i++) {
5923 for (
int j = 0; j <= ns2; j++) {
5924 for (
int k = 0; k <= ns; k++) {
5925 if (j == 0 &&
ELEM(k, 0, ns)) {
5942 int i = bndv->
index;
5947 BMVert **center_verts =
nullptr;
5948 BMEdge **center_edge_snaps =
nullptr;
5949 BMFace **center_face_interps =
nullptr;
5950 bool *frep_beats_next =
nullptr;
5951 BMFace *center_frep =
nullptr;
5958 for (
int i = 0; i < n_bndv; i++) {
5959 center_edge_snaps[i] =
nullptr;
5961 int inext = (i + 1) % n_bndv;
5962 BMFace *fchoices[2] = {bndv_rep_faces[i], bndv_rep_faces[inext]};
5964 frep_beats_next[i] = fwinner == bndv_rep_faces[i];
5970 int i = bndv->
index;
5972 BMFace *f = bndv_rep_faces[i];
5973 BMFace *f2 = bndv_rep_faces[inext];
5976 fc = frep_beats_next[i] ? f : f2;
5991 BMEdge *bmeprev = eprev ? eprev->
e :
nullptr;
5992 BMEdge *bmenext = enext ? enext->
e :
nullptr;
6000 for (
int j = 0; j < ns2; j++) {
6001 for (
int k = 0; k < ns2 + odd; k++) {
6007 BMVert *bmvs[4] = {bmv1, bmv2, bmv3, bmv4};
6017 BMEdge *se[4] = {
nullptr,
nullptr,
nullptr,
nullptr};
6019 fr[0] = fr[1] = fr[2] = fr[3] = f2;
6021 if (k == ns2 && j == ns2 - 1) {
6028 se[0] = se[2] = bme;
6035 fr[0] = fr[1] = fr[2] = fr[3] = f;
6038 BMEdge *b2 = (
e &&
e->is_seam) ? bme :
nullptr;
6054 if (!
e ||
e->is_seam) {
6055 fr[0] = fr[1] = fr[2] = fr[3] = fc;
6063 center_verts[i] = bmvs[3];
6064 center_edge_snaps[i] = se[3];
6065 center_face_interps[i] = bv->
any_seam ? center_frep : f;
6073 if (j == ns2 - 1 && bndv->
prev->
ebev) {
6076 se[2] = se[1] !=
nullptr ? se[1] : se[3];
6080 bp,
bm, bmvs, 4, fr,
nullptr, se, bv->
v,
nullptr, mat_nr,
true);
6097 center_face_interps,
6125#ifdef DEBUG_CUSTOM_PROFILE_CUTOFF
6126 printf(
"BEVEL BUILD CUTOFF\n");
6127# define F3(v) (v)[0], (v)[1], (v)[2]
6134 int i = bndv->
index;
6138 float down_direction[3];
6157#ifdef DEBUG_CUSTOM_PROFILE_CUTOFF
6158 printf(
"Corner vertices:\n");
6159 for (
int j = 0; j < n_bndv; j++) {
6165 bool build_center_face =
true;
6174#ifdef DEBUG_CUSTOM_PROFILE_CUTOFF
6175 printf(
"build_center_face: %d\n", build_center_face);
6179 if (build_center_face) {
6181 int i = bndv->
index;
6191 for (
int i = 1; i < n_bndv; i++) {
6199#ifdef DEBUG_CUSTOM_PROFILE_CUTOFF
6200 printf(
"Building profile cutoff faces.\n");
6206 int i = bndv->
index;
6211#ifdef DEBUG_CUSTOM_PROFILE_CUTOFF
6212 printf(
"Profile Number %d:\n", i);
6214 printf(
" Miter profile\n");
6220 for (
int k = 0; k < bp->
seg + 1; k++) {
6222#ifdef DEBUG_CUSTOM_PROFILE_CUTOFF
6228 if (build_center_face) {
6230#ifdef DEBUG_CUSTOM_PROFILE_CUTOFF
6240 bp->
seg + 2 + build_center_face,
6251 if (build_center_face) {
6253 for (
int i = 0; i < n_bndv; i++) {
6259 bp,
bm, face_bmverts, n_bndv,
nullptr,
nullptr,
nullptr, bv->
v,
nullptr, bp->
mat_nr,
true);
6271 BMEdge *repface_e1, *repface_e2;
6280 repface_e1 = repface_e2 =
nullptr;
6290 if (
ELEM(bndv, unsnapped[0], unsnapped[1], unsnapped[2])) {
6304 for (
int k = 1; k < bndv->
ebev->
seg; k++) {
6310 bmedges.
append(k < bndv->ebev->seg / 2 ?
nullptr : frep_e);
6356 while (f->
len > 3) {
6363 if (f_new->
len > f->
len) {
6365 if (l_new->
v == v_fan) {
6368 else if (l_new->
next->
v == v_fan) {
6369 l_fan = l_new->
next;
6371 else if (l_new->
prev->
v == v_fan) {
6372 l_fan = l_new->
prev;
6379 if (l_fan->
v == v_fan) {
6381 else if (l_fan->
next->
v == v_fan) {
6382 l_fan = l_fan->
next;
6384 else if (l_fan->
prev->
v == v_fan) {
6385 l_fan = l_fan->
prev;
6423 for (
int k = 1; k < ns; k++) {
6430 for (
int k = 1; k < ns; k++) {
6438 for (
int k = 0; k < ns; k++) {
6472 int i = bndv->
index;
6478 if (weld && bndv->
ebev) {
6499 int i = bndv->
index;
6504 for (
int k = 1; k < ns; k++) {
6513 else if (n == 2 && !bndv->
ebev) {
6525 for (
int k = 1; k < ns; k++) {
6548 for (
int k = 1; k < ns; k++) {
6587 if (
e->fprev &&
e->fnext) {
6595#define BM_BEVEL_EDGE_TAG_ENABLE(bme) BM_ELEM_API_FLAG_ENABLE((bme), _FLAG_OVERLAP)
6596#define BM_BEVEL_EDGE_TAG_DISABLE(bme) BM_ELEM_API_FLAG_DISABLE((bme), _FLAG_OVERLAP)
6597#define BM_BEVEL_EDGE_TAG_TEST(bme) BM_ELEM_API_FLAG_TEST((bme), _FLAG_OVERLAP)
6627 for (
int sucindex = 0; sucindex < nsucs; sucindex++) {
6628 BMEdge *nextbme = sucs[sucindex];
6632 bv->
edges[j + 1].
e = nextbme;
6640 for (
int k = j + 1; k <= bestj; k++) {
6645 for (
int k = j + 1; k <= tryj; k++) {
6647 bv->
edges[k].
e =
nullptr;
6654 for (
int k = j + 1; k <= bestj; k++) {
6655 BLI_assert(save_path[k - (j + 1)] !=
nullptr);
6656 bv->
edges[k].
e = save_path[k - (j + 1)];
6669#ifdef FASTER_FASTORDER
6676static bool fast_bevel_edge_order(BevVert *bv)
6678 for (
int j = 1; j < bv->edgecount; j++) {
6679 BMEdge *bme = bv->edges[j - 1].e;
6680 BMEdge *bmenext =
nullptr;
6685 BMEdge *bme2 = (l->
v == bv->v) ? l->
prev->
e : l->next->e;
6688 if (bmenext ==
nullptr) {
6693 if (nsucs == 0 || (nsucs == 2 && j != 1) || nsucs > 2 ||
6696 for (
int k = 1; k < j; k++) {
6698 bv->edges[k].e =
nullptr;
6702 bv->edges[j].e = bmenext;
6720 for (
int i = 1; i < ntot; i++) {
6722 int num_shared_face = 0;
6723 BMEdge *first_suc =
nullptr;
6736 if (first_suc ==
nullptr) {
6741 if (num_shared_face >= 3) {
6745 if (num_shared_face == 1 || (i == 1 && num_shared_face == 2)) {
6747 e->
e = bme = first_suc;
6751 for (
int k = 1; k < i; k++) {
6753 bv->
edges[k].
e =
nullptr;
6770 bv->
edges[i].
e = first_bme;
6781 first_bme =
nullptr;
6798 for (
int i = 0; i < ntot; i++) {
6804 if (
e->fnext !=
nullptr || e2->
fprev !=
nullptr) {
6816 if (!bestf ||
l->
v == bv->
v) {
6821 e->fnext = e2->
fprev = bestf;
6841 BMEdge *first_bme =
nullptr;
6854 if (face_count == 1) {
6905 for (
int i = 0; i < tot_edges; i++) {
6916 e->is_rev = (bme->
v2 ==
v);
6917 e->leftv =
e->rightv =
nullptr;
6918 e->profile_index = 0;
6928 if (tot_edges > 1) {
6929 int ccw_test_sum = 0;
6930 for (
int i = 0; i < tot_edges; i++) {
6934 if (ccw_test_sum < 0) {
6935 for (
int i = 0; i <= (tot_edges / 2) - 1; i++) {
6936 std::swap(bv->
edges[i], bv->
edges[tot_edges - i - 1]);
6940 if (tot_edges % 2 == 1) {
6941 int i = tot_edges / 2;
6948 float vert_axis[3] = {0, 0, 0};
6964 for (
int i = 0; i < tot_edges; i++,
e++) {
6975 for (
int i = 0; i < tot_edges; i++,
e++) {
6976 e->next = &bv->
edges[(i + 1) % tot_edges];
6977 e->prev = &bv->
edges[(i + tot_edges - 1) % tot_edges];
6986 e->offset_l_spec = bp->
offset;
6992 e->offset_l_spec = 0.01f * bp->
offset;
7002 e->offset_l_spec = 0.01f * bp->
offset;
7023 e->offset_l_spec = bp->
offset;
7024 e->offset_r_spec = bp->
offset;
7029 e->offset_l_spec = bp->
offset;
7034 e->offset_r_spec =
e->offset_l_spec;
7040 e->offset_l_spec *= weight;
7041 e->offset_r_spec *= weight;
7050 e->offset_l_spec = bv->
offset;
7058 e->offset_l_spec = 0.01f * bp->
offset;
7070 e->offset_l_spec = 0.01f * bp->
offset;
7082 e->offset_l_spec = bv->
offset;
7086 e->offset_r_spec =
e->offset_l_spec;
7089 e->offset_l_spec =
e->offset_r_spec = 0.0f;
7091 e->offset_l =
e->offset_l_spec;
7092 e->offset_r =
e->offset_r_spec;
7094 if (
e->fprev &&
e->fnext) {
7103 if (tot_wire != 0) {
7121 BMFace **r_new_face =
nullptr)
7123 bool do_rebuild =
false;
7143 if (
e->prev == eprev) {
7144 if (eprev->
prev ==
e) {
7146 go_ccw = (
e->fnext != f);
7152 else if (eprev->
prev ==
e) {
7167 bool on_profile_start =
false;
7173 if (
e->profile_index > 0) {
7174 vstart = vstart->
prev;
7175 on_profile_start =
true;
7179 vstart = eprev->
leftv;
7182 vstart = vstart->
next;
7183 on_profile_start =
true;
7186 BLI_assert(vstart !=
nullptr && vend !=
nullptr);
7188 if (!on_profile_start) {
7191 nv_bv_map.
add(
v->nv.v,
l->
v);
7197 if (on_profile_start) {
7198 kstart =
e->profile_index;
7199 on_profile_start =
false;
7210 for (
int k = kstart; k <= kend; k++) {
7215 nv_bv_map.
add(bmv,
l->
v);
7222 int i =
v->prev->index;
7224 if (on_profile_start) {
7226 on_profile_start =
false;
7229 kstart = vm->
seg - 1;
7231 if (
e->rightv ==
v->prev &&
e->profile_index > 0) {
7232 kend =
e->profile_index;
7237 for (
int k = kstart; k >= kend; k--) {
7242 nv_bv_map.
add(bmv,
l->
v);
7259 bp,
bm, vv.
data(), n,
nullptr, f,
nullptr,
nullptr, &nv_bv_map, -1,
true);
7263 BMEdge *bme_prev = ee[n - 1];
7264 for (
int k = 0; k < n; k++) {
7267 if (ee[k] != bme_new) {
7271 if (k < n - 1 && ee[k] == ee[k + 1]) {
7292 *r_new_face = f_new;
7324 BMFace **r_rebuilt_face_0 =
nullptr)
7332 if (!rebuilt_orig_faces.
contains(f)) {
7333 BMFace *new_face =
nullptr;
7335 rebuilt_orig_faces.
add(f);
7337 *r_rebuilt_face_0 = new_face;
7352 for (
int i = 0; i < bv->
wirecount; i++) {
7355 BMVert *vclosest =
nullptr;
7357 BMVert *votherclosest =
nullptr;
7362 if (!bvother || !bvother->
vmesh) {
7373 vclosest = bndv->
nv.
v;
7374 votherclosest = bndvother->
nv.
v;
7382 vclosest = bndv->
nv.
v;
7383 votherclosest = vother;
7426 BMEdge *bme_prev =
nullptr;
7427 BMEdge *bme_next =
nullptr;
7428 for (
int i = 0; i < 4; i++) {
7429 if (&bv->
edges[i] ==
e) {
7430 bme_prev = bv->
edges[(i + 3) % 4].
e;
7431 bme_next = bv->
edges[(i + 1) % 4].
e;
7444 for (
int i = 0; i < nseg; i++) {
7452 if (enable_smooth) {
7501 BMFace *faces[4] = {f1, f1, f2, f2};
7513 nv_bv_map.
add(verts[0], bv1->
v);
7514 nv_bv_map.
add(verts[1], bv2->
v);
7518 BMFace *fchoices[2] = {f1, f2};
7519 BMFace *f_choice =
nullptr;
7520 int center_adj_k = -1;
7524 center_adj_k = f_choice == f1 ? mid + 2 : mid;
7527 for (
int k = 1; k <= nseg; k++) {
7529 verts[2] =
mesh_vert(vm2, i2, 0, nseg - k)->
v;
7530 nv_bv_map.
add(verts[3], bv1->
v);
7531 nv_bv_map.
add(verts[2], bv2->
v);
7533 if (odd && k == mid + 1) {
7539 if (f_choice == f1) {
7540 edges[0] = edges[1] =
nullptr;
7541 edges[2] = edges[3] = bme;
7544 edges[0] = edges[1] = bme;
7545 edges[2] = edges[3] =
nullptr;
7548 bp,
bm, verts, 4,
nullptr, f_choice, edges,
nullptr, &nv_bv_map, mat_nr,
true);
7553 bp,
bm, verts, 4, faces, f_choice,
nullptr,
nullptr, &nv_bv_map, mat_nr,
true);
7556 else if (odd && k == center_adj_k && e1->
is_seam) {
7564 edges[0] = edges[1] =
nullptr;
7565 edges[2] = edges[3] = bme;
7569 edges[0] = edges[1] = bme;
7570 edges[2] = edges[3] =
nullptr;
7574 bp,
bm, verts, 4,
nullptr, f_interp, edges,
nullptr, &nv_bv_map, mat_nr,
true);
7576 else if (!odd && k == mid) {
7578 BMEdge *edges[4] = {
nullptr,
nullptr, bme, bme};
7580 bp,
bm, verts, 4,
nullptr, f1, edges,
nullptr, &nv_bv_map, mat_nr,
true);
7582 else if (!odd && k == mid + 1) {
7584 BMEdge *edges[4] = {bme, bme,
nullptr,
nullptr};
7586 bp,
bm, verts, 4,
nullptr, f2, edges,
nullptr, &nv_bv_map, mat_nr,
true);
7590 BMFace *f = (k <= mid) ? f1 : f2;
7592 bp,
bm, verts, 4,
nullptr, f,
nullptr,
nullptr, &nv_bv_map, mat_nr,
true);
7599 if (
ELEM(
l->
v, verts[0], verts[2])) {
7603 verts[0] = verts[3];
7604 verts[1] = verts[2];
7630 const double tol = 1
e-13;
7631 const int maxiter = 10;
7634 double xmin = x0 +
M_SQRT2 / 2.0 * dtarget;
7635 xmin = std::min(xmin, 1.0);
7636 double xmax = x0 + dtarget;
7637 xmax = std::min(xmax, 1.0);
7642 double dmaxerr =
sqrt(
pow((xmax - x0), 2) +
pow((ymax - y0), 2)) - dtarget;
7643 double dminerr =
sqrt(
pow((xmin - x0), 2) +
pow((ymin - y0), 2)) - dtarget;
7645 double xnew = xmax - dmaxerr * (xmax - xmin) / (dmaxerr - dminerr);
7646 bool lastupdated_upper =
true;
7648 for (
int iter = 0; iter < maxiter; iter++) {
7650 double dnewerr =
sqrt(
pow((xnew - x0), 2) +
pow((ynew - y0), 2)) - dtarget;
7651 if (
fabs(dnewerr) < tol) {
7658 if (!lastupdated_upper) {
7659 xnew = (dmaxerr / 2 * xmin - dminerr * xmax) / (dmaxerr / 2 - dminerr);
7662 xnew = xmax - dmaxerr * (xmax - xmin) / (dmaxerr - dminerr);
7664 lastupdated_upper =
false;
7670 if (lastupdated_upper) {
7671 xnew = (dmaxerr * xmin - dminerr / 2 * xmax) / (dmaxerr - dminerr / 2);
7674 xnew = xmax - dmaxerr * (xmax - xmin) / (dmaxerr - dminerr);
7676 lastupdated_upper =
true;
7693 const int smoothitermax = 10;
7694 const double error_tol = 1
e-7;
7695 int imax = (seg + 1) / 2 - 1;
7697 bool seg_odd = seg % 2;
7703 mx =
pow(0.5, 1.0 / r);
7707 mx = 1 -
pow(0.5, 1.0 / r);
7711 for (
int i = 0; i <= imax; i++) {
7712 xvals[i] = i * mx / seg * 2;
7718 for (
int iter = 0; iter < smoothitermax; iter++) {
7725 for (
int i = 0; i < imax; i++) {
7726 double d =
sqrt(
pow((xvals[i + 1] - xvals[i]), 2) +
pow((yvals[i + 1] - yvals[i]), 2));
7728 dmax = std::max(d, dmax);
7729 dmin = std::min(d, dmin);
7734 sum +=
M_SQRT2 / 2 * (yvals[imax] - xvals[imax]);
7735 davg = sum / (imax + 0.5);
7738 sum +=
sqrt(
pow((xvals[imax] - mx), 2) +
pow((yvals[imax] - mx), 2));
7739 davg = sum / (imax + 1.0);
7742 bool precision_reached =
true;
7743 if (dmax - davg > error_tol) {
7744 precision_reached =
false;
7746 if (dmin - davg < error_tol) {
7747 precision_reached =
false;
7749 if (precision_reached) {
7754 for (
int i = 1; i <= imax; i++) {
7762 xvals[imax + 1] = mx;
7763 yvals[imax + 1] = mx;
7765 for (
int i = imax + 1; i <= seg; i++) {
7766 yvals[i] = xvals[seg - i];
7767 xvals[i] = yvals[seg - i];
7771 for (
int i = 0; i <= seg; i++) {
7772 double temp = xvals[i];
7773 xvals[i] = 1.0 - yvals[i];
7774 yvals[i] = 1.0 - temp;
7789 bool seg_odd = n % 2;
7795 for (
int i = 0; i <= n; i++) {
7796 xvals[i] = double(i) / n;
7797 yvals[i] = 1.0 - double(i) / n;
7802 double temp =
M_PI_2 / n;
7804 for (
int i = 0; i <= n; i++) {
7805 xvals[i] =
sin(i * temp);
7806 yvals[i] =
cos(i * temp);
7813 for (
int i = 0; i <= n2; i++) {
7815 yvals[i] = 1.0 - double(i) / n2;
7816 xvals[n - i] = yvals[i];
7817 yvals[n - i] = xvals[i];
7822 double temp = 1.0 / (n2 +
M_SQRT2 / 2.0);
7823 for (
int i = 0; i <= n2; i++) {
7825 yvals[i] = 1.0 - double(i) * temp;
7826 xvals[n - i] = yvals[i];
7827 yvals[n - i] = xvals[i];
7835 for (
int i = 0; i <= n2; i++) {
7836 xvals[i] = double(i) / n2;
7838 xvals[n - i] = yvals[i];
7839 yvals[n - i] = xvals[i];
7844 double temp = 1.0 / (n2 +
M_SQRT2 / 2);
7845 for (
int i = 0; i <= n2; i++) {
7846 xvals[i] = double(i) * temp;
7848 xvals[n - i] = yvals[i];
7849 yvals[n - i] = xvals[i];
7868#define CIRCLE_FULLNESS_SEGS 11
7887 for (
int i = 0; i < nseg; i++) {
7898 fullness = circle_fullness[nseg - 1];
7902 if (nseg % 2 == 0) {
7903 fullness = 2.4506f * bp->
profile - 0.00000300f * nseg - 0.6266f;
7906 fullness = 2.3635f * bp->
profile + 0.000152f * nseg - 0.6060f;
7930 pro_spacing->
xvals =
nullptr;
7931 pro_spacing->
yvals =
nullptr;
7932 pro_spacing->
xvals_2 =
nullptr;
7933 pro_spacing->
yvals_2 =
nullptr;
7934 pro_spacing->
seg_2 = 0;
7947 pro_spacing->
xvals_2 =
static_cast<double *
>(
7949 pro_spacing->
yvals_2 =
static_cast<double *
>(
7956 for (
int i = 0; i < seg_2 + 1; i++) {
7968 pro_spacing->
xvals =
static_cast<double *
>(
7970 pro_spacing->
yvals =
static_cast<double *
>(
7979 for (
int i = 0; i < seg + 1; i++) {
8014 float no_collide_offset = bp->
offset + 1e6;
8015 float limit = no_collide_offset;
8016 if (bp->
offset == 0.0f) {
8017 return no_collide_offset;
8044 return bp->
offset > blen / 2.0f ? blen / 2.0f : blen;
8046 return no_collide_offset;
8048 if (ebother !=
nullptr) {
8059 if (eb->
fnext ==
nullptr) {
8060 return no_collide_offset;
8064 return no_collide_offset;
8066 if (lb->
next->
v == vc) {
8069 else if (lb->
v == vc) {
8073 return no_collide_offset;
8076 if (ea->
e == eb->
e || (ec && ec->
e == eb->
e)) {
8077 return no_collide_offset;
8084 float sin1 =
sinf(th1);
8085 float sin2 =
sinf(th2);
8086 float cos1 =
cosf(th1);
8087 float cos2 =
cosf(th2);
8092 float offsets_projected_on_B =
safe_divide(ka + cos1 * kb, sin1) +
8095 offsets_projected_on_B = bp->
offset * (
len_v3v3(vb->
co, vc->
co) / offsets_projected_on_B);
8097 limit = offsets_projected_on_B;
8106 if (kb >
FLT_EPSILON && (ka == 0.0f || kc == 0.0f)) {
8113 float A_side_slide = 0.0f;
8114 float exterior_angle = 0.0f;
8117 while (exterior_angle < 0.0001f) {
8129 limit = std::min(A_side_slide * kb, limit);
8137 float C_side_slide = 0.0f;
8138 float exterior_angle = 0.0f;
8140 while (exterior_angle < 0.0001f) {
8152 limit = std::min(C_side_slide * kb, limit);
8166 float no_collide_offset = bp->
offset + 1e6;
8167 if (bp->
offset == 0.0f) {
8168 return no_collide_offset;
8173 float kab = ka + kb;
8176 return no_collide_offset;
8188 float limited_offset = bp->
offset;
8199 for (
int i = 0; i < bv->
edgecount; i++) {
8203 limited_offset = std::min(collision_offset, limited_offset);
8207 limited_offset = std::min(collision_offset, limited_offset);
8212 if (limited_offset < bp->offset) {
8218 float offset_factor = limited_offset / bp->
offset;
8227 for (
int i = 0; i < bv->
edgecount; i++) {
8235 bp->
offset = limited_offset;
8241 const int offset_type,
8242 const int profile_type,
8244 const float profile,
8245 const bool affect_type,
8246 const bool use_weights,
8247 const bool limit_offset,
8249 const int vertex_group,
8251 const bool loop_slide,
8252 const bool mark_seam,
8253 const bool mark_sharp,
8254 const bool harden_normals,
8255 const int face_strength_mode,
8256 const int miter_outer,
8257 const int miter_inner,
8260 const int vmesh_method,
8261 const int bweight_offset_vert,
8262 const int bweight_offset_edge)
8304#ifdef BEVEL_DEBUG_TIME
8314 if (profile >= 0.950f) {
8355 if (!limit_offset && bv) {
8430 for (
BMFace *f : rebuilt_orig_faces) {
8479#ifdef BEVEL_DEBUG_TIME
8481 printf(
"BMESH BEVEL TIME = %.3f\n", end_time - start_time);
CustomData interface, see also DNA_customdata_types.h.
#define STD_UV_CONNECT_LIMIT
#define BLI_array_alloca(arr, realsize)
#define BLI_ASSERT_UNIT_V3(v)
Platform independent time functions.
#define MOD_WEIGHTEDNORMALS_FACEWEIGHT_CDLAYER_ID
Read Blender memory allocation and freeing.
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert_msg(a, msg)
#define BM_BEVEL_EDGE_TAG_DISABLE(bme)
#define BEVEL_EPSILON_ANG
#define BEVEL_SMALL_ANG_DOT
#define BM_BEVEL_EDGE_TAG_TEST(bme)
#define BEVEL_EPSILON_ANG_DOT
#define BM_BEVEL_EDGE_TAG_ENABLE(bme)
#define HASNOT_SEAMSHARP(eh, flag)
#define BEVEL_EPSILON_BIG
#define BEVEL_MATCH_SPEC_WEIGHT
#define CIRCLE_FULLNESS_SEGS
#define BM_ELEM_CD_GET_FLOAT(ele, offset)
#define BM_DISK_EDGE_NEXT(e, v)
#define BM_FACE_FIRST_LOOP(p)
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
#define BM_elem_index_get(ele)
#define BM_elem_flag_disable(ele, hflag)
#define BM_elem_flag_set(ele, hflag, val)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_ITER_MESH_MUTABLE(ele, ele_next, iter, bm, itype)
#define BMO_edge_flag_test(bm, e, oflag)
#define BMO_edge_flag_enable(bm, e, oflag)
#define BMO_vert_flag_enable(bm, e, oflag)
#define BMO_vert_flag_test(bm, e, oflag)
#define BMO_edge_flag_disable(bm, e, oflag)
#define MEM_SIZE_OPTIMAL(size)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
SIMD_FORCE_INLINE btVector3 dot3(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2) const
const Value * lookup_ptr(const Key &key) const
std::optional< Value > pop_try(const Key &key)
bool add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
bool contains(const Key &key) const
void append(const T &value)
CCL_NAMESPACE_BEGIN ccl_device_inline float frac(const float x, ccl_private int *ix)
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
float length(VecOp< float, D >) RET
void EIG_linear_solver_print_matrix(LinearSolver *solver)
void EIG_linear_solver_right_hand_side_add(LinearSolver *solver, int rhs, int index, double value)
LinearSolver * EIG_linear_least_squares_solver_new(int num_rows, int num_columns, int num_right_hand_sides)
void EIG_linear_solver_delete(LinearSolver *solver)
double EIG_linear_solver_variable_get(LinearSolver *solver, int rhs, int index)
void EIG_linear_solver_matrix_add(LinearSolver *solver, int row, int col, double value)
bool EIG_linear_solver_solve(LinearSolver *solver)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str)
ccl_device_inline float beta(const float x, const float y)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
MINLINE float min_ff(float a, float b)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
void BM_lnorspace_update(BMesh *bm)
static bool is_canon(VMesh *vm, int i, int j, int k)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void closest_to_plane_v3(float r_close[3], const float plane[4], const float pt[3])
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
BMFace * BM_face_create_verts(BMesh *bm, BMVert **vert_arr, const int len, const BMFace *f_example, const eBMCreateFlag create_flag, const bool create_edges)
static void create_mesh_bmvert(BMesh *bm, VMesh *vm, int i, int j, int k, BMVert *eg)
void BKE_curveprofile_init(struct CurveProfile *profile, short segments_len)
static void set_bound_vert_seams(BevVert *bv, bool mark_seam, bool mark_sharp)
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
static void build_boundary_terminal_edge(BevelParams *bp, BevVert *bv, EdgeHalf *efirst, const bool construct)
int BM_edge_face_count(const BMEdge *e)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
static void move_weld_profile_planes(BevVert *bv, BoundVert *bndv1, BoundVert *bndv2)
@ BEVEL_FACE_STRENGTH_ALL
@ BEVEL_FACE_STRENGTH_NEW
@ BEVEL_FACE_STRENGTH_NONE
@ BEVEL_FACE_STRENGTH_AFFECTED
BLI_INLINE bool BM_edge_is_wire(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static BMFace * frep_for_center_poly(BevelParams *bp, BevVert *bv)
static void uv_vert_map_pop(BevelParams *bp, BMVert *v)
void BLI_memarena_use_calloc(MemArena *ma) ATTR_NONNULL(1)
int CustomData_number_of_layers(const CustomData *data, eCustomDataType type)
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
static void update_uv_vert_map(BevelParams *bp, UVFace *uv_face, BMVert *bv, Map< BMVert *, BMVert * > *nv_bv_map)
Set< BMLoop * > UVVertBucket
static float vertex_collide_offset(BevelParams *bp, EdgeHalf *ea)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void fill_profile_fracs(BevelParams *bp, BoundVert *bndv, float *frac, int ns)
static EdgeHalf * next_edgehalf_bev(BevelParams *bp, EdgeHalf *start_edge, bool toward_bv, BevVert **r_bv)
static NewVert * mesh_vert_canon(VMesh *vm, int i, int j, int k)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
static BMFace * choose_rep_face(BevelParams *bp, BMFace **face, int nfaces)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
static void bevel_edges_sharp_boundary(BMesh *bm, BevelParams *bp)
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
void BM_vert_kill(BMesh *bm, BMVert *v)
static void bevel_merge_uvs(BevelParams *bp, BMesh *bm)
float BM_edge_calc_face_angle_signed_ex(const BMEdge *e, const float fallback)
BMESH EDGE/FACE ANGLE.
static bool bev_rebuild_polygon(BMesh *bm, BevelParams *bp, BMFace *f, BMFace **r_new_face=nullptr)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
MINLINE void mul_v2_fl(float r[2], float f)
static void swap_face_components(int *face_component, int totface, int c1, int c2)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
static BoundVert * add_new_bound_vert(MemArena *mem_arena, VMesh *vm, const float co[3])
static void offset_in_plane(EdgeHalf *e, const float plane_no[3], bool left, float r_co[3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
static BMFace * boundvert_rep_face(BoundVert *v, BMFace **r_fother)
float angle_v3v3v3(const float a[3], const float b[3], const float c[3]) ATTR_WARN_UNUSED_RESULT
static void build_square_in_vmesh(BevelParams *bp, BMesh *bm, BevVert *bv, VMesh *vm1)
static bool good_offset_on_edge_between(EdgeHalf *e1, EdgeHalf *e2, EdgeHalf *emid, BMVert *v)
int CustomData_get_n_offset(const CustomData *data, eCustomDataType type, int n)
static EdgeHalf * next_bev(BevVert *bv, EdgeHalf *from_e)
static AngleKind edges_angle_kind(EdgeHalf *e1, EdgeHalf *e2, BMVert *v)
float angle_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void mul_v2_m3v3(float r[2], const float M[3][3], const float a[3])
static void copy_mesh_vert(VMesh *vm, int ito, int jto, int kto, int ifrom, int jfrom, int kfrom)
BMLoop * BM_vert_step_fan_loop(BMLoop *l, BMEdge **e_step)
MINLINE int power_of_2_max_i(int n)
static BevVert * find_bevvert(BevelParams *bp, BMVert *bmv)
BMLoop * BM_face_edge_share_loop(BMFace *f, BMEdge *e)
Return the Loop Shared by Face and Edge.
bool CustomData_data_equals(eCustomDataType type, const void *data1, const void *data2)
static int interp_range(const float *frac, int n, const float f, float *r_rest)
float closest_to_line_segment_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3])
static void bevel_build_trifan(BevelParams *bp, BMesh *bm, BevVert *bv)
static bool nearly_parallel(const float d1[3], const float d2[3])
static bool bevvert_is_weld_cross(BevVert *bv)
static void adjust_miter_inner_coords(BevelParams *bp, BevVert *bv, EdgeHalf *emiter)
MINLINE int max_ii(int a, int b)
static void project_to_edge(const BMEdge *e, const float co_a[3], const float co_b[3], float projco[3])
int CustomData_get_layer_index(const CustomData *data, eCustomDataType type)
ATTR_WARN_UNUSED_RESULT const BMVert * v
BMVert * BM_vert_create(BMesh *bm, const float co[3], const BMVert *v_example, const eBMCreateFlag create_flag)
Main function for creating a new vertex.
static float geometry_collide_offset(BevelParams *bp, EdgeHalf *eb)
static bool eh_on_plane(EdgeHalf *e)
BLI_INLINE bool BM_edge_is_manifold(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static void math_layer_info_init(BevelParams *bp, BMesh *bm)
static int bevel_edge_order_extend(BMesh *bm, BevVert *bv, int i)
static void bevel_rebuild_existing_polygons(BMesh *bm, BevelParams *bp, BMVert *v, Set< BMFace * > &rebuilt_orig_faces, BMFace **r_rebuilt_face_0=nullptr)
BLI_INLINE void adjust_bound_vert(BoundVert *bv, const float co[3])
static void calculate_profile(BevelParams *bp, BoundVert *bndv, bool reversed, bool miter)
static BoundVert * pipe_test(BevVert *bv)
static void get_profile_point(BevelParams *bp, const Profile *pro, int i, int nseg, float r_co[3])
float BM_edge_calc_length(const BMEdge *e)
static void vmesh_copy_equiv_verts(VMesh *vm)
void closest_to_plane_normalized_v3(float r_close[3], const float plane[4], const float pt[3])
static void snap_to_pipe_profile(BoundVert *vpipe, bool midline, float co[3])
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
static void build_boundary_vertex_only(BevelParams *bp, BevVert *bv, bool construct)
static void record_face_kind(BevelParams *bp, BMFace *f, FKind fkind)
BLI_INLINE BMVert * BM_edge_other_vert(BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
MINLINE void mul_v3_fl(float r[3], float f)
static void set_profile_params(BevelParams *bp, BevVert *bv, BoundVert *bndv)
void BM_face_calc_center_bounds(const BMFace *f, float r_cent[3])
static void bevel_limit_offset(BevelParams *bp, BMesh *bm)
bool BM_face_point_inside_test(const BMFace *f, const float co[3])
static void calculate_vm_profiles(BevelParams *bp, BevVert *bv, VMesh *vm)
MINLINE void sub_v3_v3(float r[3], const float a[3])
static void get_incident_edges(BMFace *f, BMVert *v, BMEdge **r_e1, BMEdge **r_e2)
static void fill_vmesh_fracs(VMesh *vm, float *frac, int i)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
float BKE_defvert_find_weight(const MDeformVert *dvert, int defgroup)
float area_poly_v2(const float verts[][2], unsigned int nr)
static void adjust_the_cycle_or_chain(BoundVert *vstart, bool iscycle)
static void move_profile_plane(BoundVert *bndv, BMVert *bmvert)
static void make_unit_cube_map(const float va[3], const float vb[3], const float vc[3], const float vd[3], float r_mat[4][4])
static bool is_bad_uv_poly(BevVert *bv, BMFace *frep)
MINLINE void add_v2_v2(float r[2], const float a[2])
static BMEdge * find_closer_edge(float *co, BMEdge *e1, BMEdge *e2)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
static VMesh * make_cube_corner_square_in(MemArena *mem_arena, int nseg)
static bool edges_face_connected_at_vert(BMEdge *bme1, BMEdge *bme2)
static BMFace * bevel_build_poly(BevelParams *bp, BMesh *bm, BevVert *bv)
static void build_vmesh(BevelParams *bp, BMesh *bm, BevVert *bv)
static VMesh * interp_vmesh(BevelParams *bp, VMesh *vm_in, int nseg)
static float find_profile_fullness(BevelParams *bp)
static BevVert * bevel_vert_construct(BMesh *bm, BevelParams *bp, BMVert *v)
static UVFace * find_uv_face(BevelParams *bp, BMFace *bmf)
static bool contig_ldata_around_vert(BMesh *bm, BMVert *v)
static VMesh * pipe_adj_vmesh(BevelParams *bp, BevVert *bv, BoundVert *vpipe)
int CustomData_get_offset_named(const CustomData *data, eCustomDataType type, StringRef name)
static void bevel_reattach_wires(BMesh *bm, BevelParams *bp, BMVert *v)
static double superellipse_co(double x, float r, bool rbig)
static void flag_out_edge(BMesh *bm, BMEdge *bme)
static bool fast_bevel_edge_order(BevVert *bv)
MINLINE void negate_v3(float r[3])
static void flag_out_vert(BMesh *bm, BMVert *bmv)
static void adjust_offsets(BevelParams *bp, BMesh *bm)
static bool offset_on_edge_between(BevelParams *bp, EdgeHalf *e1, EdgeHalf *e2, EdgeHalf *emid, BMVert *v, float meetco[3], float *r_sinratio)
static void bevel_build_edge_polygons(BMesh *bm, BevelParams *bp, BMEdge *bme)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
static void find_even_superellipse_chords_general(int seg, float r, double *xvals, double *yvals)
static float sabin_gamma(int n)
static int find_face_internal_boundverts(const BevVert *bv, const BMFace *f, BoundVert *(r_internal[3]))
static void calculate_profile_segments(const Profile *profile, const float map[4][4], const bool use_map, const bool reversed, const int ns, const double *xvals, const double *yvals, float *r_prof_co)
static void bevel_harden_normals(BevelParams *bp, BMesh *bm)
Harden normals for bevel.
static float projected_boundary_area(BevVert *bv, BMFace *f)
void BKE_lnor_space_custom_normal_to_data(const MLoopNorSpace *lnor_space, const float custom_lnor[3], short r_clnor_data[2])
float dist_squared_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3])
static void slide_dist(EdgeHalf *e, BMVert *v, float d, float r_slideco[3])
static NewVert * mesh_vert(VMesh *vm, int i, int j, int k)
MINLINE void zero_v3(float r[3])
static bool is_outside_edge(EdgeHalf *e, const float co[3], BMVert **ret_closer_v)
void mul_m4_v4(const float mat[4][4], float r[4])
static UVFace * register_uv_face(BevelParams *bp, BMFace *fnew, BMFace *frep, BMFace **frep_arr)
static void snap_to_superellipsoid(float co[3], const float super_r, bool midline)
bool isect_line_plane_v3(float r_isect_co[3], const float l1[3], const float l2[3], const float plane_co[3], const float plane_no[3]) ATTR_WARN_UNUSED_RESULT
void BM_mesh_bevel(BMesh *bm, const float offset, const int offset_type, const int profile_type, const int segments, const float profile, const bool affect_type, const bool use_weights, const bool limit_offset, const MDeformVert *dvert, const int vertex_group, const int mat, const bool loop_slide, const bool mark_seam, const bool mark_sharp, const bool harden_normals, const int face_strength_mode, const int miter_outer, const int miter_inner, const float spread, const CurveProfile *custom_profile, const int vmesh_method, const int bweight_offset_vert, const int bweight_offset_edge)
static int tri_corner_test(BevelParams *bp, BevVert *bv)
static bool contig_ldata_across_edge(BMesh *bm, BMEdge *e, BMFace *f1, BMFace *f2)
int CustomData_get_named_layer_index(const CustomData *data, eCustomDataType type, StringRef name)
static void find_even_superellipse_chords(int n, float r, double *xvals, double *yvals)
static void avg4(float co[3], const NewVert *v0, const NewVert *v1, const NewVert *v2, const NewVert *v3)
static void snap_edges_for_vmesh_vert(int i, int j, int k, int ns, int ns2, int n_bndv, BMEdge *eprev, BMEdge *enext, BMEdge *enextnext, BMFace **bndv_rep_faces, BMFace *center_frep, const bool *frep_beats_next, BMEdge *r_snap_edges[4])
static void disable_flag_out_edge(BMesh *bm, BMEdge *bme)
void * BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
static bool make_unit_square_map(const float va[3], const float vmid[3], const float vb[3], float r_mat[4][4])
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
static void bevel_extend_edge_data_ex(BevVert *bv, int flag)
static void uv_vert_map_init(BevelParams *bp, BMesh *bm)
bool BM_edge_loop_pair(BMEdge *e, BMLoop **r_la, BMLoop **r_lb)
static VMesh * make_cube_corner_square(MemArena *mem_arena, int nseg)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
static float edge_face_angle(EdgeHalf *e)
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
static void bevel_build_cutoff(BevelParams *bp, BMesh *bm, BevVert *bv)
static bool point_between_edges(const float co[3], BMVert *v, BMFace *f, EdgeHalf *e1, EdgeHalf *e2)
MINLINE bool compare_v3v3(const float v1[3], const float v2[3], float limit) ATTR_WARN_UNUSED_RESULT
static void build_boundary(BevelParams *bp, BevVert *bv, bool construct)
float dist_squared_to_plane_v3(const float p[3], const float plane[4])
Map< BMVert *, Vector< UVVertBucket > > UVVertMap
static BMFace * bev_create_ngon(BevelParams *bp, BMesh *bm, BMVert **vert_arr, const int totv, BMFace **face_arr, BMFace *facerep, BMEdge **snap_edge_arr, BMVert *bv, Map< BMVert *, BMVert * > *nv_bv_map, int mat_nr, bool do_interp)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
MINLINE void copy_v3_fl(float r[3], float f)
void BM_face_kill(BMesh *bm, BMFace *f)
void interp_bilinear_quad_v3(float data[4][3], float u, float v, float res[3])
static EdgeHalf * find_edge_half(BevVert *bv, BMEdge *bme)
MINLINE float max_ff(float a, float b)
BMFace * BM_face_split(BMesh *bm, BMFace *f, BMLoop *l_a, BMLoop *l_b, BMLoop **r_l, BMEdge *example, const bool no_double)
Face Split.
static bool contig_ldata_across_loops(BMesh *bm, BMLoop *l1, BMLoop *l2, int layer_index)
static void closer_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float v[3])
static bool nearly_parallel_normalized(const float d1[3], const float d2[3])
static void weld_cross_attrs_copy(BMesh *bm, BevVert *bv, VMesh *vm, int vmindex, EdgeHalf *e)
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
static BMEdge * snap_edge_for_center_vmesh_vert(int i, int n_bndv, BMEdge *eprev, BMEdge *enext, BMFace **bndv_rep_faces, BMFace *center_frep, const bool *frep_beats_next)
static void bevel_build_rings(BevelParams *bp, BMesh *bm, BevVert *bv, BoundVert *vpipe)
static void offset_meet(BevelParams *bp, EdgeHalf *e1, EdgeHalf *e2, BMVert *v, BMFace *f, bool edges_between, float meetco[3], const EdgeHalf *e_in_plane)
static VMesh * cubic_subdiv(BevelParams *bp, VMesh *vm_in)
static double find_superellipse_chord_endpoint(double x0, double dtarget, float r, bool rbig)
@ BEVEL_PROFILE_SUPERELLIPSE
double BLI_time_now_seconds()
static VMesh * tri_corner_adj_vmesh(BevelParams *bp, BevVert *bv)
static void regularize_profile_orientation(BevelParams *bp, BMEdge *bme)
static int count_ccw_edges_between(EdgeHalf *e1, EdgeHalf *e2)
BMLoop * BM_face_vert_share_loop(BMFace *f, BMVert *v)
Return the Loop Shared by Face and Vertex.
void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const StringRef name)
static void build_center_ngon(BevelParams *bp, BMesh *bm, BevVert *bv, int mat_nr)
static EdgeHalf * find_other_end_edge_half(BevelParams *bp, EdgeHalf *e, BevVert **r_bvother)
static VMesh * square_out_adj_vmesh(BevelParams *bp, BevVert *bv)
static void bevel_extend_edge_data(BevVert *bv)
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
BLI_INLINE BMFace * BM_face_at_index(BMesh *bm, const int index)
MINLINE int is_power_of_2_i(int n)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static void find_bevel_edge_order(BMesh *bm, BevVert *bv, BMEdge *first_bme)
static void check_edge_data_seam_sharp_edges(BevVert *bv, int flag)
static VMesh * make_cube_corner_adj_vmesh(BevelParams *bp)
static void vmesh_center(VMesh *vm, float r_cent[3])
static VMesh * adj_vmesh(BevelParams *bp, BevVert *bv)
static bool offset_meet_edge(EdgeHalf *e1, EdgeHalf *e2, BMVert *v, float meetco[3], float *r_angle)
MINLINE float safe_divide(float a, float b)
static int bev_ccw_test(BMEdge *a, BMEdge *b, BMFace *f)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
BMEdge * BM_edge_create(BMesh *bm, BMVert *v1, BMVert *v2, const BMEdge *e_example, const eBMCreateFlag create_flag)
Main function for creating a new edge.
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
bool CustomData_layer_has_math(const CustomData *data, int layer_n)
static bool edge_edge_angle_less_than_180(const BMEdge *e1, const BMEdge *e2, const BMFace *f)
static void determine_uv_vert_connectivity(BevelParams *bp, BMesh *bm, BMVert *v)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
MINLINE int compare_ff(float a, float b, float max_diff)
bool BM_vert_face_check(const BMVert *v)
void BM_mesh_normals_update(BMesh *bm)
static VMesh * new_adj_vmesh(MemArena *mem_arena, int count, int seg, BoundVert *bounds)
void BM_loop_interp_from_face(BMesh *bm, BMLoop *l_dst, const BMFace *f_src, const bool do_vertex, const bool do_multires)
void axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3])
Normal to x,y matrix.
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
int isect_line_line_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float r_i1[3], float r_i2[3])
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static FKind get_face_kind(BevelParams *bp, BMFace *f)
static void offset_meet_lines_percent_or_absolute(BevelParams *bp, EdgeHalf *e1, EdgeHalf *e2, BMVert *v, float r_l1a[3], float r_l1b[3], float r_l2a[3], float r_l2b[3])
static void bevel_vert_two_edges(BevelParams *bp, BMesh *bm, BevVert *bv)
static void adjust_miter_coords(BevelParams *bp, BevVert *bv, EdgeHalf *emiter)
MINLINE bool compare_v2v2(const float v1[2], const float v2[2], float limit) ATTR_WARN_UNUSED_RESULT
static void bevel_set_weighted_normal_face_strength(BMesh *bm, BevelParams *bp)
static void set_profile_spacing(BevelParams *bp, ProfileSpacing *pro_spacing, bool custom)
vector snap(vector a, vector b)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct BMLoop * radial_next
struct MLoopNorSpaceArray * lnor_spacearr
Vector< UVVertMap > uv_vert_maps
const MDeformVert * dvert
ProfileSpacing pro_spacing
Map< BMVert *, BevVert * > vert_hash
const CurveProfile * custom_profile
Map< BMFace *, UVFace * > uv_face_hash
MathLayerInfo math_layer_info
std::optional< Map< BMFace *, FKind > > face_hash
ProfileSpacing pro_spacing_miter
CurveProfilePoint * segments
MLoopNorSpace ** lspacearr
ccl_device_inline void print_float3(const ccl_private char *label, const float3 a)