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
194 lines
4.7 KiB
C++
194 lines
4.7 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright 2001-2002 NaN Holding BV. All rights reserved. */
|
|
|
|
/** \file
|
|
* \ingroup edtransform
|
|
* \brief transform modes used by different operators.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
struct AnimData;
|
|
struct LinkNode;
|
|
struct TransData;
|
|
struct TransDataContainer;
|
|
struct TransInfo;
|
|
struct bContext;
|
|
struct wmOperator;
|
|
|
|
/* header of TransDataEdgeSlideVert, TransDataEdgeSlideEdge */
|
|
typedef struct TransDataGenericSlideVert {
|
|
struct BMVert *v;
|
|
struct LinkNode **cd_loop_groups;
|
|
float co_orig_3d[3];
|
|
} TransDataGenericSlideVert;
|
|
|
|
/* transform_mode.c */
|
|
|
|
eTfmMode transform_mode_really_used(struct bContext *C, eTfmMode mode);
|
|
bool transdata_check_local_center(const TransInfo *t, short around);
|
|
/**
|
|
* Informs if the mode can be switched during modal.
|
|
*/
|
|
bool transform_mode_is_changeable(int mode);
|
|
void protectedTransBits(short protectflag, float vec[3]);
|
|
void protectedSizeBits(short protectflag, float size[3]);
|
|
void constraintTransLim(const TransInfo *t, TransData *td);
|
|
void constraintSizeLim(const TransInfo *t, TransData *td);
|
|
/**
|
|
* Used by Transform Rotation and Transform Normal Rotation.
|
|
*/
|
|
void headerRotation(TransInfo *t, char *str, int str_size, float final);
|
|
/**
|
|
* Applies values of rotation to `td->loc` and `td->ext->quat`
|
|
* based on a rotation matrix (mat) and a pivot (center).
|
|
*
|
|
* Protected axis and other transform settings are taken into account.
|
|
*/
|
|
void ElementRotation_ex(const TransInfo *t,
|
|
const TransDataContainer *tc,
|
|
TransData *td,
|
|
const float mat[3][3],
|
|
const float *center);
|
|
void ElementRotation(const TransInfo *t,
|
|
const TransDataContainer *tc,
|
|
TransData *td,
|
|
const float mat[3][3],
|
|
short around);
|
|
void headerResize(TransInfo *t, const float vec[3], char *str, int str_size);
|
|
void ElementResize(const TransInfo *t,
|
|
const TransDataContainer *tc,
|
|
TransData *td,
|
|
const float mat[3][3]);
|
|
void transform_mode_init(TransInfo *t, struct wmOperator *op, int mode);
|
|
/**
|
|
* When in modal and not set, initializes a default orientation for the mode.
|
|
*/
|
|
void transform_mode_default_modal_orientation_set(TransInfo *t, int type);
|
|
|
|
/* transform_mode_align.c */
|
|
|
|
void initAlign(TransInfo *t);
|
|
|
|
/* transform_mode_baketime.c */
|
|
|
|
void initBakeTime(TransInfo *t);
|
|
|
|
/* transform_mode_bbone_resize.c */
|
|
|
|
void initBoneSize(TransInfo *t);
|
|
|
|
/* transform_mode_bend.c */
|
|
|
|
void initBend(TransInfo *t);
|
|
|
|
/* transform_mode_boneenvelope.c */
|
|
|
|
void initBoneEnvelope(TransInfo *t);
|
|
|
|
/* transform_mode_boneroll.c */
|
|
|
|
void initBoneRoll(TransInfo *t);
|
|
|
|
/* transform_mode_curveshrinkfatten.c */
|
|
|
|
void initCurveShrinkFatten(TransInfo *t);
|
|
|
|
/* transform_mode_edge_bevelweight.c */
|
|
|
|
void initBevelWeight(TransInfo *t);
|
|
|
|
/* transform_mode_edge_crease.c */
|
|
|
|
void initEgdeCrease(TransInfo *t);
|
|
void initVertCrease(TransInfo *t);
|
|
|
|
/* transform_mode_edge_rotate_normal.c */
|
|
|
|
void initNormalRotation(TransInfo *t);
|
|
|
|
/* transform_mode_edge_seq_slide.c */
|
|
|
|
void initSeqSlide(TransInfo *t);
|
|
|
|
/* transform_mode_edge_slide.c */
|
|
|
|
void drawEdgeSlide(TransInfo *t);
|
|
void initEdgeSlide_ex(
|
|
TransInfo *t, bool use_double_side, bool use_even, bool flipped, bool use_clamp);
|
|
void initEdgeSlide(TransInfo *t);
|
|
|
|
/* transform_mode_gpopacity.c */
|
|
|
|
void initGPOpacity(TransInfo *t);
|
|
|
|
/* transform_mode_gpshrinkfatten.c */
|
|
|
|
void initGPShrinkFatten(TransInfo *t);
|
|
|
|
/* transform_mode_maskshrinkfatten.c */
|
|
|
|
void initMaskShrinkFatten(TransInfo *t);
|
|
|
|
/* transform_mode_mirror.c */
|
|
|
|
void initMirror(TransInfo *t);
|
|
|
|
/* transform_mode_push_pull.c */
|
|
|
|
void initPushPull(TransInfo *t);
|
|
|
|
/* transform_mode_resize.c */
|
|
|
|
void initResize(TransInfo *t, float mouse_dir_constraint[3]);
|
|
|
|
/* transform_mode_rotate.c */
|
|
|
|
void initRotation(TransInfo *t);
|
|
|
|
/* transform_mode_shear.c */
|
|
|
|
void initShear(TransInfo *t);
|
|
|
|
/* transform_mode_shrink_fatten.c */
|
|
|
|
void initShrinkFatten(TransInfo *t);
|
|
|
|
/* transform_mode_skin_resize.c */
|
|
|
|
void initSkinResize(TransInfo *t);
|
|
|
|
/* transform_mode_tilt.c */
|
|
|
|
void initTilt(TransInfo *t);
|
|
|
|
/* transform_mode_timescale.c */
|
|
|
|
void initTimeScale(TransInfo *t);
|
|
|
|
/* transform_mode_timeslide.c */
|
|
|
|
void initTimeSlide(TransInfo *t);
|
|
|
|
/* transform_mode_timetranslate.c */
|
|
|
|
void initTimeTranslate(TransInfo *t);
|
|
|
|
/* transform_mode_tosphere.c */
|
|
|
|
void initToSphere(TransInfo *t);
|
|
|
|
/* transform_mode_trackball.c */
|
|
|
|
void initTrackball(TransInfo *t);
|
|
|
|
/* transform_mode_translate.c */
|
|
|
|
void initTranslation(TransInfo *t);
|
|
|
|
/* transform_mode_vert_slide.c */
|
|
|
|
void drawVertSlide(TransInfo *t);
|
|
void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp);
|
|
void initVertSlide(TransInfo *t);
|