diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2020-06-01 00:09:50 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2020-06-01 00:28:52 +0300 |
commit | fcccee0c3372dc7c8a276f1cfe7545ea2c172498 (patch) | |
tree | f241ae47fbc9e8e4de10a9cbb8e800a3efe7e2bb /source | |
parent | 14af27e63d38d736f8287897df223bad4d5c9501 (diff) |
Cleanup: Remove unnecessary step in calling snap callback
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/transform/transform_snap_object.c | 280 |
1 files changed, 109 insertions, 171 deletions
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index 77bb0c1c785..4397c0396eb 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -359,7 +359,7 @@ static SnapObjectData *snap_object_data_editmesh_get(SnapObjectContext *sctx, * \{ */ typedef void (*IterSnapObjsCallback)(SnapObjectContext *sctx, - bool is_obedit, + bool use_obedit, bool use_backface_culling, Object *ob, float obmat[4][4], @@ -920,41 +920,52 @@ static bool raycastEditMesh(SnapObjectContext *sctx, return retval; } +struct RaycastObjUserData { + const float *ray_start; + const float *ray_dir; + uint ob_index; + /* read/write args */ + float *ray_depth; + /* return args */ + float *r_loc; + float *r_no; + int *r_index; + Object **r_ob; + float (*r_obmat)[4]; + ListBase *r_hit_list; + bool use_occlusion_test; + bool ret; +}; + /** * \param use_obedit: Uses the coordinates of BMesh (if any) to do the snapping; * * \note Duplicate args here are documented at #snapObjectsRay */ -static bool raycastObj(SnapObjectContext *sctx, - const float ray_start[3], - const float ray_dir[3], - Object *ob, - const float obmat[4][4], - const uint ob_index, - bool use_obedit, - bool use_occlusion_test, - bool use_backface_culling, - /* read/write args */ - float *ray_depth, - /* return args */ - float r_loc[3], - float r_no[3], - int *r_index, - Object **r_ob, - float r_obmat[4][4], - ListBase *r_hit_list) +static void raycast_obj_fn(SnapObjectContext *sctx, + bool use_obedit, + bool use_backface_culling, + Object *ob, + float obmat[4][4], + void *data) { + struct RaycastObjUserData *dt = data; + const uint ob_index = dt->ob_index++; + bool use_occlusion_test = dt->use_occlusion_test; + /* read/write args */ + float *ray_depth = dt->ray_depth; + bool retval = false; if (use_occlusion_test) { if (use_obedit && sctx->use_v3d && XRAY_FLAG_ENABLED(sctx->v3d_data.v3d)) { /* Use of occlude geometry in editing mode disabled. */ - return false; + return; } if (ELEM(ob->dt, OB_BOUNDBOX, OB_WIRE)) { /* Do not hit objects that are in wire or bounding box * display mode. */ - return false; + return; } } @@ -967,18 +978,18 @@ static bool raycastObj(SnapObjectContext *sctx, /* Operators only update the editmesh looptris of the original mesh. */ BMEditMesh *em_orig = BKE_editmesh_from_object(DEG_get_original_object(ob)); retval = raycastEditMesh(sctx, - ray_start, - ray_dir, + dt->ray_start, + dt->ray_dir, ob, em_orig, obmat, ob_index, use_backface_culling, ray_depth, - r_loc, - r_no, - r_index, - r_hit_list); + dt->r_loc, + dt->r_no, + dt->r_index, + dt->r_hit_list); break; } else { @@ -990,8 +1001,8 @@ static bool raycastObj(SnapObjectContext *sctx, } } retval = raycastMesh(sctx, - ray_start, - ray_dir, + dt->ray_start, + dt->ray_dir, ob, me, obmat, @@ -999,10 +1010,10 @@ static bool raycastObj(SnapObjectContext *sctx, use_hide, use_backface_culling, ray_depth, - r_loc, - r_no, - r_index, - r_hit_list); + dt->r_loc, + dt->r_no, + dt->r_index, + dt->r_hit_list); break; } case OB_CURVE: @@ -1011,8 +1022,8 @@ static bool raycastObj(SnapObjectContext *sctx, Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob); if (mesh_eval) { retval = raycastMesh(sctx, - ray_start, - ray_dir, + dt->ray_start, + dt->ray_dir, ob, mesh_eval, obmat, @@ -1020,70 +1031,24 @@ static bool raycastObj(SnapObjectContext *sctx, false, use_backface_culling, ray_depth, - r_loc, - r_no, - r_index, - r_hit_list); + dt->r_loc, + dt->r_no, + dt->r_index, + dt->r_hit_list); break; } } } if (retval) { - if (r_ob) { - *r_ob = ob; + if (dt->r_ob) { + *dt->r_ob = ob; } - if (r_obmat) { - copy_m4_m4(r_obmat, obmat); + if (dt->r_obmat) { + copy_m4_m4(dt->r_obmat, obmat); } - return true; + dt->ret = true; } - - return false; -} - -struct RaycastObjUserData { - const float *ray_start; - const float *ray_dir; - uint ob_index; - /* read/write args */ - float *ray_depth; - /* return args */ - float *r_loc; - float *r_no; - int *r_index; - Object **r_ob; - float (*r_obmat)[4]; - ListBase *r_hit_list; - bool use_occlusion_test; - bool ret; -}; - -static void raycast_obj_cb(SnapObjectContext *sctx, - bool use_obedit, - bool use_backface_culling, - Object *ob, - float obmat[4][4], - void *data) -{ - struct RaycastObjUserData *dt = data; - - dt->ret |= raycastObj(sctx, - dt->ray_start, - dt->ray_dir, - ob, - obmat, - dt->ob_index++, - use_obedit, - dt->use_occlusion_test, - use_backface_culling, - dt->ray_depth, - dt->r_loc, - dt->r_no, - dt->r_index, - dt->r_ob, - dt->r_obmat, - dt->r_hit_list); } /** @@ -1144,7 +1109,7 @@ static bool raycastObjects(SnapObjectContext *sctx, .ret = false, }; - iter_snap_objects(sctx, depsgraph, params, raycast_obj_cb, &data); + iter_snap_objects(sctx, depsgraph, params, raycast_obj_fn, &data); return data.ret; } @@ -2644,26 +2609,32 @@ static short snapEditMesh(SnapObjectContext *sctx, return 0; } +struct SnapObjUserData { + SnapData *snapdata; + /* read/write args */ + float *dist_px; + /* return args */ + float *r_loc; + float *r_no; + int *r_index; + Object **r_ob; + float (*r_obmat)[4]; + short ret; +}; + /** * \param use_obedit: Uses the coordinates of BMesh (if any) to do the snapping; * * \note Duplicate args here are documented at #snapObjectsRay */ -static short snapObject(SnapObjectContext *sctx, - SnapData *snapdata, - Object *ob, - float obmat[4][4], +static void sanp_obj_fn(SnapObjectContext *sctx, bool use_obedit, bool use_backface_culling, - /* read/write args */ - float *dist_px, - /* return args */ - float r_loc[3], - float r_no[3], - int *r_index, - Object **r_ob, - float r_obmat[4][4]) + Object *ob, + float obmat[4][4], + void *data) { + struct SnapObjUserData *dt = data; short retval = 0; switch (ob->type) { @@ -2674,15 +2645,15 @@ static short snapObject(SnapObjectContext *sctx, /* Operators only update the editmesh looptris of the original mesh. */ BMEditMesh *em_orig = BKE_editmesh_from_object(DEG_get_original_object(ob)); retval = snapEditMesh(sctx, - snapdata, + dt->snapdata, ob, em_orig, obmat, use_backface_culling, - dist_px, - r_loc, - r_no, - r_index); + dt->dist_px, + dt->r_loc, + dt->r_no, + dt->r_index); break; } else { @@ -2694,99 +2665,66 @@ static short snapObject(SnapObjectContext *sctx, } else if (ob->dt == OB_BOUNDBOX) { /* Do not snap to objects that are in bounding box display mode */ - return 0; + return; } - retval = snapMesh( - sctx, snapdata, ob, me, obmat, use_backface_culling, dist_px, r_loc, r_no, r_index); + retval = snapMesh(sctx, + dt->snapdata, + ob, + me, + obmat, + use_backface_culling, + dt->dist_px, + dt->r_loc, + dt->r_no, + dt->r_index); break; } case OB_ARMATURE: - retval = snapArmature(snapdata, ob, obmat, use_obedit, dist_px, r_loc, r_no, r_index); + retval = snapArmature( + dt->snapdata, ob, obmat, use_obedit, dt->dist_px, dt->r_loc, dt->r_no, dt->r_index); break; case OB_CURVE: - retval = snapCurve(snapdata, ob, obmat, use_obedit, dist_px, r_loc, r_no, r_index); + retval = snapCurve( + dt->snapdata, ob, obmat, use_obedit, dt->dist_px, dt->r_loc, dt->r_no, dt->r_index); break; /* Use ATTR_FALLTHROUGH if we want to snap to the generated mesh. */ case OB_SURF: case OB_FONT: { Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob); if (mesh_eval) { retval |= snapMesh(sctx, - snapdata, + dt->snapdata, ob, mesh_eval, obmat, use_backface_culling, - dist_px, - r_loc, - r_no, - r_index); + dt->dist_px, + dt->r_loc, + dt->r_no, + dt->r_index); } break; } case OB_EMPTY: - retval = snapEmpty(snapdata, ob, obmat, dist_px, r_loc, r_no, r_index); + retval = snapEmpty(dt->snapdata, ob, obmat, dt->dist_px, dt->r_loc, dt->r_no, dt->r_index); break; case OB_GPENCIL: - retval = snapEmpty(snapdata, ob, obmat, dist_px, r_loc, r_no, r_index); + retval = snapEmpty(dt->snapdata, ob, obmat, dt->dist_px, dt->r_loc, dt->r_no, dt->r_index); break; case OB_CAMERA: - retval = snapCamera(sctx, snapdata, ob, obmat, dist_px, r_loc, r_no, r_index); + retval = snapCamera( + sctx, dt->snapdata, ob, obmat, dt->dist_px, dt->r_loc, dt->r_no, dt->r_index); break; } if (retval) { - if (r_ob) { - *r_ob = ob; + if (dt->r_ob) { + *dt->r_ob = ob; } - if (r_obmat) { - copy_m4_m4(r_obmat, obmat); + if (dt->r_obmat) { + copy_m4_m4(dt->r_obmat, obmat); } - return retval; - } - - return 0; -} - -struct SnapObjUserData { - SnapData *snapdata; - /* read/write args */ - float *dist_px; - /* return args */ - float *r_loc; - float *r_no; - int *r_index; - Object **r_ob; - float (*r_obmat)[4]; - short ret; -}; - -static void sanp_obj_cb(SnapObjectContext *sctx, - bool is_obedit, - bool use_backface_culling, - Object *ob, - float obmat[4][4], - void *data) -{ - struct SnapObjUserData *dt = data; - - short elem = snapObject(sctx, - dt->snapdata, - ob, - obmat, - is_obedit, - use_backface_culling, - /* read/write args */ - dt->dist_px, - /* return args */ - dt->r_loc, - dt->r_no, - dt->r_index, - dt->r_ob, - dt->r_obmat); - - if (elem) { - dt->ret = elem; + dt->ret = retval; } } @@ -2839,7 +2777,7 @@ static short snapObjectsRay(SnapObjectContext *sctx, .ret = 0, }; - iter_snap_objects(sctx, depsgraph, params, sanp_obj_cb, &data); + iter_snap_objects(sctx, depsgraph, params, sanp_obj_fn, &data); return data.ret; } |