Snap Gizmo Refactor: Implement options for the gizmo behavior
The Snap Gizmo now has options for occlusion, selection filter and edit geometry. It will be useful to implement in current tools.
This commit is contained in:
@@ -368,25 +368,39 @@ short ED_gizmotypes_snap_3d_update(wmGizmo *gz,
|
||||
snap_elements &= ~SCE_SNAP_MODE_EDGE_PERPENDICULAR;
|
||||
}
|
||||
|
||||
eSnapSelect snap_select = (snap_gizmo->flag & ED_SNAPGIZMO_SNAP_ONLY_ACTIVE) ?
|
||||
SNAP_ONLY_ACTIVE :
|
||||
SNAP_ALL;
|
||||
|
||||
eSnapEditType edit_mode_type = (snap_gizmo->flag & ED_SNAPGIZMO_SNAP_EDIT_GEOM_FINAL) ?
|
||||
SNAP_GEOM_FINAL :
|
||||
(snap_gizmo->flag & ED_SNAPGIZMO_SNAP_EDIT_GEOM_CAGE) ?
|
||||
SNAP_GEOM_CAGE :
|
||||
SNAP_GEOM_EDIT;
|
||||
|
||||
bool use_occlusion_test = (snap_gizmo->flag & ED_SNAPGIZMO_OCCLUSION_ALWAYS_TRUE) ? false :
|
||||
true;
|
||||
|
||||
float dist_px = 12.0f * U.pixelsize;
|
||||
|
||||
ED_gizmotypes_snap_3d_context_ensure(scene, region, v3d, gz);
|
||||
snap_elem = ED_transform_snap_object_project_view3d_ex(snap_gizmo->snap_context_v3d,
|
||||
depsgraph,
|
||||
snap_elements,
|
||||
&(const struct SnapObjectParams){
|
||||
.snap_select = SNAP_ALL,
|
||||
.edit_mode_type = SNAP_GEOM_EDIT,
|
||||
.use_occlusion_test = true,
|
||||
},
|
||||
mval_fl,
|
||||
prev_co,
|
||||
&dist_px,
|
||||
co,
|
||||
no,
|
||||
&index,
|
||||
NULL,
|
||||
NULL);
|
||||
snap_elem = ED_transform_snap_object_project_view3d_ex(
|
||||
snap_gizmo->snap_context_v3d,
|
||||
depsgraph,
|
||||
snap_elements,
|
||||
&(const struct SnapObjectParams){
|
||||
.snap_select = snap_select,
|
||||
.edit_mode_type = edit_mode_type,
|
||||
.use_occlusion_test = use_occlusion_test,
|
||||
},
|
||||
mval_fl,
|
||||
prev_co,
|
||||
&dist_px,
|
||||
co,
|
||||
no,
|
||||
&index,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
if (snap_elem == 0) {
|
||||
|
||||
@@ -263,6 +263,11 @@ struct SnapObjectContext *ED_gizmotypes_snap_3d_context_ensure(struct Scene *sce
|
||||
|
||||
typedef enum {
|
||||
ED_SNAPGIZMO_TOGGLE_ALWAYS_TRUE = 1 << 0,
|
||||
ED_SNAPGIZMO_OCCLUSION_ALWAYS_TRUE = 1 << 1,
|
||||
ED_SNAPGIZMO_OCCLUSION_ALWAYS_FALSE = 1 << 2, /* TODO. */
|
||||
ED_SNAPGIZMO_SNAP_ONLY_ACTIVE = 1 << 3,
|
||||
ED_SNAPGIZMO_SNAP_EDIT_GEOM_FINAL = 1 << 4,
|
||||
ED_SNAPGIZMO_SNAP_EDIT_GEOM_CAGE = 1 << 5,
|
||||
} eSnapGizmo;
|
||||
|
||||
void ED_gizmotypes_snap_3d_flag_set(struct wmGizmo *gz, eSnapGizmo flag);
|
||||
|
||||
@@ -43,6 +43,7 @@ typedef enum {
|
||||
SNAP_ALL = 0,
|
||||
SNAP_NOT_SELECTED = 1,
|
||||
SNAP_NOT_ACTIVE = 2,
|
||||
SNAP_ONLY_ACTIVE = 3,
|
||||
} eSnapSelect;
|
||||
|
||||
typedef enum {
|
||||
|
||||
@@ -418,6 +418,13 @@ static void iter_snap_objects(SnapObjectContext *sctx,
|
||||
const bool use_backface_culling = params->use_backface_culling;
|
||||
|
||||
Base *base_act = view_layer->basact;
|
||||
if (snap_select == SNAP_ONLY_ACTIVE) {
|
||||
Object *obj_eval = DEG_get_evaluated_object(depsgraph, base_act->object);
|
||||
sob_callback(
|
||||
sctx, obj_eval, obj_eval->obmat, edit_mode_type, use_backface_culling, true, data);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Base *base = view_layer->object_bases.first; base != NULL; base = base->next) {
|
||||
if (!BASE_VISIBLE(v3d, base)) {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user