bridge option to bridge loop pairs,
change the operator option to an enum: Connect Loops - open/closed/pairs because it was getting confusing having all as bools.
This commit is contained in:
@@ -190,7 +190,7 @@ void BM_mesh_edgeloops_calc_normal(BMesh *bm, ListBase *eloops)
|
||||
}
|
||||
}
|
||||
|
||||
void BM_mesh_edgeloops_calc_order(BMesh *UNUSED(bm), ListBase *eloops)
|
||||
void BM_mesh_edgeloops_calc_order(BMesh *UNUSED(bm), ListBase *eloops, const bool use_normals)
|
||||
{
|
||||
ListBase eloops_ordered = {NULL};
|
||||
BMEdgeLoopStore *el_store;
|
||||
@@ -223,9 +223,22 @@ void BM_mesh_edgeloops_calc_order(BMesh *UNUSED(bm), ListBase *eloops)
|
||||
while (eloops->first) {
|
||||
BMEdgeLoopStore *el_store_best = NULL;
|
||||
const float *co = ((BMEdgeLoopStore *)eloops_ordered.last)->co;
|
||||
const float *no = ((BMEdgeLoopStore *)eloops_ordered.last)->no;
|
||||
float len_best = FLT_MAX;
|
||||
for (el_store = eloops->first; el_store; el_store = el_store->next) {
|
||||
const float len = len_squared_v3v3(co, el_store->co);
|
||||
float len;
|
||||
if (use_normals) {
|
||||
/* scale the length by how close the loops are to pointing at eachother */
|
||||
float dir[3];
|
||||
sub_v3_v3v3(dir, co, el_store->co);
|
||||
len = normalize_v3(dir);
|
||||
len = len * ((1.0f - fabsf(dot_v3v3(dir, no))) +
|
||||
(1.0f - fabsf(dot_v3v3(dir, el_store->no))));
|
||||
}
|
||||
else {
|
||||
len = len_squared_v3v3(co, el_store->co);
|
||||
}
|
||||
|
||||
if (len < len_best) {
|
||||
len_best = len;
|
||||
el_store_best = el_store;
|
||||
|
||||
@@ -38,7 +38,7 @@ int BM_mesh_edgeloops_find(BMesh *bm, struct ListBase *r_lb,
|
||||
void BM_mesh_edgeloops_free(struct ListBase *eloops);
|
||||
void BM_mesh_edgeloops_calc_center(BMesh *bm, struct ListBase *eloops);
|
||||
void BM_mesh_edgeloops_calc_normal(BMesh *bm, struct ListBase *eloops);
|
||||
void BM_mesh_edgeloops_calc_order(BMesh *UNUSED(bm), ListBase *eloops);
|
||||
void BM_mesh_edgeloops_calc_order(BMesh *UNUSED(bm), ListBase *eloops, const bool use_normals);
|
||||
|
||||
|
||||
/* single edgeloop */
|
||||
|
||||
@@ -515,6 +515,7 @@ static BMOpDefine bmo_bridge_loops_def = {
|
||||
"bridge_loops",
|
||||
/* slots_in */
|
||||
{{"edges", BMO_OP_SLOT_ELEMENT_BUF, {BM_EDGE}}, /* input edges */
|
||||
{"use_pairs", BMO_OP_SLOT_BOOL},
|
||||
{"use_cyclic", BMO_OP_SLOT_BOOL},
|
||||
{"use_merge", BMO_OP_SLOT_BOOL},
|
||||
{"merge_factor", BMO_OP_SLOT_FLT},
|
||||
|
||||
@@ -370,6 +370,7 @@ void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op)
|
||||
LinkData *el_store;
|
||||
|
||||
/* merge-bridge support */
|
||||
const bool use_pairs = BMO_slot_bool_get(op->slots_in, "use_pairs");
|
||||
const bool use_merge = BMO_slot_bool_get(op->slots_in, "use_merge");
|
||||
const float merge_factor = BMO_slot_float_get(op->slots_in, "merge_factor");
|
||||
const bool use_cyclic = BMO_slot_bool_get(op->slots_in, "use_cyclic") && (use_merge == false);
|
||||
@@ -389,6 +390,12 @@ void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (use_pairs && (count % 2)) {
|
||||
BMO_error_raise(bm, op, BMERR_INVALID_SELECTION,
|
||||
"Select an even number of loops to bridge pairs");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (use_merge) {
|
||||
bool match = true;
|
||||
const int eloop_len = BM_edgeloop_length_get(eloops.first);
|
||||
@@ -406,7 +413,7 @@ void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op)
|
||||
}
|
||||
|
||||
if (count > 2) {
|
||||
BM_mesh_edgeloops_calc_order(bm, &eloops);
|
||||
BM_mesh_edgeloops_calc_order(bm, &eloops, use_pairs);
|
||||
}
|
||||
|
||||
for (el_store = eloops.first; el_store; el_store = el_store->next) {
|
||||
@@ -425,6 +432,9 @@ void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op)
|
||||
(struct BMEdgeLoopStore *)el_store,
|
||||
(struct BMEdgeLoopStore *)el_store_next,
|
||||
use_merge, merge_factor);
|
||||
if (use_pairs) {
|
||||
el_store = el_store->next;
|
||||
}
|
||||
change = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3672,13 +3672,15 @@ static int edbm_bridge_edge_loops_exec(bContext *C, wmOperator *op)
|
||||
BMOperator bmop;
|
||||
Object *obedit = CTX_data_edit_object(C);
|
||||
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
||||
const bool use_cyclic = RNA_boolean_get(op->ptr, "use_cyclic");
|
||||
const int type = RNA_enum_get(op->ptr, "type");
|
||||
const bool use_pairs = (type == 2);
|
||||
const bool use_cyclic = (type == 1);
|
||||
const bool use_merge = RNA_boolean_get(op->ptr, "use_merge");
|
||||
const float merge_factor = RNA_float_get(op->ptr, "merge_factor");
|
||||
|
||||
EDBM_op_init(em, &bmop, op,
|
||||
"bridge_loops edges=%he use_cyclic=%b use_merge=%b merge_factor=%f",
|
||||
BM_ELEM_SELECT, use_cyclic, use_merge, merge_factor);
|
||||
"bridge_loops edges=%he use_pairs=%b use_cyclic=%b use_merge=%b merge_factor=%f",
|
||||
BM_ELEM_SELECT, use_pairs, use_cyclic, use_merge, merge_factor);
|
||||
|
||||
BMO_op_exec(em->bm, &bmop);
|
||||
|
||||
@@ -3700,6 +3702,13 @@ static int edbm_bridge_edge_loops_exec(bContext *C, wmOperator *op)
|
||||
|
||||
void MESH_OT_bridge_edge_loops(wmOperatorType *ot)
|
||||
{
|
||||
static EnumPropertyItem type_items[] = {
|
||||
{0, "SINGLE", 0, "Open Loop", ""},
|
||||
{1, "CLOSED", 0, "Closed Loop", ""},
|
||||
{2, "PAIRS", 0, "Loop Pairs", ""},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
/* identifiers */
|
||||
ot->name = "Bridge Two Edge Loops";
|
||||
ot->description = "Make faces between two edge loops";
|
||||
@@ -3711,8 +3720,9 @@ void MESH_OT_bridge_edge_loops(wmOperatorType *ot)
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
RNA_def_boolean(ot->srna, "use_cyclic", 0, "Cyclic", "Close the bridge loop when using 3 or more");
|
||||
|
||||
ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0,
|
||||
"Connect Loops", "Method of bridging multiple loops");
|
||||
|
||||
RNA_def_boolean(ot->srna, "use_merge", false, "Merge", "Merge rather than creating faces");
|
||||
RNA_def_float(ot->srna, "merge_factor", 0.5f, 0.0f, 1.0f, "Merge Factor", "", 0.0f, 1.0f);
|
||||
|
||||
Reference in New Issue
Block a user