diff options
author | jon denning <gfxcoder@gmail.com> | 2022-06-30 03:52:00 +0300 |
---|---|---|
committer | jon denning <gfxcoder@gmail.com> | 2022-06-30 03:52:00 +0300 |
commit | 011327224ecec1312e0780865a1fb0dc83830a30 (patch) | |
tree | f6e82e3c116fd7bd18f0277bbeb4f3756124bb67 /source/blender/makesdna | |
parent | 0ea282f7462070041b2599389ba61c7ef50426b5 (diff) |
Transform Snap: nearest face snap mode, snapping options, refactoring.
This commit adds a new face nearest snapping mode, adds new snapping
options, and (lightly) refactors code around snapping.
The new face nearest snapping mode will snap transformed geometry to the
nearest surface in world space. In contrast, the original face snapping
mode uses projection (raycasting) to snap source to target geometry.
Face snapping therefore only works with what is visible, while nearest
face snapping can snap geometry to occluded parts of the scene. This new
mode is critical for retopology work, where some of the target mesh
might be occluded (ex: sliding an edge loop that wraps around the
backside of target mesh).
The nearest face snapping mode has two options: "Snap to Same Target"
and "Face Nearest Steps". When the Snap to Same Object option is
enabled, the selected source geometry will stay near the target that it
is nearest before editing started, which prevents the source geometry
from snapping to other targets. The Face Nearest Steps divides the
overall transformation for each vertex into n smaller transformations,
then applies those n transformations with surface snapping interlacing
each step. This steps option handles transformations that cross U-shaped
targets better.
The new snapping options allow the artist to better control which target
objects (objects to which the edited geometry is snapped) are considered
when snapping. In particular, the only option for filtering target
objects was a "Project onto Self", which allowed the currently edited
mesh to be considered as a target. Now, the artist can choose any
combination of the following to be considered as a target: the active
object, any edited object that isn't active (see note below), any non-
edited object. Additionally, the artist has another snapping option to
exclude objects that are not selectable as potential targets.
The Snapping Options dropdown has been lightly reorganized to allow for
the additional options.
Included in this patch:
- Snap target selection is more controllable for artist with additional
snapping options.
- Renamed a few of the snap-related functions to better reflect what
they actually do now. For example, `applySnapping` implies that this
handles the snapping, while `applyProject` implies something entirely
different is done there. However, better names would be
`applySnappingAsGroup` and `applySnappingIndividual`, respectively,
where `applySnappingIndividual` previously only does Face snapping.
- Added an initial coordinate parameter to snapping functions so that
the nearest target before transforming can be determined(for "Snap to
Same Object"), and so the transformation can be broken into smaller
steps (for "Face Nearest Steps").
- Separated the BVH Tree getter code from mesh/edit mesh to its own
function to reduce code duplication.
- Added icon for nearest face snapping.
- The original "Project onto Self" was actually not correct! This option
should be called "Project onto Active" instead, but that only matters
when editing multiple meshes at the same time. This patch makes this
change in the UI.
Reviewed By: Campbell Barton, Germano Cavalcante
Differential Revision: https://developer.blender.org/D14591
Diffstat (limited to 'source/blender/makesdna')
-rw-r--r-- | source/blender/makesdna/DNA_scene_defaults.h | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_scene_types.h | 52 |
2 files changed, 35 insertions, 19 deletions
diff --git a/source/blender/makesdna/DNA_scene_defaults.h b/source/blender/makesdna/DNA_scene_defaults.h index 74db1d14bbc..6cc01d254ce 100644 --- a/source/blender/makesdna/DNA_scene_defaults.h +++ b/source/blender/makesdna/DNA_scene_defaults.h @@ -337,7 +337,9 @@ .snap_mode = SCE_SNAP_MODE_INCREMENT, \ .snap_node_mode = SCE_SNAP_MODE_GRID, \ .snap_uv_mode = SCE_SNAP_MODE_INCREMENT, \ + .snap_flag = SCE_SNAP_TO_INCLUDE_EDITED | SCE_SNAP_TO_INCLUDE_NONEDITED, \ .snap_transform_mode_flag = SCE_SNAP_TRANSFORM_MODE_TRANSLATE, \ + .snap_face_nearest_steps = 1, \ \ .curve_paint_settings = _DNA_DEFAULTS_CurvePaintSettings, \ \ diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 1c62a550e60..c45b06f8c85 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -1496,19 +1496,24 @@ typedef struct ToolSettings { char transform_pivot_point; char transform_flag; /** Snap elements (per spacetype), #eSnapMode. */ - char snap_mode; + char _pad1[1]; + short snap_mode; char snap_node_mode; char snap_uv_mode; /** Generic flags (per spacetype), #eSnapFlag. */ - char snap_flag; - char snap_flag_node; - char snap_flag_seq; - char snap_uv_flag; + short snap_flag; + short snap_flag_node; + short snap_flag_seq; + short snap_uv_flag; /** Default snap source, #eSnapSourceSelect. */ - /* TODO(@gfxcoder): Rename `snap_target` to `snap_source_point`, because target is incorrect. */ + /* TODO(@gfxcoder): Rename `snap_target` to `snap_source` to avoid previous ambiguity of + * "target" (now, "source" is geometry to be moved and "target" is geometry to which moved + * geometry is snapped). */ char snap_target; /** Snap mask for transform modes, #eSnapTransformMode. */ char snap_transform_mode_flag; + /** Steps to break transformation into with face nearest snapping */ + short snap_face_nearest_steps; char proportional_edit, prop_mode; /** Proportional edit, object mode. */ @@ -2085,10 +2090,15 @@ typedef enum eSnapFlag { SCE_SNAP = (1 << 0), SCE_SNAP_ROTATE = (1 << 1), SCE_SNAP_PEEL_OBJECT = (1 << 2), - SCE_SNAP_PROJECT = (1 << 3), - SCE_SNAP_NO_SELF = (1 << 4), + SCE_SNAP_PROJECT = (1 << 3), /* Project individual elements instead of whole object. */ + SCE_SNAP_NOT_TO_ACTIVE = (1 << 4), /* Was `SCE_SNAP_NO_SELF`, but self should be active. */ SCE_SNAP_ABS_GRID = (1 << 5), SCE_SNAP_BACKFACE_CULLING = (1 << 6), + SCE_SNAP_KEEP_ON_SAME_OBJECT = (1 << 7), + /* see #eSnapTargetSelect */ + SCE_SNAP_TO_INCLUDE_EDITED = (1 << 8), + SCE_SNAP_TO_INCLUDE_NONEDITED = (1 << 9), + SCE_SNAP_TO_ONLY_SELECTABLE = (1 << 10), } eSnapFlag; /* Due to dependency conflicts with Cycles, header cannot directly include `BLI_utildefines.h`. */ /* TODO: move this macro to a more general place. */ @@ -2096,7 +2106,7 @@ typedef enum eSnapFlag { ENUM_OPERATORS(eSnapFlag, SCE_SNAP_BACKFACE_CULLING) #endif -/** #ToolSettings.snap_target and #TransSnap.source_select */ +/** See #ToolSettings.snap_target (to be renamed `snap_source`) and #TransSnap.source_select */ typedef enum eSnapSourceSelect { SCE_SNAP_SOURCE_CLOSEST = 0, SCE_SNAP_SOURCE_CENTER = 1, @@ -2104,13 +2114,15 @@ typedef enum eSnapSourceSelect { SCE_SNAP_SOURCE_ACTIVE = 3, } eSnapSourceSelect; -/** #TransSnap.target_select and #ToolSettings.snap_flag (SCE_SNAP_NO_SELF) */ +/** #TransSnap.target_select and #ToolSettings.snap_flag (#SCE_SNAP_NOT_TO_ACTIVE, + * #SCE_SNAP_TO_INCLUDE_EDITED, #SCE_SNAP_TO_INCLUDE_NONEDITED, #SCE_SNAP_TO_ONLY_SELECTABLE) */ typedef enum eSnapTargetSelect { SCE_SNAP_TARGET_ALL = 0, - SCE_SNAP_TARGET_NOT_SELECTED = 1, - SCE_SNAP_TARGET_NOT_ACTIVE = 2, - SCE_SNAP_TARGET_NOT_EDITED = 3, - SCE_SNAP_TARGET_ONLY_SELECTABLE = 4, + SCE_SNAP_TARGET_NOT_SELECTED = (1 << 0), + SCE_SNAP_TARGET_NOT_ACTIVE = (1 << 1), + SCE_SNAP_TARGET_NOT_EDITED = (1 << 2), + SCE_SNAP_TARGET_ONLY_SELECTABLE = (1 << 3), + SCE_SNAP_TARGET_NOT_NONEDITED = (1 << 4), } eSnapTargetSelect; /** #ToolSettings.snap_mode */ @@ -2118,19 +2130,21 @@ typedef enum eSnapMode { SCE_SNAP_MODE_NONE = 0, SCE_SNAP_MODE_VERTEX = (1 << 0), SCE_SNAP_MODE_EDGE = (1 << 1), - SCE_SNAP_MODE_FACE = (1 << 2), /* TODO(@gfxcoder): Rename to `SCE_SNAP_MODE_FACE_RAYCAST` - when other face snapping methods are added. */ + SCE_SNAP_MODE_FACE_RAYCAST = (1 << 2), SCE_SNAP_MODE_VOLUME = (1 << 3), SCE_SNAP_MODE_EDGE_MIDPOINT = (1 << 4), SCE_SNAP_MODE_EDGE_PERPENDICULAR = (1 << 5), - SCE_SNAP_MODE_GEOM = (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE | - SCE_SNAP_MODE_EDGE_PERPENDICULAR | SCE_SNAP_MODE_EDGE_MIDPOINT), + SCE_SNAP_MODE_FACE_NEAREST = (1 << 8), + + SCE_SNAP_MODE_GEOM = (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE_RAYCAST | + SCE_SNAP_MODE_EDGE_PERPENDICULAR | SCE_SNAP_MODE_EDGE_MIDPOINT | + SCE_SNAP_MODE_FACE_NEAREST), /** #ToolSettings.snap_node_mode */ SCE_SNAP_MODE_NODE_X = (1 << 0), SCE_SNAP_MODE_NODE_Y = (1 << 1), - /* #ToolSettings.snap_mode and #ToolSettings.snap_node_mode and #ToolSettings.snap_uv_mode */ + /** #ToolSettings.snap_mode and #ToolSettings.snap_node_mode and #ToolSettings.snap_uv_mode */ SCE_SNAP_MODE_INCREMENT = (1 << 6), SCE_SNAP_MODE_GRID = (1 << 7), } eSnapMode; |