30#define BARYCENTRIC_INTERP
32#ifdef BARYCENTRIC_INTERP
57 const float co_a_next[3],
58 const float co_b_next[3],
60 const float co_a_prev[3],
61 const float co_b_prev[3],
100 if (
e->l->v == v_a) {
102 l_pair[1] =
e->l->next;
105 l_pair[0] =
e->l->next;
123 if (l_pair_a[0] && l_pair_b[0] ==
nullptr) {
124 l_pair_b[0] = l_pair_a[1];
125 l_pair_b[1] = l_pair_a[0];
127 else if (l_pair_b[0] && l_pair_a[0] ==
nullptr) {
128 l_pair_a[0] = l_pair_b[1];
129 l_pair_a[1] = l_pair_b[0];
143 const void *l_cdata[4] = {
156 const float w[2] = {1.0f - t, t};
168 float (*weight_table)[4])
170 float x_step = 1.0f /
float(xtot - 1);
171 float y_step = 1.0f /
float(ytot - 1);
176 for (
y = 0;
y < ytot;
y++) {
177 xy_fl[1] = y_step *
float(
y);
178 for (
x = 0;
x < xtot;
x++) {
179 xy_fl[0] = x_step *
float(
x);
181 const float cos[4][2] = {
182 {xy_fl[0], 0.0f}, {0.0f, xy_fl[1]}, {xy_fl[0], 1.0f}, {1.0f, xy_fl[1]}};
199 const bool use_smooth,
201 const bool use_interp_simple)
208 BMLoop *(*larr_x_a)[2], *(*larr_x_b)[2], *(*larr_y_a)[2], *(*larr_y_b)[2];
210 float (*weight_table)[4];
212#define XY(_x, _y) ((_x) + ((_y) * (xtot)))
214#ifdef BARYCENTRIC_INTERP
220 v_grid[
XY(0, 0)]->co,
221 v_grid[
XY(xtot - 1, 0)]->co,
222 v_grid[
XY(0, 1)]->co,
223 v_grid[
XY(xtot - 1, 1)]->co,
229 v_grid[
XY(0, (ytot - 1))]->co,
230 v_grid[
XY(xtot - 1, (ytot - 1))]->co,
231 v_grid[
XY(0, (ytot - 2))]->co,
232 v_grid[
XY(xtot - 1, (ytot - 2))]->co,
238 if (use_interp_simple || use_vert_interp || use_loop_interp) {
243 weight_table =
nullptr;
247 if (use_loop_interp) {
256 for (
x = 0;
x < xtot - 1;
x++) {
262 for (
y = 0;
y < ytot - 1;
y++) {
270 for (
y = 1;
y < ytot - 1;
y++) {
271#ifdef BARYCENTRIC_INTERP
273 v_grid[
XY(0,
y + 0)]->co,
274 v_grid[
XY(xtot - 1,
y + 0)]->co,
275 v_grid[
XY(0,
y + 1)]->co,
276 v_grid[
XY(xtot - 1,
y + 1)]->co,
277 v_grid[
XY(0,
y - 1)]->co,
278 v_grid[
XY(xtot - 1,
y - 1)]->co,
281 for (
x = 1;
x < xtot - 1;
x++) {
288#ifdef BARYCENTRIC_INTERP
289 if (use_interp_simple ==
false) {
290 float co_a[3], co_b[3];
293 co_a, v_grid[
x]->co, tri_t[0], tri_t[1], tri_t[2], tri_a[0], tri_a[1], tri_a[2]);
295 v_grid[(xtot * ytot) + (
x - xtot)]->co,
308 const float *
w = weight_table[
XY(
x,
y)];
318 v_grid[(
y * xtot) +
x] =
v;
322 if (use_vert_interp) {
323 const float *
w = weight_table[
XY(
x,
y)];
325 const void *v_cdata[4] = {
338 for (
x = 0;
x < xtot - 1;
x++) {
339 for (
y = 0;
y < ytot - 1;
y++) {
344 v_grid[
XY(
x,
y + 0)],
345 v_grid[
XY(
x,
y + 1)],
346 v_grid[
XY(
x + 1,
y + 1)],
347 v_grid[
XY(
x + 1,
y + 0)],
353 v_grid[
XY(
x + 1,
y + 0)],
354 v_grid[
XY(
x + 1,
y + 1)],
355 v_grid[
XY(
x,
y + 1)],
356 v_grid[
XY(
x,
y + 0)],
361 if (use_loop_interp && (larr_x_a[
x][0] || larr_y_a[
y][0])) {
366 uint x_side, y_side, i;
369 if (larr_x_a[
x][0] && larr_y_a[
y][0]) {
371 l_tmp = larr_x_a[
x][0];
373 else if (larr_x_a[
x][0]) {
375 l_tmp = larr_x_a[
x][0];
379 l_tmp = larr_y_a[
y][0];
409 for (x_side = 0; x_side < 2; x_side++) {
410 for (y_side = 0; y_side < 2; y_side++) {
411 if (interp_from ==
'B') {
412 const float *
w = weight_table[
XY(
x + x_side,
y + y_side)];
413 l_bound[0] = larr_x_a[
x][x_side];
414 l_bound[1] = larr_y_a[
y][y_side];
415 l_bound[2] = larr_x_b[
x][x_side];
416 l_bound[3] = larr_y_b[
y][y_side];
420 else if (interp_from ==
'X') {
421 const float t =
float(
y + y_side) /
float(ytot - 1);
422 l_bound[0] = larr_x_a[
x][x_side];
423 l_bound[1] = larr_x_b[
x][x_side];
427 else if (interp_from ==
'Y') {
428 const float t =
float(
x + x_side) /
float(xtot - 1);
429 l_bound[0] = larr_y_a[
y][y_side];
430 l_bound[1] = larr_y_b[
y][y_side];
450 if (use_loop_interp) {
451 MEM_delete(larr_x_a);
452 MEM_delete(larr_y_a);
453 MEM_delete(larr_x_b);
454 MEM_delete(larr_y_b);
458 MEM_delete(weight_table);
470 const bool use_smooth,
471 const bool use_interp_simple)
473#define USE_FLIP_DETECT
483 bool use_flip =
false;
514 for (el = lb_a->first(), i = 0; el; el = el->
next, i++) {
517 for (el = lb_b->first(), i = 0; el; el = el->
next, i++) {
518 v_grid[(ytot * xtot) + (i - xtot)] =
static_cast<BMVert *
>(el->
data);
520 for (el = lb_rail_a->first(), i = 0; el; el = el->
next, i++) {
521 v_grid[xtot * i] =
static_cast<BMVert *
>(el->
data);
523 for (el = lb_rail_b->first(), i = 0; el; el = el->
next, i++) {
524 v_grid[(xtot * i) + (xtot - 1)] =
static_cast<BMVert *
>(el->
data);
527 for (
x = 1;
x < xtot - 1;
x++) {
528 for (
y = 1;
y < ytot - 1;
y++) {
534#ifdef USE_FLIP_DETECT
536 ListBaseT<LinkData> *lb_iter[4] = {lb_a, lb_b, lb_rail_a, lb_rail_b};
537 const int lb_iter_dir[4] = {-1, 1, 1, -1};
538 int winding_votes = 0;
540 for (i = 0; i < 4; i++) {
542 for (el = lb_iter[i]->first(); el && (el_next = el->
next); el = el->
next) {
546 winding_votes += (
e->l->v == el->
data) ? lb_iter_dir[i] : -lb_iter_dir[i];
550 use_flip = (winding_votes < 0);
557#undef USE_FLIP_DETECT
577 ListBaseT<BMEdgeLoopStore> eloops = {
nullptr,
nullptr};
578 ListBaseT<BMEdgeLoopStore> eloops_rail = {
nullptr,
nullptr};
581 BMVert *v_a_first, *v_a_last;
582 BMVert *v_b_first, *v_b_last;
586 std::unique_ptr<Set<BMEdge *>> split_edges;
589 bool changed =
false;
591 const auto edge_test_rail_fn = [](
BMEdge *
e) {
612 "Select two edge loops "
613 "or a single closed edge loop from which two edge loops can be calculated");
617 estore_a = eloops.first();
618 estore_b = eloops.last();
640 estore_rail_a = eloops_rail.first();
641 estore_rail_b = eloops_rail.last();
649 estore_rail_a = eloops_rail.first();
650 estore_rail_b = eloops_rail.last();
661 if (eloops_rail.is_empty()) {
677 {estore_a, estore_b},
678 {estore_rail_a, estore_rail_b},
682 for (i = 0; i < 2; i++) {
685 if (len_a != len_b) {
686 if (split_edges ==
nullptr) {
687 split_edges = std::make_unique<Set<BMEdge *>>();
702 bm, estore_a, estore_b, estore_rail_a, estore_rail_b, mat_nr, use_smooth, use_interp_simple);
707 for (
BMEdge *
e : *split_edges) {
CustomData interface, see also DNA_customdata_types.h.
Read Blender memory allocation and freeing.
#define BM_FACE_FIRST_LOOP(p)
#define BM_elem_flag_set(ele, hflag, val)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
#define BMO_edge_flag_test(bm, e, oflag)
#define BMO_face_flag_enable(bm, e, oflag)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ListBaseT< LinkData > * BM_edgeloop_verts_get(BMEdgeLoopStore *el_store)
int BM_mesh_edgeloops_find(BMesh *bm, ListBaseT< BMEdgeLoopStore > *r_eloops, FunctionRef< bool(BMEdge *)> test_fn, const BMEdgeLoopFind_Params *params)
static void bm_loop_pair_test_copy(BMLoop *l_pair_a[2], BMLoop *l_pair_b[2])
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
BLI_INLINE bool BM_edge_is_wire(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BM_face_as_array_loop_quad(BMFace *f, BMLoop *r_loops[4])
void BM_edgeloop_flip(BMesh *, BMEdgeLoopStore *el_store)
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
void BM_edgeloop_expand(BMesh *bm, BMEdgeLoopStore *el_store, int el_store_len, bool split, Set< BMEdge * > *split_edges)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void BM_mesh_edgeloops_free(ListBaseT< BMEdgeLoopStore > *eloops)
static void barycentric_weights_v2_grid_cache(const uint xtot, const uint ytot, float(*weight_table)[4])
bool CustomData_has_interp(const CustomData *data)
void BMO_slot_buffer_flag_enable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, short oflag)
BMO_FLAG_BUFFER.
void CustomData_bmesh_interp(CustomData *data, const void **src_blocks, const float *weights, int count, void *dst_block)
static void quad_verts_to_barycentric_tri(float tri[3][3], const float co_a[3], const float co_b[3], const float co_a_next[3], const float co_b_next[3], const float co_a_prev[3], const float co_b_prev[3], const bool is_flip)
static void bm_loop_pair_from_verts(BMVert *v_a, BMVert *v_b, BMLoop *l_pair[2])
void transform_point_by_tri_v3(float pt_tar[3], float const pt_src[3], const float tri_tar_p1[3], const float tri_tar_p2[3], const float tri_tar_p3[3], const float tri_src_p1[3], const float tri_src_p2[3], const float tri_src_p3[3])
bool BM_mesh_edgeloops_find_path(BMesh *bm, ListBaseT< BMEdgeLoopStore > *r_eloops, FunctionRef< bool(BMEdge *)> test_fn, BMVert *v_src, BMVert *v_dst)
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.
BMVert * BM_edge_collapse(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool do_del, const bool kill_degenerate_faces)
MINLINE void mul_v3_fl(float r[3], float f)
bool BM_edgeloop_is_closed(BMEdgeLoopStore *el_store)
int BM_edgeloop_length_get(BMEdgeLoopStore *el_store)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
BMFace * BM_face_create_quad_tri(BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4, const BMFace *f_example, const eBMCreateFlag create_flag)
Make Quad/Triangle.
static void quad_edges_to_normal(float no[3], const float co_a1[3], const float co_a2[3], const float co_b1[3], const float co_b2[3])
void BMO_slot_buffer_from_enabled_flag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, short oflag)
void bmo_grid_fill_exec(BMesh *bm, BMOperator *op)
void barycentric_weights_v2_quad(const float v1[2], const float v2[2], const float v3[2], const float v4[2], const float co[2], float w[4])
static void bm_grid_fill_array(BMesh *bm, BMVert **v_grid, const uint xtot, const uint ytot, const short mat_nr, const bool use_smooth, const bool use_flip, const bool use_interp_simple)
MINLINE void negate_v3(float r[3])
BLI_INLINE bool BM_edge_is_boundary(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
static void bm_edgeloop_flag_set(BMEdgeLoopStore *estore, char hflag, bool set)
MINLINE void zero_v3(float r[3])
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])
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
static void bm_loop_interp_from_grid_boundary_2(BMesh *bm, BMLoop *l, BMLoop *l_bound[2], const float t)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
bool BM_edgeloop_overlap_check(BMEdgeLoopStore *el_store_a, BMEdgeLoopStore *el_store_b)
static void bm_loop_interp_from_grid_boundary_4(BMesh *bm, BMLoop *l, BMLoop *l_bound[4], const float w[4])
void BMO_error_raise(BMesh *bm, BMOperator *owner, eBMOpErrorLevel level, const char *msg) ATTR_NONNULL(1
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static void bm_grid_fill(BMesh *bm, BMEdgeLoopStore *estore_a, BMEdgeLoopStore *estore_b, BMEdgeLoopStore *estore_rail_a, BMEdgeLoopStore *estore_rail_b, const short mat_nr, const bool use_smooth, const bool use_interp_simple)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]