Cleanup 'make vertex parent' operator code.
More localized variables, avoid ugly 'offset by one' index usage in favor of explicit `INDEX_UNSET` define, etc. No behavior change expected from this commit.
This commit is contained in:
@@ -134,13 +134,11 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
|
|||||||
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
||||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||||
Object *obedit = CTX_data_edit_object(C);
|
Object *obedit = CTX_data_edit_object(C);
|
||||||
BMVert *eve;
|
|
||||||
BMIter iter;
|
|
||||||
Nurb *nu;
|
|
||||||
BezTriple *bezt;
|
|
||||||
BPoint *bp;
|
|
||||||
Object *par;
|
Object *par;
|
||||||
int a, v1 = 0, v2 = 0, v3 = 0, v4 = 0, nr = 1;
|
|
||||||
|
#define INDEX_UNSET -1
|
||||||
|
int par1, par2, par3, par4;
|
||||||
|
par1 = par2 = par3 = par4 = INDEX_UNSET;
|
||||||
|
|
||||||
/* we need 1 to 3 selected vertices */
|
/* we need 1 to 3 selected vertices */
|
||||||
|
|
||||||
@@ -165,114 +163,108 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
|
|||||||
* objects are also up to date. */
|
* objects are also up to date. */
|
||||||
BKE_scene_graph_update_tagged(depsgraph, bmain);
|
BKE_scene_graph_update_tagged(depsgraph, bmain);
|
||||||
|
|
||||||
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
|
BMVert *eve;
|
||||||
|
BMIter iter;
|
||||||
|
int curr_index;
|
||||||
|
BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, curr_index) {
|
||||||
if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
|
if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
|
||||||
if (v1 == 0) {
|
if (par1 == INDEX_UNSET) {
|
||||||
v1 = nr;
|
par1 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v2 == 0) {
|
else if (par2 == INDEX_UNSET) {
|
||||||
v2 = nr;
|
par2 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v3 == 0) {
|
else if (par3 == INDEX_UNSET) {
|
||||||
v3 = nr;
|
par3 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v4 == 0) {
|
else if (par4 == INDEX_UNSET) {
|
||||||
v4 = nr;
|
par4 = curr_index;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nr++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ELEM(obedit->type, OB_SURF, OB_CURVE)) {
|
else if (ELEM(obedit->type, OB_SURF, OB_CURVE)) {
|
||||||
ListBase *editnurb = object_editcurve_get(obedit);
|
ListBase *editnurb = object_editcurve_get(obedit);
|
||||||
|
|
||||||
nu = editnurb->first;
|
for (Nurb *nu = editnurb->first; nu != NULL; nu = nu->next) {
|
||||||
while (nu) {
|
|
||||||
if (nu->type == CU_BEZIER) {
|
if (nu->type == CU_BEZIER) {
|
||||||
bezt = nu->bezt;
|
BezTriple *bezt = nu->bezt;
|
||||||
a = nu->pntsu;
|
for (int curr_index = 0; curr_index < nu->pntsu; curr_index++, bezt++) {
|
||||||
while (a--) {
|
|
||||||
if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
|
if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
|
||||||
if (v1 == 0) {
|
if (par1 == INDEX_UNSET) {
|
||||||
v1 = nr;
|
par1 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v2 == 0) {
|
else if (par2 == INDEX_UNSET) {
|
||||||
v2 = nr;
|
par2 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v3 == 0) {
|
else if (par3 == INDEX_UNSET) {
|
||||||
v3 = nr;
|
par3 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v4 == 0) {
|
else if (par4 == INDEX_UNSET) {
|
||||||
v4 = nr;
|
par4 = curr_index;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nr++;
|
|
||||||
bezt++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bp = nu->bp;
|
BPoint *bp = nu->bp;
|
||||||
a = nu->pntsu * nu->pntsv;
|
const int num_points = nu->pntsu * nu->pntsv;
|
||||||
while (a--) {
|
for (int curr_index = 0; curr_index < num_points; curr_index++, bp++) {
|
||||||
if (bp->f1 & SELECT) {
|
if (bp->f1 & SELECT) {
|
||||||
if (v1 == 0) {
|
if (par1 == INDEX_UNSET) {
|
||||||
v1 = nr;
|
par1 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v2 == 0) {
|
else if (par2 == INDEX_UNSET) {
|
||||||
v2 = nr;
|
par2 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v3 == 0) {
|
else if (par3 == INDEX_UNSET) {
|
||||||
v3 = nr;
|
par3 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v4 == 0) {
|
else if (par4 == INDEX_UNSET) {
|
||||||
v4 = nr;
|
par4 = curr_index;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nr++;
|
|
||||||
bp++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nu = nu->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (obedit->type == OB_LATTICE) {
|
else if (obedit->type == OB_LATTICE) {
|
||||||
Lattice *lt = obedit->data;
|
Lattice *lt = obedit->data;
|
||||||
|
|
||||||
a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
|
const int num_points = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv *
|
||||||
bp = lt->editlatt->latt->def;
|
lt->editlatt->latt->pntsw;
|
||||||
while (a--) {
|
BPoint *bp = lt->editlatt->latt->def;
|
||||||
|
for (int curr_index = 0; curr_index < num_points; curr_index++, bp++) {
|
||||||
if (bp->f1 & SELECT) {
|
if (bp->f1 & SELECT) {
|
||||||
if (v1 == 0) {
|
if (par1 == INDEX_UNSET) {
|
||||||
v1 = nr;
|
par1 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v2 == 0) {
|
else if (par2 == INDEX_UNSET) {
|
||||||
v2 = nr;
|
par2 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v3 == 0) {
|
else if (par3 == INDEX_UNSET) {
|
||||||
v3 = nr;
|
par3 = curr_index;
|
||||||
}
|
}
|
||||||
else if (v4 == 0) {
|
else if (par4 == INDEX_UNSET) {
|
||||||
v4 = nr;
|
par4 = curr_index;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nr++;
|
|
||||||
bp++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v4 || !((v1 && v2 == 0 && v3 == 0) || (v1 && v2 && v3))) {
|
if (par4 != INDEX_UNSET || par1 == INDEX_UNSET || (par2 != INDEX_UNSET && par3 == INDEX_UNSET)) {
|
||||||
BKE_report(op->reports, RPT_ERROR, "Select either 1 or 3 vertices to parent to");
|
BKE_report(op->reports, RPT_ERROR, "Select either 1 or 3 vertices to parent to");
|
||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
}
|
}
|
||||||
@@ -289,11 +281,11 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
|
|||||||
Object workob;
|
Object workob;
|
||||||
|
|
||||||
ob->parent = BASACT(view_layer)->object;
|
ob->parent = BASACT(view_layer)->object;
|
||||||
if (v3) {
|
if (par3 != INDEX_UNSET) {
|
||||||
ob->partype = PARVERT3;
|
ob->partype = PARVERT3;
|
||||||
ob->par1 = v1 - 1;
|
ob->par1 = par1;
|
||||||
ob->par2 = v2 - 1;
|
ob->par2 = par2;
|
||||||
ob->par3 = v3 - 1;
|
ob->par3 = par3;
|
||||||
|
|
||||||
/* inverse parent matrix */
|
/* inverse parent matrix */
|
||||||
BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);
|
BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);
|
||||||
@@ -301,7 +293,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ob->partype = PARVERT1;
|
ob->partype = PARVERT1;
|
||||||
ob->par1 = v1 - 1;
|
ob->par1 = par1;
|
||||||
|
|
||||||
/* inverse parent matrix */
|
/* inverse parent matrix */
|
||||||
BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);
|
BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);
|
||||||
@@ -317,6 +309,8 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
|
|||||||
WM_event_add_notifier(C, NC_OBJECT, NULL);
|
WM_event_add_notifier(C, NC_OBJECT, NULL);
|
||||||
|
|
||||||
return OPERATOR_FINISHED;
|
return OPERATOR_FINISHED;
|
||||||
|
|
||||||
|
#undef INDEX_UNSET
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBJECT_OT_vertex_parent_set(wmOperatorType *ot)
|
void OBJECT_OT_vertex_parent_set(wmOperatorType *ot)
|
||||||
@@ -1474,7 +1468,8 @@ static int make_links_scene_exec(bContext *C, wmOperator *op)
|
|||||||
/* redraw the 3D view because the object center points are colored differently */
|
/* redraw the 3D view because the object center points are colored differently */
|
||||||
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL);
|
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL);
|
||||||
|
|
||||||
/* one day multiple scenes will be visible, then we should have some update function for them */
|
/* one day multiple scenes will be visible, then we should have some update function for them
|
||||||
|
*/
|
||||||
return OPERATOR_FINISHED;
|
return OPERATOR_FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1794,9 +1789,9 @@ static Collection *single_object_users_collection(Main *bmain,
|
|||||||
|
|
||||||
if (is_master_collection && copy_collections && child->collection != collection_child_new) {
|
if (is_master_collection && copy_collections && child->collection != collection_child_new) {
|
||||||
/* We do not want a collection sync here, our collections are in a complete uninitialized
|
/* We do not want a collection sync here, our collections are in a complete uninitialized
|
||||||
* state currently. With current code, that would lead to a memory leak - because of reasons.
|
* state currently. With current code, that would lead to a memory leak - because of
|
||||||
* It would be a useless loss of computing anyway, since caller has to fully refresh
|
* reasons. It would be a useless loss of computing anyway, since caller has to fully
|
||||||
* view-layers/collections caching at the end. */
|
* refresh view-layers/collections caching at the end. */
|
||||||
BKE_collection_child_add_no_sync(collection, collection_child_new);
|
BKE_collection_child_add_no_sync(collection, collection_child_new);
|
||||||
BLI_remlink(&collection->children, child);
|
BLI_remlink(&collection->children, child);
|
||||||
MEM_freeN(child);
|
MEM_freeN(child);
|
||||||
|
|||||||
Reference in New Issue
Block a user