2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-10-29 00:45:05 +11:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup editors
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#define SNAP_MIN_DISTANCE 30
|
|
|
|
|
|
|
|
|
|
/* For enum. */
|
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
|
|
2022-10-11 18:01:08 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-10-29 00:45:05 +11:00
|
|
|
bool peelObjectsTransform(struct TransInfo *t,
|
|
|
|
|
const float mval[2],
|
2022-01-07 11:38:08 +11:00
|
|
|
bool use_peel_object,
|
2019-10-29 00:45:05 +11:00
|
|
|
/* return args */
|
|
|
|
|
float r_loc[3],
|
|
|
|
|
float r_no[3],
|
|
|
|
|
float *r_thickness);
|
|
|
|
|
|
Refactor: Snap-related. Clarified attribute names and refactored #defines into enums
The transformation snapping code contains a bunch of `#define`s, some ambiguously or incorrectly named attributes. This patch contains refactored code to improve this. This patch does (should) not change functionality of snapping.
Clarified ambiguously / incorrectly named attributes.
- "Target" is used to refer to the part of the source that is to be snapped (Active, Median, Center, Closest), but several other areas of Blender use the term "target" to refer to the thing being snapped to and "source" to refer to the thing getting snapped. Moreover, the implications of the previous terms do not match the descriptions. For example: `SCE_SNAP_TARGET_CENTER` does not snap the grabbed geometry to the center of the target, but instead "Snap transforamtion center onto target".
- "Select" refers to the condition for an object to be a possible target for snapping.
- `SCE_SNAP_MODE_FACE` is renamed to `SCE_SNAP_MODE_FACE_RAYCAST` to better describe its affect and to make way for other face snapping methods (ex: nearest).
Refactored related `#define` into `enum`s. In particular, constants relating to...
- `ToolSettings.snap_flag` are now in `enum eSnapFlag`
- `ToolSettings.snap_mode` are now in `enum eSnapMode`
- `ToolSettings.snap_source` (was `snap_target`) are now in `enum eSnapSourceSelect`
- `ToolSettings.snap_flag` (`SCE_SNAP_NO_SELF`) and `TransSnap.target_select` are now in `enum eSnapTargetSelect`
As the terms became more consistent and the constants were packed together into meaningful enumerations, some of the attribute names seemed ambiguous. For example, it is unclear whether `SnapObjectParams.snap_select` referred to the target or the source. This patch also adds a small amount of clarity.
This patch also swaps out generic types (ex: `char`, `short`, `ushort`) and unclear hard coded numbers (ex: `0`) used with snap-related enumerations with the actual `enum`s and values.
Note: I did leave myself some comments to follow-up with further refactoring. Specifically, using "target" and "source" consistently will mean the Python API will need to change (ex: `ToolSettings.snap_target` is not `ToolSettings.snap_source`). If the API is going to change, it would be good to make sure that the used terms are descriptive enough. For example, `bpy.ops.transform.translate` uses a `snap` argument to determine if snapping should be enabled while transforming. Perhaps `use_snap` might be an improvement that's more consistent with other conventions.
This patch is (mostly) a subset of D14591, as suggested by @mano-wii.
Task T69342 proposes to separate the `Absolute Grid Snap` option out from `Increment` snapping method into its own method. Also, there might be reason to create additional snapping methods or options. (Indeed, D14591 heads in this direction). This patch can work along with these suggestions, as this patch is trying to clarify the snapping code and to prompt more work in this area.
Reviewed By: mano-wii
Differential Revision: https://developer.blender.org/D15037
2022-06-06 10:28:14 -04:00
|
|
|
eSnapMode snapObjectsTransform(struct TransInfo *t,
|
|
|
|
|
const float mval[2],
|
|
|
|
|
float *dist_px,
|
|
|
|
|
/* return args */
|
|
|
|
|
float r_loc[3],
|
|
|
|
|
float r_no[3]);
|
2019-10-29 00:45:05 +11:00
|
|
|
bool snapNodesTransform(struct TransInfo *t,
|
|
|
|
|
const int mval[2],
|
|
|
|
|
/* return args */
|
|
|
|
|
float r_loc[2],
|
|
|
|
|
float *r_dist_px,
|
|
|
|
|
char *r_node_border);
|
|
|
|
|
|
|
|
|
|
bool transformModeUseSnap(const TransInfo *t);
|
|
|
|
|
|
2022-10-22 12:27:59 -03:00
|
|
|
void tranform_snap_target_median_calc(const TransInfo *t, float r_median[3]);
|
2021-06-29 20:13:55 +10:00
|
|
|
bool transform_snap_increment_ex(const TransInfo *t, bool use_local_space, float *r_val);
|
|
|
|
|
bool transform_snap_increment(const TransInfo *t, float *val);
|
2022-06-06 22:59:32 -03:00
|
|
|
float transform_snap_increment_get(const TransInfo *t);
|
2019-10-29 00:45:05 +11:00
|
|
|
|
|
|
|
|
bool activeSnap(const TransInfo *t);
|
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
2022-06-29 20:52:00 -04:00
|
|
|
bool activeSnap_SnappingIndividual(const TransInfo *t);
|
|
|
|
|
bool activeSnap_SnappingAsGroup(const TransInfo *t);
|
2021-06-26 16:57:03 +10:00
|
|
|
|
2019-10-29 00:45:05 +11:00
|
|
|
bool validSnap(const TransInfo *t);
|
|
|
|
|
|
|
|
|
|
void initSnapping(struct TransInfo *t, struct wmOperator *op);
|
|
|
|
|
void freeSnapping(struct TransInfo *t);
|
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
2022-06-29 20:52:00 -04:00
|
|
|
void applySnappingIndividual(TransInfo *t);
|
|
|
|
|
void applySnappingAsGroup(TransInfo *t, float *vec);
|
2019-10-29 00:45:05 +11:00
|
|
|
void resetSnapping(TransInfo *t);
|
|
|
|
|
eRedrawFlag handleSnapping(TransInfo *t, const struct wmEvent *event);
|
|
|
|
|
void drawSnapping(const struct bContext *C, TransInfo *t);
|
|
|
|
|
bool usingSnappingNormal(const TransInfo *t);
|
|
|
|
|
bool validSnappingNormal(const TransInfo *t);
|
|
|
|
|
|
|
|
|
|
void getSnapPoint(const TransInfo *t, float vec[3]);
|
|
|
|
|
void addSnapPoint(TransInfo *t);
|
|
|
|
|
eRedrawFlag updateSelectedSnapPoint(TransInfo *t);
|
|
|
|
|
void removeSnapPoint(TransInfo *t);
|
|
|
|
|
|
2020-06-22 09:07:51 -03:00
|
|
|
float transform_snap_distance_len_squared_fn(TransInfo *t, const float p1[3], const float p2[3]);
|
2021-06-29 20:12:19 +02:00
|
|
|
|
|
|
|
|
/* transform_snap_sequencer.c */
|
2021-12-09 00:55:11 +11:00
|
|
|
|
2021-06-29 20:12:19 +02:00
|
|
|
struct TransSeqSnapData *transform_snap_sequencer_data_alloc(const TransInfo *t);
|
|
|
|
|
void transform_snap_sequencer_data_free(struct TransSeqSnapData *data);
|
2021-06-29 18:08:41 -03:00
|
|
|
bool transform_snap_sequencer_calc(struct TransInfo *t);
|
|
|
|
|
void transform_snap_sequencer_apply_translate(TransInfo *t, float *vec);
|
2021-08-19 09:52:09 -03:00
|
|
|
|
|
|
|
|
/* transform_snap_animation.c */
|
2021-12-09 00:55:11 +11:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function returns the snapping 'mode' for Animation Editors only.
|
|
|
|
|
* We cannot use the standard snapping due to NLA-strip scaling complexities.
|
|
|
|
|
*
|
|
|
|
|
* TODO: these modifier checks should be accessible from the key-map.
|
|
|
|
|
*/
|
2021-08-19 09:52:09 -03:00
|
|
|
short getAnimEdit_SnapMode(TransInfo *t);
|
2021-08-19 10:28:43 -03:00
|
|
|
void snapFrameTransform(TransInfo *t,
|
2022-01-07 11:38:08 +11:00
|
|
|
eAnimEdit_AutoSnap autosnap,
|
|
|
|
|
float val_initial,
|
|
|
|
|
float val_final,
|
2021-08-19 10:28:43 -03:00
|
|
|
float *r_val_final);
|
2021-12-09 00:55:11 +11:00
|
|
|
/**
|
|
|
|
|
* This function is used by Animation Editor specific transform functions to do
|
|
|
|
|
* the Snap Keyframe to Nearest Frame/Marker
|
|
|
|
|
*/
|
2021-08-19 10:28:43 -03:00
|
|
|
void transform_snap_anim_flush_data(TransInfo *t,
|
|
|
|
|
TransData *td,
|
2022-01-07 11:38:08 +11:00
|
|
|
eAnimEdit_AutoSnap autosnap,
|
2021-08-19 10:28:43 -03:00
|
|
|
float *r_val_final);
|
2022-10-11 18:01:08 -05:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|