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/makesrna/intern | |
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/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index cc7df54e648..daf4c99845d 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -151,7 +151,16 @@ const EnumPropertyItem rna_enum_snap_element_items[] = { "Snap to increments of grid"}, {SCE_SNAP_MODE_VERTEX, "VERTEX", ICON_SNAP_VERTEX, "Vertex", "Snap to vertices"}, {SCE_SNAP_MODE_EDGE, "EDGE", ICON_SNAP_EDGE, "Edge", "Snap to edges"}, - {SCE_SNAP_MODE_FACE, "FACE", ICON_SNAP_FACE, "Face", "Snap to faces"}, + {SCE_SNAP_MODE_FACE_RAYCAST, + "FACE", /* TODO(@gfxcoder): replace with "FACE_RAYCAST" as "FACE" is not descriptive. */ + ICON_SNAP_FACE, + "Face Project", + "Snap by projecting onto faces"}, + {SCE_SNAP_MODE_FACE_NEAREST, + "FACE_NEAREST", + ICON_SNAP_FACE_NEAREST, + "Face Nearest", + "Snap to nearest point on faces"}, {SCE_SNAP_MODE_VOLUME, "VOLUME", ICON_SNAP_VOLUME, "Volume", "Snap to volume"}, {SCE_SNAP_MODE_EDGE_MIDPOINT, "EDGE_MIDPOINT", @@ -3301,6 +3310,21 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Snap Element", "Type of element to snap to"); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ + prop = RNA_def_property(srna, "snap_face_nearest_steps", PROP_INT, PROP_FACTOR); + RNA_def_property_int_sdna(prop, NULL, "snap_face_nearest_steps"); + RNA_def_property_range(prop, 1, 100); + RNA_def_property_ui_text( + prop, + "Face Nearest Steps", + "Number of steps to break transformation into for face nearest snapping"); + + prop = RNA_def_property(srna, "use_snap_to_same_target", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "snap_flag", SCE_SNAP_KEEP_ON_SAME_OBJECT); + RNA_def_property_ui_text( + prop, + "Snap to Same Target", + "Snap only to target that source was initially near (Face Nearest Only)"); + /* node editor uses own set of snap modes */ prop = RNA_def_property(srna, "snap_node_element", PROP_ENUM, PROP_NONE); RNA_def_property_enum_bitflag_sdna(prop, NULL, "snap_node_mode"); @@ -3323,9 +3347,9 @@ static void rna_def_tool_settings(BlenderRNA *brna) "Absolute grid alignment while translating (based on the pivot center)"); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ - /* 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). */ + /* 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). */ prop = RNA_def_property(srna, "snap_target", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "snap_target"); RNA_def_property_enum_items(prop, rna_enum_snap_source_items); @@ -3350,9 +3374,30 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Backface Culling", "Exclude back facing geometry from snapping"); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ + /* TODO(@gfxcoder): Rename `use_snap_self` to `use_snap_active`, because active is correct but + * self is not (breaks API). This only makes a difference when more than one mesh is edited. */ prop = RNA_def_property(srna, "use_snap_self", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_negative_sdna(prop, NULL, "snap_flag", SCE_SNAP_NO_SELF); - RNA_def_property_ui_text(prop, "Project onto Self", "Snap onto itself (Edit Mode Only)"); + RNA_def_property_boolean_negative_sdna(prop, NULL, "snap_flag", SCE_SNAP_NOT_TO_ACTIVE); + RNA_def_property_ui_text( + prop, "Snap onto Active", "Snap onto itself only if enabled (Edit Mode Only)"); + RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ + + prop = RNA_def_property(srna, "use_snap_edit", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "snap_flag", SCE_SNAP_TO_INCLUDE_EDITED); + RNA_def_property_ui_text( + prop, "Snap onto Edited", "Snap onto non-active objects in Edit Mode (Edit Mode Only)"); + RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ + + prop = RNA_def_property(srna, "use_snap_nonedit", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "snap_flag", SCE_SNAP_TO_INCLUDE_NONEDITED); + RNA_def_property_ui_text( + prop, "Snap onto Non-edited", "Snap onto objects not in Edit Mode (Edit Mode Only)"); + RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ + + prop = RNA_def_property(srna, "use_snap_selectable", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "snap_flag", SCE_SNAP_TO_ONLY_SELECTABLE); + RNA_def_property_ui_text( + prop, "Snap onto Selectable Only", "Snap only onto objects that are selectable"); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ prop = RNA_def_property(srna, "use_snap_translate", PROP_BOOLEAN, PROP_NONE); |