Object Mode: use eval_ctx mode in transform code

This adds EvaluationContext into TransInfo
This commit is contained in:
Campbell Barton 2018-02-06 16:34:11 +11:00
parent 91db372b48
commit ef11113399
Notes: blender-bot 2023-02-14 11:07:28 +01:00
Referenced by issue #54028, Pose bone animation not working
7 changed files with 74 additions and 60 deletions

View File

@ -41,6 +41,8 @@
#include "DNA_listBase.h"
#include "DEG_depsgraph.h"
/* ************************** Types ***************************** */
struct Depsgraph;
@ -465,6 +467,7 @@ typedef struct TransInfo {
bool remove_on_cancel; /* remove elements if operator is canceled */
EvaluationContext eval_ctx;
void *view;
struct bContext *context; /* Only valid (non null) during an operator called function. */
struct ScrArea *sa;
@ -649,7 +652,8 @@ void restoreBones(TransInfo *t);
#define MANIPULATOR_AXIS_LINE_WIDTH 2.0f
bool gimbal_axis(struct Object *ob, float gmat[3][3]); /* return 0 when no gimbal for selection */
/* return 0 when no gimbal for selection */
bool gimbal_axis(struct Object *ob, float gmat[3][3], const short object_mode);
/*********************** TransData Creation and General Handling *********** */
void createTransData(struct bContext *C, TransInfo *t);

View File

@ -998,10 +998,13 @@ static short pose_grab_with_ik(Object *ob)
Bone *bonec;
short tot_ik = 0;
if ((ob == NULL) || (ob->pose == NULL) || (ob->mode & OB_MODE_POSE) == 0)
if ((ob == NULL) || (ob->pose == NULL))
return 0;
arm = ob->data;
if ((arm->flag & ARM_POSEMODE) == 0) {
return 0;
}
/* Rule: allow multiple Bones (but they must be selected, and only one ik-solver per chain should get added) */
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
@ -2049,9 +2052,7 @@ void flushTransParticles(TransInfo *t)
point->flag |= PEP_EDIT_RECALC;
}
EvaluationContext eval_ctx;
CTX_data_eval_ctx(t->context, &eval_ctx);
PE_update_object(&eval_ctx, scene, view_layer, OBACT(view_layer), 1);
PE_update_object(&t->eval_ctx, scene, view_layer, OBACT(view_layer), 1);
}
/* ********************* mesh ****************** */
@ -2463,7 +2464,6 @@ static void createTransEditVerts(TransInfo *t)
{
TransData *tob = NULL;
TransDataExtension *tx = NULL;
EvaluationContext eval_ctx;
BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
Mesh *me = t->obedit->data;
BMesh *bm = em->bm;
@ -2482,11 +2482,6 @@ static void createTransEditVerts(TransInfo *t)
int island_info_tot;
int *island_vert_map = NULL;
DEG_evaluation_context_init_from_scene(
&eval_ctx,
t->scene, t->view_layer, t->engine_type, t->obedit->mode,
DAG_EVAL_VIEWPORT);
/* Even for translation this is needed because of island-orientation, see: T51651. */
const bool is_island_center = (t->around == V3D_AROUND_LOCAL_ORIGINS);
/* Original index of our connected vertex when connected distances are calculated.
@ -2570,7 +2565,7 @@ static void createTransEditVerts(TransInfo *t)
if (modifiers_isCorrectableDeformed(t->scene, t->obedit)) {
/* check if we can use deform matrices for modifier from the
* start up to stack, they are more accurate than quats */
totleft = BKE_crazyspace_get_first_deform_matrices_editbmesh(&eval_ctx, t->scene, t->obedit, em, &defmats, &defcos);
totleft = BKE_crazyspace_get_first_deform_matrices_editbmesh(&t->eval_ctx, t->scene, t->obedit, em, &defmats, &defcos);
}
/* if we still have more modifiers, also do crazyspace
@ -2583,7 +2578,7 @@ static void createTransEditVerts(TransInfo *t)
if (totleft > 0)
#endif
{
mappedcos = BKE_crazyspace_get_mapped_editverts(&eval_ctx, t->scene, t->obedit);
mappedcos = BKE_crazyspace_get_mapped_editverts(&t->eval_ctx, t->scene, t->obedit);
quats = MEM_mallocN(em->bm->totvert * sizeof(*quats), "crazy quats");
BKE_crazyspace_set_quats_editmesh(em, defcos, mappedcos, quats, !prop_mode);
if (mappedcos)
@ -5409,9 +5404,6 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob)
Scene *scene = t->scene;
bool constinv;
bool skip_invert = false;
EvaluationContext eval_ctx;
CTX_data_eval_ctx(t->context, &eval_ctx);
if (t->mode != TFM_DUMMY && ob->rigidbody_object) {
float rot[3][3], scale[3];
@ -5459,11 +5451,11 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob)
if (skip_invert == false && constinv == false) {
ob->transflag |= OB_NO_CONSTRAINTS; /* BKE_object_where_is_calc_time checks this */
BKE_object_where_is_calc(&eval_ctx, t->scene, ob);
BKE_object_where_is_calc(&t->eval_ctx, t->scene, ob);
ob->transflag &= ~OB_NO_CONSTRAINTS;
}
else
BKE_object_where_is_calc(&eval_ctx, t->scene, ob);
BKE_object_where_is_calc(&t->eval_ctx, t->scene, ob);
td->ob = ob;
@ -6104,14 +6096,11 @@ static void special_aftertrans_update__mesh(bContext *UNUSED(C), TransInfo *t)
* */
void special_aftertrans_update(bContext *C, TransInfo *t)
{
EvaluationContext eval_ctx;
Object *ob;
// short redrawipo=0, resetslowpar=1;
const bool canceled = (t->state == TRANS_CANCEL);
const bool duplicate = (t->mode == TFM_TIME_DUPLICATE);
CTX_data_eval_ctx(C, &eval_ctx);
/* early out when nothing happened */
if (t->total == 0 || t->mode == TFM_DUMMY)
return;
@ -6450,7 +6439,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
* we need to update the pose otherwise no updates get called during
* transform and the auto-ik is not applied. see [#26164] */
struct Object *pose_ob = t->poseobj;
BKE_pose_where_is(&eval_ctx, t->scene, pose_ob);
BKE_pose_where_is(&t->eval_ctx, t->scene, pose_ob);
}
/* set BONE_TRANSFORM flags for autokey, manipulator draw might have changed them */
@ -6494,7 +6483,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
}
else if ((t->view_layer->basact) &&
(ob = t->view_layer->basact->object) &&
(ob->mode & OB_MODE_PARTICLE_EDIT) &&
(t->eval_ctx.object_mode & OB_MODE_PARTICLE_EDIT) &&
PE_get_current(t->scene, t->view_layer, ob))
{
/* do nothing */
@ -8232,26 +8221,30 @@ void createTransData(bContext *C, TransInfo *t)
t->poseobj = ob; /* <- tsk tsk, this is going to give issues one day */
}
}
else if (ob && (ob->mode & OB_MODE_POSE)) {
else if (ob && (t->eval_ctx.object_mode & OB_MODE_POSE)) {
// XXX this is currently limited to active armature only...
// XXX active-layer checking isn't done as that should probably be checked through context instead
createTransPose(t, ob);
}
else if (ob && (ob->mode & OB_MODE_WEIGHT_PAINT) && !(t->options & CTX_PAINT_CURVE)) {
else if (ob && (t->eval_ctx.object_mode & OB_MODE_WEIGHT_PAINT) && !(t->options & CTX_PAINT_CURVE)) {
/* important that ob_armature can be set even when its not selected [#23412]
* lines below just check is also visible */
Object *ob_armature = modifiers_isDeformedByArmature(ob);
if (ob_armature && ob_armature->mode & OB_MODE_POSE) {
Base *base_arm = BKE_view_layer_base_find(t->view_layer, ob_armature);
if (base_arm) {
if (BASE_VISIBLE(base_arm)) {
createTransPose(t, ob_armature);
if (ob_armature) {
const bArmature *arm = ob_armature->data;
if (arm->flag & ARM_POSEMODE) {
Base *base_arm = BKE_view_layer_base_find(t->view_layer, ob_armature);
if (base_arm) {
if (BASE_VISIBLE(base_arm)) {
createTransPose(t, ob_armature);
}
}
}
}
}
else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT) && PE_start_edit(PE_get_current(scene, view_layer, ob))) {
else if (ob && (t->eval_ctx.object_mode & OB_MODE_PARTICLE_EDIT) &&
PE_start_edit(PE_get_current(scene, view_layer, ob)))
{
createTransParticleVerts(C, t);
t->flag |= T_POINTS;
@ -8261,7 +8254,7 @@ void createTransData(bContext *C, TransInfo *t)
sort_trans_data_dist(t);
}
}
else if (ob && (ob->mode & OB_MODE_ALL_PAINT)) {
else if (ob && (t->eval_ctx.object_mode & OB_MODE_ALL_PAINT)) {
if ((t->options & CTX_PAINT_CURVE) && !ELEM(t->mode, TFM_SHEAR, TFM_SHRINKFATTEN)) {
t->flag |= T_POINTS | T_2D_EDIT;
createTransPaintCurveVerts(C, t);

View File

@ -904,7 +904,9 @@ static void recalcData_objects(TransInfo *t)
else
BKE_pose_where_is(&eval_ctx, t->scene, ob);
}
else if (base && (base->object->mode & OB_MODE_PARTICLE_EDIT) && PE_get_current(t->scene, t->view_layer, base->object)) {
else if (base && (eval_ctx.object_mode & OB_MODE_PARTICLE_EDIT) &&
PE_get_current(t->scene, t->view_layer, base->object))
{
if (t->state != TRANS_CANCEL) {
applyProject(t);
}
@ -1115,6 +1117,8 @@ static int initTransInfo_edit_pet_to_flag(const int proportional)
*/
void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event)
{
EvaluationContext eval_ctx;
CTX_data_eval_ctx(C, &eval_ctx);
Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *sce = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
@ -1266,7 +1270,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
}
if (ob && ob->mode & OB_MODE_ALL_PAINT) {
if (ob && eval_ctx.object_mode & OB_MODE_ALL_PAINT) {
Paint *p = BKE_paint_get_active_from_context(C);
if (p && p->brush && (p->brush->flag & BRUSH_CURVE)) {
t->options |= CTX_PAINT_CURVE;

View File

@ -63,6 +63,8 @@
#include "BIF_gl.h"
#include "DEG_depsgraph.h"
#include "WM_api.h"
#include "WM_types.h"
#include "WM_message.h"
@ -518,9 +520,9 @@ static bool test_rotmode_euler(short rotmode)
return (ELEM(rotmode, ROT_MODE_AXISANGLE, ROT_MODE_QUAT)) ? 0 : 1;
}
bool gimbal_axis(Object *ob, float gmat[3][3])
bool gimbal_axis(Object *ob, float gmat[3][3], const short object_mode)
{
if (ob->mode & OB_MODE_POSE) {
if (object_mode & OB_MODE_POSE) {
bPoseChannel *pchan = BKE_pose_channel_active(ob);
if (pchan) {
@ -589,6 +591,8 @@ static int calc_manipulator_stats(
const bContext *C, bool use_only_center,
struct TransformBounds *tbounds)
{
EvaluationContext eval_ctx;
CTX_data_eval_ctx(C, &eval_ctx);
ScrArea *sa = CTX_wm_area(C);
ARegion *ar = CTX_wm_region(C);
Scene *scene = CTX_data_scene(C);
@ -626,7 +630,7 @@ static int calc_manipulator_stats(
case V3D_MANIP_GIMBAL:
{
float mat[3][3];
if (gimbal_axis(ob, mat)) {
if (gimbal_axis(ob, mat, eval_ctx.object_mode)) {
copy_m4_m3(rv3d->twmat, mat);
break;
}
@ -635,7 +639,7 @@ static int calc_manipulator_stats(
}
case V3D_MANIP_NORMAL:
{
if (obedit || ob->mode & OB_MODE_POSE) {
if (obedit || eval_ctx.object_mode & OB_MODE_POSE) {
float mat[3][3];
ED_getTransformOrientationMatrix(C, mat, v3d->around);
copy_m4_m3(rv3d->twmat, mat);
@ -646,7 +650,7 @@ static int calc_manipulator_stats(
}
case V3D_MANIP_LOCAL:
{
if (ob->mode & OB_MODE_POSE) {
if (eval_ctx.object_mode & OB_MODE_POSE) {
/* each bone moves on its own local axis, but to avoid confusion,
* use the active pones axis for display [#33575], this works as expected on a single bone
* and users who select many bones will understand whats going on and what local means
@ -688,7 +692,7 @@ static int calc_manipulator_stats(
#ifdef USE_AXIS_BOUNDS
copy_m3_m4(tbounds->axis, rv3d->twmat);
if (ob && ob->mode & OB_MODE_EDIT) {
if (ob && eval_ctx.object_mode & OB_MODE_EDIT) {
float diff_mat[3][3];
copy_m3_m4(diff_mat, ob->obmat);
normalize_m3(diff_mat);
@ -931,7 +935,7 @@ static int calc_manipulator_stats(
mul_m4_v3(obedit->obmat, tbounds->max);
}
}
else if (ob && (ob->mode & OB_MODE_POSE)) {
else if (ob && (eval_ctx.object_mode & OB_MODE_POSE)) {
bPoseChannel *pchan;
int mode = TFM_ROTATION; // mislead counting bones... bah. We don't know the manipulator mode, could be mixed
bool ok = false;
@ -969,10 +973,10 @@ static int calc_manipulator_stats(
mul_m4_v3(ob->obmat, tbounds->max);
}
}
else if (ob && (ob->mode & OB_MODE_ALL_PAINT)) {
else if (ob && (eval_ctx.object_mode & OB_MODE_ALL_PAINT)) {
/* pass */
}
else if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) {
else if (ob && eval_ctx.object_mode & OB_MODE_PARTICLE_EDIT) {
PTCacheEdit *edit = PE_get_current(scene, view_layer, ob);
PTCacheEditPoint *point;
PTCacheEditKey *ek;
@ -1062,12 +1066,14 @@ static void manipulator_prepare_mat(
case V3D_AROUND_CENTER_BOUNDS:
case V3D_AROUND_ACTIVE:
{
EvaluationContext eval_ctx;
CTX_data_eval_ctx(C, &eval_ctx);
bGPdata *gpd = CTX_data_gpencil_data(C);
Object *ob = OBACT(view_layer);
if (((v3d->around == V3D_AROUND_ACTIVE) && (scene->obedit == NULL)) &&
((gpd == NULL) || !(gpd->flag & GP_DATA_STROKE_EDITMODE)) &&
(!(ob->mode & OB_MODE_POSE)))
(!(eval_ctx.object_mode & OB_MODE_POSE)))
{
copy_v3_v3(rv3d->twmat[3], ob->obmat[3]);
}
@ -1657,9 +1663,11 @@ static void WIDGETGROUP_xform_cage_draw_prepare(const bContext *C, wmManipulator
struct XFormCageWidgetGroup *xmgroup = mgroup->customdata;
wmManipulator *mpr = xmgroup->manipulator;
EvaluationContext eval_ctx;
CTX_data_eval_ctx(C, &eval_ctx);
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob = OBACT(view_layer);
if (ob && ob->mode & OB_MODE_EDIT) {
if (ob && eval_ctx.object_mode & OB_MODE_EDIT) {
copy_m4_m4(mpr->matrix_space, ob->obmat);
}
else {

View File

@ -55,6 +55,8 @@
#include "BKE_screen.h"
#include "BKE_workspace.h"
#include "DEG_depsgraph.h"
#include "BLT_translation.h"
#include "ED_armature.h"
@ -296,6 +298,8 @@ void BIF_createTransformOrientation(bContext *C, ReportList *reports,
ts = createViewSpace(C, reports, name, overwrite);
}
else {
EvaluationContext eval_ctx;
CTX_data_eval_ctx(C, &eval_ctx);
Object *obedit = CTX_data_edit_object(C);
Object *ob = CTX_data_active_object(C);
if (obedit) {
@ -306,7 +310,7 @@ void BIF_createTransformOrientation(bContext *C, ReportList *reports,
else if (obedit->type == OB_CURVE)
ts = createCurveSpace(C, reports, name, overwrite);
}
else if (ob && (ob->mode & OB_MODE_POSE)) {
else if (ob && (eval_ctx.object_mode & OB_MODE_POSE)) {
ts = createBoneSpace(C, reports, name, overwrite);
}
else {
@ -441,13 +445,13 @@ void initTransformOrientation(bContext *C, TransInfo *t)
case V3D_MANIP_GIMBAL:
unit_m3(t->spacemtx);
if (ob && gimbal_axis(ob, t->spacemtx)) {
if (ob && gimbal_axis(ob, t->spacemtx, t->eval_ctx.object_mode)) {
BLI_strncpy(t->spacename, IFACE_("gimbal"), sizeof(t->spacename));
break;
}
ATTR_FALLTHROUGH; /* no gimbal fallthrough to normal */
case V3D_MANIP_NORMAL:
if (obedit || (ob && ob->mode & OB_MODE_POSE)) {
if (obedit || (ob && t->eval_ctx.object_mode & OB_MODE_POSE)) {
BLI_strncpy(t->spacename, IFACE_("normal"), sizeof(t->spacename));
ED_getTransformOrientationMatrix(C, t->spacemtx, t->around);
break;
@ -578,6 +582,8 @@ static unsigned int bm_mesh_faces_select_get_n(BMesh *bm, BMVert **elems, const
int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3], const short around)
{
EvaluationContext eval_ctx;
CTX_data_eval_ctx(C, &eval_ctx);
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *obedit = CTX_data_edit_object(C);
Base *base;
@ -1008,7 +1014,7 @@ int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3
mul_m3_v3(mat, plane);
}
}
else if (ob && (ob->mode & OB_MODE_POSE)) {
else if (ob && (eval_ctx.object_mode & OB_MODE_POSE)) {
bArmature *arm = ob->data;
bPoseChannel *pchan;
float imat[3][3], mat[3][3];
@ -1048,7 +1054,7 @@ int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3
result = ORIENTATION_EDGE;
}
}
else if (ob && (ob->mode & (OB_MODE_ALL_PAINT | OB_MODE_PARTICLE_EDIT))) {
else if (ob && (eval_ctx.object_mode & (OB_MODE_ALL_PAINT | OB_MODE_PARTICLE_EDIT))) {
/* pass */
}
else {

View File

@ -70,6 +70,8 @@
#include "ED_view3d.h"
#include "ED_transform_snap_object_context.h"
#include "DEG_depsgraph.h"
#include "UI_resources.h"
#include "UI_view2d.h"
@ -542,7 +544,7 @@ static void initSnappingMode(TransInfo *t)
}
/* Particles edit mode*/
else if (t->tsnap.applySnap != NULL && // A snapping function actually exist
(obedit == NULL && base_act && base_act->object && base_act->object->mode & OB_MODE_PARTICLE_EDIT))
(obedit == NULL && base_act && base_act->object && t->eval_ctx.object_mode & OB_MODE_PARTICLE_EDIT))
{
t->tsnap.modeSelect = SNAP_ALL;
}

View File

@ -1358,7 +1358,7 @@ static bool snapArmature(
static bool snapCurve(
SnapData *snapdata,
Object *ob, Curve *cu, float obmat[4][4],
Curve *cu, float obmat[4][4], bool use_obedit,
/* read/write args */
float *ray_depth, float *dist_px,
/* return args */
@ -1376,12 +1376,12 @@ static bool snapCurve(
mul_m4_m4m4(lpmat, snapdata->pmat, obmat);
dist_px_sq = SQUARE(*dist_px);
for (Nurb *nu = (ob->mode == OB_MODE_EDIT ? cu->editnurb->nurbs.first : cu->nurb.first); nu; nu = nu->next) {
for (Nurb *nu = (use_obedit ? cu->editnurb->nurbs.first : cu->nurb.first); nu; nu = nu->next) {
for (int u = 0; u < nu->pntsu; u++) {
switch (snapdata->snap_to) {
case SCE_SNAP_MODE_VERTEX:
{
if (ob->mode == OB_MODE_EDIT) {
if (use_obedit) {
if (nu->bezt) {
/* don't snap to selected (moving) or hidden */
if (nu->bezt[u].f2 & SELECT || nu->bezt[u].hide != 0) {
@ -1966,7 +1966,7 @@ static bool snapObject(
else if (ob->type == OB_CURVE) {
retval = snapCurve(
snapdata,
ob, ob->data, obmat,
ob->data, obmat, use_obedit,
ray_depth, dist_px,
r_loc, r_no);
}
@ -2096,11 +2096,8 @@ SnapObjectContext *ED_transform_snap_object_context_create(
sctx->bmain = bmain;
sctx->scene = scene;
Object *obact = OBACT(view_layer);
DEG_evaluation_context_init_from_scene(
&sctx->eval_ctx, scene, view_layer, engine_type,
obact ? obact->mode : OB_MODE_OBJECT, DAG_EVAL_VIEWPORT);
&sctx->eval_ctx, scene, view_layer, engine_type, OB_MODE_OBJECT, DAG_EVAL_VIEWPORT);
sctx->cache.object_map = BLI_ghash_ptr_new(__func__);
sctx->cache.mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);