Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorGermano Cavalcante <germano.costa@ig.com.br>2021-10-26 01:39:56 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2021-10-26 01:40:08 +0300
commit40f59b5dad15eab01ddd326fbffd59846f398c34 (patch)
treef51029a08752c89fd28769bcc8430ef1c1f8331c /source
parent4468c343787471df8a7a71ceb066301d2eaa6dc6 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c10
-rw-r--r--source/blender/editors/space_view3d/space_view3d.c57
-rw-r--r--source/blender/editors/space_view3d/view3d_cursor_snap.c10
-rw-r--r--source/blender/editors/space_view3d/view3d_placement.c21
4 files changed, 56 insertions, 42 deletions
diff --git a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c
index 33532bd0549..93ee6ec2d81 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c
@@ -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)
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index eaf90aabe8c..d20a07d3517 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -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];
-
- 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);
-
- 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]);
+ 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);
+
+ 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]);
}
static void view3d_collection_drop_copy(wmDrag *drag, wmDropBox *drop)
diff --git a/source/blender/editors/space_view3d/view3d_cursor_snap.c b/source/blender/editors/space_view3d/view3d_cursor_snap.c
index 5eb9ec3625c..9c45a89c3ff 100644
--- a/source/blender/editors/space_view3d/view3d_cursor_snap.c
+++ b/source/blender/editors/space_view3d/view3d_cursor_snap.c
@@ -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;
diff --git a/source/blender/editors/space_view3d/view3d_placement.c b/source/blender/editors/space_view3d/view3d_placement.c
index 7fe97705765..572fc8e3156 100644
--- a/source/blender/editors/space_view3d/view3d_placement.c
+++ b/source/blender/editors/space_view3d/view3d_placement.c
@@ -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)