View3D Snap Cursor: sanitize and increase the maximum amount of states
3 is a small amount as each viewport creates a gizmo that creates its own state Now if the state is not created, the gizmos use the last state.
This commit is contained in:
parent
4468c34378
commit
40f59b5dad
|
@ -225,8 +225,10 @@ static void snap_gizmo_setup(wmGizmo *gz)
|
|||
gz->flag |= WM_GIZMO_NO_TOOLTIP;
|
||||
SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
|
||||
snap_gizmo->snap_state = ED_view3d_cursor_snap_active();
|
||||
snap_gizmo->snap_state->draw_point = true;
|
||||
snap_gizmo->snap_state->draw_plane = false;
|
||||
if (snap_gizmo->snap_state) {
|
||||
snap_gizmo->snap_state->draw_point = true;
|
||||
snap_gizmo->snap_state->draw_plane = false;
|
||||
}
|
||||
|
||||
rgba_float_to_uchar(snap_gizmo->snap_state->color_point, gz->color);
|
||||
}
|
||||
|
@ -284,7 +286,9 @@ static int snap_gizmo_invoke(bContext *UNUSED(C),
|
|||
static void snap_gizmo_free(wmGizmo *gz)
|
||||
{
|
||||
SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
|
||||
ED_view3d_cursor_snap_deactive(snap_gizmo->snap_state);
|
||||
if (snap_gizmo->snap_state) {
|
||||
ED_view3d_cursor_snap_deactive(snap_gizmo->snap_state);
|
||||
}
|
||||
}
|
||||
|
||||
static void GIZMO_GT_snap_3d(wmGizmoType *gzt)
|
||||
|
|
|
@ -522,9 +522,12 @@ static void view3d_ob_drop_draw_activate(struct wmDropBox *drop, wmDrag *drag)
|
|||
if (state) {
|
||||
return;
|
||||
}
|
||||
|
||||
state = drop->draw_data = ED_view3d_cursor_snap_active();
|
||||
state->draw_point = true;
|
||||
state->draw_plane = true;
|
||||
if (!state) {
|
||||
/* The maximum snap status stack value has been reached. */
|
||||
return;
|
||||
}
|
||||
|
||||
float dimensions[3] = {0.0f};
|
||||
if (drag->type == WM_DRAG_ID) {
|
||||
|
@ -549,10 +552,8 @@ static void view3d_ob_drop_draw_activate(struct wmDropBox *drop, wmDrag *drag)
|
|||
static void view3d_ob_drop_draw_deactivate(struct wmDropBox *drop, wmDrag *UNUSED(drag))
|
||||
{
|
||||
V3DSnapCursorState *state = drop->draw_data;
|
||||
if (state) {
|
||||
ED_view3d_cursor_snap_deactive(state);
|
||||
drop->draw_data = NULL;
|
||||
}
|
||||
ED_view3d_cursor_snap_deactive(state);
|
||||
drop->draw_data = NULL;
|
||||
}
|
||||
|
||||
static bool view3d_ob_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
|
||||
|
@ -680,30 +681,28 @@ static void view3d_ob_drop_copy(wmDrag *drag, wmDropBox *drop)
|
|||
const bool is_imported_id = drag->type == WM_DRAG_ASSET;
|
||||
RNA_boolean_set(drop->ptr, "duplicate", !is_imported_id);
|
||||
|
||||
V3DSnapCursorState *snap_state = drop->draw_data;
|
||||
if (snap_state) {
|
||||
Object *ob = (Object *)id;
|
||||
float obmat_final[4][4];
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
Object *ob = (Object *)id;
|
||||
float obmat_final[4][4];
|
||||
|
||||
V3DSnapCursorData *snap_data;
|
||||
snap_data = ED_view3d_cursor_snap_data_get(snap_state, NULL, 0, 0);
|
||||
copy_m4_m3(obmat_final, snap_data->plane_omat);
|
||||
copy_v3_v3(obmat_final[3], snap_data->loc);
|
||||
V3DSnapCursorData *snap_data;
|
||||
snap_data = ED_view3d_cursor_snap_data_get(snap_state, NULL, 0, 0);
|
||||
copy_m4_m3(obmat_final, snap_data->plane_omat);
|
||||
copy_v3_v3(obmat_final[3], snap_data->loc);
|
||||
|
||||
float scale[3];
|
||||
mat4_to_size(scale, ob->obmat);
|
||||
rescale_m4(obmat_final, scale);
|
||||
float scale[3];
|
||||
mat4_to_size(scale, ob->obmat);
|
||||
rescale_m4(obmat_final, scale);
|
||||
|
||||
BoundBox *bb = BKE_object_boundbox_get(ob);
|
||||
if (bb) {
|
||||
float offset[3];
|
||||
BKE_boundbox_calc_center_aabb(bb, offset);
|
||||
offset[2] = bb->vec[0][2];
|
||||
mul_mat3_m4_v3(obmat_final, offset);
|
||||
sub_v3_v3(obmat_final[3], offset);
|
||||
}
|
||||
RNA_float_set_array(drop->ptr, "matrix", &obmat_final[0][0]);
|
||||
BoundBox *bb = BKE_object_boundbox_get(ob);
|
||||
if (bb) {
|
||||
float offset[3];
|
||||
BKE_boundbox_calc_center_aabb(bb, offset);
|
||||
offset[2] = bb->vec[0][2];
|
||||
mul_mat3_m4_v3(obmat_final, offset);
|
||||
sub_v3_v3(obmat_final[3], offset);
|
||||
}
|
||||
RNA_float_set_array(drop->ptr, "matrix", &obmat_final[0][0]);
|
||||
}
|
||||
|
||||
static void view3d_collection_drop_copy(wmDrag *drag, wmDropBox *drop)
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
|
||||
#include "WM_api.h"
|
||||
|
||||
#define STATE_LEN 3
|
||||
#define STATE_LEN 8
|
||||
|
||||
typedef struct SnapStateIntern {
|
||||
V3DSnapCursorState snap_state;
|
||||
|
@ -925,7 +925,6 @@ V3DSnapCursorState *ED_view3d_cursor_snap_active(void)
|
|||
}
|
||||
}
|
||||
|
||||
BLI_assert(false);
|
||||
data_intern->state_active_len--;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -938,6 +937,10 @@ void ED_view3d_cursor_snap_deactive(V3DSnapCursorState *state)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!state) {
|
||||
return;
|
||||
}
|
||||
|
||||
SnapStateIntern *state_intern = (SnapStateIntern *)state;
|
||||
if (!state_intern->is_active) {
|
||||
return;
|
||||
|
@ -956,6 +959,9 @@ void ED_view3d_cursor_snap_deactive(V3DSnapCursorState *state)
|
|||
void ED_view3d_cursor_snap_prevpoint_set(V3DSnapCursorState *state, const float prev_point[3])
|
||||
{
|
||||
SnapCursorDataIntern *data_intern = &g_data_intern;
|
||||
if (!state) {
|
||||
state = ED_view3d_cursor_snap_state_get();
|
||||
}
|
||||
if (prev_point) {
|
||||
copy_v3_v3(data_intern->prevpoint_stack, prev_point);
|
||||
state->prevpoint = data_intern->prevpoint_stack;
|
||||
|
|
|
@ -742,16 +742,19 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv
|
|||
|
||||
ipd->launch_event = WM_userdef_event_type_from_keymap_type(event->type);
|
||||
|
||||
ipd->snap_state = ED_view3d_cursor_snap_active();
|
||||
ipd->snap_state->draw_point = true;
|
||||
ipd->snap_state->draw_plane = true;
|
||||
V3DSnapCursorState *snap_state_new = ED_view3d_cursor_snap_active();
|
||||
if (snap_state_new) {
|
||||
ipd->snap_state = snap_state = snap_state_new;
|
||||
}
|
||||
|
||||
snap_state->draw_point = true;
|
||||
snap_state->draw_plane = true;
|
||||
ipd->is_snap_found =
|
||||
view3d_interactive_add_calc_snap(
|
||||
C, event, ipd->co_src, ipd->matrix_orient, &ipd->use_snap, &ipd->is_snap_invert) != 0;
|
||||
|
||||
ipd->snap_state->draw_plane = false;
|
||||
ED_view3d_cursor_snap_prevpoint_set(ipd->snap_state, ipd->co_src);
|
||||
snap_state->draw_plane = false;
|
||||
ED_view3d_cursor_snap_prevpoint_set(snap_state, ipd->co_src);
|
||||
|
||||
ipd->orient_axis = plane_axis;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
@ -1515,10 +1518,12 @@ static void preview_plane_free_fn(void *customdata)
|
|||
static void WIDGETGROUP_placement_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_active();
|
||||
snap_state->draw_plane = true;
|
||||
if (snap_state) {
|
||||
snap_state->draw_plane = true;
|
||||
|
||||
gzgroup->customdata = snap_state;
|
||||
gzgroup->customdata_free = preview_plane_free_fn;
|
||||
gzgroup->customdata = snap_state;
|
||||
gzgroup->customdata_free = preview_plane_free_fn;
|
||||
}
|
||||
}
|
||||
|
||||
void VIEW3D_GGT_placement(wmGizmoGroupType *gzgt)
|
||||
|
|
Loading…
Reference in New Issue