This diff 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.
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 objects 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.
Not included in this patch / future updates:
- Snapping "Target" is a confusing named, as "Target" is used as both the transformed items (or SCE_SNAP_TARGET_CLOSEST, etc.) and for the objects to which the transformed items are snapped (especially Shrinkwrap modifier). I plan to submit another patch to make this clearer after this is accepted.
- Many of the functions do not specify in which space the point info (coordinates and normal) is defined.
- Target selection code could be simplified by separating it from the uber snap_flag variable.
- The snapping dropdown is feeling very disorganized. Also, since enabling both the Face Projection and the Face Nearest methods does not make sense, perhaps the switch between these methods could be a checkbox (similar to snapping to relative or absolute grid).