Cleanup: Remove unused grease pencil legacy handling in some operators

See #123468.
This commit is contained in:
Hans Goudey
2024-11-02 23:14:41 +01:00
parent a1e63eeb8a
commit a804320138
9 changed files with 28 additions and 242 deletions

View File

@@ -1957,11 +1957,6 @@ static int object_mode_set_exec(bContext *C, wmOperator *op)
eObjectMode mode = eObjectMode(RNA_enum_get(op->ptr, "mode"));
const bool toggle = RNA_boolean_get(op->ptr, "toggle");
/* by default the operator assume is a mesh, but if gp object change mode */
if ((ob->type == OB_GPENCIL_LEGACY) && (mode == OB_MODE_EDIT)) {
mode = OB_MODE_EDIT_GPENCIL_LEGACY;
}
if (!mode_compat_test(ob, mode)) {
return OPERATOR_PASS_THROUGH;
}

View File

@@ -717,7 +717,6 @@ static int apply_objects_internal(bContext *C,
OB_CURVES_LEGACY,
OB_SURF,
OB_FONT,
OB_GPENCIL_LEGACY,
OB_CURVES,
OB_POINTCLOUD,
OB_GREASE_PENCIL))
@@ -779,46 +778,6 @@ static int apply_objects_internal(bContext *C,
}
}
if (ob->type == OB_GPENCIL_LEGACY) {
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
if (gpd) {
if (gpd->layers.first) {
/* Unsupported configuration */
bool has_unparented_layers = false;
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
/* Parented layers aren't supported as we can't easily re-evaluate
* the scene to sample parent movement */
if (gpl->parent == nullptr) {
has_unparented_layers = true;
break;
}
}
if (has_unparented_layers == false) {
BKE_reportf(reports,
RPT_ERROR,
"Can't apply to a GP data-block where all layers are parented: Object "
"\"%s\", %s \"%s\", aborting",
ob->id.name + 2,
BKE_idtype_idcode_to_name(ID_GD_LEGACY),
gpd->id.name + 2);
changed = false;
}
}
else {
/* No layers/data */
BKE_reportf(
reports,
RPT_ERROR,
R"(Can't apply to GP data-block with no layers: Object "%s", %s "%s", aborting)",
ob->id.name + 2,
BKE_idtype_idcode_to_name(ID_GD_LEGACY),
gpd->id.name + 2);
}
}
}
if (ob->type == OB_LAMP) {
Light *la = static_cast<Light *>(ob->data);
if (la->type == LA_AREA) {
@@ -948,10 +907,6 @@ static int apply_objects_internal(bContext *C,
cu->fsize *= scale;
}
}
else if (ob->type == OB_GPENCIL_LEGACY) {
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
BKE_gpencil_transform(gpd, mat);
}
else if (ob->type == OB_CURVES) {
Curves &curves = *static_cast<Curves *>(ob->data);
curves.geometry.wrap().transform(float4x4(mat));
@@ -1647,83 +1602,6 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
lt->id.tag |= ID_TAG_DOIT;
do_inverse_offset = true;
}
else if (ob->type == OB_GPENCIL_LEGACY) {
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
float gpcenter[3];
if (gpd) {
if (centermode == ORIGIN_TO_GEOMETRY) {
zero_v3(gpcenter);
BKE_gpencil_centroid_3d(gpd, gpcenter);
add_v3_v3(gpcenter, ob->object_to_world().location());
}
if (centermode == ORIGIN_TO_CURSOR) {
copy_v3_v3(gpcenter, cursor);
}
if (ELEM(centermode, ORIGIN_TO_GEOMETRY, ORIGIN_TO_CURSOR)) {
bGPDspoint *pt;
float imat[3][3], bmat[3][3];
float offset_global[3];
float offset_local[3];
int i;
sub_v3_v3v3(offset_global, gpcenter, ob->object_to_world().location());
copy_m3_m4(bmat, obact->object_to_world().ptr());
invert_m3_m3(imat, bmat);
mul_m3_v3(imat, offset_global);
mul_v3_m3v3(offset_local, imat, offset_global);
float diff_mat[4][4];
float inverse_diff_mat[4][4];
/* recalculate all strokes
* (all layers are considered without evaluating lock attributes) */
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
/* calculate difference matrix */
BKE_gpencil_layer_transform_matrix_get(depsgraph, obact, gpl, diff_mat);
/* undo matrix */
invert_m4_m4(inverse_diff_mat, diff_mat);
LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
float mpt[3];
mul_v3_m4v3(mpt, inverse_diff_mat, &pt->x);
sub_v3_v3(mpt, offset_local);
mul_v3_m4v3(&pt->x, diff_mat, mpt);
}
/* Apply transform to edit-curve. */
if (gps->editcurve != nullptr) {
for (i = 0; i < gps->editcurve->tot_curve_points; i++) {
BezTriple *bezt = &gps->editcurve->curve_points[i].bezt;
for (int j = 0; j < 3; j++) {
float mpt[3];
mul_v3_m4v3(mpt, inverse_diff_mat, bezt->vec[j]);
sub_v3_v3(mpt, offset_local);
mul_v3_m4v3(bezt->vec[j], diff_mat, mpt);
}
}
}
BKE_gpencil_stroke_geometry_update(gpd, gps);
}
}
}
tot_change++;
if (centermode == ORIGIN_TO_GEOMETRY) {
copy_v3_v3(ob->loc, gpcenter);
}
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
ob->id.tag |= ID_TAG_DOIT;
do_inverse_offset = true;
}
else {
BKE_report(op->reports,
RPT_WARNING,
"Grease Pencil Object does not support this set origin option");
}
}
}
else if (ob->type == OB_CURVES) {
Curves &curves_id = *static_cast<Curves *>(ob->data);
bke::CurvesGeometry &curves = curves_id.geometry.wrap();

View File

@@ -3643,38 +3643,15 @@ static int vgroup_do_remap(Object *ob, const char *name_array, wmOperator *op)
}
else {
int dvert_tot = 0;
/* Grease pencil stores vertex groups separately for each stroke,
* so remap each stroke's weights separately. */
if (ob->type == OB_GPENCIL_LEGACY) {
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
dvert = gps->dvert;
dvert_tot = gps->totpoints;
if (dvert) {
while (dvert_tot--) {
if (dvert->totweight) {
BKE_defvert_remap(dvert, sort_map, defbase_tot);
}
dvert++;
}
}
}
}
}
}
else {
BKE_object_defgroup_array_get(static_cast<ID *>(ob->data), &dvert, &dvert_tot);
BKE_object_defgroup_array_get(static_cast<ID *>(ob->data), &dvert, &dvert_tot);
/* Create as necessary. */
if (dvert) {
while (dvert_tot--) {
if (dvert->totweight) {
BKE_defvert_remap(dvert, sort_map, defbase_tot);
}
dvert++;
/* Create as necessary. */
if (dvert) {
while (dvert_tot--) {
if (dvert->totweight) {
BKE_defvert_remap(dvert, sort_map, defbase_tot);
}
dvert++;
}
}
}

View File

@@ -3378,17 +3378,6 @@ static int view3d_select_exec(bContext *C, wmOperator *op)
Object *obedit = CTX_data_edit_object(C);
Object *obact = CTX_data_active_object(C);
if (obact && obact->type == OB_GPENCIL_LEGACY && GPENCIL_ANY_MODE((bGPdata *)obact->data) &&
(BKE_object_pose_armature_get_with_wpaint_check(obact) == nullptr))
{
/* Prevent acting on Grease Pencil (when not in object mode -- or not in weight-paint + pose
* selection), it implements its own selection operator in other modes. We might still fall
* trough to here (because that operator uses OPERATOR_PASS_THROUGH to make tweak work) but if
* we don't stop here code below assumes we are in object mode it might falsely toggle object
* selection. Alternatively, this could be put in the poll function instead. */
return OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED;
}
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
const ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);

View File

@@ -76,8 +76,7 @@ bool transdata_check_local_islands(TransInfo *t, short around)
if (t->options & (CTX_CURSOR | CTX_TEXTURE_SPACE)) {
return false;
}
return ((around == V3D_AROUND_LOCAL_ORIGINS) &&
ELEM(t->obedit_type, OB_MESH, OB_GPENCIL_LEGACY));
return ((around == V3D_AROUND_LOCAL_ORIGINS) && ELEM(t->obedit_type, OB_MESH));
}
/** \} */
@@ -435,13 +434,6 @@ static void viewRedrawForce(const bContext *C, TransInfo *t)
if (t->obedit_type == OB_GREASE_PENCIL) {
WM_event_add_notifier(C, NC_GEOM | ND_DATA, nullptr);
}
else if (t->obedit_type == OB_GPENCIL_LEGACY) {
bGPdata *gpd = ED_gpencil_data_get_active(C);
if (gpd) {
DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY);
}
WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, nullptr);
}
}
else if (t->spacetype == SPACE_VIEW3D) {
if (t->options & CTX_PAINT_CURVE) {

View File

@@ -762,9 +762,7 @@ void postTrans(bContext *C, TransInfo *t)
if (t->data_len_all != 0) {
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
/* Free data malloced per trans-data. */
if (ELEM(t->obedit_type, OB_CURVES_LEGACY, OB_SURF, OB_GPENCIL_LEGACY) ||
(t->spacetype == SPACE_GRAPH))
{
if (ELEM(t->obedit_type, OB_CURVES_LEGACY, OB_SURF) || (t->spacetype == SPACE_GRAPH)) {
TransData *td = tc->data;
for (int a = 0; a < tc->data_len; a++, td++) {
if (td->flag & TD_BEZTRIPLE) {

View File

@@ -54,13 +54,12 @@ eTfmMode transform_mode_really_used(bContext *C, eTfmMode mode)
bool transdata_check_local_center(const TransInfo *t, short around)
{
return (
(around == V3D_AROUND_LOCAL_ORIGINS) &&
((t->options & (CTX_OBJECT | CTX_POSE_BONE)) ||
/* Implicit: `(t->flag & T_EDIT)`. */
ELEM(t->obedit_type, OB_MESH, OB_CURVES_LEGACY, OB_MBALL, OB_ARMATURE, OB_GPENCIL_LEGACY) ||
(t->spacetype == SPACE_GRAPH) ||
(t->options & (CTX_MOVIECLIP | CTX_MASK | CTX_PAINT_CURVE | CTX_SEQUENCER_IMAGE))));
return ((around == V3D_AROUND_LOCAL_ORIGINS) &&
((t->options & (CTX_OBJECT | CTX_POSE_BONE)) ||
/* Implicit: `(t->flag & T_EDIT)`. */
ELEM(t->obedit_type, OB_MESH, OB_CURVES_LEGACY, OB_MBALL, OB_ARMATURE) ||
(t->spacetype == SPACE_GRAPH) ||
(t->options & (CTX_MOVIECLIP | CTX_MASK | CTX_PAINT_CURVE | CTX_SEQUENCER_IMAGE))));
}
bool transform_mode_is_changeable(const int mode)
@@ -571,18 +570,7 @@ void ElementRotation_ex(const TransInfo *t,
/* Apply gpencil falloff. */
if (t->options & CTX_GPENCIL_STROKES) {
if (t->obedit_type == OB_GPENCIL_LEGACY) {
bGPDstroke *gps = (bGPDstroke *)td->extra;
if (gps->runtime.multi_frame_falloff != 1.0f) {
float ident_mat[3][3];
unit_m3(ident_mat);
interp_m3_m3m3(smat, ident_mat, smat, gps->runtime.multi_frame_falloff);
}
}
else if (t->obedit_type == OB_GREASE_PENCIL) {
/* Pass. */
}
/* Pass. */
}
sub_v3_v3v3(vec, td->iloc, center);
@@ -1045,39 +1033,19 @@ void ElementResize(const TransInfo *t,
* Operating on copies as a temporary solution.
*/
if (t->options & CTX_GPENCIL_STROKES) {
if (t->obedit_type == OB_GPENCIL_LEGACY) {
bGPDstroke *gps = (bGPDstroke *)td->extra;
mul_v3_fl(vec, td->factor * gps->runtime.multi_frame_falloff);
mul_v3_fl(vec, td->factor);
/* Scale stroke thickness. */
if (td->val) {
NumInput num_evil = t->num;
float values_final_evil[4];
copy_v4_v4(values_final_evil, t->values_final);
transform_snap_increment(t, values_final_evil);
applyNumInput(&num_evil, values_final_evil);
/* Scale stroke thickness. */
if (td->val) {
NumInput num_evil = t->num;
float values_final_evil[4];
copy_v4_v4(values_final_evil, t->values_final);
transform_snap_increment(t, values_final_evil);
applyNumInput(&num_evil, values_final_evil);
float ratio = values_final_evil[0];
float transformed_value = td->ival * fabs(ratio);
*td->val = max_ff(interpf(transformed_value, td->ival, gps->runtime.multi_frame_falloff),
0.001f);
}
}
else if (t->obedit_type == OB_GREASE_PENCIL) {
mul_v3_fl(vec, td->factor);
/* Scale stroke thickness. */
if (td->val) {
NumInput num_evil = t->num;
float values_final_evil[4];
copy_v4_v4(values_final_evil, t->values_final);
transform_snap_increment(t, values_final_evil);
applyNumInput(&num_evil, values_final_evil);
float ratio = values_final_evil[0];
float transformed_value = td->ival * fabs(ratio);
*td->val = transformed_value;
}
float ratio = values_final_evil[0];
float transformed_value = td->ival * fabs(ratio);
*td->val = transformed_value;
}
}
else {

View File

@@ -60,17 +60,7 @@ static void applyGPOpacity(TransInfo *t)
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
TransData *td = tc->data;
if (t->obedit_type == OB_GPENCIL_LEGACY) {
bGPdata *gpd = static_cast<bGPdata *>(td->ob->data);
const bool is_curve_edit = bool(GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd));
/* Only recalculate data when in curve edit mode. */
if (is_curve_edit) {
recalc = true;
}
}
else if (t->obedit_type == OB_GREASE_PENCIL) {
recalc = true;
}
recalc = true;
for (i = 0; i < tc->data_len; i++, td++) {
if (td->flag & TD_SKIP) {

View File

@@ -924,7 +924,6 @@ static eSnapMode snap_obj_fn(SnapObjectContext *sctx,
break;
case OB_FONT:
case OB_EMPTY:
case OB_GPENCIL_LEGACY:
case OB_LAMP:
retval = snap_object_center(sctx, ob_eval, obmat, sctx->runtime.snap_to_flag);
break;