14#include <fmt/format.h>
272 EdgeMap edge_lookup_;
295 int edge_create(
const int v1,
const int v2,
int example_edge = -1);
323 if (new_idx >= 0 && new_idx <
int(new_edge_examples_.size())) {
324 new_edge_examples_[new_idx] = example_edge;
334 if (new_idx >= 0 && new_idx <
int(new_edge_seam_overrides_.size())) {
335 new_edge_seam_overrides_[new_idx] = value;
343 if (new_idx >= 0 && new_idx <
int(new_edge_sharp_overrides_.size())) {
344 new_edge_sharp_overrides_[new_idx] = value;
355 return new_corner_uvs_[layer_index].as_mutable_span();
359 return new_corner_uvs_[layer_index].as_span();
369 return new_vert_to_new_corners_;
380 return new_vert_bev_origin_;
398 return int(new_face_offsets_.size()) - 1;
403 return new_vert_positions_;
412 return new_face_offsets_;
416 return new_corner_verts_;
420 return new_corner_edges_;
427 return new_vert_examples_;
431 return new_edge_examples_;
435 return new_edge_seam_overrides_;
439 return new_edge_sharp_overrides_;
443 return new_face_examples_;
447 return new_face_kinds_;
451 return new_face_kinds_.as_mutable_span();
455 return new_edge_kinds_;
460 if (!new_face_kinds_.is_empty()) {
461 new_face_kinds_.last() = kind;
471 if (ni >= 0 && ni <
int(new_edge_kinds_.size())) {
472 new_edge_kinds_[ni] = kind;
479 return new_corner_face_reps_;
484 return new_corner_snap_edges_;
500 return kill_corners_;
519 edge_to_face_map_indices_,
520 edge_to_face_map_offsets_);
530 for (
const int e : this->
src_edges.index_range()) {
534 new_face_offsets_.append(0);
550 return int2(edge_lookup_[
e].v_low, edge_lookup_[
e].v_high);
559 const int start = new_face_offsets_[f_new];
560 const int size = new_face_offsets_[f_new + 1] - start;
583 new_vert_positions_.append(co);
584 new_vert_examples_.append(example_vert);
585 if (example_vert >= 0) {
586 new_vert_bev_origin_.add_overwrite(
index, example_vert);
593 const int start_size = edge_lookup_.size();
595 if (edge_lookup_.size() != start_size) {
596 new_edge_examples_.append(example_edge);
597 new_edge_seam_overrides_.append(-1);
598 new_edge_sharp_overrides_.append(-1);
606 const int face_index =
mesh.
faces_num + new_face_offsets_.size() - 1;
609 const int v1 = verts[i];
610 const int v2 = verts[(i + 1) % verts.
size()];
614 const int nc = int(new_corner_verts_.size());
615 new_corner_verts_.append(v1);
616 new_corner_edges_.append(
e);
618 new_corner_face_reps_.append(-1);
619 new_corner_snap_edges_.append(-1);
622 layer_uvs.append(
float2(0.0f));
625 new_vert_to_new_corners_.lookup_or_add_default(v1).append(nc);
628 new_face_offsets_.append(
int(new_corner_verts_.size()));
629 new_face_examples_.append(example_face);
637 new_corner_uvs_.resize(uv_layers_num);
648 const int c_start = new_face_offsets_[f_new];
649 const int c_end = new_face_offsets_[f_new + 1];
650 const int n = c_end - c_start;
651 for (
int i = 0; i < n; i++) {
653 new_corner_face_reps_[c_start + i] = face_reps[i];
656 new_corner_snap_edges_[c_start + i] = snap_edges[i];
664 kill_verts_[
v] =
true;
667 kill_edges_[
e] =
true;
675 kill_edges_[
e] =
true;
682 kill_faces_[f] =
true;
685 kill_corners_[c] =
true;
693 kill_corners_[c] =
true;
778 const int v1 = edge_verts[0];
779 const int v2 = edge_verts[1];
790 if (c1_v1 == -1 || c1_v2 == -1 || c2_v1 == -1 || c2_v2 == -1) {
795 if (attr.values[c1_v1] != attr.values[c2_v1]) {
798 if (attr.values[c1_v2] != attr.values[c2_v2]) {
827 int current_component = -1;
836 in_stack[f_curr] =
false;
845 for (
const int e_index : face_edges) {
846 const Span<int> adj_faces = edge_faces[e_index];
847 for (
const int f_other : adj_faces) {
848 if (f_other != f_curr) {
854 in_stack[f_other] =
true;
866 if (current_component <= 0) {
871 float top_face_z = -1e30f;
872 int top_face_component = -1;
873 float bot_face_z = 1e30f;
874 int bot_face_component = -1;
878 float max_z = -1e30f;
879 for (
const int corner : faces[f]) {
880 const float fz = positions[corner_verts[corner]].z;
881 min_z = std::min(min_z, fz);
882 max_z = std::max(max_z, fz);
884 const float fz = (min_z + max_z) * 0.5f;
886 if (fz > top_face_z) {
890 if (fz < bot_face_z) {
896 auto swap_face_components = [&](
int c1,
int c2) {
910 swap_face_components(this->
face_component[0], top_face_component);
911 if (bot_face_component != top_face_component) {
912 if (bot_face_component == 0) {
914 bot_face_component = top_face_component;
916 swap_face_components(this->
face_component[1], bot_face_component);
927 if (corners.size() < 2) {
930 const int c_first = corners[0];
933 for (
const int c : corners.drop_front(1)) {
934 if (attr.values[c] != uv_ref) {
1003 this->bevel_affected_vertices = selection;
1009 const GroupedSpan<int> edge_faces = emesh.src_edge_to_face;
1010 this->selection = IndexMask::from_predicate(
1011 selection, memory, [&](const int i) { return edge_faces[i].size() == 2; });
1015 src_edges, this->selection,
mesh.verts_num,
memory);
1020 this->bevel_affected_vertices.to_bools(is_vert_affected.as_mutable_span());
1026 return std::ranges::any_of(corner_verts.slice(faces[i]),
1027 [&](const int v) { return is_vert_affected[v]; });
1032 this->bevel_affected_faces.foreach_index(
1035 corner_verts.
slice(faces[f]));
1039 this->affect_vertices_odd =
false;
1040 this->limit_offset =
false;
1041 this->mark_seam =
false;
1042 this->mark_sharp =
false;
1043 this->vmesh_method = VMeshMethod::Adj;
1044 if (this->vmesh_method == VMeshMethod::Cutoff) {
1046 this->params.miter.fill(
false);
1052 this->all_miters_off = this->params.miter.is_empty() ||
1054 this->all_miters_on = !this->params.miter.is_empty() &&
1071 return verts[0] ==
v ? verts[1] : verts[0];
1085 return v_co + dir * d;
1157 if (edges_between) {
1179 for (
EdgeHalf *eloop = e1; eloop != e2; eloop = eloop->
next) {
1180 if (eloop->fnext != -1) {
1189 norm_v /=
float(fcount);
1192 float3 dir_sum = dir1 + dir2;
1196 meetco = v_co + norm_perp1 * d;
1216 else if (!edges_between) {
1229 int f_curr = e1->
fnext;
1252 float3 off1b = off1a + dir1;
1254 float3 off2b = off2a + dir2;
1259 if (isect_kind == 0) {
1277 if (isect_kind == 2) {
1281 for (
EdgeHalf *e_loop = e1; e_loop != e2; e_loop = e_loop->
next) {
1282 int fnext = e_loop->fnext;
1320 const int nk = vm->
seg + 1;
1321 const int nj = vm->
seg / 2 + 1;
1322 return &vm->
mesh[i * nj * nk + j * nk + k];
1333 const int n = vm->
count;
1334 const int ns = vm->
seg;
1335 const int ns2 = ns / 2;
1336 const int odd = ns % 2;
1337 BLI_assert(0 <= i && i <= n && 0 <= j && j <= ns && 0 <= k && k <= ns);
1339 if (!odd && j == ns2 && k == ns2) {
1342 if (j <= ns2 - 1 + odd && k <= ns2) {
1346 return mesh_vert(vm, (i + n - 1) % n, k, ns - j);
1348 return mesh_vert(vm, (i + 1) % n, ns - k, j);
1354 const int ns2 = vm->
seg / 2;
1355 if (vm->
seg % 2 == 1) {
1356 return (j <= ns2 && k <= ns2);
1358 return ((j < ns2 && k <= ns2) || (j == ns2 && k == ns2 && i == 0));
1364 const int n = vm->
count;
1365 const int ns = vm->
seg;
1366 const int ns2 = ns / 2;
1367 for (
int i = 0; i < n; i++) {
1368 for (
int j = 0; j <= ns2; j++) {
1369 for (
int k = 0; k <= ns; k++) {
1385 const int n = vm->
count;
1386 const int ns2 = vm->
seg / 2;
1389 for (
int i = 0; i < n; i++) {
1392 return cent * (1.0f /
float(n));
1400 return (v0->
co + v1->
co +
v2->
co + v3->
co) * 0.25f;
1426 const float3 va_vmid = vmid - va;
1427 const float3 vb_vmid = vmid - vb;
1438 const float3 vo = va - vb_vmid;
1440 const float3 vd = vo + vddir;
1443 r_mat[0] =
float4(vmid - va, 0.0f);
1444 r_mat[1] =
float4(vmid - vb, 0.0f);
1445 r_mat[2] =
float4(vmid + vd - va - vb, 0.0f);
1446 r_mat[3] =
float4(va + vb - vmid, 1.0f);
1461 return 0.065247584f;
1467 return 0.401983447f;
1470 return 0.523423277f;
1472 const double k =
cos(
M_PI /
double(n));
1473 const double k2 = k * k;
1474 const double k4 = k2 * k2;
1475 const double k6 = k4 * k2;
1476 const double y =
pow(
M_SQRT3 *
sqrt(64.0 * k6 - 144.0 * k4 + 135.0 * k2 - 27.0) + 9.0 * k,
1478 const double x = 0.480749856769136 *
y - (0.231120424783545 * (12.0 * k2 - 9.0)) /
y;
1479 return float((k *
x + 2.0 * k2 - 1.0) / (
x *
x * (k *
x + 1.0)));
1497 if (span.
size() == 0) {
1500 fmt::print(
"{}:", label);
1503 fmt::print(
"\n[{}] ", i);
1505 fmt::print(
"{} ", span[i]);
1513 fmt::print(
"({},{},{})",
v[0],
v[1],
v[2]);
1519 if (span.
size() == 0) {
1522 fmt::print(
"{}:", label);
1525 fmt::print(
"\n[{}] ", i);
1536 fmt::print(
"({},{})", pair[0], pair[1]);
1542 if (span.
size() == 0) {
1545 fmt::print(
"{}:", label);
1548 fmt::print(
"\n[{}] ", i);
1559 if (range.
size() == 0) {
1563 fmt::print(
"[{}..{}]", range.
first(), range.
last());
1571 if (groupedspan.
size() == 0) {
1574 fmt::println(
"{}:", label);
1576 fmt::print(
"[{}] ", i);
1577 for (
int v : groupedspan[i]) {
1578 fmt::print(
"{} ",
v);
1606 fmt::print(
" Profile: super_r={} height={} special_params={}\n",
1610 fmt::print(
" start=");
1612 fmt::print(
" middle=");
1614 fmt::print(
" end=");
1617 fmt::print(
" plane_no=");
1619 fmt::print(
" plane_co=");
1621 fmt::print(
" proj_dir=");
1632 fmt::println(
" EdgeHalf[{}]: e={} fprev={} fnext={}",
index, eh.
e, eh.
fprev, eh.
fnext);
1633 fmt::println(
" offset_l={} offset_r={} offset_l_spec={} offset_r_spec={}",
1638 fmt::println(
" is_bev={} is_rev={} is_seam={} visited_rpo={}",
1643 fmt::println(
" leftv={} rightv={}",
1651 fmt::print(
" BoundVert[{}]: co=", bndv.
index);
1654 fmt::println(
" efirst={} elast={} ebev={}",
1659 fmt::println(
" is_arc_start={} is_patch_start={} is_profile_start={}",
1673 fmt::println(
" (no boundverts)");
1684 if (!vm.
mesh.is_empty()) {
1685 const int n = vm.
count;
1686 const int ns = vm.
seg;
1687 const int ns2 = ns / 2;
1690 fmt::println(
" NewVerts (i, j, k) for 0<=i<{} 0<=j<={} 0<=k<{}:", n, ns2, ns);
1691 for (
int i = 0; i < n; i++) {
1692 for (
int j = 0; j <= ns2; j++) {
1693 fmt::print(
" ({},{}): ", i, j);
1694 for (
int k = 0; k < ns; k++) {
1696 fmt::print(
"({},({:.3f},{:.3f},{:.3f})) ", nv->
v, nv->
co[0], nv->
co[1], nv->
co[2]);
1707 fmt::println(
"BevVert: v={} edgecount={} selcount={} wirecount={}",
1715 fmt::println(
" edges ({}):", bv.
edges.size());
1716 for (
const int i : bv.
edges.index_range()) {
1730 fmt::println(
" (no vmesh)");
1752 const int ns = vm->
seg;
1754 fmt::println(
" Edge polygons for bv={}:", bv.
v);
1756 for (
int ei = 0; ei < bv.
edgecount; ei++) {
1762 fmt::println(
" EdgeHalf[{}] e={} i={}:", ei, eh.
e, i);
1764 for (
int k = 0; k < ns; k++) {
1768 if (va < 0 || vb < 0) {
1775 const int past_new_face = first_new_face + emesh.
new_faces_num();
1777 for (
int fi = first_new_face; fi < past_new_face && !found; fi++) {
1781 const int sz = int(corners.size());
1782 int pos_va = -1, pos_vb = -1;
1783 for (
int ci = 0; ci < sz; ci++) {
1792 if (pos_va >= 0 && pos_vb >= 0 && (pos_vb + 1) % sz == pos_va) {
1794 fmt::print(
" k={} face={} corners:", k, fi);
1795 for (
int ci = 0; ci < sz; ci++) {
1796 const int c = corners[ci];
1799 fmt::print(
" [c={} v={} e={}]", c, cv, ce);
1805 fmt::println(
" k={} va={} vb={}: no matching face found", k, va, vb);
1819 fmt::print(
" Rebuilt face={} ({} verts):", face_idx, corners.size());
1820 for (
const int c : corners) {
1824 fmt::print(
" [v={} e={} co=({:.3f},{:.3f},{:.3f})]",
v,
e, co[0], co[1], co[2]);
1838 fmt::println(
"MESH new face examples ({} new faces):", n_new);
1841 for (
int i = 0; i < n_new; i++) {
1843 const int ex = (i < int(exs.
size())) ? exs[i] : -1;
1847 fmt::println(
" new_face={} example={} comp={} center=({:.3f},{:.3f},{:.3f})",
1856 fmt::println(
" new_face={} example={}", face_idx, ex);
1870 const int n_new = int(new_edges.
size());
1871 fmt::println(
"MESH new edge examples ({} new edges):", n_new);
1873 for (
int i = 0; i < n_new; i++) {
1875 const int ex = (i < int(exs.
size())) ? exs[i] : -1;
1877 " new_edge={} (v{}--v{}) example={}", edge_idx, new_edges[i][0], new_edges[i][1], ex);
1903 const Span<int> e1_faces = edge_faces[e1];
1904 const Span<int> e2_faces = edge_faces[e2];
1905 for (
const int f1 : e1_faces) {
1923 for (
const int c : corners) {
1925 ca = c - corners.start();
1928 cb = c - corners.start();
1931 if (ca == -1 || cb == -1) {
1934 return ((cb + 1) % corners.size() == ca) ? 1 : -1;
1956 for (
int i = 1; i < ntot; i++) {
1957 int num_shared_face = 0;
1961 for (
int k = 0; k < i; k++) {
1962 if (bv->
edges[k].e == e2) {
1976 if (first_suc == -1) {
1981 if (num_shared_face >= 3) {
1985 if (num_shared_face == 1 || (i == 1 && num_shared_face == 2)) {
1987 eh->
e =
e = first_suc;
1990 for (
int k = 1; k < i; k++) {
1991 bv->
edges[k].e = -1;
2022 for (
int k = 0; k <= i; k++) {
2023 if (bv->
edges[k].e == e2) {
2037 const int nsucs = sucs.
size();
2041 for (
int sucindex = 0; sucindex < nsucs; sucindex++) {
2042 int nexte = sucs[sucindex];
2043 bv->
edges[j + 1].e = nexte;
2050 for (
int k = j + 1; k <= bestj; k++) {
2054 for (
int k = j + 1; k <= tryj; k++) {
2055 bv->
edges[k].e = -1;
2060 for (
int k = j + 1; k <= bestj; k++) {
2061 bv->
edges[k].e = save_path[k - (j + 1)];
2072 auto new_bv = std::make_unique<BoundVert>();
2077 bv->
vmesh = std::make_unique<VMesh>();
2082 v->next =
v->prev =
v;
2092 v->profile.super_r = 1.0f;
2136 auto hasnot = [&](
const EdgeHalf *
e) ->
bool {
2138 if (uv_seam_attr.
is_empty() ||
e->
e < 0 ||
e->
e >=
int(uv_seam_attr.
size())) {
2141 return !uv_seam_attr[
e->
e];
2144 if (sharp_edge_attr.
is_empty() ||
e->
e < 0 ||
e->
e >=
int(sharp_edge_attr.
size())) {
2147 return !sharp_edge_attr[
e->
e];
2175 while (hasnot(ne) && ne != efirst) {
2181 if (ne ==
e || (ne == efirst && hasnot(efirst))) {
2186 e->rightv->seam_len = flag_count;
2189 e->rightv->sharp_len = flag_count;
2192 }
while (
e != efirst);
2204 v->any_seam =
false;
2206 v->any_seam |=
e->is_seam;
2207 if (
e ==
v->elast) {
2212 }
while ((
v =
v->next) != bv->
vmesh->boundstart);
2247 return v_co + fdir * (left ?
e->offset_l :
e->offset_r);
2260 v->efirst =
v->elast =
e;
2261 e->leftv =
e->rightv =
v;
2266 }
while ((
e =
e->next) != efirst);
2273 if (
state.params.segments % 2 == 1) {
2274 if (!bv->
any_seam && !
state.uv_layer_info.contig_uv_maps_around_vert(
state.emesh, bv->
v)) {
2279 if (vm->
count == 2) {
2282 else if (
state.params.segments == 1) {
2300 const float3 *no =
e->fprev != -1 ?
2328 e->next->leftv =
e->next->rightv = bndv;
2345 e->prev->leftv =
e->prev->rightv = bndv;
2356 e->leftv =
e->rightv = bndv;
2357 e->prev->rightv = bndv;
2363 if (!
state.params.custom_profile_samples.is_empty() ||
state.params.shape < 0.25f) {
2366 for (
e =
e->next;
e->next != efirst;
e =
e->next) {
2371 e->leftv =
e->rightv = bndv;
2396 else if (vm->
count == 3) {
2399 bool use_tri_fan =
true;
2400 if (!
state.params.custom_profile_samples.is_empty()) {
2407 use_tri_fan =
false;
2423 if (from_e ==
nullptr) {
2424 from_e = &bv->
edges.last();
2431 }
while ((
e =
e->next) != from_e);
2439 const float direction_dot =
math::dot(d1, d2);
2464 if (e1->
fnext != -1) {
2467 else if (e2->
fprev != -1) {
2487 if (
state.all_miters_off) {
2490 if (
state.all_miters_on) {
2494 if (
e->fnext == -1) {
2498 const Span<int> face_verts =
state.emesh.src_corner_verts.slice(face);
2500 if (face_verts[i] ==
v) {
2501 const int corner = face.
start() + i;
2502 return (corner <
int(
state.params.miter.size())) &&
state.params.miter[corner];
2563 e3->leftv = e3->rightv =
v;
2572 const bool do_outer_miter = (want_miter && !emiter && ang_kind ==
ANGLE_LARGER);
2573 const bool do_inner_miter = (want_miter && ang_kind ==
ANGLE_SMALLER);
2575 if (do_outer_miter || do_inner_miter) {
2582 if (do_outer_miter) {
2591 if (do_outer_miter) {
2596 if (
e->next == e2) {
2597 v2->efirst =
nullptr;
2598 v2->elast =
nullptr;
2601 v2->efirst =
e->next;
2603 e3->leftv = e3->rightv =
v2;
2613 if (
e->next == e2) {
2617 int bet2 = between / 2;
2618 bool betodd = (between % 2) == 1;
2625 e3->profile_index = 0;
2627 else if (betodd && i == bet2) {
2628 e3->profile_index =
state.params.segments / 2;
2631 e3->profile_index =
state.params.segments;
2642 const bool do_outer_miter = (want_miter && !emiter && ang_kind ==
ANGLE_LARGER);
2643 const bool do_inner_miter = (want_miter && ang_kind ==
ANGLE_SMALLER);
2644 if (do_outer_miter || do_inner_miter) {
2651 if (do_outer_miter) {
2668 }
while ((
e = e2) != efirst);
2672 if (!
state.all_miters_off) {
2682 if (vm->
count == 2) {
2685 else if (efirst->
seg == 1) {
2689 switch (
state.vmesh_method) {
2732 state.emesh.src_positions[vother]);
2733 float3 line_p = co2 + d * edge_dir;
2741 line_p = co2 + d * edge_dir;
2754 if (
v->is_arc_start) {
2762 if (
e->fnext != -1) {
2764 const Span<int> face_verts =
state.emesh.src_corner_verts.slice(face);
2766 if (face_verts[i] == bv->
v) {
2767 corner = face.
start() + i;
2772 const float spread = (corner >= 0 && corner < int(
state.params.spread.size())) ?
2773 state.params.spread[corner] :
2778 state.emesh.src_positions[bv->
v]);
2779 v->nv.
co = co + edge_dir * spread;
2784 state.emesh.src_positions[bv->
v]);
2785 v3->
nv.
co = co + edge_dir * spread;
2792 }
while (
v != vstart);
2802 bv->
edges[i].e = first_e;
2814 for (
int k = 0; k < i; k++) {
2815 if (bv->
edges[k].e ==
e) {
2825 if (first_e == -1) {
2834 for (
int i = 0; i < ntot; i++) {
2843 bool bestf_is_directional =
false;
2849 for (
const int c : corners) {
2860 bestf_is_directional =
true;
2868 if (bestf_is_directional) {
2895 int vother =
e->is_rev ? verts[0] : verts[1];
2896 BevVert *bvo =
state.vert_hash.lookup_default(vother,
nullptr);
2906 *r_bvother =
nullptr;
2934 if ((*r_bv)->selcount == 1) {
2938 if ((*r_bv)->selcount == 2) {
2941 new_edge = new_edge->
next;
2942 }
while (!new_edge->
is_bev);
2946 const int2 start_e_verts =
state.emesh.src_edges[start_edge->
e];
2947 const float3 v1_co =
state.emesh.src_positions[start_e_verts[0]];
2948 const float3 v2_co =
state.emesh.src_positions[start_e_verts[1]];
2951 if (start_e_verts[0] == (*r_bv)->v) {
2959 float second_best_dot = 0.0f, best_dot = 0.0f;
2961 while (new_edge != start_edge) {
2963 new_edge = new_edge->
next;
2967 const int2 new_e_verts =
state.emesh.edge_verts(new_edge->
e);
2968 const float3 nv1_co =
state.emesh.vert_position(new_e_verts[0]);
2969 const float3 nv2_co =
state.emesh.vert_position(new_e_verts[1]);
2972 if (new_e_verts[1] == (*r_bv)->v) {
2979 float new_dot =
math::dot(dir_new_edge, dir_start_edge);
2980 if (new_dot > best_dot) {
2981 second_best_dot = best_dot;
2983 next_edge = new_edge;
2985 else if (new_dot > second_best_dot) {
2986 second_best_dot = new_dot;
2989 new_edge = new_edge->
next;
3008 const int2 ev =
state.emesh.edge_verts(edge_index);
3009 BevVert *start_bv =
state.vert_hash.lookup_default(ev[0],
nullptr);
3011 start_bv =
state.vert_hash.lookup_default(ev[1],
nullptr);
3017 if (!start_edgehalf || !start_edgehalf->
is_bev || start_edgehalf->
visited_rpo) {
3028 for (
int i = 0; i < 2; i++) {
3029 EdgeHalf *edgehalf = start_edgehalf;
3031 bool toward_bv = (i == 0);
3048 toward_bv = !toward_bv;
3090 const double tol = 1
e-13;
3091 const int maxiter = 10;
3093 double xmin = x0 + std::numbers::sqrt2 / 2.0 * dtarget;
3094 xmin = std::min(xmin, 1.0);
3095 double xmax = x0 + dtarget;
3096 xmax = std::min(xmax, 1.0);
3103 double xnew = xmax - dmaxerr * (xmax - xmin) / (dmaxerr - dminerr);
3104 bool lastupdated_upper =
true;
3106 for (
int iter = 0; iter < maxiter; iter++) {
3110 if (
abs(dnewerr) < tol) {
3117 if (!lastupdated_upper) {
3118 xnew = (dmaxerr / 2 * xmin - dminerr * xmax) / (dmaxerr / 2 - dminerr);
3121 xnew = xmax - dmaxerr * (xmax - xmin) / (dmaxerr - dminerr);
3123 lastupdated_upper =
false;
3129 if (lastupdated_upper) {
3130 xnew = (dmaxerr * xmin - dminerr / 2 * xmax) / (dmaxerr - dminerr / 2);
3133 xnew = xmax - dmaxerr * (xmax - xmin) / (dmaxerr - dminerr);
3135 lastupdated_upper =
true;
3155 const int smoothitermax = 10;
3156 const double error_tol = 1
e-7;
3157 int imax = (seg + 1) / 2 - 1;
3159 bool seg_odd = seg % 2;
3172 for (
int i = 0; i <= imax; i++) {
3173 xvals[i] = i * mx / seg * 2;
3178 for (
int iter = 0; iter < smoothitermax; iter++) {
3182 for (
int i = 0; i < imax; i++) {
3184 math::pow((yvals[i + 1] - yvals[i]), 2.0));
3186 dmax = std::max(d, dmax);
3187 dmin = std::min(d, dmin);
3191 sum += std::numbers::sqrt2 / 2 * (yvals[imax] - xvals[imax]);
3192 davg = sum / (imax + 0.5);
3196 davg = sum / (imax + 1.0);
3198 bool precision_reached =
true;
3199 if (dmax - davg > error_tol) {
3200 precision_reached =
false;
3202 if (dmin - davg < error_tol) {
3203 precision_reached =
false;
3205 if (precision_reached) {
3209 for (
int i = 1; i <= imax; i++) {
3216 xvals[imax + 1] = mx;
3217 yvals[imax + 1] = mx;
3219 for (
int i = imax + 1; i <= seg; i++) {
3220 yvals[i] = xvals[seg - i];
3221 xvals[i] = yvals[seg - i];
3225 for (
int i = 0; i <= seg; i++) {
3226 double temp = xvals[i];
3227 xvals[i] = 1.0 - yvals[i];
3228 yvals[i] = 1.0 - temp;
3246 bool seg_odd = n % 2;
3250 for (
int i = 0; i <= n; i++) {
3251 xvals[i] = double(i) / n;
3252 yvals[i] = 1.0 - double(i) / n;
3257 double temp =
M_PI_2 / n;
3258 for (
int i = 0; i <= n; i++) {
3266 for (
int i = 0; i <= n2; i++) {
3268 yvals[i] = 1.0 - double(i) / n2;
3269 xvals[n - i] = yvals[i];
3270 yvals[n - i] = xvals[i];
3274 double temp = 1.0 / (n2 + std::numbers::sqrt2 / 2.0);
3275 for (
int i = 0; i <= n2; i++) {
3277 yvals[i] = 1.0 - double(i) * temp;
3278 xvals[n - i] = yvals[i];
3279 yvals[n - i] = xvals[i];
3286 for (
int i = 0; i <= n2; i++) {
3287 xvals[i] = double(i) / n2;
3289 xvals[n - i] = yvals[i];
3290 yvals[n - i] = xvals[i];
3294 double temp = 1.0 / (n2 + std::numbers::sqrt2 / 2.0);
3295 for (
int i = 0; i <= n2; i++) {
3296 xvals[i] = double(i) * temp;
3298 xvals[n - i] = yvals[i];
3299 yvals[n - i] = xvals[i];
3315 constexpr int circle_fullness_segs = 11;
3316 static const float circle_fullness[circle_fullness_segs] = {
3333 for (
int i = 0; i < nseg; i++) {
3342 fullness = circle_fullness[nseg - 1];
3345 if (nseg % 2 == 0) {
3346 fullness = 2.4506f * bs->
params.
shape - 0.00000300f * nseg - 0.6266f;
3349 fullness = 2.3635f * bs->
params.
shape + 0.000152f * nseg - 0.6060f;
3371 if (segments <= 1) {
3372 pro_spacing->
seg_2 = 0;
3387 const int src_n = int(src.
size()) - 1;
3393 const int lo = std::min(
int(t), src_n - 1);
3394 const int hi = lo + 1;
3395 const float f = t -
float(lo);
3396 const float x = (1.0f - f) * src[lo].
x + f * src[hi].
x;
3397 const float y = (1.0f - f) * src[lo].
y + f * src[hi].
y;
3403 r_xvals[i] = double(
x);
3404 r_yvals[i] = double(
y);
3409 if (seg_2 != segments) {
3411 fill_from_custom(pro_spacing->
xvals_2, pro_spacing->
yvals_2, seg_2);
3423 fill_from_custom(pro_spacing->
xvals, pro_spacing->
yvals, segments);
3432 if (seg_2 == segments) {
3469 bool do_linear_interp =
true;
3478 do_linear_interp =
false;
3503 if (
e->prev->is_bev &&
e->next->is_bev && bv->
selcount >= 3) {
3512 do_linear_interp =
true;
3515 const float3 co3 = start + d3;
3516 const float3 co4 = end + d4;
3524 do_linear_interp =
true;
3533 do_linear_interp =
true;
3549 do_linear_interp =
false;
3559 do_linear_interp =
false;
3562 if (do_linear_interp) {
3642 if (l1 != 0.0f && (l2 != 0.0f || l3 != 0.0f)) {
3664 const bool reversed,
3666 const double *xvals,
3667 const double *yvals,
3670 for (
int k = 0; k <= ns; k++) {
3681 reversed ?
float(yvals[ns - k]) :
float(xvals[k]),
3682 reversed ?
float(xvals[ns - k]) :
float(yvals[k]),
3713 if (
state.params.segments <= 1) {
3717 const bool need_2 = (
state.params.segments != pro_spacing.
seg_2);
3744 state.params.segments,
3771 if (
state.params.segments == 1) {
3772 return (i == 0 ? pro->
start : pro->
end);
3774 if (nseg ==
state.params.segments) {
3779 const int subsample_spacing =
state.pro_spacing.seg_2 / nseg;
3780 return pro->
prof_co_2[i * subsample_spacing];
3794 bool miter_profile =
false;
3795 bool reverse_profile =
false;
3796 if (!
state.params.custom_profile_samples.is_empty()) {
3818 const float psr = -std::numbers::ln2_v<float> /
3819 std::log(
math::sqrt(this->
params.shape > 0 ? this->params.shape : 1e-20f));
3822 if (this->
params.shape >= 0.950f) {
3831 else if (
abs(psr) < 1e-4f) {
3838 if (this->
params.segments > 1) {
3846 if (this->
params.segments % 2 != 0) {
3892 const int vert = face_verts[i];
3893 projverts[i] =
float2(axis_mat * positions[vert]);
3905 const ExtendableMesh &emesh,
const int f,
const int v_idx,
int *r_e1,
int *r_e2)
3915 for (
const int e : corner_edges.
slice(faces[f])) {
3916 const int2 &ev = edges[
e];
3917 if (ev[0] == v_idx || ev[1] == v_idx) {
3921 else if (*r_e2 < 0) {
3941 r_internal[0] = r_internal[1] = r_internal[2] =
nullptr;
3950 r_internal[n_internal++] =
v;
3951 if (n_internal == 3) {
3956 for (
int i = n_internal; i < 3; i++) {
3957 r_internal[i] =
nullptr;
3977 int e1 = -1, e2 = -1;
3987 const float3 e1v1 = positions[ev1[0]];
3988 const float3 e1v2 = positions[ev1[1]];
3989 const float3 e2v1 = positions[ev2[0]];
3990 const float3 e2v2 = positions[ev2[1]];
3992 const int count = vm->
count;
3998 if (
ELEM(
v, unsnapped[0], unsnapped[1], unsnapped[2])) {
3999 proj_co[i] =
float2(axis_mat * co);
4006 proj_co[i] =
float2(axis_mat * (d1_sq <= d2_sq ? snap1 : snap2));
4011 return area_poly_v2(
reinterpret_cast<const float (*)[2]
>(proj_co.
data()), count);
4023 return area < 1e-4f;
4043 const int nfaces = int(faces.
size());
4066 for (
int fi = 0; fi < nfaces; fi++) {
4067 const int f = faces[fi];
4068 if (f < 0 || f >=
mesh.faces_num) {
4071 still_viable[fi] =
true;
4078 value_vecs[fi][vi++] = 0.0f;
4080 value_vecs[fi][vi++] = mat_span.
is_empty() ? 0.0f :
float(mat_span[f]);
4083 value_vecs[fi][vi++] = cent.z;
4084 value_vecs[fi][vi++] = cent.x;
4085 value_vecs[fi][vi++] = cent.y;
4089 if (num_viable == 0) {
4095 for (
int vi = 0; num_viable > 1 && vi <
VEC_VALUE_LEN; vi++) {
4096 for (
int fi = 0; fi < nfaces; fi++) {
4097 if (!still_viable[fi] || fi == best_fi) {
4100 if (best_fi == -1) {
4104 if (value_vecs[fi][vi] < value_vecs[best_fi][vi]) {
4107 for (
int j = fi - 1; j >= 0; j--) {
4108 if (still_viable[j]) {
4109 still_viable[j] =
false;
4114 else if (value_vecs[fi][vi] > value_vecs[best_fi][vi]) {
4115 still_viable[fi] =
false;
4120 if (best_fi == -1) {
4123 return faces[best_fi];
4138 frep =
v->ebev->fprev;
4139 if (
v->efirst->fprev != frep) {
4140 frep2 =
v->efirst->fprev;
4143 else if (
v->efirst) {
4144 frep =
v->efirst->fprev;
4146 if (
v->elast->fnext != frep) {
4147 frep2 =
v->elast->fnext;
4149 else if (
v->efirst->fnext != frep) {
4150 frep2 =
v->efirst->fnext;
4152 else if (
v->elast->fprev != frep) {
4153 frep2 =
v->elast->fprev;
4156 else if (
v->efirst->fnext >= 0) {
4157 frep =
v->efirst->fnext;
4158 if (
v->elast->fnext != frep) {
4159 frep2 =
v->elast->fnext;
4162 else if (
v->elast->fprev >= 0) {
4163 frep =
v->elast->fprev;
4166 else if (
v->prev->elast) {
4167 frep =
v->prev->elast->fnext;
4168 if (
v->next->efirst) {
4170 frep2 =
v->next->efirst->fprev;
4173 frep =
v->next->efirst->fprev;
4203 return (dsq1 <= dsq2) ? e1 : e2;
4216 const int center_frep,
4219 const int previ = (i + n_bndv - 1) % n_bndv;
4220 const int nexti = (i + 1) % n_bndv;
4221 if (frep_beats_next[previ] && bndv_rep_faces[previ] == center_frep) {
4224 if (!frep_beats_next[i] && bndv_rep_faces[nexti] == center_frep) {
4243 const int enextnext,
4245 const int center_frep,
4247 int r_snap_edges[4])
4249 BLI_assert(0 <= i && i < n_bndv && 0 <= j && j < ns2 && 0 <= k && k <= ns2);
4250 for (
int corner = 0; corner < 4; corner++) {
4251 r_snap_edges[corner] = -1;
4255 const int previ = (i + n_bndv - 1) % n_bndv;
4257 const int jj = corner < 2 ? j : j + 1;
4258 const int kk =
ELEM(corner, 0, 3) ? k : k + 1;
4259 if (jj < ns2 && kk < ns2) {
4262 else if (jj < ns2 && kk == ns2) {
4263 if (!frep_beats_next[i]) {
4264 r_snap_edges[corner] = enext;
4267 else if (jj < ns2 && kk == ns2 + 1) {
4268 if (frep_beats_next[i]) {
4269 r_snap_edges[corner] = enext;
4272 else if (jj == ns2 && kk < ns2) {
4273 if (frep_beats_next[previ]) {
4274 r_snap_edges[corner] = eprev;
4277 else if (jj == ns2 && kk == ns2) {
4279 i, n_bndv, eprev, enext, bndv_rep_faces, center_frep, frep_beats_next);
4281 else if (jj == ns2 && kk == ns2 + 1) {
4282 const int nexti = (i + 1) % n_bndv;
4284 nexti, n_bndv, enext, enextnext, bndv_rep_faces, center_frep, frep_beats_next);
4297 const bool consider_all_faces = (bv->
selcount == 1 ||
state.affect_vertices_odd);
4304 for (
int i = 0; i < bv->
edgecount; i++) {
4306 if (!
e.is_bev && !consider_all_faces) {
4309 const int candidates[2] = {
e.fprev,
e.fnext};
4318 bool already_there =
false;
4319 for (
int j = fcount - 1; j >= 0; j--) {
4320 if (fchoices[j] == bmf) {
4321 already_there =
true;
4325 if (!already_there) {
4326 if (
state.uv_layer_info.has_uv_maps) {
4332 fchoices[fcount++] = bmf;
4356 const int ns = vm->
seg;
4361 int frep_e1 = -1, frep_e2 = -1;
4362 BoundVert *frep_unsnapped[3] = {
nullptr,
nullptr,
nullptr};
4374 const int bndv_i = bndv->
index;
4376 auto append_corner = [&](
int vert_idx) {
4381 corner_reps.
append(frep);
4382 const bool is_unsnapped =
ELEM(
4383 bndv, frep_unsnapped[0], frep_unsnapped[1], frep_unsnapped[2]);
4384 if (is_unsnapped || frep_e1 < 0 || frep_e2 < 0) {
4401 if (bndv->
ebev && ns > 1) {
4402 for (
int k = 1; k < ns; k++) {
4407 corner_reps.
append(frep);
4408 if (frep_e1 >= 0 && frep_e2 >= 0) {
4412 const int snap_e = (k < ns / 2) ? -1 :
find_closer_edge(emesh, co, frep_e1, frep_e2);
4413 corner_snaps.
append(snap_e);
4427 if (verts.
size() < 3) {
4430 const int new_face =
state.emesh.face_create(verts.
as_span(), frep);
4431 state.emesh.face_set_corner_reps(new_face, corner_reps.
as_span(), corner_snaps.
as_span());
4434 fmt::println(
"bevel_build_poly: bv->v={} any_seam={} frep={} ns={} n_verts={}",
4440 for (
int ci = 0; ci < int(verts.
size()); ci++) {
4442 " corner[{}] v={} rep={} snap={}", ci, verts[ci], corner_reps[ci], corner_snaps[ci]);
4457 const int ns = vm->
seg;
4463 int frep_e1 = -1, frep_e2 = -1;
4464 BoundVert *frep_unsnapped[3] = {
nullptr,
nullptr,
nullptr};
4477 const int bndv_i = bndv->
index;
4478 auto append_ring_corner = [&](
int vert_idx) {
4482 const bool is_unsnapped =
ELEM(
4483 bndv, frep_unsnapped[0], frep_unsnapped[1], frep_unsnapped[2]);
4484 if (is_unsnapped || frep_e1 < 0 || frep_e2 < 0) {
4498 if (bndv->
ebev && ns > 1) {
4499 for (
int k = 1; k < ns; k++) {
4507 if (ring.
size() < 3) {
4513 const int n = int(ring.
size());
4514 const int v_fan_idx = n - 1;
4515 const int v_fan = ring[v_fan_idx];
4516 for (
int i = 0; i + 1 < v_fan_idx; i++) {
4517 const int tri[3] = {v_fan, ring[i], ring[i + 1]};
4518 const int tri_reps[3] = {ring_reps[v_fan_idx], ring_reps[i], ring_reps[i + 1]};
4519 const int tri_snaps[3] = {ring_snaps[v_fan_idx], ring_snaps[i], ring_snaps[i + 1]};
4523 const int face_example = (frep >= 0) ? frep : tri_reps[1];
4524 const int new_face =
state.emesh.face_create(
Span<int>(tri, 3), face_example);
4538 const int ns = vm->
seg;
4555 for (
int k = 1; k < ns; k++) {
4557 const int nv =
state.emesh.vert_create(co, bv->
v);
4565 for (
int k = 1; k < ns; k++) {
4572 for (
int k = 0; k < ns; k++) {
4575 if (va >= 0 && vb >= 0) {
4576 state.emesh.edge_create(va, vb);
4592 const int n_bndv = vm->
count;
4593 const int ns = vm->
seg;
4594 const int ns2 = ns / 2;
4595 const int odd = ns % 2;
4610 int center_frep = -1;
4616 for (
int i = 0; i < n_bndv; i++) {
4617 const int inext = (i + 1) % n_bndv;
4618 const int candidates[2] = {bndv_rep_faces[i], bndv_rep_faces[inext]};
4620 frep_beats_next[i] = (winner == bndv_rep_faces[i]);
4626 const int i = bndv->
index;
4629 const int f = bndv_rep_faces[i];
4630 const int f2 = bndv_rep_faces[inext];
4632 (frep_beats_next[i] ? f : f2) :
4644 const int bme = ebev ? ebev->
e : -1;
4645 const int bmeprev = ebev_prev ? ebev_prev->
e : -1;
4646 const int bmenext = ebev_next ? ebev_next->
e : -1;
4648 for (
int j = 0; j < ns2; j++) {
4649 for (
int k = 0; k < ns2 + odd; k++) {
4655 if (va < 0 || vb < 0 || vc < 0 || vd < 0) {
4662 int se[4] = {-1, -1, -1, -1};
4664 int cr[4] = {-1, -1, -1, -1};
4670 if (k == ns2 && j == ns2 - 1) {
4676 se[0] = se[2] = bme;
4677 if (!ebev || !ebev->
is_seam) {
4689 const int b1 = (ebev_prev && ebev_prev->
is_seam) ? bmeprev : -1;
4690 const int b2 = (ebev && ebev->
is_seam) ? bme : -1;
4691 const int b3 = (ebev_next && ebev_next->
is_seam) ? bmenext : -1;
4717 center_snap_edges[i] = se[3];
4726 if (j == ns2 - 1 && ebev_prev) {
4729 se[2] = (se[1] >= 0) ? se[1] : se[3];
4733 const int quad[4] = {va, vb, vc, vd};
4736 const bool any_snaps = se[0] >= 0 || se[1] >= 0 || se[2] >= 0 || se[3] >= 0;
4737 const bool any_corner_reps = cr[0] >= 0 || cr[1] >= 0 || cr[2] >= 0 || cr[3] >= 0;
4738 if (any_snaps || any_corner_reps) {
4739 state.emesh.face_set_corner_reps(new_face,
4760 const bool have_seam = bv->
any_seam;
4761 const int cfrep = center_frep;
4764 const int ci = bndv->
index;
4766 center_reps_vec.
append(have_seam ? cfrep : bndv_rep_faces[ci]);
4767 center_snaps_vec.
append(center_snap_edges[ci]);
4775 center_reps_vec.
append(-1);
4776 center_snaps_vec.
append(-1);
4780 if (center_verts_vec.
size() >= 3) {
4781 const int cface =
state.emesh.face_create(center_verts_vec.
as_span(), center_frep);
4782 state.emesh.face_set_corner_reps(
4790 const int i = bndv->
index;
4791 for (
int j = 0; j < ns2; j++) {
4794 if (va >= 0 && vb >= 0) {
4795 const int mid_edge =
state.emesh.find_edge(va, vb);
4796 if (mid_edge >= 0) {
4838 if (corners.size() < 3) {
4842 bool do_rebuild =
false;
4858 const int sz = int(corners.size());
4859 for (
int ci = 0; ci < sz; ci++) {
4860 const int c = corners[ci];
4863 const int c_prev = corners[(ci + sz - 1) % sz];
4866 BevVert *bv =
state.vert_hash.lookup_default(v_idx,
nullptr);
4867 if (bv && bv->
vmesh) {
4876 const int bme =
e->
e;
4880 if (
e->prev == eprev) {
4881 if (eprev->
prev ==
e) {
4883 go_ccw = (
e->fnext != f_idx);
4889 else if (eprev->
prev ==
e) {
4906 vstart = eprev->
leftv;
4919 const int i =
v->index;
4920 for (
int k = 1; k <= vm->
seg; k++) {
4931 const int i =
v->prev->index;
4932 for (
int k = vm->
seg - 1; k >= 0; k--) {
4953 if (do_rebuild && vv.
size() >= 3) {
4957 const int n = int(vv.
size());
4958 for (
int i = 0; i < n; i++) {
4959 const int ov_a = orig_v[i];
4960 const int ov_b = orig_v[(i + 1) % n];
4962 const int example_edge = emesh.
find_edge(ov_a, ov_b);
4963 if (example_edge >= 0 && example_edge < emesh.
mesh.
edges_num) {
4964 state.emesh.edge_create(vv[i], vv[(i + 1) % n], example_edge);
4969 const int new_face_idx =
state.emesh.face_create(vv.
as_span(), f_idx);
4977 for (
int i = 0; i < n; i++) {
4978 const int ov_a = orig_v[i];
4979 const int ov_b = orig_v[(i + 1) % n];
4982 example_edge = emesh.
find_edge(ov_a, ov_b);
4983 if (example_edge < 0 || example_edge >= emesh.
mesh.
edges_num) {
4989 example_edge = orig_e[i];
4991 if (example_edge >= 0) {
4992 const int new_edge =
state.emesh.find_edge(vv[i], vv[(i + 1) % n]);
4993 if (new_edge >= 0) {
4994 state.emesh.edge_set_example(new_edge, example_edge);
5015 auto orig_has_seam = [&](
int e_idx) ->
bool {
5016 if (!seam_reader || e_idx < 0 || e_idx >=
int(emesh.
mesh.
edges_num)) {
5019 return bool(seam_reader.
varray[e_idx]);
5021 auto orig_has_sharp = [&](
int e_idx) ->
bool {
5022 if (!sharp_reader || e_idx < 0 || e_idx >=
int(emesh.
mesh.
edges_num)) {
5025 return bool(sharp_reader.varray[e_idx]);
5028 int bme_prev_idx = orig_e[(n - 1) % n];
5029 for (
int k = 0; k < n; k++) {
5030 const int oe_k = orig_e[k];
5031 const int new_edge =
state.emesh.find_edge(vv[k], vv[(k + 1) % n]);
5032 if (new_edge < 0 || oe_k < 0) {
5033 bme_prev_idx = oe_k;
5037 if (k < n - 1 && oe_k == orig_e[k + 1]) {
5039 if (orig_has_seam(oe_k) && !orig_has_seam(bme_prev_idx)) {
5040 state.emesh.edge_set_seam_override(new_edge, 0);
5043 if (orig_has_sharp(oe_k) && !orig_has_sharp(bme_prev_idx)) {
5044 state.emesh.edge_set_sharp_override(new_edge, 0);
5048 bme_prev_idx = oe_k;
5053 return new_face_idx;
5064 int &r_rebuilt_face_0)
5072 r_rebuilt_face_0 = -1;
5074 state.bevel_affected_vertices.foreach_index([&](
const int v) {
5077 if (f_idx < orig_faces_num && !rebuilt[f_idx]) {
5080 rebuilt[f_idx] =
true;
5081 r_rebuilt_orig_faces.
append(f_idx);
5083 r_rebuilt_face_0 = new_f;
5103 for (
int i = 0; i < bv->
edgecount; i++) {
5104 if (bv->
edges[i].e == edge_index) {
5105 return &bv->
edges[i];
5118 ((bv->
edges[0].is_bev && bv->
edges[2].is_bev) ||
5119 (bv->
edges[1].is_bev && bv->
edges[3].is_bev)));
5143 const int v1_idx = edge_verts[0];
5144 const int v2_idx = edge_verts[1];
5152 BevVert *bv1 =
state.vert_hash.lookup_default(v1_idx,
nullptr);
5153 BevVert *bv2 =
state.vert_hash.lookup_default(v2_idx,
nullptr);
5164 const int nseg = e1->
seg;
5175 const int f1 = e1->
fprev;
5176 const int f2 = e1->
fnext;
5178 const int odd = nseg % 2;
5179 const int mid = nseg / 2;
5185 int center_adj_k = -1;
5187 const int candidates[2] = {f1, f2};
5190 center_adj_k = (f_choice == f1) ? mid + 2 : mid;
5201 int v_prev_1 = v_bme1;
5202 int v_prev_2 = v_bme2;
5204 for (
int k = 1; k <= nseg; k++) {
5214 int corner_reps[4] = {-1, -1, -1, -1};
5215 int corner_snaps[4] = {-1, -1, -1, -1};
5217 if (odd && k == mid + 1) {
5222 face_rep = f_choice;
5223 if (f_choice == f1) {
5224 corner_snaps[2] = corner_snaps[3] = edge_index;
5227 corner_snaps[0] = corner_snaps[1] = edge_index;
5229 corner_reps[0] = corner_reps[1] = corner_reps[2] = corner_reps[3] = f_choice;
5235 corner_reps[0] = corner_reps[1] = f1;
5236 corner_reps[2] = corner_reps[3] = f2;
5239 else if (odd && k == center_adj_k && e1->
is_seam) {
5244 corner_snaps[2] = corner_snaps[3] = edge_index;
5248 corner_snaps[0] = corner_snaps[1] = edge_index;
5251 else if (!odd && k == mid) {
5254 corner_snaps[2] = corner_snaps[3] = edge_index;
5256 else if (!odd && k == mid + 1) {
5259 corner_snaps[0] = corner_snaps[1] = edge_index;
5263 face_rep = (k <= mid) ? f1 : f2;
5267 const int quad[4] = {v_prev_1, v_prev_2, v_next_2, v_next_1};
5276 if (nseg >= 2 && k == mid) {
5277 const int mid_edge =
state.emesh.find_edge(v_next_1, v_next_2);
5278 if (mid_edge >= 0) {
5284 const bool any_corner_reps = corner_reps[0] >= 0 || corner_reps[1] >= 0 ||
5285 corner_reps[2] >= 0 || corner_reps[3] >= 0;
5286 const bool any_corner_snaps = corner_snaps[0] >= 0 || corner_snaps[1] >= 0 ||
5287 corner_snaps[2] >= 0 || corner_snaps[3] >= 0;
5288 if (any_corner_reps || any_corner_snaps) {
5289 state.emesh.face_set_corner_reps(new_face,
5291 any_corner_snaps ?
Span<int>(corner_snaps, 4) :
5297 "bevel_build_edge_polygons: edge={} k={}/{} f1={} f2={} is_seam={} face_rep={} "
5298 "verts=[{},{},{},{}] creps=[{},{},{},{}] csnaps=[{},{},{},{}]",
5321 v_prev_1 = v_next_1;
5322 v_prev_2 = v_next_2;
5331 const int outer_edge1 =
state.emesh.find_edge(v_bme1, v_bme2);
5332 const int outer_edge2 =
state.emesh.find_edge(v_prev_2, v_prev_1);
5333 if (outer_edge1 >= 0) {
5334 state.emesh.edge_set_example(outer_edge1, edge_index);
5336 state.outer_edge_src_indices.append(edge_index);
5338 if (outer_edge2 >= 0) {
5339 state.emesh.edge_set_example(outer_edge2, edge_index);
5341 if (outer_edge2 != outer_edge1) {
5343 state.outer_edge_src_indices.append(edge_index);
5356 for (
int i = 0; i < 4; i++) {
5357 if (&bv->
edges[i] ==
e) {
5358 e_prev = bv->
edges[(i + 3) % 4].
e;
5359 e_next = bv->
edges[(i + 1) % 4].
e;
5370 const bool prev_seam = seam_reader ? bool(seam_reader.
varray[e_prev]) :
false;
5371 const bool next_seam = seam_reader ? bool(seam_reader.
varray[e_next]) :
false;
5372 const bool disable_seam = (prev_seam != next_seam);
5374 for (
int i = 0; i < nseg; i++) {
5377 const int arc_edge =
state.emesh.find_edge(va, vb);
5378 if (arc_edge >= 0) {
5379 state.emesh.edge_set_example(arc_edge, e_prev);
5389 weld_cross_attrs_copy(bv1, vm1, i1, e1);
5392 weld_cross_attrs_copy(bv2, vm2, i2, e2);
5414 const int n = vm->
count;
5415 const int ns = vm->
seg;
5416 const int ns2 = ns / 2;
5429 const int i = bndv->
index;
5434 if (weld && bndv->
ebev) {
5447 if (weld && weld1 && weld2) {
5459 const int i = bndv->
index;
5465 for (
int k = 1; k < ns; k++) {
5473 else if (n == 2 && !bndv->
ebev) {
5485 for (
int k = 1; k < ns; k++) {
5501 co = (v_w1 + v_w2) * 0.5f;
5503 const int nv =
state.emesh.vert_create(co, bv->
v);
5507 for (
int k = 1; k < ns; k++) {
5531 state.params.custom_profile_samples.is_empty())
5542 for (
int i = 0; i < n; i++) {
5543 for (
int j = 0; j <= ns2; j++) {
5544 for (
int k = 0; k <= ns; k++) {
5545 if (j == 0 &&
ELEM(k, 0, ns)) {
5552 const int nv =
state.emesh.vert_create(co, bv->
v);
5580 const int num_uv_layers = int(
state.uv_layer_info.uv_maps.size());
5583 for (
int i = 0; i < num_uv_layers; i++) {
5587 for (
const int c :
state.emesh.src_vert_to_corner[
v]) {
5588 const float2 &luv = uv_vals[c];
5589 bool is_overlap_found =
false;
5591 for (
const int c2 : bucket) {
5594 is_overlap_found =
true;
5598 if (is_overlap_found) {
5602 if (!is_overlap_found) {
5608 state.uv_vert_maps[i].add_new(
v, uv_vert_buckets);
5631 const int ns = vm->
seg;
5634 for (
int k = 0; k < ns; k++) {
5637 frac[k + 1] = total;
5640 for (
int k = 1; k <= ns; k++) {
5658 for (
int k = 0; k < ns; k++) {
5661 frac[k + 1] = total;
5665 for (
int k = 1; k <= ns; k++) {
5677 for (
int i = 0; i < n; i++) {
5678 if (f <=
frac[i + 1]) {
5679 float rest = f -
frac[i];
5680 *r_rest = (rest == 0.0f) ? 0.0f : rest / (
frac[i + 1] -
frac[i]);
5681 if (i == n - 1 && *r_rest == 1.0f) {
5695 const int n_bndv = vm_in.
count;
5696 const int ns_in = vm_in.
seg;
5697 const int nseg2 = nseg / 2;
5698 const int odd = nseg % 2;
5710 for (
int i = 0; i < n_bndv; i++) {
5713 for (
int j = 0; j <= nseg2 - 1 + odd; j++) {
5714 for (
int k = 0; k <= nseg2; k++) {
5715 float restk, restkprev;
5717 int k_in_prev =
interp_range(prev_frac, ns_in, prev_new_frac[nseg - j], &restkprev);
5718 int j_in = ns_in - k_in_prev;
5719 float restj = -restkprev;
5725 restj = 1.0f + restj;
5746 prev_new_frac = new_frac;
5761 const int n_boundary = vm_in.
count;
5762 const int ns_in = vm_in.
seg;
5763 const int ns_in2 = ns_in / 2;
5765 const int ns_out = 2 * ns_in;
5769 for (
int i = 0; i < n_boundary; i++) {
5771 for (
int k = 1; k < ns_in; k++) {
5774 if (
state.params.custom_profile_samples.is_empty()) {
5778 co += acc * (-1.0f / 6.0f);
5786 for (
int i = 0; i < n_boundary; i++) {
5787 for (
int k = 1; k < ns_out; k += 2) {
5789 if (
state.params.custom_profile_samples.is_empty()) {
5793 co += acc * (-1.0f / 6.0f);
5802 for (
int i = 0; i < n_boundary; i++) {
5803 for (
int k = 0; k < ns_in; k++) {
5810 for (
int i = 0; i < n_boundary; i++) {
5811 for (
int j = 0; j < ns_in2; j++) {
5812 for (
int k = 0; k < ns_in2; k++) {
5823 for (
int i = 0; i < n_boundary; i++) {
5824 for (
int j = 0; j < ns_in2; j++) {
5825 for (
int k = 1; k <= ns_in2; k++) {
5836 for (
int i = 0; i < n_boundary; i++) {
5837 for (
int j = 1; j < ns_in2; j++) {
5838 for (
int k = 0; k < ns_in2; k++) {
5849 constexpr float gamma_interior = 0.25f;
5850 constexpr float beta_interior = -gamma_interior;
5851 for (
int i = 0; i < n_boundary; i++) {
5852 for (
int j = 1; j < ns_in2; j++) {
5853 for (
int k = 1; k <= ns_in2; k++) {
5862 const float3 co = co1 + co2 * beta_interior +
5873 const float beta_c = -gamma_c;
5874 float3 co1(0.0f), co2(0.0f);
5875 for (
int i = 0; i < n_boundary; i++) {
5880 const float3 co = co1 * (1.0f /
float(n_boundary)) +
5881 co2 * (beta_c / (2.0f *
float(n_boundary))) +
5883 for (
int i = 0; i < n_boundary; i++) {
5889 for (
int i = 0; i < n_boundary; i++) {
5890 const int inext = (i + 1) % n_boundary;
5891 for (
int k = 0; k <= ns_out; k++) {
5894 if (k >= ns_in && k < ns_out) {
5911 const float r = super_r;
5920 float x = a,
y =
b,
z = c;
5927 const float dx = 1.0f -
x;
5928 const float dy = 1.0f -
y;
5931 y = midline ? 1.0f :
y;
5935 x = midline ? 1.0f :
x;
5941 y = midline ? 0.0f :
y;
5945 x = midline ? 0.0f :
x;
5950 const float rinv = 1.0f / r;
5959 y =
powf(1.0f / (1.0f +
powf(c /
b, r)), rinv);
5986 mat[0] =
float4((va - vb - vc + vd) * 0.5f, 0.0f);
5987 mat[1] =
float4((vb - va - vc + vd) * 0.5f, 0.0f);
5988 mat[2] =
float4((vc - va - vb + vd) * 0.5f, 0.0f);
5989 mat[3] =
float4((va + vb + vc - vd) * 0.5f, 1.0f);
6001 const int ns2 = nseg / 2;
6005 for (
int i = 0; i < 3; i++) {
6006 bvs[i].
next = &bvs[(i + 1) % 3];
6007 bvs[i].
prev = &bvs[(i + 2) % 3];
6009 bvs[i].
nv.
co[i] = 1.0f;
6014 for (
int i = 0; i < 3; i++) {
6015 for (
int j = 0; j <= ns2; j++) {
6016 for (
int k = 0; k <= ns2; k++) {
6022 co[(i + 1) % 3] =
float(k) * 2.0f /
float(nseg);
6023 co[(i + 2) % 3] =
float(j) * 2.0f /
float(nseg);
6039 const int ns2 = nseg / 2;
6040 const int odd = nseg % 2;
6043 for (
int i = 0; i < 3; i++) {
6044 bvs[i].
next = &bvs[(i + 1) % 3];
6045 bvs[i].
prev = &bvs[(i + 2) % 3];
6047 bvs[i].
nv.
co[i] = 1.0f;
6054 for (
int i = 0; i < 3; i++) {
6055 for (
int k = 0; k <= ns2; k++) {
6057 co[i] = 1.0f -
float(k) *
b;
6060 co[(i + 1) % 3] = 1.0f -
float(k) *
b;
6082 const float r =
state.pro_super_r;
6083 const int nseg =
state.params.segments;
6088 if (
state.params.custom_profile_samples.is_empty()) {
6103 for (
int i = 0; i < 3; i++) {
6108 co_end[(i + 1) % 3] = 1.0f;
6110 co_mid[(i + 1) % 3] = 1.0f;
6113 unit_bv[i].
next = &unit_bv[(i + 1) % 3];
6114 unit_bv[i].
prev = &unit_bv[(i + 2) % 3];
6115 unit_bv[i].
index = i;
6116 unit_bv[i].
nv.
co = co_start;
6120 pro.
start = co_start;
6146 const bool need_2 = (nseg != ps.
seg_2);
6167 for (
int i = 0; i < 3; i++) {
6181 else if (r < 0.75f) {
6189 VMesh vm1 = std::move(vm0);
6190 while (vm1.
seg < nseg) {
6192 vm1 = std::move(next);
6194 if (vm1.
seg != nseg) {
6196 vm1 = std::move(resampled);
6200 const int ns2 = nseg / 2;
6201 for (
int i = 0; i < 3; i++) {
6202 for (
int j = 0; j <= ns2; j++) {
6203 for (
int k = 0; k <= nseg; k++) {
6243 const float3 co_v1 =
state.emesh.src_positions[other_v1];
6244 const float3 co_v3 =
state.emesh.src_positions[other_v3];
6260 for (
int i = 0; i < bv->
edgecount; i++) {
6262 if (
e->fnext >= 0) {
6263 const float3 face_no =
state.emesh.src_face_normals[
e->fnext];
6289 const float3 other_co =
state.emesh.src_positions[other_v];
6290 const float3 edir = v_co - other_co;
6323 const int n_bndv = bv->
vmesh->count;
6324 const int ns = bv->
vmesh->seg;
6325 const int half_ns = ns / 2;
6326 const int ipipe1 = vpipe->
index;
6329 for (
int i = 0; i < n_bndv; i++) {
6330 for (
int j = 1; j <= half_ns; j++) {
6331 for (
int k = 0; k <= half_ns; k++) {
6336 if (!
state.params.custom_profile_samples.is_empty()) {
6338 float3 *profile_point_pipe1, *profile_point_pipe2;
6340 if (
ELEM(i, ipipe1, ipipe2)) {
6341 if (n_bndv == 3 && i == ipipe1) {
6343 const int ring = std::max(j, k);
6347 f = ((k < j) ? std::min(j, k) : ((2.0f * ring) - j)) / (2.0f * ring);
6352 profile_point_pipe2 =
6353 &
geom::mesh_vert(&vm, (i == ipipe1) ? ipipe2 : ipipe1, 0, ns - k)->co;
6366 *profile_point_pipe1, *profile_point_pipe2, f);
6371 const bool even = (ns % 2) == 0;
6372 const bool midline = even && k == half_ns &&
6373 ((i == 0 && j == half_ns) ||
ELEM(i, ipipe1, ipipe2));
6397 const int n_bndv = bv->
vmesh->count;
6398 const int ns = bv->
vmesh->seg;
6399 const int ns2 = ns / 2;
6400 const int odd = ns % 2;
6401 float ns2inv = 1.0f /
float(ns2);
6403 const int clstride = ns2 + 1;
6412 for (
int i = 0; i < n_bndv; i++) {
6443 const float3 e1_other_co =
state.emesh.src_positions[e1_other_v];
6444 const float3 e2_other_co =
state.emesh.src_positions[e2_other_v];
6452 float3(bv_co), e1_other_co,
float3(bndco), co2, meet1, meet2);
6476 float3 &on_edge_cur = centerline[clstride * i];
6477 int iprev = (i == 0) ? n_bndv - 1 : i - 1;
6478 float3 &on_edge_prev = centerline[clstride * iprev];
6493 on_edge_prev = v1co;
6502 for (
int i = 0; i < n_bndv; i++) {
6504 float3 &on_edge_cur = centerline[clstride * i];
6510 const float3 e1_other_co =
state.emesh.src_positions[e1_other_v];
6515 on_edge_cur = meet1;
6538 const float3 co2 = bv_co;
6540 for (
int i = 0; i < n_bndv; i++) {
6550 finalfrac = 0.5f /
sinf(ang);
6551 finalfrac = std::min(finalfrac, 0.8f);
6556 ns2inv = 1.0f / (ns2 + finalfrac);
6559 const float3 co1 = centerline[clstride * i];
6560 for (
int j = 1; j <= ns2; j++) {
6568 for (
int i = 0; i < n_bndv; i++) {
6570 const float3 &prev_cl = centerline[clstride * (i == 0 ? n_bndv - 1 : i - 1)];
6571 for (
int j = 0; j < ns2 + odd; j++) {
6574 const float3 &cur_cl = centerline[clstride * i];
6575 for (
int k = 1; k <= ns2; k++) {
6587 for (
int i = 0; i < n_bndv; i++) {
6588 int im1 = (i == 0) ? n_bndv - 1 : i - 1;
6589 for (
int j = 1; j < ns2 + odd; j++) {
6590 for (
int k = 1; k <= ns2; k++) {
6593 centerline[clstride * im1 + k],
6595 centerline[clstride * i + j],
6601 centerline[clstride * im1 + k],
6604 else if (ikind == 1) {
6629 !
state.params.custom_profile_samples.is_empty())
6633 if (bv->
vmesh->count != 3) {
6637 const float offset = bv->
edges[0].offset_l;
6639 float totang = 0.0f;
6642 for (
int i = 0; i < bv->
edgecount; i++) {
6646 if (
e.fprev >= 0 &&
e.fnext >= 0) {
6659 if (absang <=
float(
M_PI_4)) {
6662 else if (absang >= 3.0f *
float(
M_PI_4)) {
6677 (angdiff >
float(
M_PI_4)))
6707 const int ns = vm.
seg;
6708 const int ns2 = ns / 2;
6709 for (
int i = 0; i < 3; i++) {
6710 for (
int j = 0; j <= ns2; j++) {
6711 for (
int k = 0; k <= ns; k++) {
6728 const int n_bndv = bv->
vmesh->count;
6729 const int nseg = bv->
vmesh->seg;
6743 for (
int i = 0; i < n_bndv; i++) {
6750 center /=
float(n_bndv);
6754 const float3 center_dir = v_co - center;
6756 const float fullness =
state.pro_spacing.fullness;
6770 VMesh vm1 = std::move(vm0);
6773 vm1 = std::move(next);
6774 }
while (vm1.
seg < nseg);
6775 if (vm1.
seg != nseg) {
6777 vm1 = std::move(resampled);
6808 state.selection.contains(
e));
6812 if (first_e == -1) {
6816 if (face_count == 1) {
6822 if (face_count == 0) {
6837 state.bev_verts.append({});
6851 bv->
offset = (first_e != -1) ?
state.params.offsets[0][first_e] : 1.0f;
6866 bv->
vmesh = std::make_unique<VMesh>();
6872 for (
int i = 0; i < tot_edges; i++) {
6876 state.selection.contains(
e));
6883 eh->
is_rev = (edge_verts[1] ==
v);
6886 if (tot_edges > 1) {
6889 int ccw_test_sum = 0;
6890 for (
int i = 0; i < tot_edges; i++) {
6892 emesh, bv->
edges[i].e, bv->
edges[(i + 1) % tot_edges].e, bv->
edges[i].fnext);
6894 if (ccw_test_sum < 0) {
6895 for (
int i = 0; i <= (tot_edges / 2) - 1; i++) {
6896 std::swap(bv->
edges[i], bv->
edges[tot_edges - i - 1]);
6897 std::swap(bv->
edges[i].fprev, bv->
edges[i].fnext);
6898 std::swap(bv->
edges[tot_edges - i - 1].fprev, bv->
edges[tot_edges - i - 1].fnext);
6900 if (tot_edges % 2 == 1) {
6901 int i = tot_edges / 2;
6902 std::swap(bv->
edges[i].fprev, bv->
edges[i].fnext);
6908 for (
int i = 0; i < tot_edges; i++) {
6910 eh->
next = &bv->
edges[(i + 1) % tot_edges];
6911 eh->
prev = &bv->
edges[(i + tot_edges - 1) % tot_edges];
6924 const bool at_src = (ev[0] ==
v);
6952 eh->
is_seam = !
state.uv_layer_info.contig_uv_maps_across_edge(
6960 state.vert_hash.add_new(
v, bv);
7007 const ExtendableMesh &emesh,
const int nc,
const int new_face_fallback)
7010 const int f_src = (face_reps[nc] >= 0) ? face_reps[nc] : new_face_fallback;
7012 return std::nullopt;
7060 for (
const int nc : new_faces[nf]) {
7062 emesh, nc, face_fallback);
7064 data.src_faces[nc] = interp_data->src_face;
7065 co[nc] = interp_data->co;
7066 data.offsets[nc] = int(emesh.
src_faces[interp_data->src_face].size());
7077 for (
const int nc :
IndexRange(n_new_corners)) {
7078 if (
data.src_faces[nc] == -1) {
7082 data.src_corners.as_mutable_span().slice(corner_offsets[nc]),
7087 data.weights.as_mutable_span().slice(corner_offsets[nc]));
7106 [&](
const int64_t corner) { return interp_weights.src_faces[corner] == -1; },
7118 const int num_uv_layers = int(
state.uv_layer_info.uv_maps.size());
7119 if (num_uv_layers == 0) {
7126 for (
int i = 0; i < num_uv_layers; i++) {
7127 src_uv_layers[i] =
state.uv_layer_info.uv_maps[i].values;
7132 const int src_face = interp_weights.
src_faces[nc];
7133 if (src_face == -1) {
7139 for (
const int uv_i :
IndexRange(num_uv_layers)) {
7142 result += weights[i] * src_uv_layers[uv_i][face_corners[i]];
7144 dst_uv_layers[uv_i][nc] =
result;
7169 const int num_uv_layers = int(
state.uv_layer_info.uv_maps.size());
7170 if (num_uv_layers == 0) {
7186 const int f_src = new_face_exs[nf];
7187 for (
const int nc : new_faces[nf]) {
7188 nc_face_rep[nc] = f_src;
7201 for (
const int sc : src_faces[f]) {
7203 face_vert_to_src_corner.
add_new(key, sc);
7207 for (
int uv_i = 0; uv_i < num_uv_layers; uv_i++) {
7212 for (
auto item :
state.uv_vert_maps[uv_i].items()) {
7215 if (bucket.size() <= 1) {
7219 for (
const int src_c : bucket) {
7220 avg += src_uv_vals[src_c];
7222 avg /=
float(bucket.size());
7223 for (
const int src_c : bucket) {
7224 src_uv_vals[src_c] = avg;
7230 for (
const auto &[nv, new_corners] : vert_nc_map.
items()) {
7234 if (new_corners.size() <= 1) {
7239 const int *origin_v_ptr = bev_origin.
lookup_ptr(nv);
7240 if (origin_v_ptr ==
nullptr) {
7243 const int origin_v = *origin_v_ptr;
7247 if (buckets ==
nullptr) {
7257 for (
const int nc : new_corners) {
7258 const int f_rep = nc_face_rep[nc];
7263 const int *src_c_ptr = face_vert_to_src_corner.
lookup_ptr(key);
7264 if (src_c_ptr ==
nullptr) {
7267 if (bucket.contains(*src_c_ptr)) {
7271 if (matching.
size() <= 1) {
7275 for (
const int nc : matching) {
7276 avg += new_uv_vals[nc];
7279 for (
const int nc : matching) {
7280 new_uv_vals[nc] = avg;
7300 for (
auto bv_entry :
state.vert_hash.items()) {
7302 if (!bv || !bv->
vmesh) {
7314 auto find_example_edge_for_flag = [&](
BoundVert *bcur,
bool is_seam_flag) ->
int {
7315 for (
int ei = 0; ei < bv->
edgecount; ei++) {
7317 if (eh->
rightv == bcur) {
7327 auto extend_arcs = [&](
BoundVert *&bcur,
int extend_len,
int example) {
7328 const int idx_end = bcur->
index + extend_len;
7329 for (
int i = bcur->
index; i < idx_end; i++) {
7330 for (
int k = 0; k < vm->
seg; k++) {
7333 if (va >= 0 && vb >= 0) {
7334 const int arc_edge =
state.emesh.find_edge(va, vb);
7335 if (arc_edge >= 0 && example >= 0) {
7336 state.emesh.edge_set_example(arc_edge, example);
7342 if (va >= 0 && vb >= 0) {
7343 const int spoke_edge =
state.emesh.find_edge(va, vb);
7344 if (spoke_edge >= 0 && example >= 0) {
7345 state.emesh.edge_set_example(spoke_edge, example);
7356 const int extend_len = bcur->
seam_len;
7357 if (extend_len > 0) {
7361 const int example = find_example_edge_for_flag(bcur,
true);
7362 extend_arcs(bcur, extend_len, example);
7367 }
while (bcur != start);
7374 if (extend_len > 0) {
7378 const int example = find_example_edge_for_flag(bcur,
false);
7379 extend_arcs(bcur, extend_len, example);
7384 }
while (bcur != start);
7435 const Span<float3> src_positions = src_mesh.vert_positions();
7436 const Span<int2> src_edges = src_mesh.edges();
7438 const Span<int> src_corner_verts = src_mesh.corner_verts();
7439 const Span<int> src_corner_edges = src_mesh.corner_edges();
7441 const int n_surv_verts = src_survive_verts.
size();
7442 const int n_surv_edges = src_survive_edges.
size();
7443 const int n_surv_faces = src_survive_faces.
size();
7451 const int n_new_verts = int(new_positions.
size());
7452 const int n_new_edges = int(new_edge_data.
size());
7454 const int n_new_corners = int(new_corner_verts.
size());
7457 n_surv_edges + n_new_edges,
7458 n_surv_faces + n_new_faces,
7459 n_surv_corners + n_new_corners);
7469 auto mixed_vert_map = [&](
const int v) ->
int {
7471 return src_vert_map[
v];
7473 return n_surv_verts + (
v - src_mesh.
verts_num);
7476 auto mixed_edge_map = [&](
const int e) ->
int {
7478 return src_edge_map[
e];
7480 return n_surv_edges + (
e - src_mesh.
edges_num);
7485 src_positions, src_survive_verts, dst_positions.
take_front(src_survive_verts.
size()));
7490 dst_edges[dst_e][0] = src_vert_map[src_edges[src_e][0]];
7491 dst_edges[dst_e][1] = src_vert_map[src_edges[src_e][1]];
7493 for (
const int ne :
IndexRange(n_new_edges)) {
7494 dst_edges[n_surv_edges + ne][0] = mixed_vert_map(new_edge_data[ne][0]);
7495 dst_edges[n_surv_edges + ne][1] = mixed_vert_map(new_edge_data[ne][1]);
7500 src_faces, src_survive_faces, dst_face_offsets.
take_front(src_survive_faces.
size() + 1));
7501 for (
const int nf :
IndexRange(n_new_faces)) {
7502 dst_face_offsets[n_surv_faces + nf] = n_surv_corners + new_face_offs[nf];
7505 if (!dst_face_offsets.
is_empty()) {
7506 dst_face_offsets[n_surv_faces + n_new_faces] = n_surv_corners + new_face_offs[n_new_faces];
7514 const IndexRange src_face = src_faces[src_f];
7515 const IndexRange dst_face = dst_faces[dst_f];
7517 dst_corner_verts[dst_face[i]] = src_vert_map[src_corner_verts[src_face[i]]];
7518 dst_corner_edges[dst_face[i]] = src_edge_map[src_corner_edges[src_face[i]]];
7522 for (
const int nc :
IndexRange(n_new_corners)) {
7523 dst_corner_verts[n_surv_corners + nc] = mixed_vert_map(new_corner_verts[nc]);
7524 dst_corner_edges[n_surv_corners + nc] = mixed_edge_map(new_corner_edges[nc]);
7533 vert_src_by_dst.
index_range(), vert_src_by_dst, memory);
7539 edge_src_by_dst.
index_range(), edge_src_by_dst, memory);
7545 face_src_by_dst.
index_range(), face_src_by_dst, memory);
7553 if (
ELEM(iter.
name,
"position",
".edge_verts",
".corner_vert",
".corner_edge")) {
7600 src_faces, dst_faces, src_survive_faces, src_span, surv_values);
7622 for (
const int ni :
IndexRange(n_new_edges)) {
7625 seam_span[n_surv_edges + ni] = (ov == 1);
7628 seam_writer.finish();
7635 for (
const int ni :
IndexRange(n_new_edges)) {
7638 sharp_span[n_surv_edges + ni] = (ov == 1);
7641 sharp_writer.finish();
7645 for (
const int i :
state.uv_layer_info.uv_maps.index_range()) {
7654 src_faces, dst_faces, src_survive_faces, src_uvs, dst_uvs.span.
take_front(n_surv_corners));
7676 for (
const int nf :
IndexRange(n_new_faces)) {
7684 for (
const int nf :
IndexRange(n_new_faces)) {
7695 for (
const int se :
state.outer_edge_src_indices) {
7696 const int dst_e = src_edge_map[se];
7698 writer.
span[dst_e] =
true;
7703 for (
const int ne :
IndexRange(n_new_edges)) {
7705 writer.
span[n_surv_edges + ne] =
true;
7715 for (
const int ne :
IndexRange(n_new_edges)) {
7717 writer.
span[n_surv_edges + ne] =
true;
7736 auto all_non_positive = [](
const Span<float> span) {
7737 return std::ranges::all_of(span, [](
float value) {
return value <= 0.0f; });
7739 if (all_non_positive(params.
offsets[0]) && all_non_positive(params.
offsets[1]) &&
7740 all_non_positive(params.
offsets[2]) && all_non_positive(params.
offsets[3]))
7742 return std::nullopt;
7746 fmt::println(
"BEVEL NODE starts");
7750 if (
state.bevel_affected_vertices.size() == 0) {
7751 return std::nullopt;
7753 state.initialize_profile_data();
7756 state.bev_verts.reserve(
state.bevel_affected_vertices.size());
7759 fmt::println(
"BEVEL NODE initialization, {:.4} ms", (init_time - start_time).count() / 1.0e6f);
7763 state.bevel_affected_vertices.foreach_index([&](
const int v) {
7773 fmt::println(
"BEVEL NODE bevel construct and build boundaries,{:.4} ms",
7774 (vert_and_boundaries_time - init_time).count() / 1.0e6f);
7779 state.selection.foreach_index(
7785 fmt::println(
"BEVEL NODE adjust offsets, {:.4} ms",
7786 (adjust_time - vert_and_boundaries_time).count() / 1.0e6f);
7790 state.bevel_affected_vertices.foreach_index([&](
const int v) {
7798 const int faces_before =
state.emesh.new_faces_num();
7800 const int faces_after =
state.emesh.new_faces_num();
7802 for (
int nf = faces_before; nf < faces_after; nf++) {
7809 fmt::println(
"BEVEL NODE vmesh and uv connectivity, {:.4} ms",
7810 (vmesh_and_uv_time - vert_and_boundaries_time).count() / 1.0e6f);
7815 state.selection.foreach_index(
7821 fmt::println(
"BEVEL NODE edge mesh, {:.4} ms", (edge_time - vmesh_and_uv_time).count() / 1.0e6f);
7826 int rebuilt_face_0 = -1;
7831 fmt::println(
"BEVEL NODE face mesh, {:.4} ms", (face_time - edge_time).count() / 1.0e6f);
7835 for (
const int f : rebuilt_orig_faces) {
7836 state.emesh.face_kill(f);
7840 state.bevel_affected_vertices.foreach_index([&](
const int v) {
state.emesh.vert_kill(
v); });
7846 if (
state.uv_layer_info.has_uv_maps) {
7853 for (
int nf = 0; nf <
state.emesh.new_faces_num(); nf++) {
7855 fmt::println(
"new_face[{}] (corners {}-{}):",
7856 nf +
state.emesh.mesh.faces_num,
7859 for (
const int uv_i :
state.uv_layer_info.uv_maps.index_range()) {
7861 for (
const int nc : nc_range) {
7862 fmt::println(
" uv_i={} corner={} v={} uv=({:.5f},{:.5f})",
7873#ifndef BEVEL_DEBUG_SKIP_MERGE_UVS
7876 fmt::println(
"merge_uvs SKIPPED (BEVEL_DEBUG_SKIP_MERGE_UVS)");
7884 fmt::println(
"BEVEL NODE uvs and edge data, {:.4} ms",
7885 (uv_edge_data_time - face_time).count() / 1.0e6f);
7889 state, new_corner_interp_weights, attribute_filter);
7893 fmt::println(
"BEVEL NODE construct output mesh, {:.4} ms",
7894 (end_time - uv_edge_data_time).count() / 1.0e6f);
7895 fmt::println(
"BEVEL NODE total, {:5} ms", (end_time - start_time).count() / 1.0e6f);
#define STD_UV_CONNECT_LIMIT
#define BLI_assert_unreachable()
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE btVector3 dot3(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2) const
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
IndexRange index_range() const
void fill_assign_indices(const void *value, void *dst, const IndexMask &mask) const
bool is_equal_or_false(const void *a, const void *b) const
const void * default_value() const
GMutableSpan take_front(const int64_t n) const
GMutableSpan take_back(const int64_t n) const
const CPPType & type() const
CommonVArrayInfo common_info() const
const CPPType & type() const
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
constexpr int64_t first() const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr int64_t start() const
constexpr IndexRange index_range() const
const Value * lookup_ptr(const Key &key) const
void add_new(const Key &key, const Value &value)
ItemIterator items() const &
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr MutableSpan take_back(const int64_t n) const
constexpr void copy_from(Span< T > values) const
constexpr MutableSpan take_front(const int64_t n) const
constexpr Span slice(int64_t start, int64_t size) const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
constexpr bool contains(const T &value) const
static VArray from_span(Span< T > values)
bool contains(const Key &key) const
void append(const T &value)
void reserve(const int64_t min_capacity)
Span< T > as_span() const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
GAttributeReader lookup(const StringRef name) const
GAttributeReader get() const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
GSpanAttributeWriter lookup_for_write_span(StringRef name)
constexpr bool is_empty() const
constexpr Span take_front(int64_t n) const
constexpr int64_t size() const
Span< int > src_corner_verts
GroupedSpan< int > src_edge_to_face
void tag_last_face(const NewFaceKind kind)
void face_set_corner_reps(int face_idx, Span< int > face_reps, Span< int > snap_edges)
Span< NewFaceKind > new_face_kinds() const
Span< int > new_corner_snap_edges() const
GroupedSpan< int > src_vert_to_corner
Span< float3 > src_vert_normals
Array< int > src_corner_to_face
void edge_set_sharp_override(const int edge_index, int8_t value)
void edge_set_example(const int edge_index, const int example_edge)
Span< bool > kill_edges_array() const
ExtendableMesh(const Mesh &mesh)
bool is_corner_killed(const int c) const
void edge_set_seam_override(const int edge_index, int8_t value)
int corner_vert(const int c) const
Span< int8_t > new_edge_sharp_overrides() const
Span< int > src_corner_edges
void init_uv_storage(int uv_layers_num)
int2 edge_verts(const int e) const
Span< bool > kill_faces_array() const
Span< float3 > new_vert_positions() const
int new_faces_num() const
Span< float3 > src_face_normals
OffsetIndices< int > src_faces
Span< int > new_corner_verts() const
Span< bool > kill_verts_array() const
Span< float2 > new_corner_uvs(int layer_index) const
int face_create(Span< int > verts, int example_face=-1)
MutableSpan< NewFaceKind > new_face_kinds()
Span< int > new_edge_examples() const
Span< int2 > new_edges() const
int vert_create(const float3 &co, int example_vert=-1)
IndexRange face_corners(const int f) const
Span< int > new_face_offsets() const
int find_edge(const int v1, const int v2) const
bool is_edge_killed(const int e) const
void corner_kill(const int c)
const Map< int, Vector< int > > & vert_to_new_corners() const
void face_kill(const int f)
void tag_edge_kind(const int edge_index, const NewEdgeKind kind)
Span< int > new_vert_examples() const
Span< int > new_corner_face_reps() const
bool is_vert_killed(const int v) const
const Map< int, int > & vert_bev_origin() const
Span< int > new_corner_edges() const
Span< int > new_face_examples() const
void edge_kill(const int e)
GroupedSpan< int > src_vert_to_edge
Span< int8_t > new_edge_seam_overrides() const
MutableSpan< float2 > new_corner_uvs(int layer_index)
void vert_kill(const int v)
float3 vert_position(const int v) const
int corner_edge(const int c) const
Span< NewEdgeKind > new_edge_kinds() const
bool is_face_killed(const int f) const
int edge_create(const int v1, const int v2, int example_edge=-1)
Span< bool > kill_corners_array() const
Span< float3 > src_positions
bool contig_uv_maps_across_edge(const ExtendableMesh &mesh, int e, int f1, int f2) const
bool contig_uv_maps_around_vert(const ExtendableMesh &emesh, int v) const
Vector< UVLayer > uv_maps
void init(const Mesh &mesh)
void find_components(const ExtendableMesh &emesh)
Array< int > face_component
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask complement(const IndexMask &universe, LinearAllocator<> &memory) const
IndexRange index_range() const
CCL_NAMESPACE_BEGIN ccl_device_inline float frac(const float x, ccl_private int *ix)
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
IndexMask indices_non_negative(const IndexMask &universe, Span< int > values, LinearAllocator<> &memory)
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
BooleanMix booleans_mix_calc(const VArray< bool > &varray, IndexRange range_to_check)
void fill_index_range(MutableSpan< T > span, const T start=0)
void gather(GSpan src, Span< int > map, GMutableSpan dst)
void gather_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
void mix_groups(GSpan src, OffsetIndices< int > groups, Span< int > all_indices, std::optional< Span< float > > all_weights, GMutableSpan dst)
GroupedSpan< int > build_edge_to_face_map(OffsetIndices< int > faces, Span< int > corner_edges, int edges_num, Array< int > &r_offsets, Array< int > &r_indices)
int face_find_corner_from_vert(const IndexRange face, const Span< int > corner_verts, const int vert)
bool is_uv_map(const AttributeMetaData &meta_data)
Array< int > build_corner_to_face_map(OffsetIndices< int > faces)
float3 face_center_calc(Span< float3 > vert_positions, Span< int > face_verts)
GroupedSpan< int > build_vert_to_edge_map(Span< int2 > edges, int verts_num, Array< int > &r_offsets, Array< int > &r_indices)
bool mesh_is_valid(const Mesh &mesh, bool verbose=true)
constexpr ParallelGrainSize grain_size(int grain_size)
static void snap_to_superellipsoid(float3 &co, const float super_r, const bool midline)
static VMesh tri_corner_adj_vmesh(BevelState &state, BevVert *bv)
static EdgeHalf * next_bev(BevVert *bv, EdgeHalf *from_e)
static void merge_uvs(BevelState &state)
static bool face_point_inside_test(const ExtendableMesh &emesh, const int f, const float3 co)
static bool edge_has_miter(const BevelState &state, const EdgeHalf *e, int v)
static int choose_rep_face(const BevelState &state, const Span< int > faces)
static int tri_corner_test(const BevelState &state, const BevVert *bv)
static void find_bevel_edge_order(const ExtendableMesh &emesh, BevVert *bv, int first_e, bool is_edge_bevel)
static int find_closer_edge(const ExtendableMesh &emesh, const float3 &co, const int e1, const int e2)
static void fill_vmesh_fracs(VMesh *vm, MutableSpan< float > frac, int i)
static VMesh new_adj_vmesh(int count, int seg, BoundVert *bounds)
static void bevel_build_edge_polygons(BevelState &state, const int edge_index)
static VMesh make_cube_corner_adj_vmesh(BevelState &state)
static float4x4 make_unit_cube_map(const float3 &va, const float3 &vb, const float3 &vc, const float3 &vd)
static BoundVert * pipe_test(const BevelState &state, BevVert *bv)
static void get_incident_edges(const ExtendableMesh &emesh, const int f, const int v_idx, int *r_e1, int *r_e2)
static VMesh square_out_adj_vmesh(BevelState &state, BevVert *bv)
static int bevel_build_poly(BevelState &state, BevVert *bv)
static VMesh cubic_subdiv(const BevelState &state, VMesh &vm_in)
static float3 offset_in_plane(const ExtendableMesh &emesh, EdgeHalf *e, const float3 *plane_no, bool left)
static float3 snap_to_pipe_profile(const BevelState &state, BevVert *bv, BoundVert *vpipe, bool midline, const float3 &co)
static bool edges_face_connected_at_vert(const ExtendableMesh &emesh, const int e1, const int e2)
static void compute_face_interp_weights(const ExtendableMesh &emesh, const int f_src, const float3 &co, MutableSpan< float > weights)
static void build_boundary_vertex_only(const BevelState &state, BevVert *bv, bool construct)
static std::optional< Mesh * > build_output_mesh(const BevelState &state, const NewCornerInterpWeights &interp_weights, const bke::AttributeFilter &attribute_filter)
static AngleKind edges_angle_kind(const ExtendableMesh &emesh, EdgeHalf *e1, EdgeHalf *e2, int v)
static VMesh make_cube_corner_square(const int nseg)
static NewCornerInterpWeights compute_new_corner_interp_weights(const ExtendableMesh &emesh)
static bool is_bad_uv_poly(const BevelState &state, BevVert *bv, const int frep)
static void bevel_build_rings(BevelState &state, BevVert *bv)
static int bev_ccw_test(const ExtendableMesh &emesh, const int a, const int b, const int f)
static void fill_new_corner_uvs(BevelState &state, const NewCornerInterpWeights &interp_weights)
static int find_face_internal_boundverts(const ExtendableMesh &emesh, const BevVert *bv, const int f, BoundVert *(r_internal[3]))
static int interp_range(const Span< float > frac, const int n, const float f, float *r_rest)
static VMesh interp_vmesh(const BevelState &state, VMesh &vm_in, int nseg)
static int bev_rebuild_polygon(BevelState &state, const int f_idx)
static EdgeHalf * next_edgehalf_bev(const BevelState &state, EdgeHalf *start_edge, bool toward_bv, BevVert **r_bv)
static void build_vmesh(BevelState &state, BevVert *bv)
static void set_bound_vert_seams(const BevelState &state, BevVert *bv, bool mark_seam, bool mark_sharp)
static void adjust_bound_vert(BoundVert *bndv, const float3 &co)
static bool fast_bevel_edge_order(const ExtendableMesh &emesh, BevVert *bv, bool is_edge_bevel)
static VMesh pipe_adj_vmesh(BevelState &state, BevVert *bv, BoundVert *vpipe)
static int count_ccw_edges_between(const EdgeHalf *e1, const EdgeHalf *e2)
static int bevel_edge_order_extend(const ExtendableMesh &emesh, BevVert *bv, int i, bool is_edge_bevel)
static void bevel_extend_edge_data(BevelState &state)
static void bevel_rebuild_existing_polygons(BevelState &state, Vector< int > &r_rebuilt_orig_faces, int &r_rebuilt_face_0)
static EdgeHalf * find_other_end_edge_half(const BevelState &state, EdgeHalf *e, BevVert **r_bvother)
static bool bevvert_is_weld_cross(const BevVert *bv)
static void bevel_vert_construct(BevelState &state, int v)
static int frep_for_center_poly(const BevelState &state, const BevVert *bv)
static void adjust_miter_coords(const BevelState &state, BevVert *bv, EdgeHalf *emiter)
static void bevel_vert_two_edges(BevelState &state, BevVert *bv)
static float projected_boundary_area(const BevelState &state, BevVert *bv, const int f)
static void build_boundary_terminal_edge(const BevelState &state, BevVert *bv, EdgeHalf *efirst, const bool construct)
static VMesh make_cube_corner_square_in(const int nseg)
static void snap_edges_for_vmesh_vert(const int i, const int j, const int k, const int ns, const int ns2, const int n_bndv, const int eprev, const int enext, const int enextnext, const Span< int > bndv_rep_faces, const int center_frep, const Span< bool > frep_beats_next, int r_snap_edges[4])
static float3 closer_v3_v3v3v3(const float3 &a, const float3 &b, const float3 &v)
static void determine_uv_vert_connectivity(BevelState &state, const int v)
static int boundvert_rep_face(const BoundVert *v, int *r_fother)
static void adjust_miter_inner_coords(const BevelState &state, BevVert *bv, EdgeHalf *emiter)
static void bevel_build_trifan(BevelState &state, BevVert *bv)
static void build_boundary(const BevelState &state, BevVert *bv, bool construct)
static bool try_propagate_single_value(const bke::AttributeIter &iter, const GVArray &src, const IndexMask &edges_new_no_src, bke::MutableAttributeAccessor &dst_attrs)
static void fill_profile_fracs(const BevelState &state, const BoundVert *bndv, MutableSpan< float > frac, const int ns)
static bool nearly_parallel_normalized(const float3 &d1, const float3 &d2)
static int snap_edge_for_center_vmesh_vert(const int i, const int n_bndv, const int eprev, const int enext, const Span< int > bndv_rep_faces, const int center_frep, const Span< bool > frep_beats_next)
static VMesh adj_vmesh(BevelState &state, BevVert *bv)
static void regularize_profile_orientation(const BevelState &state, int edge_index)
static EdgeHalf * find_edge_half_for_edge(BevVert *bv, int edge_index)
static BoundVert * add_new_bound_vert(BevVert *bv, const float3 &co)
static std::optional< NewCornerInterpData > resolve_new_corner_interp_data(const ExtendableMesh &emesh, const int nc, const int new_face_fallback)
static void check_edge_data_seam_sharp_edges(const BevelState &state, BevVert *bv, bool check_seam, bool check_sharp)
static void interpolate_new_corner_attribute_from_faces(const NewCornerInterpWeights &interp_weights, const GSpan src, GMutableSpan dst)
static void dump_edge_half(const EdgeHalf &eh, const int index)
static void dump_bound_vert(const BoundVert &bndv)
static void dump_profile(const Profile &prof)
static void dump_new_edge_examples(const BevelState &state)
static void print_float3_span(Span< float3 > span, const char *label)
static void dump_bev_vert(const BevVert &bv)
static void print_groupedspan(const GroupedSpan< int > &groupedspan, const char *label)
static void dump_edge_polygons(const BevelState &state, const BevVert &bv)
static void dump_new_face_examples(const BevelState &state)
static void print_int2(const int2 pair)
static const char * mesh_kind_name(MeshKind kind)
static void print_float3(const float3 &v)
static void dump_vmesh(const VMesh &vm)
static void print_indexrange(const IndexRange &range)
static void dump_rebuilt_face(const BevelState &state, const int face_idx)
static void print_int2_span(Span< int2 > span, const char *label)
static void print_span(Span< T > span, const char *label)
constexpr float BEVEL_EPSILON_BIG
constexpr float BEVEL_SMALL_ANG
const float BEVEL_SMALL_ANG_DOT
static bool nearly_parallel(const float3 &d1, const float3 &d2)
static float3 vmesh_center(VMesh *vm)
static NewVert * mesh_vert_canon(VMesh *vm, int i, int j, int k)
constexpr float BEVEL_EPSILON_SQ
static bool is_outside_edge(const ExtendableMesh &emesh, EdgeHalf *eh, const float co[3], int *ret_closer_v)
static float3 avg4(const NewVert *v0, const NewVert *v1, const NewVert *v2, const NewVert *v3)
constexpr float BEVEL_EPSILON_ANG
static bool point_between_edges(const ExtendableMesh &emesh, const float co[3], int v, int f, EdgeHalf *e1, EdgeHalf *e2)
const float BEVEL_EPSILON_ANG_DOT
static int edge_other_vert(const ExtendableMesh &emesh, int e, int v)
constexpr float BEVEL_EPSILON_D
static float3 slide_dist(const ExtendableMesh &emesh, int e, int v, float d)
static bool make_unit_square_map(const float3 &va, const float3 &vmid, const float3 &vb, float4x4 &r_mat)
static float3 offset_meet(const ExtendableMesh &emesh, EdgeHalf *e1, EdgeHalf *e2, int v, int f, bool edges_between, const EdgeHalf *e_in_plane)
static void vmesh_copy_equiv_verts(VMesh *vm)
static bool is_canon(const VMesh *vm, int i, int j, int k)
static NewVert * mesh_vert(VMesh *vm, int i, int j, int k)
static float sabin_gamma(int n)
static float3 get_profile_point(const BevelState &state, const Profile *pro, int i, int nseg)
static void set_profile_params(const BevelState &state, const BevVert *bv, BoundVert *bndv)
static void calculate_profile(BevelState &state, BoundVert *bndv, bool reversed, bool)
static void calculate_vm_profiles(BevelState &state, BevVert *bv, VMesh *vm)
static void find_even_superellipse_chords_general(int seg, float r, MutableSpan< double > xvals, MutableSpan< double > yvals)
static float3 project_to_edge(const ExtendableMesh &emesh, int e_idx, const float3 &co_a, const float3 &co_b)
static float find_profile_fullness(BevelState *bs)
static void move_weld_profile_planes(BoundVert *bndv1, BoundVert *bndv2, const float3 v_co)
static double superellipse_co(double x, float r, bool rbig)
static void calculate_profile_segments(const Profile &pro, const float4x4 &map, const bool use_map, const bool reversed, const int ns, const double *xvals, const double *yvals, MutableSpan< float3 > r_prof_co)
constexpr float PRO_SQUARE_R
constexpr float PRO_SQUARE_IN_R
constexpr float PRO_LINE_R
static void find_even_superellipse_chords(int n, float r, MutableSpan< double > xvals, MutableSpan< double > yvals)
static void set_profile_spacing(BevelState *bs, ProfileSpacing *pro_spacing, bool custom)
static void move_profile_plane(BoundVert *bndv, float3 bmvert_co)
constexpr float PRO_CIRCLE_R
static double find_superellipse_chord_endpoint(double x0, double dtarget, float r, bool rbig)
Map< int, Vector< UVVertBucket > > UVVertMap
std::optional< Mesh * > mesh_bevel(const Mesh &src_mesh, const IndexMask &selection, const BevelParameters ¶ms, const bke::AttributeFilter &attribute_filter)
IndexMask vert_selection_from_edge(Span< int2 > edges, const IndexMask &edge_mask, int verts_num, IndexMaskMemory &memory)
void build_reverse_map(const IndexMask &mask, MutableSpan< T > r_map)
T length_squared(const VecBase< T, Size > &a)
float3x3 axis_dominant_to_m3(const float3 &normal)
T cos(const AngleRadianBase< T > &a)
T pow(const T &x, const T &power)
T dist_squared_to_line_segment(const VecBase< T, Size > &p, const VecBase< T, Size > &l1, const VecBase< T, Size > &l2)
VecBase< T, Size > closest_to_line_segment(const VecBase< T, Size > &p, const VecBase< T, Size > &l1, const VecBase< T, Size > &l2)
T dist_squared_to_plane(const VecBase< T, 3 > &p, const VecBase< T, 4 > &plane)
std::optional< float3 > isect_line_plane(const float3 &l1, const float3 &l2, const float3 &plane_co, const float3 &plane_no)
T distance(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
AngleRadianBase< T > angle_between(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
QuaternionBase< T > normalize_and_get_length(const QuaternionBase< T > &q, T &out_length)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T min(const T &a, const T &b)
CartesianBasis invert(const CartesianBasis &basis)
T midpoint(const T &a, const T &b)
AxisSigned cross(const AxisSigned a, const AxisSigned b)
T interpolate(const T &a, const T &b, const FactorT &t)
VecBase< T, 3 > closest_to_plane_normalized(const VecBase< T, 4 > &plane, const VecBase< T, 3 > &pt)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
bool is_equal(const MatBase< T, NumCol, NumRow > &a, const MatBase< T, NumCol, NumRow > &b, const T epsilon=T(0))
T sin(const AngleRadianBase< T > &a)
T max(const T &a, const T &b)
int isect_line_line(const float3 &v1, const float3 &v2, const float3 &v3, const float3 &v4, float3 &r_i1, float3 &r_i2)
VecBase< T, 4 > plane_from_point_normal(const VecBase< T, 3 > &co, const VecBase< T, 3 > &no)
VecBase< T, 3 > closest_to_plane(const VecBase< T, 4 > &plane, const VecBase< T, 3 > &pt)
void interp_weights_poly(MutableSpan< float > r_weights, Span< float2 > verts, const float2 &co)
bool isect_point_poly(const float2 &pt, Span< float2 > verts)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
int sum_group_sizes(OffsetIndices< int > offsets, const IndexMask &mask)
OffsetIndices< int > gather_selected_offsets(OffsetIndices< int > src_offsets, const IndexMask &selection, int start_offset, MutableSpan< int > dst_offsets)
Clock::time_point TimePoint
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE int power_of_2_max_i(int n)
ATTR_WARN_UNUSED_RESULT const BMVert * v
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
float area_poly_v2(const float verts[][2], unsigned int nr)
void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
BMesh const char void * data
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
MatBase< float, 3, 3 > float3x3
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void interp_bilinear_quad_v3(float data[4][3], float u, float v, float res[3])
PythonProbingStrategy<> DefaultProbingStrategy
VecBase< float, 3 > float3
MINLINE int is_power_of_2_i(int n)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
MINLINE bool compare_v2v2(const float v1[2], const float v2[2], float limit) ATTR_WARN_UNUSED_RESULT
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
OrderedEdge(const int v1, const int v2)
bool allow_skip(const StringRef name) const
MutableVArraySpan< T > span
std::array< T, Size > values
Vector< std::unique_ptr< BoundVert > > owned_bound_verts
std::unique_ptr< VMesh > vmesh
std::optional< std::string > edge_face_id
std::optional< std::string > vertex_face_id
std::optional< std::string > mid_edge_id
std::optional< std::string > outer_edge_id
Array< float2 > custom_profile_samples
std::array< Array< float >, 4 > offsets
IndexMask bevel_affected_faces
Array< float3 > face_centers
index_mask::IndexMaskMemory memory
float3 face_center(const int f) const
void initialize_profile_data()
Vector< BevVert > bev_verts
Vector< UVVertMap > uv_vert_maps
uv::UVMapInfo uv_layer_info
IndexMask bevel_affected_vertices
BevelState(const Mesh &mesh, const BevelParameters ¶ms, const IndexMask &selection)
Map< int, BevVert * > vert_hash
ProfileSpacing pro_spacing_miter
ProfileSpacing pro_spacing
Vector< int > outer_edge_src_indices
Array< float3 > prof_co_2
Span< float > weights_for(const int nc) const
IndexRange index_range() const