diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-08-11 04:23:39 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-08-11 04:23:39 +0300 |
commit | 317b8d96690cec6255a1e954ba642b08ef5d54fb (patch) | |
tree | eb2c37bc74d60a00fe5a52a77997c559847361e5 /source/blender/editors/transform | |
parent | d1328feeb125328615bcf832cbc82d9f9a18e023 (diff) |
Transform: Snap used multiple eval contexts
Changes for 2.8x to use EvaluationContext caused some confusion
- Would use scene layer passed from snap context.
- Would generate duplis from Main eval context.
- Would take context argument and use it to create another eval context.
Adding context args all over and filling in a new eval-context
for every ray-cast test isn't ideal either.
Remove the context argument since the purpose of
SnapObjectContext is to avoid this kind of confusion.
Store the EvaluationContext once and re-use.
Diffstat (limited to 'source/blender/editors/transform')
-rw-r--r-- | source/blender/editors/transform/transform_snap.c | 8 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_snap_object.c | 95 |
2 files changed, 49 insertions, 54 deletions
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 906a6ce20ef..1181f584313 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -1197,7 +1197,7 @@ bool snapObjectsTransform( float r_loc[3], float r_no[3]) { return ED_transform_snap_object_project_view3d_ex( - t->context, t->tsnap.object_context, + t->tsnap.object_context, t->scene->toolsettings->snap_mode, &(const struct SnapObjectParams){ .snap_select = t->tsnap.modeSelect, @@ -1211,7 +1211,7 @@ bool snapObjectsTransform( /******************** PEELING *********************************/ bool peelObjectsSnapContext( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const float mval[2], const struct SnapObjectParams *params, const bool use_peel_object, @@ -1220,7 +1220,7 @@ bool peelObjectsSnapContext( { ListBase depths_peel = {0}; ED_transform_snap_object_project_all_view3d_ex( - C, sctx, + sctx, params, mval, -1.0f, false, &depths_peel); @@ -1287,7 +1287,7 @@ bool peelObjectsTransform( float r_loc[3], float r_no[3], float *r_thickness) { return peelObjectsSnapContext( - t->context, t->tsnap.object_context, + t->tsnap.object_context, mval, &(const struct SnapObjectParams){ .snap_select = t->tsnap.modeSelect, diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index ae4190026f8..d9dd4707ff6 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -104,7 +104,8 @@ typedef struct SnapObjectData_EditMesh { struct SnapObjectContext { Main *bmain; Scene *scene; - SceneLayer *scene_layer; + EvaluationContext eval_ctx; + int flag; /* Optional: when performing screen-space projection. @@ -143,7 +144,7 @@ struct SnapObjectContext { * \{ */ -typedef void(*IterSnapObjsCallback)(const bContext *C, SnapObjectContext *sctx, bool is_obedit, Object *ob, float obmat[4][4], void *data); +typedef void(*IterSnapObjsCallback)(SnapObjectContext *sctx, bool is_obedit, Object *ob, float obmat[4][4], void *data); /** * Walks through all objects in the scene to create the list of objets to snap. @@ -153,24 +154,23 @@ typedef void(*IterSnapObjsCallback)(const bContext *C, SnapObjectContext *sctx, * \param obedit : Object Edited to use its coordinates of BMesh(if any) to do the snapping. */ static void iter_snap_objects( - const bContext *C, SnapObjectContext *sctx, const SnapSelect snap_select, Object *obedit, IterSnapObjsCallback sob_callback, void *data) { - Base *base_act = sctx->scene_layer->basact; + Base *base_act = sctx->eval_ctx.scene_layer->basact; /* Need an exception for particle edit because the base is flagged with BA_HAS_RECALC_DATA * which makes the loop skip it, even the derived mesh will never change * * To solve that problem, we do it first as an exception. * */ if (base_act && base_act->object && base_act->object->mode & OB_MODE_PARTICLE_EDIT) { - sob_callback(C, sctx, false, base_act->object, base_act->object->obmat, data); + sob_callback(sctx, false, base_act->object, base_act->object->obmat, data); } - for (Base *base = sctx->scene_layer->object_bases.first; base != NULL; base = base->next) { + for (Base *base = sctx->eval_ctx.scene_layer->object_bases.first; base != NULL; base = base->next) { if ((BASE_VISIBLE_NEW(base)) && (base->flag_legacy & (BA_HAS_RECALC_OB | BA_HAS_RECALC_DATA)) == 0 && !((snap_select == SNAP_NOT_SELECTED && ((base->flag & BASE_SELECTED) || (base->flag_legacy & BA_WAS_SEL))) || (snap_select == SNAP_NOT_ACTIVE && base == base_act))) @@ -179,16 +179,16 @@ static void iter_snap_objects( Object *obj = base->object; if (obj->transflag & OB_DUPLI) { DupliObject *dupli_ob; - ListBase *lb = object_duplilist(sctx->bmain->eval_ctx, sctx->scene, obj); + ListBase *lb = object_duplilist(&sctx->eval_ctx, sctx->scene, obj); for (dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next) { use_obedit = obedit && dupli_ob->ob->data == obedit->data; - sob_callback(C, sctx, use_obedit, use_obedit ? obedit : dupli_ob->ob, dupli_ob->mat, data); + sob_callback(sctx, use_obedit, use_obedit ? obedit : dupli_ob->ob, dupli_ob->mat, data); } free_object_duplilist(lb); } use_obedit = obedit && obj->data == obedit->data; - sob_callback(C, sctx, use_obedit, use_obedit ? obedit : obj, obj->obmat, data); + sob_callback(sctx, use_obedit, use_obedit ? obedit : obj, obj->obmat, data); } } } @@ -711,7 +711,7 @@ static bool raycastEditMesh( * \note Duplicate args here are documented at #snapObjectsRay */ static bool raycastObj( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const float ray_start[3], const float ray_dir[3], Object *ob, float obmat[4][4], const unsigned int ob_index, bool use_obedit, @@ -722,11 +722,8 @@ static bool raycastObj( Object **r_ob, float r_obmat[4][4], ListBase *r_hit_list) { - EvaluationContext eval_ctx; bool retval = false; - CTX_data_eval_ctx(C, &eval_ctx); - if (ob->type == OB_MESH) { BMEditMesh *em; @@ -744,10 +741,10 @@ static bool raycastObj( DerivedMesh *dm; em = BKE_editmesh_from_object(ob); if (em) { - editbmesh_get_derived_cage_and_final(&eval_ctx, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm); + editbmesh_get_derived_cage_and_final(&sctx->eval_ctx, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm); } else { - dm = mesh_get_derived_final(&eval_ctx, sctx->scene, ob, CD_MASK_BAREMESH); + dm = mesh_get_derived_final(&sctx->eval_ctx, sctx->scene, ob, CD_MASK_BAREMESH); } retval = raycastDerivedMesh( sctx, @@ -786,11 +783,11 @@ struct RaycastObjUserData { bool ret; }; -static void raycast_obj_cb(const bContext *C, SnapObjectContext *sctx, bool is_obedit, Object *ob, float obmat[4][4], void *data) +static void raycast_obj_cb(SnapObjectContext *sctx, bool is_obedit, Object *ob, float obmat[4][4], void *data) { struct RaycastObjUserData *dt = data; dt->ret |= raycastObj( - C, sctx, + sctx, dt->ray_start, dt->ray_dir, ob, obmat, dt->ob_index++, is_obedit, dt->ray_depth, @@ -829,7 +826,7 @@ static void raycast_obj_cb(const bContext *C, SnapObjectContext *sctx, bool is_o * */ static bool raycastObjects( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const float ray_start[3], const float ray_dir[3], const SnapSelect snap_select, const bool use_object_edit_cage, /* read/write args */ @@ -855,7 +852,7 @@ static bool raycastObjects( .ret = false, }; - iter_snap_objects(C, sctx, snap_select, obedit, raycast_obj_cb, &data); + iter_snap_objects(sctx, snap_select, obedit, raycast_obj_cb, &data); return data.ret; } @@ -1948,7 +1945,7 @@ static bool snapEditMesh( * \note Duplicate args here are documented at #snapObjectsRay */ static bool snapObject( - const bContext *C, SnapObjectContext *sctx, SnapData *snapdata, + SnapObjectContext *sctx, SnapData *snapdata, Object *ob, float obmat[4][4], bool use_obedit, /* read/write args */ @@ -1957,11 +1954,8 @@ static bool snapObject( float r_loc[3], float r_no[3], Object **r_ob, float r_obmat[4][4]) { - EvaluationContext eval_ctx; bool retval = false; - CTX_data_eval_ctx(C, &eval_ctx); - if (ob->type == OB_MESH) { BMEditMesh *em; @@ -1978,10 +1972,10 @@ static bool snapObject( DerivedMesh *dm; em = BKE_editmesh_from_object(ob); if (em) { - editbmesh_get_derived_cage_and_final(&eval_ctx, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm); + editbmesh_get_derived_cage_and_final(&sctx->eval_ctx, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm); } else { - dm = mesh_get_derived_final(&eval_ctx, sctx->scene, ob, CD_MASK_BAREMESH); + dm = mesh_get_derived_final(&sctx->eval_ctx, sctx->scene, ob, CD_MASK_BAREMESH); } retval = snapDerivedMesh( sctx, snapdata, ob, dm, obmat, @@ -2045,11 +2039,11 @@ struct SnapObjUserData { bool ret; }; -static void sanp_obj_cb(const bContext *C, SnapObjectContext *sctx, bool is_obedit, Object *ob, float obmat[4][4], void *data) +static void sanp_obj_cb(SnapObjectContext *sctx, bool is_obedit, Object *ob, float obmat[4][4], void *data) { struct SnapObjUserData *dt = data; dt->ret |= snapObject( - C, sctx, dt->snapdata, + sctx, dt->snapdata, ob, obmat, is_obedit, /* read/write args */ dt->ray_depth, dt->dist_px, @@ -2088,7 +2082,7 @@ static void sanp_obj_cb(const bContext *C, SnapObjectContext *sctx, bool is_obed * */ static bool snapObjectsRay( - const bContext *C, SnapObjectContext *sctx, SnapData *snapdata, + SnapObjectContext *sctx, SnapData *snapdata, const SnapSelect snap_select, const bool use_object_edit_cage, /* read/write args */ float *ray_depth, float *dist_px, @@ -2109,7 +2103,7 @@ static bool snapObjectsRay( .ret = false, }; - iter_snap_objects(C, sctx, snap_select, obedit, sanp_obj_cb, &data); + iter_snap_objects(sctx, snap_select, obedit, sanp_obj_cb, &data); return data.ret; } @@ -2131,7 +2125,8 @@ SnapObjectContext *ED_transform_snap_object_context_create( sctx->bmain = bmain; sctx->scene = scene; - sctx->scene_layer = sl; + + DEG_evaluation_context_init_from_scene(&sctx->eval_ctx, scene, sl, DAG_EVAL_VIEWPORT); sctx->cache.object_map = BLI_ghash_ptr_new(__func__); sctx->cache.mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__); @@ -2205,7 +2200,7 @@ void ED_transform_snap_object_context_set_editmesh_callbacks( } bool ED_transform_snap_object_project_ray_ex( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const struct SnapObjectParams *params, const float ray_start[3], const float ray_normal[3], float *ray_depth, @@ -2213,7 +2208,7 @@ bool ED_transform_snap_object_project_ray_ex( Object **r_ob, float r_obmat[4][4]) { return raycastObjects( - C, sctx, + sctx, ray_start, ray_normal, params->snap_select, params->use_object_edit_cage, ray_depth, r_loc, r_no, r_index, r_ob, r_obmat, NULL); @@ -2227,7 +2222,7 @@ bool ED_transform_snap_object_project_ray_ex( * \param r_hit_list: List of #SnapObjectHitDepth (caller must free). */ bool ED_transform_snap_object_project_ray_all( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const struct SnapObjectParams *params, const float ray_start[3], const float ray_normal[3], float ray_depth, bool sort, @@ -2242,7 +2237,7 @@ bool ED_transform_snap_object_project_ray_all( #endif bool retval = raycastObjects( - C, sctx, + sctx, ray_start, ray_normal, params->snap_select, params->use_object_edit_cage, &ray_depth, NULL, NULL, NULL, NULL, NULL, @@ -2268,7 +2263,7 @@ bool ED_transform_snap_object_project_ray_all( * \return Snap success */ static bool transform_snap_context_project_ray_impl( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const struct SnapObjectParams *params, const float ray_start[3], const float ray_normal[3], float *ray_depth, float r_co[3], float r_no[3]) @@ -2277,7 +2272,7 @@ static bool transform_snap_context_project_ray_impl( /* try snap edge, then face if it fails */ ret = ED_transform_snap_object_project_ray_ex( - C, sctx, + sctx, params, ray_start, ray_normal, ray_depth, r_co, r_no, NULL, @@ -2287,7 +2282,7 @@ static bool transform_snap_context_project_ray_impl( } bool ED_transform_snap_object_project_ray( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const struct SnapObjectParams *params, const float ray_origin[3], const float ray_direction[3], float *ray_depth, float r_co[3], float r_no[3]) @@ -2299,14 +2294,14 @@ bool ED_transform_snap_object_project_ray( } return transform_snap_context_project_ray_impl( - C, sctx, + sctx, params, ray_origin, ray_direction, ray_depth, r_co, r_no); } static bool transform_snap_context_project_view3d_mixed_impl( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const unsigned short snap_to_flag, const struct SnapObjectParams *params, const float mval[2], float *dist_px, @@ -2330,7 +2325,7 @@ static bool transform_snap_context_project_view3d_mixed_impl( *dist_px = dist_px_orig; } if (ED_transform_snap_object_project_view3d( - C, sctx, + sctx, elem_type[i], params, mval, dist_px, &ray_depth, r_co, r_no)) @@ -2347,7 +2342,7 @@ static bool transform_snap_context_project_view3d_mixed_impl( for (int i = 0; i < 3; i++) { if (snap_to_flag & (1 << i)) { if (ED_transform_snap_object_project_view3d( - C, sctx, + sctx, elem_type[i], params, mval, dist_px, &ray_depth, r_co, r_no)) @@ -2376,7 +2371,7 @@ static bool transform_snap_context_project_view3d_mixed_impl( * \return Snap success */ bool ED_transform_snap_object_project_view3d_mixed( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const unsigned short snap_to_flag, const struct SnapObjectParams *params, const float mval_fl[2], float *dist_px, @@ -2384,14 +2379,14 @@ bool ED_transform_snap_object_project_view3d_mixed( float r_co[3], float r_no[3]) { return transform_snap_context_project_view3d_mixed_impl( - C, sctx, + sctx, snap_to_flag, params, mval_fl, dist_px, use_depth, r_co, r_no); } bool ED_transform_snap_object_project_view3d_ex( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const unsigned short snap_to, const struct SnapObjectParams *params, const float mval[2], float *dist_px, @@ -2425,7 +2420,7 @@ bool ED_transform_snap_object_project_view3d_ex( if (snap_to == SCE_SNAP_MODE_FACE) { return raycastObjects( - C, sctx, + sctx, ray_start, ray_normal, params->snap_select, params->use_object_edit_cage, ray_depth, r_loc, r_no, r_index, NULL, NULL, NULL); @@ -2437,14 +2432,14 @@ bool ED_transform_snap_object_project_view3d_ex( ray_origin, ray_start, ray_normal, depth_range); return snapObjectsRay( - C, sctx, &snapdata, + sctx, &snapdata, params->snap_select, params->use_object_edit_cage, ray_depth, dist_px, r_loc, r_no, NULL, NULL); } } bool ED_transform_snap_object_project_view3d( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const unsigned short snap_to, const struct SnapObjectParams *params, const float mval[2], float *dist_px, @@ -2452,7 +2447,7 @@ bool ED_transform_snap_object_project_view3d( float r_loc[3], float r_no[3]) { return ED_transform_snap_object_project_view3d_ex( - C, sctx, + sctx, snap_to, params, mval, dist_px, @@ -2464,7 +2459,7 @@ bool ED_transform_snap_object_project_view3d( * see: #ED_transform_snap_object_project_ray_all */ bool ED_transform_snap_object_project_all_view3d_ex( - const bContext *C, SnapObjectContext *sctx, + SnapObjectContext *sctx, const struct SnapObjectParams *params, const float mval[2], float ray_depth, bool sort, @@ -2480,7 +2475,7 @@ bool ED_transform_snap_object_project_all_view3d_ex( } return ED_transform_snap_object_project_ray_all( - C, sctx, + sctx, params, ray_start, ray_normal, ray_depth, sort, r_hit_list); |