Page MenuHome

Use Snap Gizmo for the knife tool widget
Needs ReviewPublic

Authored by Germano Cavalcante (mano-wii) on Jul 6 2020, 3:30 PM.
Tags
None
Tokens
"Love" token, awarded by HEYPictures."Love" token, awarded by JulienKaspar."Like" token, awarded by hitrpr."Love" token, awarded by lone_noel."Love" token, awarded by wilBr."Love" token, awarded by Slowwkidd."Like" token, awarded by duarteframos."Like" token, awarded by APEC."Love" token, awarded by 14AUDDIN."Love" token, awarded by jc4d."Like" token, awarded by Kickflipkid687.

Details

Summary

Since the tool knife, when enabled, has no gizmo, users often may not
realize that it is enabled or may not understand how to test it.

This patch proposes to correct this by using the snap gizmo on it.

With this patch the knife tool now uses 2 snap systems.

  • The own knife snap system that is used with the shortcut k.
  • The snap system of the snap gizmo, which is used whenever the tool is enabled.

This is what it currently does:

Diff Detail

Repository
rB Blender
Branch
knife_widget (branched from master)
Build Status
Buildable 9122
Build 9122: arc lint + arc unit

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
Germano Cavalcante (mano-wii) planned changes to this revision.Jul 14 2020, 1:22 PM
  • It needs D6731 to work properly
  • The gizmo snap system currently ignores KnifeEdges and KnifeVerts
  • Fix gizmo not being drawn after navigating
  • Fixes and Snap to knife elements
  • Fix snap in angle and snap to middle
  • Fix first snap element
  • Fix first snap element

Germano, is very hard to expose the 'snap gizmo' in python api??? ... if we had access to internal snap in python addons, all these problems would be solved by users with fast and standardized snap.

  • Remove ED_SNAPGIZMO_EVENTSTATE_INGNORE

I believe that the patch is ready.

Part of the initial idea regarding the automatic snap to the middle point (as seen in the GIF) has been removed. (This is discussed further in another patch).

One point that can still be considered is the drawing. The circle follows a convection seen in other tools with snapping (measure, transform, add object), but it can also add a lot of information.
However, I didn't want to change much, further complicating the patch.

Knife with snap_gizmo can now snap to other objects? like emptys, curves...
if yes we can use knife as quick slice option for precise interactive cuts..

Correct order of vertex/edge checks

Now the vertex is set after the edge, drawing checks need to be flipped.

Without this the active edge is always drawn, even when the vertex is snapped to.

Extracted a refactor from this patch into master rB52d09dad9c03d2214d1fde20bdc543f70b0174d3

Rebase on master.

Campbell Barton (campbellbarton) requested changes to this revision.Mar 30 2021, 7:38 AM

Mostly fine, noticed some issues though:

  • There is a bug when using the K-key while the tool is active. When clicking snapping starts at the cursor location when K was pressed.
  • Having both the snap circle and the knifes own snapping drawing feels cluttered - better only draw one.
  • The knife tool should the same highlighted circle as is shown before snapping, as the addition of this new snapping gizmo is visibly different before/after the knife tool has begun (while this is a detail, feels odd the way it is currently).
  • As noted in comments, the object member of the snap gizmo can be removed.

Supporting the snap gizmo in knife_snap_update_from_mval seems like an unnecessary complication, as it requires additional functions that only do something that's already supported when run without the gizmo.

It doesn't seem like we get any advantage from integrating the gizmo while the knife operator is running, AFAICS the gizmo can be hidden/disabled when the modal operator runs.

source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c
78

This doesn't seem to be necessary, it's only used to check if the snap gizmo object is active. However this should already be ensured by ED_SNAPGIZMO_SNAP_ONLY_ACTIVE.

I'd rather avoid using the snap gizmo to store context which could become outdated, leading to bugs.

source/blender/editors/mesh/editmesh_knife.c
2284

Could use equals_v3v3_int here.

2304

knife_project_v2 could be used here.

source/blender/editors/space_view3d/view3d_gizmo_knife.c
53

C is unused.

76

C, gzgroup, are unused.

This revision now requires changes to proceed.Mar 30 2021, 7:38 AM

Extracted a refactor from this patch into master rB52d09dad9c03d2214d1fde20bdc543f70b0174d3

Thanks for the commit :)
(In fact over time I ended up forgetting what was an improvement in the code and what was an addition to the snap gizmo)


Knife with snap_gizmo can now snap to other objects? like emptys, curves...
if yes we can use knife as quick slice option for precise interactive cuts..

It is possible, but it needs to be carefully thought of in another patch.


Supporting the snap gizmo in knife_snap_update_from_mval seems like an unnecessary complication, as it requires additional functions that only do something that's already supported when run without the gizmo.

It doesn't seem like we get any advantage from integrating the gizmo while the knife operator is running, AFAICS the gizmo can be hidden/disabled when the modal operator runs.

Supporting it for now doesn't really bring much advantage, but the code is still needed to get the first snapping point and in the future it may allow for easy implementation of features like snap to auto midpoint and perpendicular edge.
The only simplicity this would bring is to remove knife_find_closest_edge_of_bmedge.


(coding)

Germano Cavalcante (mano-wii) marked 5 inline comments as done.
  • Remove unnecessary "ob" member from the snap gizmo
  • Use "equals_v3v3_int" to compare vetors
  • Use "knife_project_v2" instead "ED_view3d_project_float_v2_m4"
  • Comments
  • Silence warnings: Unused parameter
  • Fix bug when using the K-key while the tool is active
  • Redo knife drawing

Now the knife tool has a new drawing indicating the "current point".
Before it was a filled green square, now it is a green circle.

This is the same circle as Gizmo, but in Gizmo this circle is red when the operation is not inited.

  • Remove use of the gizmo snapping system in the knife modal (only use to invoke)
  • Rebase on master
  • Revert changes in knife design (needs to be better discussed)
  • Change the color of the gizmo to the TH_HANDLE_SEL_VECT theme (that green one)
  • Remove snapping option to the middle point (best matches the default knife snapping)

This patch has been simplified to just add a simple gizmo to the knife tool (green circle).
Other changes such as: knife tool design, auto snap to middle point and snap to perpendicular are out of scope.
These changes can be thought of later.

so bad :-(

Maybe you can add snap_gizmo to bisect tool.... for start and end points.

We need some 'quick precise slice' tool with snap to other objects outside of current editing mesh.... bisect tool with snap_gizmo maybe to do the work.
:-)

  • Snap Gizmo: Add 'SNAP_GEOM_EDIT_DEFORMED'
  • Knife Tool Widget: snap to deformed cage
  • Fix crash in Measure tool
source/blender/editors/include/ED_gizmo_library.h
265

See note on SNAP_GEOM_EDIT_DEFORMED, the docstring could be linked from here.

source/blender/editors/include/ED_transform_snap_object_context.h
51–53 ↗(On Diff #36269)

While CAGE can work in object mode and SNAP_GEOM_EDIT_DEFORMED can't be, they seem as if they would be quite similar.

It would be good to include a doc-string explaining the difference between the two (for e.g. handling of hidden geometry).

  • Rebase on tmp-snap-bmesh-cageco