2023-05-31 16:19:06 +02:00
|
|
|
|
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
|
|
|
|
|
*
|
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2011-02-27 20:29:51 +00:00
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
|
/** \file
|
|
|
|
|
|
* \ingroup edtransform
|
2011-02-27 20:29:51 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
2025-06-16 15:49:14 +02:00
|
|
|
|
#include "BLI_bounds.hh"
|
2025-02-11 16:59:42 +01:00
|
|
|
|
#include "BLI_listbase.h"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
|
#include "BLI_math_matrix.h"
|
|
|
|
|
|
#include "BLI_math_rotation.h"
|
2025-02-24 16:08:30 +01:00
|
|
|
|
#include "BLI_math_vector.h"
|
2024-01-19 14:32:28 +01:00
|
|
|
|
#include "BLI_time.h"
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
|
2025-02-11 16:59:42 +01:00
|
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
|
#include "GPU_immediate.hh"
|
|
|
|
|
|
#include "GPU_matrix.hh"
|
2025-01-26 20:08:00 +01:00
|
|
|
|
#include "GPU_state.hh"
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
|
#include "BKE_editmesh.hh"
|
2024-01-23 15:18:09 -05:00
|
|
|
|
#include "BKE_layer.hh"
|
2023-10-09 23:41:53 +02:00
|
|
|
|
#include "BKE_object.hh"
|
2024-02-10 19:16:25 +01:00
|
|
|
|
#include "BKE_scene.hh"
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
|
#include "RNA_access.hh"
|
2024-10-08 18:45:01 -03:00
|
|
|
|
#include "RNA_prototypes.hh"
|
2013-03-07 02:44:55 +00:00
|
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
|
#include "WM_api.hh"
|
2013-03-07 02:44:55 +00:00
|
|
|
|
|
2024-10-08 23:29:57 -03:00
|
|
|
|
#include "ED_image.hh"
|
2023-08-05 02:57:52 +02:00
|
|
|
|
#include "ED_node.hh"
|
|
|
|
|
|
#include "ED_transform_snap_object_context.hh"
|
|
|
|
|
|
#include "ED_uvedit.hh"
|
|
|
|
|
|
|
|
|
|
|
|
#include "UI_resources.hh"
|
|
|
|
|
|
#include "UI_view2d.hh"
|
2009-01-10 18:33:16 +00:00
|
|
|
|
|
2023-11-02 01:05:06 +01:00
|
|
|
|
#include "SEQ_sequencer.hh"
|
2021-06-29 20:12:19 +02:00
|
|
|
|
|
2023-07-13 17:59:52 +02:00
|
|
|
|
#include "transform.hh"
|
2024-04-01 11:12:39 -03:00
|
|
|
|
#include "transform_constraints.hh"
|
2023-07-13 17:59:52 +02:00
|
|
|
|
#include "transform_convert.hh"
|
|
|
|
|
|
#include "transform_mode.hh"
|
|
|
|
|
|
#include "transform_snap.hh"
|
2009-01-10 18:33:16 +00:00
|
|
|
|
|
2025-02-18 01:27:04 +01:00
|
|
|
|
namespace blender::ed::transform {
|
2023-08-02 15:00:47 -03:00
|
|
|
|
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Use half of flt-max so we can scale up without an exception. */
|
2012-10-05 01:34:47 +00:00
|
|
|
|
|
2019-10-28 09:32:59 -03:00
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
/** \name Prototypes
|
|
|
|
|
|
* \{ */
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
|
2011-11-15 16:38:48 +00:00
|
|
|
|
static void setSnappingCallback(TransInfo *t);
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
static void snap_target_view3d_fn(TransInfo *t, float *vec);
|
|
|
|
|
|
static void snap_target_uv_fn(TransInfo *t, float *vec);
|
|
|
|
|
|
static void snap_target_sequencer_fn(TransInfo *t, float *vec);
|
2023-10-20 14:24:50 +02:00
|
|
|
|
static void snap_target_nla_fn(TransInfo *t, float *vec);
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
static void snap_source_median_fn(TransInfo *t);
|
|
|
|
|
|
static void snap_source_center_fn(TransInfo *t);
|
|
|
|
|
|
static void snap_source_closest_fn(TransInfo *t);
|
|
|
|
|
|
static void snap_source_active_fn(TransInfo *t);
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
|
2024-04-01 11:12:39 -03:00
|
|
|
|
static eSnapMode snapObjectsTransform(
|
|
|
|
|
|
TransInfo *t, const float mval[2], float *dist_px, float r_loc[3], float r_no[3]);
|
2024-03-27 13:17:24 +01:00
|
|
|
|
|
2019-10-28 09:32:59 -03:00
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
/** \name Implementations
|
|
|
|
|
|
* \{ */
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
|
2011-02-07 12:07:26 +00:00
|
|
|
|
#if 0
|
2008-12-31 22:43:29 +00:00
|
|
|
|
int BIF_snappingSupported(Object *obedit)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
|
|
|
|
|
int status = 0;
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Only support object mesh, armature, curves. */
|
2023-07-12 14:18:59 +02:00
|
|
|
|
if (obedit == nullptr ||
|
|
|
|
|
|
ELEM(obedit->type, OB_MESH, OB_ARMATURE, OB_CURVES_LEGACY, OB_LATTICE, OB_MBALL))
|
|
|
|
|
|
{
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
status = 1;
|
|
|
|
|
|
}
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
return status;
|
|
|
|
|
|
}
|
2011-02-07 12:07:26 +00:00
|
|
|
|
#endif
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
|
2020-07-22 12:00:02 -03:00
|
|
|
|
static bool snap_use_backface_culling(const TransInfo *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
BLI_assert(t->spacetype == SPACE_VIEW3D);
|
2022-11-17 17:13:38 +01:00
|
|
|
|
View3D *v3d = static_cast<View3D *>(t->view);
|
2020-07-22 12:00:02 -03:00
|
|
|
|
if ((v3d->shading.type == OB_SOLID) && (v3d->shading.flag & V3D_SHADING_BACKFACE_CULLING)) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (v3d->shading.type == OB_RENDER &&
|
|
|
|
|
|
(t->scene->display.shading.flag & V3D_SHADING_BACKFACE_CULLING) &&
|
|
|
|
|
|
BKE_scene_uses_blender_workbench(t->scene))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (t->settings->snap_flag & SCE_SNAP_BACKFACE_CULLING) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-09 17:57:05 +02:00
|
|
|
|
bool validSnap(const TransInfo *t)
|
2009-12-03 19:18:00 +00:00
|
|
|
|
{
|
2023-01-12 10:16:25 -03:00
|
|
|
|
return (t->tsnap.status & (SNAP_TARGET_FOUND | SNAP_SOURCE_FOUND)) ==
|
|
|
|
|
|
(SNAP_TARGET_FOUND | SNAP_SOURCE_FOUND) ||
|
|
|
|
|
|
(t->tsnap.status & (SNAP_MULTI_POINTS | SNAP_SOURCE_FOUND)) ==
|
|
|
|
|
|
(SNAP_MULTI_POINTS | SNAP_SOURCE_FOUND);
|
2009-12-01 18:26:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-20 20:11:22 -03:00
|
|
|
|
void transform_snap_flag_from_modifiers_set(TransInfo *t)
|
|
|
|
|
|
{
|
2023-11-09 14:38:30 +01:00
|
|
|
|
if (ELEM(t->spacetype, SPACE_ACTION, SPACE_NLA)) {
|
2023-09-06 14:23:01 +10:00
|
|
|
|
/* Those space-types define their own invert behavior instead of toggling it on/off. */
|
2023-09-05 10:06:55 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-11-09 14:38:30 +01:00
|
|
|
|
if (t->spacetype == SPACE_GRAPH) {
|
|
|
|
|
|
/* This is to stay consistent with the behavior from 3.6. */
|
|
|
|
|
|
if (t->modifiers & MOD_SNAP_INVERT) {
|
|
|
|
|
|
t->tsnap.mode |= SCE_SNAP_TO_INCREMENT;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
t->tsnap.mode &= ~SCE_SNAP_TO_INCREMENT;
|
|
|
|
|
|
}
|
|
|
|
|
|
/* In 3.6 when snapping was disabled, pressing the invert button would turn on snapping.
|
|
|
|
|
|
* But it wouldn't turn it off when it was enabled. */
|
|
|
|
|
|
if ((t->modifiers & MOD_SNAP) || (t->modifiers & MOD_SNAP_INVERT)) {
|
|
|
|
|
|
t->tsnap.flag |= SCE_SNAP;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
t->tsnap.flag &= ~SCE_SNAP;
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-20 20:11:22 -03:00
|
|
|
|
SET_FLAG_FROM_TEST(t->tsnap.flag,
|
|
|
|
|
|
(((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP) ||
|
|
|
|
|
|
((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP_INVERT)),
|
|
|
|
|
|
SCE_SNAP);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-09 23:45:12 -03:00
|
|
|
|
bool transform_snap_is_active(const TransInfo *t)
|
2009-12-03 19:18:00 +00:00
|
|
|
|
{
|
2023-03-20 20:11:22 -03:00
|
|
|
|
return (t->tsnap.flag & SCE_SNAP) != 0;
|
2009-12-03 19:18:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-18 11:54:02 +01:00
|
|
|
|
bool transformModeUseSnap(const TransInfo *t)
|
2018-12-18 10:03:50 +11:00
|
|
|
|
{
|
2025-01-19 20:56:56 +01:00
|
|
|
|
/* The VSE and animation editors should not depend on the snapping options of the 3D viewport. */
|
|
|
|
|
|
if (ELEM(t->spacetype, SPACE_ACTION, SPACE_GRAPH, SPACE_NLA, SPACE_SEQ)) {
|
2024-01-04 14:03:57 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2018-12-18 11:54:02 +01:00
|
|
|
|
ToolSettings *ts = t->settings;
|
2018-12-18 10:03:50 +11:00
|
|
|
|
if (t->mode == TFM_TRANSLATION) {
|
2018-12-18 11:54:02 +01:00
|
|
|
|
return (ts->snap_transform_mode_flag & SCE_SNAP_TRANSFORM_MODE_TRANSLATE) != 0;
|
2018-12-18 10:03:50 +11:00
|
|
|
|
}
|
|
|
|
|
|
if (t->mode == TFM_ROTATION) {
|
2018-12-18 11:54:02 +01:00
|
|
|
|
return (ts->snap_transform_mode_flag & SCE_SNAP_TRANSFORM_MODE_ROTATE) != 0;
|
2018-12-18 10:03:50 +11:00
|
|
|
|
}
|
|
|
|
|
|
if (t->mode == TFM_RESIZE) {
|
2018-12-18 11:54:02 +01:00
|
|
|
|
return (ts->snap_transform_mode_flag & SCE_SNAP_TRANSFORM_MODE_SCALE) != 0;
|
2018-12-18 10:03:50 +11:00
|
|
|
|
}
|
2024-01-08 14:18:55 +01:00
|
|
|
|
if (ELEM(t->mode,
|
|
|
|
|
|
TFM_VERT_SLIDE,
|
|
|
|
|
|
TFM_EDGE_SLIDE,
|
|
|
|
|
|
TFM_SEQ_SLIDE,
|
|
|
|
|
|
TFM_TIME_TRANSLATE,
|
|
|
|
|
|
TFM_TIME_EXTEND))
|
|
|
|
|
|
{
|
2020-06-22 15:28:25 -03:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2018-12-18 10:03:50 +11:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-18 11:54:02 +01:00
|
|
|
|
static bool doForceIncrementSnap(const TransInfo *t)
|
|
|
|
|
|
{
|
2023-09-08 11:34:17 +02:00
|
|
|
|
if (ELEM(t->spacetype, SPACE_GRAPH, SPACE_ACTION, SPACE_NLA)) {
|
|
|
|
|
|
/* These spaces don't support increment snapping. */
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2025-01-19 20:56:56 +01:00
|
|
|
|
|
|
|
|
|
|
if (t->spacetype == SPACE_SEQ && ELEM(t->mode, TFM_ROTATION, TFM_RESIZE)) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-06 11:04:07 -03:00
|
|
|
|
if (t->modifiers & MOD_SNAP_FORCED) {
|
2023-01-24 17:06:53 -03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-18 14:19:59 -03:00
|
|
|
|
return !transformModeUseSnap(t);
|
2018-12-18 11:54:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-25 10:25:58 +10:00
|
|
|
|
void drawSnapping(TransInfo *t)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
2020-04-03 16:21:24 +11:00
|
|
|
|
uchar col[4], selectedCol[4], activeCol[4];
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
if (!(transform_snap_is_active(t) || t->modifiers & MOD_EDIT_SNAP_SOURCE)) {
|
2012-06-29 14:34:46 +00:00
|
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
|
}
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2023-06-23 15:36:57 -03:00
|
|
|
|
const bool draw_source = (t->flag & T_DRAW_SNAP_SOURCE) &&
|
|
|
|
|
|
(t->tsnap.status & (SNAP_SOURCE_FOUND | SNAP_MULTI_POINTS));
|
2023-06-09 14:12:15 +02:00
|
|
|
|
const bool draw_target = (t->tsnap.status & (SNAP_TARGET_FOUND | SNAP_MULTI_POINTS));
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
|
2023-06-09 14:12:15 +02:00
|
|
|
|
if (!(draw_source || draw_target)) {
|
2022-08-26 14:16:29 -03:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-05-03 10:09:22 -03:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
if (t->spacetype == SPACE_SEQ) {
|
|
|
|
|
|
UI_GetThemeColor3ubv(TH_SEQ_ACTIVE, col);
|
|
|
|
|
|
col[3] = 128;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (t->spacetype != SPACE_IMAGE) {
|
|
|
|
|
|
UI_GetThemeColor3ubv(TH_TRANSFORM, col);
|
|
|
|
|
|
col[3] = 128;
|
2022-05-03 10:09:22 -03:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
UI_GetThemeColor3ubv(TH_SELECT, selectedCol);
|
|
|
|
|
|
selectedCol[3] = 128;
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
UI_GetThemeColor3ubv(TH_ACTIVE, activeCol);
|
|
|
|
|
|
activeCol[3] = 192;
|
|
|
|
|
|
}
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
if (t->spacetype == SPACE_VIEW3D) {
|
2023-06-23 15:36:57 -03:00
|
|
|
|
const float *source_loc = nullptr;
|
|
|
|
|
|
const float *target_loc = nullptr;
|
2020-05-27 00:14:11 -03:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
GPU_depth_test(GPU_DEPTH_NONE);
|
2020-05-27 00:14:11 -03:00
|
|
|
|
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
RegionView3D *rv3d = (RegionView3D *)t->region->regiondata;
|
2023-06-06 15:30:18 -03:00
|
|
|
|
if (!BLI_listbase_is_empty(&t->tsnap.points)) {
|
2022-08-26 14:16:29 -03:00
|
|
|
|
/* Draw snap points. */
|
2020-05-27 00:14:11 -03:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
float size = 2.0f * UI_GetThemeValuef(TH_VERTEX_SIZE);
|
|
|
|
|
|
float view_inv[4][4];
|
|
|
|
|
|
copy_m4_m4(view_inv, rv3d->viewinv);
|
2020-05-27 00:14:11 -03:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
uint pos = GPU_vertformat_attr_add(
|
2025-06-10 17:20:45 +02:00
|
|
|
|
immVertexFormat(), "pos", blender::gpu::VertAttrType::SFLOAT_32_32_32);
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
if (!BLI_listbase_is_empty(&t->tsnap.points)) {
|
|
|
|
|
|
LISTBASE_FOREACH (TransSnapPoint *, p, &t->tsnap.points) {
|
|
|
|
|
|
if (p == t->tsnap.selectedPoint) {
|
|
|
|
|
|
immUniformColor4ubv(selectedCol);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
immUniformColor4ubv(col);
|
|
|
|
|
|
}
|
|
|
|
|
|
imm_drawcircball(p->co, ED_view3d_pixel_size(rv3d, p->co) * size, view_inv, pos);
|
2022-08-26 14:16:29 -03:00
|
|
|
|
}
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
2017-02-02 03:14:52 -02:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
immUnbindProgram();
|
|
|
|
|
|
}
|
2019-08-23 15:20:25 -03:00
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
if (draw_source) {
|
2023-06-23 15:36:57 -03:00
|
|
|
|
source_loc = t->tsnap.snap_source;
|
2022-08-26 14:16:29 -03:00
|
|
|
|
}
|
2017-02-02 03:14:52 -02:00
|
|
|
|
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
if (t->tsnap.status & SNAP_TARGET_FOUND) {
|
2023-06-23 15:36:57 -03:00
|
|
|
|
target_loc = t->tsnap.snap_target;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
2022-08-26 14:16:29 -03:00
|
|
|
|
|
2023-09-01 11:09:12 -07:00
|
|
|
|
ED_view3d_cursor_snap_draw_util(
|
2023-09-27 16:25:55 -03:00
|
|
|
|
rv3d, source_loc, target_loc, t->tsnap.source_type, t->tsnap.target_type, col, activeCol);
|
2023-09-01 17:08:07 +02:00
|
|
|
|
|
|
|
|
|
|
/* Draw normal if needed. */
|
2024-01-15 22:57:28 +11:00
|
|
|
|
if (target_loc && usingSnappingNormal(t) && validSnappingNormal(t)) {
|
2023-09-01 17:08:07 +02:00
|
|
|
|
uint pos = GPU_vertformat_attr_add(
|
2025-06-10 17:20:45 +02:00
|
|
|
|
immVertexFormat(), "pos", blender::gpu::VertAttrType::SFLOAT_32_32_32);
|
2023-09-01 17:08:07 +02:00
|
|
|
|
|
|
|
|
|
|
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
|
|
|
|
|
|
immUniformColor4ubv(activeCol);
|
|
|
|
|
|
immBegin(GPU_PRIM_LINES, 2);
|
|
|
|
|
|
immVertex3fv(pos, target_loc);
|
|
|
|
|
|
immVertex3f(pos,
|
|
|
|
|
|
target_loc[0] + t->tsnap.snapNormal[0],
|
|
|
|
|
|
target_loc[1] + t->tsnap.snapNormal[1],
|
|
|
|
|
|
target_loc[2] + t->tsnap.snapNormal[2]);
|
|
|
|
|
|
immEnd();
|
|
|
|
|
|
immUnbindProgram();
|
|
|
|
|
|
}
|
2022-08-26 14:16:29 -03:00
|
|
|
|
|
|
|
|
|
|
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
|
2012-06-29 14:34:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (t->spacetype == SPACE_IMAGE) {
|
2025-06-10 17:20:45 +02:00
|
|
|
|
uint pos = GPU_vertformat_attr_add(
|
|
|
|
|
|
immVertexFormat(), "pos", blender::gpu::VertAttrType::SFLOAT_32_32);
|
2022-05-03 10:09:22 -03:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
float x, y;
|
|
|
|
|
|
const float snap_point[2] = {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.snap_target[0] / t->aspect[0],
|
|
|
|
|
|
t->tsnap.snap_target[1] / t->aspect[1],
|
2022-08-26 14:16:29 -03:00
|
|
|
|
};
|
|
|
|
|
|
UI_view2d_view_to_region_fl(&t->region->v2d, UNPACK2(snap_point), &x, &y);
|
|
|
|
|
|
float radius = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE) * U.pixelsize;
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
GPU_matrix_push_projection();
|
|
|
|
|
|
wmOrtho2_region_pixelspace(t->region);
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2022-09-01 09:31:07 -03:00
|
|
|
|
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
|
2022-08-26 14:16:29 -03:00
|
|
|
|
immUniformColor3ub(255, 255, 255);
|
|
|
|
|
|
imm_draw_circle_wire_2d(pos, x, y, radius, 8);
|
|
|
|
|
|
immUnbindProgram();
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
GPU_matrix_pop_projection();
|
|
|
|
|
|
}
|
2021-06-29 20:12:19 +02:00
|
|
|
|
else if (t->spacetype == SPACE_SEQ) {
|
2023-08-25 10:25:58 +10:00
|
|
|
|
const ARegion *region = t->region;
|
2022-08-26 14:16:29 -03:00
|
|
|
|
GPU_blend(GPU_BLEND_ALPHA);
|
2025-06-10 17:20:45 +02:00
|
|
|
|
uint pos = GPU_vertformat_attr_add(
|
|
|
|
|
|
immVertexFormat(), "pos", blender::gpu::VertAttrType::SFLOAT_32_32);
|
2022-09-01 09:31:07 -03:00
|
|
|
|
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
|
2022-08-26 14:16:29 -03:00
|
|
|
|
immUniformColor4ubv(col);
|
|
|
|
|
|
float pixelx = BLI_rctf_size_x(®ion->v2d.cur) / BLI_rcti_size_x(®ion->v2d.mask);
|
2024-07-06 15:24:52 +02:00
|
|
|
|
|
|
|
|
|
|
if (region->regiontype == RGN_TYPE_PREVIEW) {
|
|
|
|
|
|
if (t->tsnap.direction & DIR_GLOBAL_X) {
|
|
|
|
|
|
immRectf(pos,
|
|
|
|
|
|
t->tsnap.snap_target[0] - pixelx,
|
|
|
|
|
|
region->v2d.cur.ymax,
|
|
|
|
|
|
t->tsnap.snap_target[0] + pixelx,
|
|
|
|
|
|
region->v2d.cur.ymin);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (t->tsnap.direction & DIR_GLOBAL_Y) {
|
|
|
|
|
|
immRectf(pos,
|
|
|
|
|
|
region->v2d.cur.xmin,
|
|
|
|
|
|
t->tsnap.snap_target[1] - pixelx,
|
|
|
|
|
|
region->v2d.cur.xmax,
|
|
|
|
|
|
t->tsnap.snap_target[1] + pixelx);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
immRectf(pos,
|
|
|
|
|
|
t->tsnap.snap_target[0] - pixelx,
|
|
|
|
|
|
region->v2d.cur.ymax,
|
|
|
|
|
|
t->tsnap.snap_target[0] + pixelx,
|
|
|
|
|
|
region->v2d.cur.ymin);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-26 14:16:29 -03:00
|
|
|
|
immUnbindProgram();
|
|
|
|
|
|
GPU_blend(GPU_BLEND_NONE);
|
2021-06-29 20:12:19 +02:00
|
|
|
|
}
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-23 06:48:36 +00:00
|
|
|
|
eRedrawFlag handleSnapping(TransInfo *t, const wmEvent *event)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
2013-10-23 06:48:36 +00:00
|
|
|
|
eRedrawFlag status = TREDRAW_NOTHING;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2024-03-09 23:25:40 +11:00
|
|
|
|
#if 0 /* XXX: need a proper selector for all snap mode. */
|
2022-02-24 22:48:34 +11:00
|
|
|
|
if (BIF_snappingSupported(t->obedit) && (event->type == EVT_TABKEY) &&
|
2023-07-12 14:18:59 +02:00
|
|
|
|
(event->modifier & KM_SHIFT))
|
|
|
|
|
|
{
|
2023-07-05 13:58:04 +10:00
|
|
|
|
/* Toggle snap and reinitialize. */
|
2009-06-23 00:41:55 +00:00
|
|
|
|
t->settings->snap_flag ^= SCE_SNAP;
|
2022-11-17 17:13:38 +01:00
|
|
|
|
initSnapping(t, nullptr);
|
2013-10-23 06:48:36 +00:00
|
|
|
|
status = TREDRAW_HARD;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
2009-11-26 19:47:55 +00:00
|
|
|
|
#endif
|
2012-04-28 06:31:57 +00:00
|
|
|
|
if (event->type == MOUSEMOVE) {
|
2011-12-26 20:23:07 +00:00
|
|
|
|
status |= updateSelectedSnapPoint(t);
|
|
|
|
|
|
}
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
return status;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-08 20:47:56 +02:00
|
|
|
|
static bool applyFaceProject(TransInfo *t,
|
|
|
|
|
|
TransDataContainer *tc,
|
|
|
|
|
|
TransData *td,
|
|
|
|
|
|
TransDataExtension *td_ext)
|
2009-10-22 23:22:05 +00:00
|
|
|
|
{
|
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
|
|
|
|
float iloc[3], loc[3], no[3];
|
|
|
|
|
|
float mval_fl[2];
|
|
|
|
|
|
|
|
|
|
|
|
copy_v3_v3(iloc, td->loc);
|
|
|
|
|
|
if (tc->use_local_mat) {
|
|
|
|
|
|
mul_m4_v3(tc->mat, iloc);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (t->options & CTX_OBJECT) {
|
2024-11-17 02:22:29 -03:00
|
|
|
|
Object *ob = static_cast<Object *>(td->extra);
|
|
|
|
|
|
BKE_object_eval_transform_all(t->depsgraph, t->scene, ob);
|
|
|
|
|
|
copy_v3_v3(iloc, ob->object_to_world().location());
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ED_view3d_project_float_global(t->region, iloc, mval_fl, V3D_PROJ_TEST_NOP) !=
|
2024-01-02 18:12:54 +01:00
|
|
|
|
V3D_PROJ_RET_OK)
|
|
|
|
|
|
{
|
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
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-17 17:13:38 +01:00
|
|
|
|
SnapObjectParams snap_object_params{};
|
2023-01-12 10:16:25 -03:00
|
|
|
|
snap_object_params.snap_target_select = t->tsnap.target_operation;
|
2022-11-17 17:13:38 +01:00
|
|
|
|
snap_object_params.edit_mode_type = (t->flag & T_EDIT) != 0 ? SNAP_GEOM_EDIT : SNAP_GEOM_FINAL;
|
2024-11-11 14:26:52 +01:00
|
|
|
|
snap_object_params.occlusion_test = SNAP_OCCLUSION_ALWAYS;
|
2023-03-20 18:51:09 -03:00
|
|
|
|
snap_object_params.use_backface_culling = (t->tsnap.flag & SCE_SNAP_BACKFACE_CULLING) != 0;
|
2022-11-17 17:13:38 +01:00
|
|
|
|
|
2025-02-18 01:27:04 +01:00
|
|
|
|
eSnapMode hit = blender::ed::transform::snap_object_project_view3d(
|
|
|
|
|
|
t->tsnap.object_context,
|
|
|
|
|
|
t->depsgraph,
|
|
|
|
|
|
t->region,
|
|
|
|
|
|
static_cast<const View3D *>(t->view),
|
|
|
|
|
|
SCE_SNAP_TO_FACE,
|
|
|
|
|
|
&snap_object_params,
|
|
|
|
|
|
nullptr,
|
|
|
|
|
|
mval_fl,
|
|
|
|
|
|
nullptr,
|
|
|
|
|
|
nullptr,
|
|
|
|
|
|
loc,
|
|
|
|
|
|
no);
|
2023-06-23 16:58:16 -03:00
|
|
|
|
if (hit != SCE_SNAP_TO_FACE) {
|
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
|
|
|
|
return false;
|
2021-01-18 10:57:35 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float tvec[3];
|
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
|
|
|
|
sub_v3_v3v3(tvec, loc, iloc);
|
2021-01-18 10:57:35 -03:00
|
|
|
|
|
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
|
|
|
|
mul_m3_v3(td->smtx, tvec);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
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
|
|
|
|
add_v3_v3(td->loc, tvec);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2023-03-20 18:51:09 -03:00
|
|
|
|
if ((t->tsnap.flag & SCE_SNAP_ROTATE) && (t->options & CTX_OBJECT)) {
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Handle alignment as well. */
|
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
|
|
|
|
const float *original_normal;
|
|
|
|
|
|
float mat[3][3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
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
|
|
|
|
/* In pose mode, we want to align normals with Y axis of bones. */
|
|
|
|
|
|
original_normal = td->axismtx[2];
|
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
|
|
|
|
|
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
|
|
|
|
rotation_between_vecs_to_mat3(mat, original_normal, no);
|
|
|
|
|
|
|
2025-07-08 20:47:56 +02:00
|
|
|
|
transform_data_ext_rotate(td, td_ext, mat, true);
|
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
|
|
|
|
|
|
|
|
|
|
/* TODO: support constraints for rotation too? see #ElementRotation. */
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void applyFaceNearest(TransInfo *t, TransDataContainer *tc, TransData *td)
|
|
|
|
|
|
{
|
|
|
|
|
|
float init_loc[3];
|
|
|
|
|
|
float prev_loc[3];
|
|
|
|
|
|
float snap_loc[3], snap_no[3];
|
2018-04-16 17:54:33 +02:00
|
|
|
|
|
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
|
|
|
|
copy_v3_v3(init_loc, td->iloc);
|
|
|
|
|
|
copy_v3_v3(prev_loc, td->loc);
|
|
|
|
|
|
if (tc->use_local_mat) {
|
|
|
|
|
|
mul_m4_v3(tc->mat, init_loc);
|
|
|
|
|
|
mul_m4_v3(tc->mat, prev_loc);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (t->options & CTX_OBJECT) {
|
2024-11-17 02:22:29 -03:00
|
|
|
|
Object *ob = static_cast<Object *>(td->extra);
|
|
|
|
|
|
BKE_object_eval_transform_all(t->depsgraph, t->scene, ob);
|
|
|
|
|
|
copy_v3_v3(init_loc, ob->object_to_world().location());
|
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
|
|
|
|
}
|
2018-04-16 17:54:33 +02:00
|
|
|
|
|
2022-11-17 17:13:38 +01:00
|
|
|
|
SnapObjectParams snap_object_params{};
|
2023-01-12 10:16:25 -03:00
|
|
|
|
snap_object_params.snap_target_select = t->tsnap.target_operation;
|
2022-11-17 17:13:38 +01:00
|
|
|
|
snap_object_params.edit_mode_type = (t->flag & T_EDIT) != 0 ? SNAP_GEOM_EDIT : SNAP_GEOM_FINAL;
|
2024-11-11 14:26:52 +01:00
|
|
|
|
snap_object_params.occlusion_test = SNAP_OCCLUSION_ALWAYS;
|
2022-11-17 17:13:38 +01:00
|
|
|
|
snap_object_params.use_backface_culling = false;
|
|
|
|
|
|
snap_object_params.face_nearest_steps = t->tsnap.face_nearest_steps;
|
|
|
|
|
|
snap_object_params.keep_on_same_target = t->tsnap.flag & SCE_SNAP_KEEP_ON_SAME_OBJECT;
|
|
|
|
|
|
|
2025-02-18 01:27:04 +01:00
|
|
|
|
eSnapMode hit = blender::ed::transform::snap_object_project_view3d(
|
|
|
|
|
|
t->tsnap.object_context,
|
|
|
|
|
|
t->depsgraph,
|
|
|
|
|
|
t->region,
|
|
|
|
|
|
static_cast<const View3D *>(t->view),
|
|
|
|
|
|
SCE_SNAP_INDIVIDUAL_NEAREST,
|
|
|
|
|
|
&snap_object_params,
|
|
|
|
|
|
init_loc,
|
|
|
|
|
|
nullptr,
|
|
|
|
|
|
prev_loc,
|
|
|
|
|
|
nullptr,
|
|
|
|
|
|
snap_loc,
|
|
|
|
|
|
snap_no);
|
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
|
|
|
|
|
2023-06-23 16:58:16 -03:00
|
|
|
|
if (hit != SCE_SNAP_INDIVIDUAL_NEAREST) {
|
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
|
|
|
|
return;
|
|
|
|
|
|
}
|
2014-07-31 17:02:03 +02:00
|
|
|
|
|
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
|
|
|
|
float tvec[3];
|
|
|
|
|
|
sub_v3_v3v3(tvec, snap_loc, prev_loc);
|
|
|
|
|
|
mul_m3_v3(td->smtx, tvec);
|
|
|
|
|
|
add_v3_v3(td->loc, tvec);
|
2014-07-31 17:02:03 +02:00
|
|
|
|
|
2023-06-23 16:58:16 -03:00
|
|
|
|
/* TODO: support snap alignment similar to #SCE_SNAP_INDIVIDUAL_PROJECT? */
|
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
|
|
|
|
}
|
2018-04-16 17:54:33 +02:00
|
|
|
|
|
2023-01-09 23:45:12 -03:00
|
|
|
|
bool transform_snap_project_individual_is_active(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
|
|
|
|
{
|
2023-01-09 23:56:14 -03:00
|
|
|
|
if (!transform_snap_is_active(t)) {
|
2023-01-09 23:45:12 -03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-23 16:58:16 -03:00
|
|
|
|
return (t->tsnap.mode & (SCE_SNAP_INDIVIDUAL_PROJECT | SCE_SNAP_INDIVIDUAL_NEAREST)) != 0;
|
2023-01-09 23:45:12 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void transform_snap_project_individual_apply(TransInfo *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!transform_snap_project_individual_is_active(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
|
|
|
|
return;
|
|
|
|
|
|
}
|
2018-04-16 17:54:33 +02:00
|
|
|
|
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* XXX: flickers in object mode. */
|
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
|
|
|
|
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
|
|
|
|
|
|
TransData *td = tc->data;
|
2025-07-08 20:47:56 +02:00
|
|
|
|
TransDataExtension *td_ext = tc->data_ext;
|
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
|
|
|
|
for (int i = 0; i < tc->data_len; i++, td++) {
|
|
|
|
|
|
if (td->flag & TD_SKIP) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2018-04-16 17:54:33 +02:00
|
|
|
|
|
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
|
|
|
|
if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) {
|
|
|
|
|
|
continue;
|
2021-01-18 10:57:35 -03:00
|
|
|
|
}
|
2018-04-16 17:54:33 +02:00
|
|
|
|
|
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
|
|
|
|
/* If both face ray-cast and face nearest methods are enabled, start with face ray-cast and
|
2025-06-02 17:13:56 -04:00
|
|
|
|
* fall back to face nearest ray-cast does not hit. */
|
2023-06-06 19:35:57 +02:00
|
|
|
|
bool hit = false;
|
2023-06-23 16:58:16 -03:00
|
|
|
|
if (t->tsnap.mode & SCE_SNAP_INDIVIDUAL_PROJECT) {
|
2025-07-08 20:47:56 +02:00
|
|
|
|
hit = applyFaceProject(t, tc, td, td_ext);
|
|
|
|
|
|
if (td_ext) {
|
|
|
|
|
|
td_ext++;
|
|
|
|
|
|
}
|
2023-06-06 19:35:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-23 16:58:16 -03:00
|
|
|
|
if (!hit && t->tsnap.mode & SCE_SNAP_INDIVIDUAL_NEAREST) {
|
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
|
|
|
|
applyFaceNearest(t, tc, td);
|
|
|
|
|
|
}
|
2021-02-05 16:23:34 +11:00
|
|
|
|
#if 0 /* TODO: support this? */
|
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
|
|
|
|
constraintTransLim(t, td);
|
2020-10-10 18:19:55 +11:00
|
|
|
|
#endif
|
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
|
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-09 23:45:12 -03:00
|
|
|
|
static bool transform_snap_mixed_is_active(const TransInfo *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!transform_snap_is_active(t)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-06 19:35:57 +02:00
|
|
|
|
return (t->tsnap.mode &
|
2023-06-23 16:58:16 -03:00
|
|
|
|
(SCE_SNAP_TO_VERTEX | SCE_SNAP_TO_EDGE | SCE_SNAP_TO_FACE | SCE_SNAP_TO_VOLUME |
|
2024-03-27 13:17:24 +01:00
|
|
|
|
SCE_SNAP_TO_EDGE_MIDPOINT | SCE_SNAP_TO_EDGE_PERPENDICULAR | SCE_SNAP_TO_GRID)) != 0;
|
2023-01-09 23:45:12 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void transform_snap_mixed_apply(TransInfo *t, float *vec)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
2023-01-09 23:45:12 -03:00
|
|
|
|
if (!transform_snap_mixed_is_active(t)) {
|
2018-06-04 13:33:19 -03:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2024-03-27 13:17:24 +01:00
|
|
|
|
if (t->tsnap.mode != SCE_SNAP_TO_INCREMENT) {
|
2024-02-15 13:15:56 +11:00
|
|
|
|
double current = BLI_time_now_seconds();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2021-02-13 17:44:51 +11:00
|
|
|
|
/* Time base quirky code to go around find-nearest slowness. */
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
/* TODO: add exception for object mode, no need to slow it down then. */
|
2012-05-20 19:49:27 +00:00
|
|
|
|
if (current - t->tsnap.last >= 0.01) {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
if (t->tsnap.snap_target_fn) {
|
|
|
|
|
|
t->tsnap.snap_target_fn(t, vec);
|
2021-12-16 13:45:27 -03:00
|
|
|
|
}
|
2023-01-12 10:16:25 -03:00
|
|
|
|
if (t->tsnap.snap_source_fn) {
|
|
|
|
|
|
t->tsnap.snap_source_fn(t);
|
2021-06-29 20:12:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-22 16:11:05 -03:00
|
|
|
|
t->tsnap.last = current;
|
|
|
|
|
|
}
|
2021-06-29 20:12:19 +02:00
|
|
|
|
|
2021-06-29 18:08:41 -03:00
|
|
|
|
if (validSnap(t)) {
|
2023-06-02 14:42:27 +02:00
|
|
|
|
t->mode_info->snap_apply_fn(t, vec);
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void resetSnapping(TransInfo *t)
|
|
|
|
|
|
{
|
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
|
|
|
|
t->tsnap.status = SNAP_RESETTED;
|
2023-09-27 16:25:55 -03:00
|
|
|
|
t->tsnap.source_type = SCE_SNAP_TO_NONE;
|
2023-06-23 15:36:57 -03:00
|
|
|
|
t->tsnap.target_type = SCE_SNAP_TO_NONE;
|
2023-06-23 16:58:16 -03:00
|
|
|
|
t->tsnap.mode = SCE_SNAP_TO_NONE;
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.target_operation = SCE_SNAP_TARGET_ALL;
|
|
|
|
|
|
t->tsnap.source_operation = SCE_SNAP_SOURCE_CLOSEST;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
t->tsnap.last = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
t->tsnap.snapNormal[0] = 0;
|
|
|
|
|
|
t->tsnap.snapNormal[1] = 0;
|
|
|
|
|
|
t->tsnap.snapNormal[2] = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-09 17:57:05 +02:00
|
|
|
|
bool usingSnappingNormal(const TransInfo *t)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
2023-03-20 18:51:09 -03:00
|
|
|
|
return (t->tsnap.flag & SCE_SNAP_ROTATE) != 0;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-09 17:57:05 +02:00
|
|
|
|
bool validSnappingNormal(const TransInfo *t)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
2012-04-28 06:31:57 +00:00
|
|
|
|
if (validSnap(t)) {
|
2014-03-29 22:23:27 +11:00
|
|
|
|
if (!is_zero_v3(t->tsnap.snapNormal)) {
|
2013-04-04 09:20:46 +00:00
|
|
|
|
return true;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2013-04-04 09:20:46 +00:00
|
|
|
|
return false;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-20 15:51:47 -03:00
|
|
|
|
static bool bm_edge_is_snap_target(BMEdge *e, void * /*user_data*/)
|
2016-05-06 07:44:07 +10:00
|
|
|
|
{
|
|
|
|
|
|
if (BM_elem_flag_test(e, BM_ELEM_SELECT | BM_ELEM_HIDDEN) ||
|
|
|
|
|
|
BM_elem_flag_test(e->v1, BM_ELEM_SELECT) || BM_elem_flag_test(e->v2, BM_ELEM_SELECT))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2016-05-06 07:44:07 +10:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-20 15:51:47 -03:00
|
|
|
|
static bool bm_face_is_snap_target(BMFace *f, void * /*user_data*/)
|
2016-05-06 07:44:07 +10:00
|
|
|
|
{
|
|
|
|
|
|
if (BM_elem_flag_test(f, BM_ELEM_SELECT | BM_ELEM_HIDDEN)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2016-05-06 07:44:07 +10:00
|
|
|
|
BMLoop *l_iter, *l_first;
|
|
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
|
|
|
|
|
|
do {
|
|
|
|
|
|
if (BM_elem_flag_test(l_iter->v, BM_ELEM_SELECT)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2016-05-06 07:44:07 +10:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-08 18:45:01 -03:00
|
|
|
|
short *transform_snap_flag_from_spacetype_ptr(TransInfo *t, const PropertyRNA **r_prop = nullptr)
|
2022-03-10 18:33:04 -03:00
|
|
|
|
{
|
|
|
|
|
|
ToolSettings *ts = t->settings;
|
2022-11-23 14:06:21 -03:00
|
|
|
|
switch (t->spacetype) {
|
|
|
|
|
|
case SPACE_VIEW3D:
|
2024-10-08 18:45:01 -03:00
|
|
|
|
if (r_prop) {
|
|
|
|
|
|
*r_prop = &rna_ToolSettings_use_snap;
|
|
|
|
|
|
}
|
|
|
|
|
|
return &ts->snap_flag;
|
2022-11-23 14:06:21 -03:00
|
|
|
|
case SPACE_NODE:
|
2024-10-08 18:45:01 -03:00
|
|
|
|
if (r_prop) {
|
|
|
|
|
|
*r_prop = &rna_ToolSettings_use_snap_node;
|
|
|
|
|
|
}
|
|
|
|
|
|
return &ts->snap_flag_node;
|
2022-11-23 14:06:21 -03:00
|
|
|
|
case SPACE_IMAGE:
|
2024-10-08 18:45:01 -03:00
|
|
|
|
if (r_prop) {
|
|
|
|
|
|
*r_prop = &rna_ToolSettings_use_snap_uv;
|
|
|
|
|
|
}
|
|
|
|
|
|
return &ts->snap_uv_flag;
|
2022-11-23 14:06:21 -03:00
|
|
|
|
case SPACE_SEQ:
|
2024-10-08 18:45:01 -03:00
|
|
|
|
if (r_prop) {
|
|
|
|
|
|
*r_prop = &rna_ToolSettings_use_snap_sequencer;
|
|
|
|
|
|
}
|
|
|
|
|
|
return &ts->snap_flag_seq;
|
2022-11-23 14:06:21 -03:00
|
|
|
|
case SPACE_ACTION:
|
|
|
|
|
|
case SPACE_NLA:
|
2024-10-08 18:45:01 -03:00
|
|
|
|
if (r_prop) {
|
|
|
|
|
|
*r_prop = &rna_ToolSettings_use_snap_anim;
|
|
|
|
|
|
}
|
|
|
|
|
|
return &ts->snap_flag_anim;
|
2025-04-15 12:35:18 +02:00
|
|
|
|
case SPACE_GRAPH: {
|
|
|
|
|
|
SpaceGraph *graph_editor = static_cast<SpaceGraph *>(t->area->spacedata.first);
|
|
|
|
|
|
switch (graph_editor->mode) {
|
|
|
|
|
|
case SIPO_MODE_DRIVERS:
|
|
|
|
|
|
/* The driver editor has a separate snapping flag so it can be kept disabled while
|
|
|
|
|
|
* keeping it enabled in the Graph Editor. */
|
|
|
|
|
|
return &ts->snap_flag_driver;
|
|
|
|
|
|
|
|
|
|
|
|
case SIPO_MODE_ANIMATION: {
|
|
|
|
|
|
if (r_prop) {
|
|
|
|
|
|
*r_prop = &rna_ToolSettings_use_snap_anim;
|
|
|
|
|
|
}
|
|
|
|
|
|
return &ts->snap_flag_anim;
|
|
|
|
|
|
}
|
|
|
|
|
|
default:
|
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-08 18:45:01 -03:00
|
|
|
|
}
|
|
|
|
|
|
/* #SPACE_EMPTY.
|
|
|
|
|
|
* It can happen when the operator is called via a handle in `bpy.app.handlers`. */
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static eSnapFlag snap_flag_from_spacetype(TransInfo *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (short *snap_flag = transform_snap_flag_from_spacetype_ptr(t)) {
|
|
|
|
|
|
return eSnapFlag(*snap_flag);
|
2022-11-23 14:06:21 -03:00
|
|
|
|
}
|
2024-10-08 18:45:01 -03:00
|
|
|
|
|
2022-11-28 15:49:18 -03:00
|
|
|
|
/* #SPACE_EMPTY.
|
|
|
|
|
|
* It can happen when the operator is called via a handle in `bpy.app.handlers`. */
|
2022-11-23 14:15:22 -03:00
|
|
|
|
return eSnapFlag(0);
|
2022-03-10 18:33:04 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
static eSnapMode snap_mode_from_spacetype(TransInfo *t)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
2009-06-23 00:41:55 +00:00
|
|
|
|
ToolSettings *ts = t->settings;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2012-06-29 14:34:46 +00:00
|
|
|
|
if (t->spacetype == SPACE_NODE) {
|
2022-11-17 17:13:38 +01:00
|
|
|
|
return eSnapMode(ts->snap_node_mode);
|
2012-06-29 14:34:46 +00:00
|
|
|
|
}
|
2022-03-28 13:01:08 -03:00
|
|
|
|
|
|
|
|
|
|
if (t->spacetype == SPACE_IMAGE) {
|
2024-03-27 13:17:24 +01:00
|
|
|
|
return eSnapMode(ts->snap_uv_mode);
|
2012-12-03 12:03:16 +00:00
|
|
|
|
}
|
2022-03-28 13:01:08 -03:00
|
|
|
|
|
|
|
|
|
|
if (t->spacetype == SPACE_SEQ) {
|
2025-03-06 13:04:39 +01:00
|
|
|
|
return eSnapMode(seq::tool_settings_snap_mode_get(t->scene));
|
2021-06-29 20:12:19 +02:00
|
|
|
|
}
|
2022-03-28 13:01:08 -03:00
|
|
|
|
|
2022-03-28 13:40:28 -03:00
|
|
|
|
if (t->spacetype == SPACE_VIEW3D) {
|
|
|
|
|
|
if (t->options & (CTX_CAMERA | CTX_EDGE_DATA | CTX_PAINT_CURVE)) {
|
2023-06-23 16:58:16 -03:00
|
|
|
|
return SCE_SNAP_TO_INCREMENT;
|
2020-08-31 10:14:40 -03:00
|
|
|
|
}
|
2022-03-28 13:40:28 -03:00
|
|
|
|
|
2024-03-27 13:17:24 +01:00
|
|
|
|
return eSnapMode(ts->snap_mode);
|
2009-03-29 19:52:53 +00:00
|
|
|
|
}
|
2022-03-28 13:01:08 -03:00
|
|
|
|
|
2025-04-15 12:35:18 +02:00
|
|
|
|
if (ELEM(t->spacetype, SPACE_ACTION, SPACE_NLA)) {
|
2023-09-05 10:06:55 +02:00
|
|
|
|
return eSnapMode(ts->snap_anim_mode);
|
2021-08-18 11:02:24 -03:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2025-04-15 12:35:18 +02:00
|
|
|
|
if (t->spacetype == SPACE_GRAPH) {
|
|
|
|
|
|
SpaceGraph *graph_editor = static_cast<SpaceGraph *>(t->area->spacedata.first);
|
|
|
|
|
|
switch (graph_editor->mode) {
|
|
|
|
|
|
case SIPO_MODE_DRIVERS:
|
|
|
|
|
|
/* Snapping to full values is the only mode that currently makes
|
|
|
|
|
|
* sense for the driver editor. */
|
|
|
|
|
|
return SCE_SNAP_TO_FRAME;
|
|
|
|
|
|
|
|
|
|
|
|
case SIPO_MODE_ANIMATION:
|
|
|
|
|
|
return eSnapMode(ts->snap_anim_mode);
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-23 16:58:16 -03:00
|
|
|
|
return SCE_SNAP_TO_INCREMENT;
|
2021-11-12 16:22:10 -03:00
|
|
|
|
}
|
2020-06-18 09:08:27 -03:00
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
static eSnapTargetOP snap_target_select_from_spacetype_and_tool_settings(TransInfo *t)
|
2021-11-12 16:22:10 -03:00
|
|
|
|
{
|
2023-01-12 10:16:25 -03:00
|
|
|
|
/* `t->tsnap.target_operation` not initialized yet. */
|
|
|
|
|
|
BLI_assert(t->tsnap.target_operation == SCE_SNAP_TARGET_ALL);
|
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
|
|
|
|
|
2025-09-14 11:08:50 +00:00
|
|
|
|
eSnapTargetOP target_operation = SCE_SNAP_TARGET_ALL;
|
2025-06-26 10:36:45 -03:00
|
|
|
|
|
2021-11-12 16:22:10 -03:00
|
|
|
|
if (ELEM(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE) && !(t->options & CTX_CAMERA)) {
|
2025-06-26 10:36:45 -03:00
|
|
|
|
BKE_view_layer_synced_ensure(t->scene, t->view_layer);
|
|
|
|
|
|
Base *base_act = BKE_view_layer_active_base_get(t->view_layer);
|
|
|
|
|
|
const int obedit_type = t->obedit_type;
|
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
|
|
|
|
if (base_act && (base_act->object->mode & OB_MODE_PARTICLE_EDIT)) {
|
|
|
|
|
|
/* Particles edit mode. */
|
|
|
|
|
|
}
|
2025-06-26 10:36:45 -03:00
|
|
|
|
else if (t->options & (CTX_GPENCIL_STROKES | CTX_CURSOR | CTX_OBMODE_XFORM_OBDATA)) {
|
2021-08-06 11:44:15 -03:00
|
|
|
|
/* In "Edit Strokes" mode,
|
2023-02-12 14:37:16 +11:00
|
|
|
|
* snap tool can perform snap to selected or active objects (see #49632)
|
2021-08-06 11:44:15 -03:00
|
|
|
|
* TODO: perform self snap in gpencil_strokes.
|
|
|
|
|
|
*
|
2023-02-12 14:37:16 +11:00
|
|
|
|
* When we're moving the origins, allow snapping onto our own geometry (see #69132). */
|
2021-08-06 11:44:15 -03:00
|
|
|
|
}
|
2025-06-26 10:36:45 -03:00
|
|
|
|
else if (obedit_type != -1) {
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Edit mode. */
|
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
|
|
|
|
if (obedit_type == OB_MESH) {
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Editing a mesh. */
|
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
|
|
|
|
if ((t->flag & T_PROP_EDIT) != 0) {
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Exclude editmesh when using proportional edit. */
|
2025-09-14 11:08:50 +00:00
|
|
|
|
target_operation |= SCE_SNAP_TARGET_NOT_EDITED;
|
2022-03-28 13:01:08 -03:00
|
|
|
|
}
|
2023-05-20 20:28:11 +10:00
|
|
|
|
/* UV editing must never snap to the selection as this is what is transformed. */
|
|
|
|
|
|
if (t->spacetype == SPACE_IMAGE) {
|
2025-09-14 11:08:50 +00:00
|
|
|
|
target_operation |= SCE_SNAP_TARGET_NOT_SELECTED;
|
2023-05-20 20:28:11 +10:00
|
|
|
|
}
|
2022-02-12 16:13:28 -03:00
|
|
|
|
}
|
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
|
|
|
|
else if (ELEM(obedit_type, OB_ARMATURE, OB_CURVES_LEGACY, OB_SURF, OB_LATTICE, OB_MBALL)) {
|
2025-06-26 10:36:45 -03:00
|
|
|
|
/* Temporary limited to edit mode armature, curves, surfaces, lattices, and meta-balls.
|
|
|
|
|
|
*/
|
2025-09-14 11:08:50 +00:00
|
|
|
|
target_operation |= SCE_SNAP_TARGET_NOT_SELECTED;
|
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
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
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
|
|
|
|
else {
|
|
|
|
|
|
/* Object or pose mode. */
|
2025-09-14 11:08:50 +00:00
|
|
|
|
target_operation |= SCE_SNAP_TARGET_NOT_SELECTED | SCE_SNAP_TARGET_NOT_ACTIVE;
|
2009-11-01 00:06:53 +00:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
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
|
|
|
|
else if (ELEM(t->spacetype, SPACE_NODE, SPACE_SEQ)) {
|
2025-09-14 11:08:50 +00:00
|
|
|
|
target_operation |= SCE_SNAP_TARGET_NOT_SELECTED;
|
2025-06-26 10:36:45 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Use scene defaults only when transform is modal. */
|
|
|
|
|
|
if (t->flag & T_MODAL) {
|
|
|
|
|
|
ToolSettings *ts = t->settings;
|
|
|
|
|
|
SET_FLAG_FROM_TEST(
|
2025-09-14 11:08:50 +00:00
|
|
|
|
target_operation, (ts->snap_flag & SCE_SNAP_NOT_TO_ACTIVE), SCE_SNAP_TARGET_NOT_ACTIVE);
|
|
|
|
|
|
SET_FLAG_FROM_TEST(target_operation,
|
2025-06-26 10:36:45 -03:00
|
|
|
|
!(ts->snap_flag & SCE_SNAP_TO_INCLUDE_EDITED),
|
|
|
|
|
|
SCE_SNAP_TARGET_NOT_EDITED);
|
2025-09-14 11:08:50 +00:00
|
|
|
|
SET_FLAG_FROM_TEST(target_operation,
|
2025-06-26 10:36:45 -03:00
|
|
|
|
!(ts->snap_flag & SCE_SNAP_TO_INCLUDE_NONEDITED),
|
|
|
|
|
|
SCE_SNAP_TARGET_NOT_NONEDITED);
|
2025-09-14 11:08:50 +00:00
|
|
|
|
SET_FLAG_FROM_TEST(target_operation,
|
2025-06-26 10:36:45 -03:00
|
|
|
|
(ts->snap_flag & SCE_SNAP_TO_ONLY_SELECTABLE),
|
|
|
|
|
|
SCE_SNAP_TARGET_ONLY_SELECTABLE);
|
2021-11-12 16:22:10 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-14 11:08:50 +00:00
|
|
|
|
return target_operation;
|
2021-11-12 16:22:10 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
static void snap_object_context_init(TransInfo *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (t->data_type == &TransConvertType_Mesh) {
|
|
|
|
|
|
/* Ignore elements being transformed. */
|
2025-02-18 01:27:04 +01:00
|
|
|
|
blender::ed::transform::snap_object_context_set_editmesh_callbacks(
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
t->tsnap.object_context,
|
|
|
|
|
|
(bool (*)(BMVert *, void *))BM_elem_cb_check_hflag_disabled,
|
|
|
|
|
|
bm_edge_is_snap_target,
|
|
|
|
|
|
bm_face_is_snap_target,
|
|
|
|
|
|
POINTER_FROM_UINT(BM_ELEM_SELECT | BM_ELEM_HIDDEN));
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
/* Ignore hidden geometry in the general case. */
|
2025-02-18 01:27:04 +01:00
|
|
|
|
blender::ed::transform::snap_object_context_set_editmesh_callbacks(
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
t->tsnap.object_context,
|
|
|
|
|
|
(bool (*)(BMVert *, void *))BM_elem_cb_check_hflag_disabled,
|
|
|
|
|
|
(bool (*)(BMEdge *, void *))BM_elem_cb_check_hflag_disabled,
|
|
|
|
|
|
(bool (*)(BMFace *, void *))BM_elem_cb_check_hflag_disabled,
|
|
|
|
|
|
POINTER_FROM_UINT(BM_ELEM_HIDDEN));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-12 16:22:10 -03:00
|
|
|
|
static void initSnappingMode(TransInfo *t)
|
|
|
|
|
|
{
|
2023-03-31 16:30:55 -03:00
|
|
|
|
if (!transformModeUseSnap(t)) {
|
|
|
|
|
|
/* In this case, snapping is always disabled by default. */
|
|
|
|
|
|
t->modifiers &= ~MOD_SNAP;
|
|
|
|
|
|
}
|
2025-06-26 10:36:45 -03:00
|
|
|
|
else if (t->flag & T_MODAL) {
|
|
|
|
|
|
/* Use scene defaults only when transform is modal. */
|
|
|
|
|
|
if (t->tsnap.flag & SCE_SNAP) {
|
|
|
|
|
|
t->modifiers |= MOD_SNAP;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-31 16:30:55 -03:00
|
|
|
|
|
2023-03-20 20:11:22 -03:00
|
|
|
|
if (doForceIncrementSnap(t)) {
|
2023-06-23 16:58:16 -03:00
|
|
|
|
t->tsnap.mode = SCE_SNAP_TO_INCREMENT;
|
2023-03-20 20:11:22 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-06 19:35:57 +02:00
|
|
|
|
if ((t->spacetype != SPACE_VIEW3D) || (t->flag & T_NO_PROJECT)) {
|
2021-11-12 16:22:10 -03:00
|
|
|
|
/* Force project off when not supported. */
|
2023-06-23 16:58:16 -03:00
|
|
|
|
t->tsnap.mode &= ~(SCE_SNAP_INDIVIDUAL_PROJECT | SCE_SNAP_INDIVIDUAL_NEAREST);
|
2023-03-31 17:30:26 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-23 16:58:16 -03:00
|
|
|
|
if (t->tsnap.mode & SCE_SNAP_TO_EDGE_PERPENDICULAR) {
|
2023-06-09 14:12:15 +02:00
|
|
|
|
t->flag |= T_DRAW_SNAP_SOURCE;
|
|
|
|
|
|
}
|
2009-12-03 19:18:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-08 23:29:57 -03:00
|
|
|
|
void transform_snap_grid_init(const TransInfo *t, float r_snap[3], float *r_snap_precision)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Default values. */
|
|
|
|
|
|
r_snap[0] = r_snap[1] = 1.0f;
|
|
|
|
|
|
r_snap[2] = 0.0f;
|
|
|
|
|
|
*r_snap_precision = 0.1f;
|
|
|
|
|
|
|
|
|
|
|
|
if (t->spacetype == SPACE_VIEW3D) {
|
|
|
|
|
|
/* Used by incremental snap. */
|
2025-06-26 05:00:31 +00:00
|
|
|
|
if (t->region->regiontype == RGN_TYPE_WINDOW) {
|
2024-10-08 23:29:57 -03:00
|
|
|
|
View3D *v3d = static_cast<View3D *>(t->area->spacedata.first);
|
|
|
|
|
|
r_snap[0] = r_snap[1] = r_snap[2] = ED_view3d_grid_view_scale(
|
|
|
|
|
|
t->scene, v3d, t->region, nullptr);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (t->spacetype == SPACE_IMAGE) {
|
|
|
|
|
|
SpaceImage *sima = static_cast<SpaceImage *>(t->area->spacedata.first);
|
|
|
|
|
|
const View2D *v2d = &t->region->v2d;
|
|
|
|
|
|
int grid_size = SI_GRID_STEPS_LEN;
|
|
|
|
|
|
float zoom_factor = ED_space_image_zoom_level(v2d, grid_size);
|
|
|
|
|
|
float grid_steps_x[SI_GRID_STEPS_LEN];
|
|
|
|
|
|
float grid_steps_y[SI_GRID_STEPS_LEN];
|
|
|
|
|
|
|
|
|
|
|
|
ED_space_image_grid_steps(sima, grid_steps_x, grid_steps_y, grid_size);
|
|
|
|
|
|
/* Snapping value based on what type of grid is used (adaptive-subdividing or custom-grid). */
|
|
|
|
|
|
r_snap[0] = ED_space_image_increment_snap_value(grid_size, grid_steps_x, zoom_factor);
|
|
|
|
|
|
r_snap[1] = ED_space_image_increment_snap_value(grid_size, grid_steps_y, zoom_factor);
|
|
|
|
|
|
*r_snap_precision = 0.5f;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (t->spacetype == SPACE_CLIP) {
|
|
|
|
|
|
r_snap[0] = r_snap[1] = 0.125f;
|
|
|
|
|
|
*r_snap_precision = 0.5f;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (t->spacetype == SPACE_NODE) {
|
2025-02-18 01:27:04 +01:00
|
|
|
|
r_snap[0] = r_snap[1] = space_node::grid_size_get();
|
2024-10-08 23:29:57 -03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
void transform_snap_reset_from_mode(TransInfo *t, wmOperator *op)
|
2009-12-03 19:18:00 +00:00
|
|
|
|
{
|
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
|
|
|
|
ToolSettings *ts = t->settings;
|
2023-01-12 10:16:25 -03:00
|
|
|
|
eSnapSourceOP snap_source = eSnapSourceOP(ts->snap_target);
|
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
|
|
|
|
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
resetSnapping(t);
|
2025-06-26 10:36:45 -03:00
|
|
|
|
|
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
|
|
|
|
t->tsnap.mode = snap_mode_from_spacetype(t);
|
2022-03-10 18:33:04 -03:00
|
|
|
|
t->tsnap.flag = snap_flag_from_spacetype(t);
|
2025-06-26 10:36:45 -03:00
|
|
|
|
t->tsnap.target_operation = snap_target_select_from_spacetype_and_tool_settings(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
|
|
|
|
t->tsnap.face_nearest_steps = max_ii(ts->snap_face_nearest_steps, 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
initSnappingMode(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
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
/* Overwrite defaults with values in properties. */
|
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
if (op && (prop = RNA_struct_find_property(op->ptr, "snap"))) {
|
|
|
|
|
|
if (RNA_property_is_set(op->ptr, prop)) {
|
|
|
|
|
|
SET_FLAG_FROM_TEST(t->modifiers, RNA_property_boolean_get(op->ptr, prop), MOD_SNAP);
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "snap_elements")) &&
|
|
|
|
|
|
RNA_property_is_set(op->ptr, prop))
|
|
|
|
|
|
{
|
|
|
|
|
|
t->tsnap.mode = eSnapMode(RNA_property_enum_get(op->ptr, prop));
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
/* 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). */
|
|
|
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "snap_target")) &&
|
|
|
|
|
|
RNA_property_is_set(op->ptr, prop))
|
|
|
|
|
|
{
|
|
|
|
|
|
snap_source = eSnapSourceOP(RNA_property_enum_get(op->ptr, prop));
|
|
|
|
|
|
}
|
2023-03-20 18:51:09 -03:00
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "snap_point")) &&
|
|
|
|
|
|
RNA_property_is_set(op->ptr, prop))
|
|
|
|
|
|
{
|
|
|
|
|
|
RNA_property_float_get_array(op->ptr, prop, t->tsnap.snap_target);
|
|
|
|
|
|
t->modifiers |= MOD_SNAP_FORCED;
|
|
|
|
|
|
t->tsnap.status |= SNAP_TARGET_FOUND;
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
/* Snap align only defined in specific cases. */
|
|
|
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "snap_align")) &&
|
|
|
|
|
|
RNA_property_is_set(op->ptr, prop))
|
|
|
|
|
|
{
|
|
|
|
|
|
SET_FLAG_FROM_TEST(t->tsnap.flag, RNA_property_boolean_get(op->ptr, prop), SCE_SNAP_ROTATE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
RNA_float_get_array(op->ptr, "snap_normal", t->tsnap.snapNormal);
|
|
|
|
|
|
normalize_v3(t->tsnap.snapNormal);
|
|
|
|
|
|
}
|
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
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "use_snap_project")) &&
|
|
|
|
|
|
RNA_property_is_set(op->ptr, prop))
|
|
|
|
|
|
{
|
|
|
|
|
|
SET_FLAG_FROM_TEST(
|
|
|
|
|
|
t->tsnap.mode, RNA_property_boolean_get(op->ptr, prop), SCE_SNAP_INDIVIDUAL_PROJECT);
|
|
|
|
|
|
}
|
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
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
/* Use_snap_self is misnamed and should be use_snap_active. */
|
|
|
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "use_snap_self")) &&
|
|
|
|
|
|
RNA_property_is_set(op->ptr, prop))
|
|
|
|
|
|
{
|
|
|
|
|
|
SET_FLAG_FROM_TEST(t->tsnap.target_operation,
|
|
|
|
|
|
!RNA_property_boolean_get(op->ptr, prop),
|
|
|
|
|
|
SCE_SNAP_TARGET_NOT_ACTIVE);
|
|
|
|
|
|
}
|
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
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "use_snap_edit")) &&
|
|
|
|
|
|
RNA_property_is_set(op->ptr, prop))
|
|
|
|
|
|
{
|
|
|
|
|
|
SET_FLAG_FROM_TEST(t->tsnap.target_operation,
|
|
|
|
|
|
!RNA_property_boolean_get(op->ptr, prop),
|
|
|
|
|
|
SCE_SNAP_TARGET_NOT_EDITED);
|
2009-03-29 19:52:53 +00:00
|
|
|
|
}
|
2025-06-26 10:36:45 -03:00
|
|
|
|
|
|
|
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "use_snap_nonedit")) &&
|
|
|
|
|
|
RNA_property_is_set(op->ptr, prop))
|
|
|
|
|
|
{
|
|
|
|
|
|
SET_FLAG_FROM_TEST(t->tsnap.target_operation,
|
|
|
|
|
|
!RNA_property_boolean_get(op->ptr, prop),
|
|
|
|
|
|
SCE_SNAP_TARGET_NOT_NONEDITED);
|
2021-06-29 20:12:19 +02:00
|
|
|
|
}
|
2022-03-10 18:33:04 -03:00
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "use_snap_selectable")) &&
|
|
|
|
|
|
RNA_property_is_set(op->ptr, prop))
|
|
|
|
|
|
{
|
|
|
|
|
|
SET_FLAG_FROM_TEST(t->tsnap.target_operation,
|
|
|
|
|
|
RNA_property_boolean_get(op->ptr, prop),
|
|
|
|
|
|
SCE_SNAP_TARGET_ONLY_SELECTABLE);
|
|
|
|
|
|
}
|
2009-10-12 22:33:32 +00:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.source_operation = snap_source;
|
2025-06-26 10:36:45 -03:00
|
|
|
|
transform_snap_flag_from_modifiers_set(t);
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2025-06-26 10:36:45 -03:00
|
|
|
|
void initSnapping(TransInfo *t, wmOperator *op)
|
|
|
|
|
|
{
|
|
|
|
|
|
transform_snap_reset_from_mode(t, op);
|
2024-10-08 23:29:57 -03:00
|
|
|
|
transform_snap_grid_init(t, t->snap_spatial, &t->snap_spatial_precision);
|
2025-06-26 10:36:45 -03:00
|
|
|
|
setSnappingCallback(t);
|
|
|
|
|
|
|
|
|
|
|
|
if (t->spacetype == SPACE_VIEW3D) {
|
|
|
|
|
|
if (t->tsnap.object_context == nullptr) {
|
|
|
|
|
|
SET_FLAG_FROM_TEST(t->tsnap.flag, snap_use_backface_culling(t), SCE_SNAP_BACKFACE_CULLING);
|
|
|
|
|
|
t->tsnap.object_context = snap_object_context_create(t->scene, 0);
|
|
|
|
|
|
snap_object_context_init(t);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (t->spacetype == SPACE_SEQ) {
|
|
|
|
|
|
if (t->tsnap.seq_context == nullptr) {
|
|
|
|
|
|
t->tsnap.seq_context = snap_sequencer_data_alloc(t);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-25 17:31:01 +02:00
|
|
|
|
|
|
|
|
|
|
/* Default increment values. */
|
|
|
|
|
|
t->increment = float3(1.0f);
|
|
|
|
|
|
t->increment_precision = 0.1f;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-21 11:29:32 +10:00
|
|
|
|
void freeSnapping(TransInfo *t)
|
|
|
|
|
|
{
|
2021-06-29 20:12:19 +02:00
|
|
|
|
if ((t->spacetype == SPACE_SEQ) && t->tsnap.seq_context) {
|
2025-02-18 01:27:04 +01:00
|
|
|
|
snap_sequencer_data_free(t->tsnap.seq_context);
|
2022-11-17 17:13:38 +01:00
|
|
|
|
t->tsnap.seq_context = nullptr;
|
2021-06-29 20:12:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
else if (t->tsnap.object_context) {
|
2025-02-18 01:27:04 +01:00
|
|
|
|
blender::ed::transform::snap_object_context_destroy(t->tsnap.object_context);
|
2022-11-17 17:13:38 +01:00
|
|
|
|
t->tsnap.object_context = nullptr;
|
2023-06-20 22:06:04 -03:00
|
|
|
|
|
|
|
|
|
|
ED_transform_snap_object_time_average_print();
|
2016-04-21 11:29:32 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-09 16:50:06 +11:00
|
|
|
|
void initSnapAngleIncrements(TransInfo *t)
|
|
|
|
|
|
{
|
2025-06-25 17:31:01 +02:00
|
|
|
|
/* The final value of increment with precision is `t->increment[0] * t->increment_precision`.
|
|
|
|
|
|
* Therefore, we divide `snap_angle_increment_*_precision` by `snap_angle_increment_*`
|
|
|
|
|
|
* to compute `increment_precision`. */
|
2025-06-26 10:36:45 -03:00
|
|
|
|
float increment;
|
|
|
|
|
|
float increment_precision;
|
2024-03-09 16:50:06 +11:00
|
|
|
|
if (t->spacetype == SPACE_VIEW3D) {
|
2025-06-26 10:36:45 -03:00
|
|
|
|
increment = t->settings->snap_angle_increment_3d;
|
|
|
|
|
|
increment_precision = t->settings->snap_angle_increment_3d_precision;
|
2024-03-09 16:50:06 +11:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
2025-06-26 10:36:45 -03:00
|
|
|
|
increment = t->settings->snap_angle_increment_2d;
|
|
|
|
|
|
increment_precision = t->settings->snap_angle_increment_2d_precision;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
t->increment[0] = increment;
|
|
|
|
|
|
if (increment != 0.0f) {
|
|
|
|
|
|
t->increment_precision = float(double(increment_precision) / double(increment));
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
t->increment_precision = 1.0f;
|
2024-03-09 16:50:06 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-11-15 16:38:48 +00:00
|
|
|
|
static void setSnappingCallback(TransInfo *t)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
2021-06-29 17:38:34 -03:00
|
|
|
|
if (t->spacetype == SPACE_VIEW3D) {
|
2023-01-10 09:35:59 -03:00
|
|
|
|
if (t->options & CTX_CAMERA) {
|
|
|
|
|
|
/* Not with camera selected in camera view. */
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.snap_target_fn = snap_target_view3d_fn;
|
2021-06-29 17:38:34 -03:00
|
|
|
|
}
|
2021-12-16 13:45:27 -03:00
|
|
|
|
else if (t->spacetype == SPACE_IMAGE) {
|
2022-11-17 17:13:38 +01:00
|
|
|
|
SpaceImage *sima = static_cast<SpaceImage *>(t->area->spacedata.first);
|
2022-09-14 21:33:51 +02:00
|
|
|
|
BKE_view_layer_synced_ensure(t->scene, t->view_layer);
|
|
|
|
|
|
Object *obact = BKE_view_layer_active_object_get(t->view_layer);
|
2021-12-16 13:45:27 -03:00
|
|
|
|
|
|
|
|
|
|
const bool is_uv_editor = sima->mode == SI_MODE_UV;
|
|
|
|
|
|
const bool has_edit_object = obact && BKE_object_is_in_editmode(obact);
|
|
|
|
|
|
if (is_uv_editor && has_edit_object) {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.snap_target_fn = snap_target_uv_fn;
|
2021-12-16 13:45:27 -03:00
|
|
|
|
}
|
2021-06-29 17:38:34 -03:00
|
|
|
|
}
|
|
|
|
|
|
else if (t->spacetype == SPACE_NODE) {
|
2024-11-24 14:30:22 +01:00
|
|
|
|
/* Pass. */
|
2021-06-29 17:38:34 -03:00
|
|
|
|
}
|
|
|
|
|
|
else if (t->spacetype == SPACE_SEQ) {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.snap_target_fn = snap_target_sequencer_fn;
|
2021-06-29 20:12:19 +02:00
|
|
|
|
/* The target is calculated along with the snap point. */
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-10-20 14:24:50 +02:00
|
|
|
|
else if (t->spacetype == SPACE_NLA) {
|
|
|
|
|
|
t->tsnap.snap_target_fn = snap_target_nla_fn;
|
|
|
|
|
|
/* The target is calculated along with the snap point. */
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-01-10 09:35:59 -03:00
|
|
|
|
else {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-06-29 20:12:19 +02:00
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
switch (t->tsnap.source_operation) {
|
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
|
|
|
|
case SCE_SNAP_SOURCE_CLOSEST:
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.snap_source_fn = snap_source_closest_fn;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
break;
|
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
|
|
|
|
case SCE_SNAP_SOURCE_CENTER:
|
2020-06-19 09:44:57 +10:00
|
|
|
|
if (!ELEM(t->mode, TFM_ROTATION, TFM_RESIZE)) {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.snap_source_fn = snap_source_center_fn;
|
2020-06-18 09:08:27 -03:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-06-19 09:44:57 +10:00
|
|
|
|
/* Can't do TARGET_CENTER with these modes,
|
|
|
|
|
|
* use TARGET_MEDIAN instead. */
|
|
|
|
|
|
ATTR_FALLTHROUGH;
|
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
|
|
|
|
case SCE_SNAP_SOURCE_MEDIAN:
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.snap_source_fn = snap_source_median_fn;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
break;
|
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
|
|
|
|
case SCE_SNAP_SOURCE_ACTIVE:
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.snap_source_fn = snap_source_active_fn;
|
2023-03-24 17:04:51 -03:00
|
|
|
|
|
|
|
|
|
|
/* XXX, workaround: active needs to be calculated before transforming, otherwise
|
|
|
|
|
|
* `t->tsnap.snap_source` will be calculated with the transformed data since we're not
|
|
|
|
|
|
* reading from 'td->center' in this case. (See: #40241 and #40348). */
|
|
|
|
|
|
snap_source_active_fn(t);
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-12-01 18:26:18 +00:00
|
|
|
|
void addSnapPoint(TransInfo *t)
|
|
|
|
|
|
{
|
2014-07-28 17:10:33 +06:00
|
|
|
|
/* Currently only 3D viewport works for snapping points. */
|
2023-01-12 10:16:25 -03:00
|
|
|
|
if (t->tsnap.status & SNAP_TARGET_FOUND && t->spacetype == SPACE_VIEW3D) {
|
2025-03-05 16:35:09 +01:00
|
|
|
|
TransSnapPoint *p = MEM_callocN<TransSnapPoint>("SnapPoint");
|
2009-12-01 18:26:18 +00:00
|
|
|
|
|
2011-12-26 20:23:07 +00:00
|
|
|
|
t->tsnap.selectedPoint = p;
|
|
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
copy_v3_v3(p->co, t->tsnap.snap_target);
|
2009-12-01 18:26:18 +00:00
|
|
|
|
|
|
|
|
|
|
BLI_addtail(&t->tsnap.points, p);
|
|
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.status |= SNAP_MULTI_POINTS;
|
2009-12-01 18:26:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-23 06:48:36 +00:00
|
|
|
|
eRedrawFlag updateSelectedSnapPoint(TransInfo *t)
|
2011-12-26 20:23:07 +00:00
|
|
|
|
{
|
2013-10-23 06:48:36 +00:00
|
|
|
|
eRedrawFlag status = TREDRAW_NOTHING;
|
|
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
if (t->tsnap.status & SNAP_MULTI_POINTS) {
|
2023-08-04 08:51:13 +10:00
|
|
|
|
TransSnapPoint *closest_p = nullptr;
|
2014-02-03 02:46:45 +11:00
|
|
|
|
float dist_min_sq = TRANSFORM_SNAP_MAX_PX;
|
2013-04-03 07:36:37 +00:00
|
|
|
|
float screen_loc[2];
|
2011-12-26 20:23:07 +00:00
|
|
|
|
|
2023-08-04 08:51:13 +10:00
|
|
|
|
LISTBASE_FOREACH (TransSnapPoint *, p, &t->tsnap.points) {
|
2014-02-03 02:46:45 +11:00
|
|
|
|
float dist_sq;
|
2011-12-26 20:23:07 +00:00
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
|
if (ED_view3d_project_float_global(t->region, p->co, screen_loc, V3D_PROJ_TEST_NOP) !=
|
2013-04-03 07:36:37 +00:00
|
|
|
|
V3D_PROJ_RET_OK)
|
|
|
|
|
|
{
|
2012-10-04 17:52:12 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2011-12-26 20:23:07 +00:00
|
|
|
|
|
2023-08-02 15:00:47 -03:00
|
|
|
|
dist_sq = len_squared_v2v2(t->mval, screen_loc);
|
2011-12-26 20:23:07 +00:00
|
|
|
|
|
2014-02-03 02:46:45 +11:00
|
|
|
|
if (dist_sq < dist_min_sq) {
|
2011-12-26 20:23:07 +00:00
|
|
|
|
closest_p = p;
|
2014-02-03 02:46:45 +11:00
|
|
|
|
dist_min_sq = dist_sq;
|
2011-12-26 20:23:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (closest_p) {
|
2013-10-23 06:48:36 +00:00
|
|
|
|
if (t->tsnap.selectedPoint != closest_p) {
|
|
|
|
|
|
status = TREDRAW_HARD;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-12-26 20:23:07 +00:00
|
|
|
|
t->tsnap.selectedPoint = closest_p;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-12-01 18:26:18 +00:00
|
|
|
|
void removeSnapPoint(TransInfo *t)
|
|
|
|
|
|
{
|
2023-01-12 10:16:25 -03:00
|
|
|
|
if (t->tsnap.status & SNAP_MULTI_POINTS) {
|
2011-12-26 20:23:07 +00:00
|
|
|
|
updateSelectedSnapPoint(t);
|
|
|
|
|
|
|
2014-02-08 06:07:10 +11:00
|
|
|
|
if (t->tsnap.selectedPoint) {
|
2011-12-26 20:23:07 +00:00
|
|
|
|
BLI_freelinkN(&t->tsnap.points, t->tsnap.selectedPoint);
|
|
|
|
|
|
|
|
|
|
|
|
if (BLI_listbase_is_empty(&t->tsnap.points)) {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.status &= ~SNAP_MULTI_POINTS;
|
2011-12-26 20:23:07 +00:00
|
|
|
|
}
|
2009-12-01 18:26:18 +00:00
|
|
|
|
|
2022-11-17 17:13:38 +01:00
|
|
|
|
t->tsnap.selectedPoint = nullptr;
|
2009-12-01 18:26:18 +00:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
2009-12-01 18:26:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-09 17:57:05 +02:00
|
|
|
|
void getSnapPoint(const TransInfo *t, float vec[3])
|
2009-12-01 18:26:18 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (t->tsnap.points.first) {
|
|
|
|
|
|
TransSnapPoint *p;
|
|
|
|
|
|
int total = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2009-12-01 18:26:18 +00:00
|
|
|
|
vec[0] = vec[1] = vec[2] = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2022-11-17 17:13:38 +01:00
|
|
|
|
for (p = static_cast<TransSnapPoint *>(t->tsnap.points.first); p; p = p->next, total++) {
|
2009-12-01 18:26:18 +00:00
|
|
|
|
add_v3_v3(vec, p->co);
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
if (t->tsnap.status & SNAP_TARGET_FOUND) {
|
|
|
|
|
|
add_v3_v3(vec, t->tsnap.snap_target);
|
2009-12-01 18:26:18 +00:00
|
|
|
|
total++;
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2009-12-01 18:26:18 +00:00
|
|
|
|
mul_v3_fl(vec, 1.0f / total);
|
2012-03-24 06:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
copy_v3_v3(vec, t->tsnap.snap_target);
|
2009-12-01 18:26:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
static void snap_multipoints_free(TransInfo *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (t->tsnap.status & SNAP_MULTI_POINTS) {
|
|
|
|
|
|
BLI_freelistN(&t->tsnap.points);
|
|
|
|
|
|
t->tsnap.status &= ~SNAP_MULTI_POINTS;
|
2023-06-04 19:07:26 +10:00
|
|
|
|
t->tsnap.selectedPoint = nullptr;
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-28 09:32:59 -03:00
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2021-06-29 17:38:34 -03:00
|
|
|
|
/** \name Calc Snap
|
2019-10-28 09:32:59 -03:00
|
|
|
|
* \{ */
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
|
2024-04-01 11:12:39 -03:00
|
|
|
|
static void snap_grid_uv_apply(TransInfo *t, const float grid_dist[2], float r_out[2])
|
2024-03-27 13:17:24 +01:00
|
|
|
|
{
|
2024-04-01 11:12:39 -03:00
|
|
|
|
float3 in;
|
|
|
|
|
|
convertViewVec(t, in, t->mval[0] - t->center2d[0], t->mval[1] - t->center2d[1]);
|
|
|
|
|
|
|
2024-03-27 13:17:24 +01:00
|
|
|
|
if (t->con.mode & CON_APPLY) {
|
|
|
|
|
|
/* We need to clear the previous Snap to Grid result,
|
|
|
|
|
|
* otherwise #t->con.applyVec will have no effect. */
|
|
|
|
|
|
t->tsnap.target_type = SCE_SNAP_TO_NONE;
|
2024-04-01 11:12:39 -03:00
|
|
|
|
t->tsnap.status &= ~SNAP_TARGET_FOUND;
|
|
|
|
|
|
transform_constraint_get_nearest(t, in, in);
|
2024-03-27 13:17:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-01 11:12:39 -03:00
|
|
|
|
const float *center_global = t->center_global;
|
2024-03-27 13:17:24 +01:00
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
|
|
const float iter_fac = grid_dist[i];
|
|
|
|
|
|
r_out[i] = iter_fac * roundf((in[i] + center_global[i]) / iter_fac);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-01 11:12:39 -03:00
|
|
|
|
static bool snap_grid_uv(TransInfo *t, float r_val[2])
|
2024-03-27 13:17:24 +01:00
|
|
|
|
{
|
|
|
|
|
|
float grid_dist[2];
|
|
|
|
|
|
mul_v2_v2v2(grid_dist, t->snap_spatial, t->aspect);
|
|
|
|
|
|
if (t->modifiers & MOD_PRECISION) {
|
|
|
|
|
|
mul_v2_fl(grid_dist, t->snap_spatial_precision);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Early bailing out if no need to snap */
|
|
|
|
|
|
if (is_zero_v2(grid_dist)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-01 11:12:39 -03:00
|
|
|
|
snap_grid_uv_apply(t, grid_dist, r_val);
|
2024-03-27 13:17:24 +01:00
|
|
|
|
t->tsnap.target_type = SCE_SNAP_TO_GRID;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
/** \name Calc Snap
|
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
2024-04-01 11:12:39 -03:00
|
|
|
|
static void snap_target_view3d_fn(TransInfo *t, float * /*vec*/)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
2021-06-29 17:38:34 -03:00
|
|
|
|
BLI_assert(t->spacetype == SPACE_VIEW3D);
|
|
|
|
|
|
float loc[3];
|
|
|
|
|
|
float no[3];
|
|
|
|
|
|
bool found = false;
|
2023-06-23 16:58:16 -03:00
|
|
|
|
eSnapMode snap_elem = SCE_SNAP_TO_NONE;
|
2021-06-29 17:38:34 -03:00
|
|
|
|
float dist_px = SNAP_MIN_DISTANCE; /* Use a user defined value here. */
|
|
|
|
|
|
|
2024-03-27 13:17:24 +01:00
|
|
|
|
if (t->tsnap.mode & (SCE_SNAP_TO_GEOM | SCE_SNAP_TO_GRID)) {
|
|
|
|
|
|
zero_v3(no); /* objects won't set this */
|
2024-04-01 11:12:39 -03:00
|
|
|
|
snap_elem = snapObjectsTransform(t, t->mval, &dist_px, loc, no);
|
2023-06-23 16:58:16 -03:00
|
|
|
|
found = (snap_elem != SCE_SNAP_TO_NONE);
|
2021-06-29 17:38:34 -03:00
|
|
|
|
}
|
2023-06-23 16:58:16 -03:00
|
|
|
|
if ((found == false) && (t->tsnap.mode & SCE_SNAP_TO_VOLUME)) {
|
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 use_peel = (t->settings->snap_flag & SCE_SNAP_PEEL_OBJECT) != 0;
|
2023-08-02 15:00:47 -03:00
|
|
|
|
found = peelObjectsTransform(t, t->mval, use_peel, loc, no, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2021-06-29 17:38:34 -03:00
|
|
|
|
if (found) {
|
2023-06-23 16:58:16 -03:00
|
|
|
|
snap_elem = SCE_SNAP_TO_VOLUME;
|
2011-05-11 09:28:00 +00:00
|
|
|
|
}
|
2021-06-29 17:38:34 -03:00
|
|
|
|
}
|
2019-08-23 15:20:25 -03:00
|
|
|
|
|
2021-06-29 17:38:34 -03:00
|
|
|
|
if (found == true) {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
copy_v3_v3(t->tsnap.snap_target, loc);
|
2021-06-29 17:38:34 -03:00
|
|
|
|
copy_v3_v3(t->tsnap.snapNormal, no);
|
|
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.status |= SNAP_TARGET_FOUND;
|
2024-03-27 13:17:24 +01:00
|
|
|
|
|
|
|
|
|
|
if (snap_elem == SCE_SNAP_TO_GRID && t->mode_info != &TransMode_translate) {
|
|
|
|
|
|
/* Change it to #SCE_SNAP_TO_POINT so we can see the symbol for other modes. */
|
|
|
|
|
|
snap_elem = SCE_SNAP_TO_POINT;
|
|
|
|
|
|
}
|
2021-06-29 17:38:34 -03:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.status &= ~SNAP_TARGET_FOUND;
|
2021-06-29 17:38:34 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-23 15:36:57 -03:00
|
|
|
|
t->tsnap.target_type = snap_elem;
|
2021-06-29 17:38:34 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-01 11:12:39 -03:00
|
|
|
|
static void snap_target_uv_fn(TransInfo *t, float * /*vec*/)
|
2021-06-29 17:38:34 -03:00
|
|
|
|
{
|
2021-12-16 13:45:27 -03:00
|
|
|
|
BLI_assert(t->spacetype == SPACE_IMAGE);
|
2024-06-07 17:52:03 -03:00
|
|
|
|
bool found = false;
|
|
|
|
|
|
if (t->tsnap.mode & SCE_SNAP_TO_VERTEX) {
|
2024-01-24 18:18:14 +01:00
|
|
|
|
const Vector<Object *> objects =
|
|
|
|
|
|
BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
|
|
|
|
|
|
t->scene, t->view_layer, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2022-12-08 13:04:50 +11:00
|
|
|
|
float dist_sq = square_f(float(SNAP_MIN_DISTANCE));
|
2022-05-03 10:09:22 -03:00
|
|
|
|
if (ED_uvedit_nearest_uv_multi(&t->region->v2d,
|
|
|
|
|
|
t->scene,
|
|
|
|
|
|
objects,
|
2023-08-02 15:00:47 -03:00
|
|
|
|
t->mval,
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.target_operation & SCE_SNAP_TARGET_NOT_SELECTED,
|
2022-05-03 10:09:22 -03:00
|
|
|
|
&dist_sq,
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.snap_target))
|
|
|
|
|
|
{
|
|
|
|
|
|
t->tsnap.snap_target[0] *= t->aspect[0];
|
|
|
|
|
|
t->tsnap.snap_target[1] *= t->aspect[1];
|
2024-07-26 14:59:13 +02:00
|
|
|
|
t->tsnap.target_type = SCE_SNAP_TO_EDGE_ENDPOINT;
|
2024-06-07 17:52:03 -03:00
|
|
|
|
found = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
2009-02-24 00:45:40 +00:00
|
|
|
|
}
|
2024-06-07 17:52:03 -03:00
|
|
|
|
|
|
|
|
|
|
if (!found && (t->tsnap.mode & SCE_SNAP_TO_GRID)) {
|
|
|
|
|
|
found = snap_grid_uv(t, t->tsnap.snap_target);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SET_FLAG_FROM_TEST(t->tsnap.status, found, SNAP_TARGET_FOUND);
|
2021-06-29 17:38:34 -03:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
static void snap_target_sequencer_fn(TransInfo *t, float * /*vec*/)
|
2021-06-29 17:38:34 -03:00
|
|
|
|
{
|
|
|
|
|
|
BLI_assert(t->spacetype == SPACE_SEQ);
|
2025-02-18 01:27:04 +01:00
|
|
|
|
if (snap_sequencer_calc(t)) {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.status |= (SNAP_TARGET_FOUND | SNAP_SOURCE_FOUND);
|
2012-06-29 14:34:46 +00:00
|
|
|
|
}
|
2021-06-29 17:38:34 -03:00
|
|
|
|
else {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.status &= ~(SNAP_TARGET_FOUND | SNAP_SOURCE_FOUND);
|
2021-06-29 20:12:19 +02:00
|
|
|
|
}
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-20 14:24:50 +02:00
|
|
|
|
static void snap_target_nla_fn(TransInfo *t, float *vec)
|
|
|
|
|
|
{
|
|
|
|
|
|
BLI_assert(t->spacetype == SPACE_NLA);
|
|
|
|
|
|
if (transform_snap_nla_calc(t, vec)) {
|
|
|
|
|
|
t->tsnap.status |= (SNAP_TARGET_FOUND | SNAP_SOURCE_FOUND);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
t->tsnap.status &= ~(SNAP_TARGET_FOUND | SNAP_SOURCE_FOUND);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-28 09:32:59 -03:00
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
/** \name Target
|
|
|
|
|
|
* \{ */
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
|
2022-10-22 12:27:59 -03:00
|
|
|
|
void tranform_snap_target_median_calc(const TransInfo *t, float r_median[3])
|
2021-02-05 11:01:30 -03:00
|
|
|
|
{
|
|
|
|
|
|
int i_accum = 0;
|
|
|
|
|
|
|
|
|
|
|
|
zero_v3(r_median);
|
|
|
|
|
|
|
|
|
|
|
|
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
|
|
|
|
|
|
float v[3];
|
|
|
|
|
|
zero_v3(v);
|
|
|
|
|
|
|
2025-08-09 12:28:34 +02:00
|
|
|
|
int num_selected = 0;
|
|
|
|
|
|
tc->foreach_index_selected([&](const int i) {
|
|
|
|
|
|
add_v3_v3(v, tc->data[i].center);
|
|
|
|
|
|
num_selected++;
|
|
|
|
|
|
});
|
2021-02-05 11:01:30 -03:00
|
|
|
|
|
2025-08-09 12:28:34 +02:00
|
|
|
|
if (num_selected == 0) {
|
2021-02-05 11:01:30 -03:00
|
|
|
|
/* Is this possible? */
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-09 12:28:34 +02:00
|
|
|
|
mul_v3_fl(v, 1.0 / num_selected);
|
2021-02-05 11:01:30 -03:00
|
|
|
|
|
|
|
|
|
|
if (tc->use_local_mat) {
|
|
|
|
|
|
mul_m4_v3(tc->mat, v);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
add_v3_v3(r_median, v);
|
|
|
|
|
|
i_accum++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mul_v3_fl(r_median, 1.0 / i_accum);
|
2012-06-29 14:34:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
static void snap_source_center_fn(TransInfo *t)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Only need to calculate once. */
|
2023-01-12 10:16:25 -03:00
|
|
|
|
if ((t->tsnap.status & SNAP_SOURCE_FOUND) == 0) {
|
|
|
|
|
|
copy_v3_v3(t->tsnap.snap_source, t->center_global);
|
2018-05-13 06:44:03 +02:00
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.status |= SNAP_SOURCE_FOUND;
|
2023-09-27 16:25:55 -03:00
|
|
|
|
t->tsnap.source_type = SCE_SNAP_TO_NONE;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
static void snap_source_active_fn(TransInfo *t)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Only need to calculate once. */
|
2023-01-12 10:16:25 -03:00
|
|
|
|
if ((t->tsnap.status & SNAP_SOURCE_FOUND) == 0) {
|
2023-04-24 11:41:15 -03:00
|
|
|
|
if (calculateCenterActive(t, true, t->tsnap.snap_source)) {
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.status |= SNAP_SOURCE_FOUND;
|
2023-09-27 16:25:55 -03:00
|
|
|
|
t->tsnap.source_type = SCE_SNAP_TO_NONE;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
2012-03-06 18:40:15 +00:00
|
|
|
|
else {
|
2023-03-24 17:04:51 -03:00
|
|
|
|
/* No active, default to median, */
|
2023-01-12 10:16:25 -03:00
|
|
|
|
t->tsnap.source_operation = SCE_SNAP_SOURCE_MEDIAN;
|
|
|
|
|
|
t->tsnap.snap_source_fn = snap_source_median_fn;
|
|
|
|
|
|
snap_source_median_fn(t);
|
2012-10-21 05:46:41 +00:00
|
|
|
|
}
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
static void snap_source_median_fn(TransInfo *t)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
|
|
|
|
|
/* Only need to calculate once. */
|
2023-01-12 10:16:25 -03:00
|
|
|
|
if ((t->tsnap.status & SNAP_SOURCE_FOUND) == 0) {
|
|
|
|
|
|
tranform_snap_target_median_calc(t, t->tsnap.snap_source);
|
|
|
|
|
|
t->tsnap.status |= SNAP_SOURCE_FOUND;
|
2023-09-27 16:25:55 -03:00
|
|
|
|
t->tsnap.source_type = SCE_SNAP_TO_NONE;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-12 10:16:25 -03:00
|
|
|
|
static void snap_source_closest_fn(TransInfo *t)
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
|
|
|
|
|
/* Only valid if a snap point has been selected. */
|
2024-03-27 13:17:24 +01:00
|
|
|
|
if (!(t->tsnap.status & SNAP_TARGET_FOUND)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (t->tsnap.target_type == SCE_SNAP_TO_GRID) {
|
|
|
|
|
|
/* Previously Snap to Grid had its own snap source which was always the result of
|
|
|
|
|
|
* #snap_source_median_fn. Now this mode shares the same code, so to not change the behavior
|
|
|
|
|
|
* too much when using Closest, use the transform pivot as the snap source in this case. */
|
2024-09-28 17:45:25 -03:00
|
|
|
|
if (t->tsnap.source_type != SCE_SNAP_TO_POINT) {
|
|
|
|
|
|
tranform_snap_target_median_calc(t, t->tsnap.snap_source);
|
|
|
|
|
|
/* Use #SCE_SNAP_TO_POINT to differentiate from 'Closest' bounds and thus avoid recalculating
|
|
|
|
|
|
* the median center. */
|
|
|
|
|
|
t->tsnap.source_type = SCE_SNAP_TO_POINT;
|
|
|
|
|
|
}
|
2024-03-27 13:17:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
2016-01-18 13:15:38 +11:00
|
|
|
|
float dist_closest = 0.0f;
|
2022-11-17 17:13:38 +01:00
|
|
|
|
TransData *closest = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Object mode. */
|
2021-02-05 11:56:43 -03:00
|
|
|
|
if (t->options & CTX_OBJECT) {
|
2019-04-21 04:40:16 +10:00
|
|
|
|
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
|
2025-06-22 11:54:17 +02:00
|
|
|
|
tc->foreach_index_selected([&](const int i) {
|
Fix #139042: use index map instead of sorting transform system data
Avoid modifying the order of transform system data. Instead, create an
index map and use that to traverse the data arrays in sorted order.
The issue observed in #139042 stems from the assumption, in _some_ of
the code, that `tc->data[i]`, `tc->data_ext[i]`, and `tc->data_2d[i]`
all contain information about the same "transformable thing". Since
`tc->data` was sorted (by selection state and, optionally for
proportional editing, by distance) but the other arrays were not, this
caused issues.
The most obvious solution, sorting all arrays the same way, turned out
to be hard to do, as some elements in one array have pointers to
elements in another array. Reordering those arrays would therefore
also make it necessary to find and update those pointers.
Instead, I decided to implement a sorted index map. The arrays can
then be kept in their original order, and the index map can be used to
visit them in sorted order.
Pull Request: https://projects.blender.org/blender/blender/pulls/140132
2025-06-19 11:20:08 +02:00
|
|
|
|
TransData *td = &tc->data[i];
|
|
|
|
|
|
|
2025-02-18 01:27:04 +01:00
|
|
|
|
std::optional<Bounds<float3>> bounds;
|
2019-08-24 21:22:30 +10:00
|
|
|
|
|
2019-08-28 13:42:22 +10:00
|
|
|
|
if ((t->options & CTX_OBMODE_XFORM_OBDATA) == 0) {
|
2024-11-17 02:22:29 -03:00
|
|
|
|
Object *ob = static_cast<Object *>(td->extra);
|
|
|
|
|
|
bounds = BKE_object_boundbox_eval_cached_get(ob);
|
2019-08-24 21:22:30 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Use bound-box if possible. */
|
2023-11-27 16:14:49 +01:00
|
|
|
|
if (bounds) {
|
2025-07-08 20:47:56 +02:00
|
|
|
|
TransDataExtension *td_ext = &tc->data_ext[i];
|
2025-06-16 15:49:14 +02:00
|
|
|
|
const std::array<float3, 8> bounds_corners = bounds::corners(*bounds);
|
2018-04-16 17:54:33 +02:00
|
|
|
|
int j;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2018-04-16 17:54:33 +02:00
|
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
|
|
float loc[3];
|
|
|
|
|
|
float dist;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2025-06-16 15:49:14 +02:00
|
|
|
|
copy_v3_v3(loc, bounds_corners[j]);
|
2025-07-08 20:47:56 +02:00
|
|
|
|
mul_m4_v3(td_ext->obmat, loc);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2023-06-02 14:42:27 +02:00
|
|
|
|
dist = t->mode_info->snap_distance_fn(t, loc, t->tsnap.snap_target);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2018-04-16 17:54:33 +02:00
|
|
|
|
if ((dist != TRANSFORM_DIST_INVALID) &&
|
2024-01-02 18:12:54 +01:00
|
|
|
|
(closest == nullptr || fabsf(dist) < fabsf(dist_closest)))
|
|
|
|
|
|
{
|
2023-01-12 10:16:25 -03:00
|
|
|
|
copy_v3_v3(t->tsnap.snap_source, loc);
|
2018-04-16 17:54:33 +02:00
|
|
|
|
closest = td;
|
|
|
|
|
|
dist_closest = dist;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Use element center otherwise. */
|
2018-04-16 17:54:33 +02:00
|
|
|
|
else {
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
float loc[3];
|
|
|
|
|
|
float dist;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2018-04-16 17:54:33 +02:00
|
|
|
|
copy_v3_v3(loc, td->center);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2023-06-02 14:42:27 +02:00
|
|
|
|
dist = t->mode_info->snap_distance_fn(t, loc, t->tsnap.snap_target);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2015-10-16 14:45:05 +11:00
|
|
|
|
if ((dist != TRANSFORM_DIST_INVALID) &&
|
2024-01-02 18:12:54 +01:00
|
|
|
|
(closest == nullptr || fabsf(dist) < fabsf(dist_closest)))
|
|
|
|
|
|
{
|
2023-01-12 10:16:25 -03:00
|
|
|
|
copy_v3_v3(t->tsnap.snap_source, loc);
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
closest = td;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-22 11:54:17 +02:00
|
|
|
|
});
|
2018-04-16 17:54:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
2019-04-21 04:40:16 +10:00
|
|
|
|
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
|
2025-06-22 11:54:17 +02:00
|
|
|
|
tc->foreach_index_selected([&](const int i) {
|
Fix #139042: use index map instead of sorting transform system data
Avoid modifying the order of transform system data. Instead, create an
index map and use that to traverse the data arrays in sorted order.
The issue observed in #139042 stems from the assumption, in _some_ of
the code, that `tc->data[i]`, `tc->data_ext[i]`, and `tc->data_2d[i]`
all contain information about the same "transformable thing". Since
`tc->data` was sorted (by selection state and, optionally for
proportional editing, by distance) but the other arrays were not, this
caused issues.
The most obvious solution, sorting all arrays the same way, turned out
to be hard to do, as some elements in one array have pointers to
elements in another array. Reordering those arrays would therefore
also make it necessary to find and update those pointers.
Instead, I decided to implement a sorted index map. The arrays can
then be kept in their original order, and the index map can be used to
visit them in sorted order.
Pull Request: https://projects.blender.org/blender/blender/pulls/140132
2025-06-19 11:20:08 +02:00
|
|
|
|
TransData *td = &tc->data[i];
|
|
|
|
|
|
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
float loc[3];
|
|
|
|
|
|
float dist;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2011-09-12 04:14:12 +00:00
|
|
|
|
copy_v3_v3(loc, td->center);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2018-05-04 14:41:51 +02:00
|
|
|
|
if (tc->use_local_mat) {
|
|
|
|
|
|
mul_m4_v3(tc->mat, loc);
|
2018-04-16 17:54:33 +02:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2023-06-02 14:42:27 +02:00
|
|
|
|
dist = t->mode_info->snap_distance_fn(t, loc, t->tsnap.snap_target);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2015-10-16 14:45:05 +11:00
|
|
|
|
if ((dist != TRANSFORM_DIST_INVALID) &&
|
2024-01-02 18:12:54 +01:00
|
|
|
|
(closest == nullptr || fabsf(dist) < fabsf(dist_closest)))
|
|
|
|
|
|
{
|
2023-01-12 10:16:25 -03:00
|
|
|
|
copy_v3_v3(t->tsnap.snap_source, loc);
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
closest = td;
|
2018-04-16 17:54:33 +02:00
|
|
|
|
dist_closest = dist;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
2025-06-22 11:54:17 +02:00
|
|
|
|
});
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-27 13:17:24 +01:00
|
|
|
|
|
|
|
|
|
|
t->tsnap.status |= SNAP_SOURCE_FOUND;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
2009-02-24 21:25:36 +00:00
|
|
|
|
|
2019-10-28 09:32:59 -03:00
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
/** \name Snap Objects
|
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
2024-04-01 11:12:39 -03:00
|
|
|
|
static eSnapMode snapObjectsTransform(
|
|
|
|
|
|
TransInfo *t, const float mval[2], float *dist_px, float r_loc[3], float r_no[3])
|
2009-03-20 18:00:51 +00:00
|
|
|
|
{
|
2022-11-17 17:13:38 +01:00
|
|
|
|
SnapObjectParams snap_object_params{};
|
2023-01-12 10:16:25 -03:00
|
|
|
|
snap_object_params.snap_target_select = t->tsnap.target_operation;
|
2024-10-08 23:29:57 -03:00
|
|
|
|
snap_object_params.grid_size = (t->modifiers & MOD_PRECISION) ?
|
|
|
|
|
|
t->snap_spatial[0] * t->snap_spatial_precision :
|
|
|
|
|
|
t->snap_spatial[0];
|
2022-11-17 17:13:38 +01:00
|
|
|
|
snap_object_params.edit_mode_type = (t->flag & T_EDIT) != 0 ? SNAP_GEOM_EDIT : SNAP_GEOM_FINAL;
|
2024-11-11 14:26:52 +01:00
|
|
|
|
snap_object_params.occlusion_test = SNAP_OCCLUSION_AS_SEEM;
|
2023-03-20 18:51:09 -03:00
|
|
|
|
snap_object_params.use_backface_culling = (t->tsnap.flag & SCE_SNAP_BACKFACE_CULLING) != 0;
|
2022-11-17 17:13:38 +01:00
|
|
|
|
|
2023-06-15 11:27:22 -03:00
|
|
|
|
float *prev_co = (t->tsnap.status & SNAP_SOURCE_FOUND) ? t->tsnap.snap_source : t->center_global;
|
2024-03-27 13:17:24 +01:00
|
|
|
|
float *grid_co = nullptr, grid_co_stack[3];
|
2024-10-01 13:16:07 -03:00
|
|
|
|
if ((t->tsnap.mode & SCE_SNAP_TO_GRID) && (t->con.mode & CON_APPLY) && t->mode != TFM_ROTATION) {
|
2024-03-27 13:17:24 +01:00
|
|
|
|
/* Without this position adjustment, the snap may be far from the expected constraint point. */
|
|
|
|
|
|
grid_co = grid_co_stack;
|
2024-04-01 11:12:39 -03:00
|
|
|
|
convertViewVec(t, grid_co, mval[0] - t->center2d[0], mval[1] - t->center2d[1]);
|
2024-03-27 13:17:24 +01:00
|
|
|
|
t->tsnap.status &= ~SNAP_TARGET_FOUND;
|
2024-04-01 11:12:39 -03:00
|
|
|
|
transform_constraint_get_nearest(t, grid_co, grid_co);
|
2024-03-27 13:17:24 +01:00
|
|
|
|
add_v3_v3(grid_co, t->center_global);
|
|
|
|
|
|
}
|
2023-06-15 11:27:22 -03:00
|
|
|
|
|
2025-02-18 01:27:04 +01:00
|
|
|
|
return blender::ed::transform::snap_object_project_view3d(t->tsnap.object_context,
|
|
|
|
|
|
t->depsgraph,
|
|
|
|
|
|
t->region,
|
|
|
|
|
|
static_cast<const View3D *>(t->view),
|
|
|
|
|
|
t->tsnap.mode,
|
|
|
|
|
|
&snap_object_params,
|
|
|
|
|
|
grid_co,
|
|
|
|
|
|
mval,
|
|
|
|
|
|
prev_co,
|
|
|
|
|
|
dist_px,
|
|
|
|
|
|
r_loc,
|
|
|
|
|
|
r_no);
|
2013-04-03 09:48:21 +00:00
|
|
|
|
}
|
2009-03-20 18:00:51 +00:00
|
|
|
|
|
2019-10-28 09:32:59 -03:00
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
/** \name Peeling
|
|
|
|
|
|
* \{ */
|
2009-02-24 00:45:40 +00:00
|
|
|
|
|
2020-03-09 10:02:11 -03:00
|
|
|
|
bool peelObjectsTransform(TransInfo *t,
|
|
|
|
|
|
const float mval[2],
|
|
|
|
|
|
const bool use_peel_object,
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Return args. */
|
2020-03-09 10:02:11 -03:00
|
|
|
|
float r_loc[3],
|
|
|
|
|
|
float r_no[3],
|
|
|
|
|
|
float *r_thickness)
|
2009-02-24 00:45:40 +00:00
|
|
|
|
{
|
2022-11-17 17:13:38 +01:00
|
|
|
|
SnapObjectParams snap_object_params{};
|
2023-01-12 10:16:25 -03:00
|
|
|
|
snap_object_params.snap_target_select = t->tsnap.target_operation;
|
2022-11-17 17:13:38 +01:00
|
|
|
|
snap_object_params.edit_mode_type = (t->flag & T_EDIT) != 0 ? SNAP_GEOM_EDIT : SNAP_GEOM_FINAL;
|
|
|
|
|
|
|
2022-12-29 12:01:32 -05:00
|
|
|
|
ListBase depths_peel = {nullptr};
|
2025-02-18 01:27:04 +01:00
|
|
|
|
blender::ed::transform::object_project_all_view3d_ex(t->tsnap.object_context,
|
|
|
|
|
|
t->depsgraph,
|
|
|
|
|
|
t->region,
|
|
|
|
|
|
static_cast<const View3D *>(t->view),
|
|
|
|
|
|
&snap_object_params,
|
|
|
|
|
|
mval,
|
|
|
|
|
|
-1.0f,
|
|
|
|
|
|
false,
|
|
|
|
|
|
&depths_peel);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2016-05-11 19:59:02 +10:00
|
|
|
|
if (!BLI_listbase_is_empty(&depths_peel)) {
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* At the moment we only use the hits of the first object. */
|
2023-06-03 08:36:28 +10:00
|
|
|
|
SnapObjectHitDepth *hit_min = static_cast<SnapObjectHitDepth *>(depths_peel.first);
|
|
|
|
|
|
for (SnapObjectHitDepth *iter = hit_min->next; iter; iter = iter->next) {
|
2016-05-11 19:59:02 +10:00
|
|
|
|
if (iter->depth < hit_min->depth) {
|
|
|
|
|
|
hit_min = iter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
2009-02-24 00:45:40 +00:00
|
|
|
|
}
|
2023-06-03 08:36:28 +10:00
|
|
|
|
SnapObjectHitDepth *hit_max = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2016-05-11 19:59:02 +10:00
|
|
|
|
if (use_peel_object) {
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* If peeling objects, take the first and last from each object. */
|
2016-05-11 19:59:02 +10:00
|
|
|
|
hit_max = hit_min;
|
2023-08-04 08:51:13 +10:00
|
|
|
|
LISTBASE_FOREACH (SnapObjectHitDepth *, iter, &depths_peel) {
|
2016-05-11 19:59:02 +10:00
|
|
|
|
if ((iter->depth > hit_max->depth) && (iter->ob_uuid == hit_min->ob_uuid)) {
|
|
|
|
|
|
hit_max = iter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-05-11 19:59:02 +10:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Otherwise, pair first with second and so on. */
|
2023-08-04 08:51:13 +10:00
|
|
|
|
LISTBASE_FOREACH (SnapObjectHitDepth *, iter, &depths_peel) {
|
2016-05-11 19:59:02 +10:00
|
|
|
|
if ((iter != hit_min) && (iter->ob_uuid == hit_min->ob_uuid)) {
|
2022-11-17 17:13:38 +01:00
|
|
|
|
if (hit_max == nullptr) {
|
2016-05-11 19:59:02 +10:00
|
|
|
|
hit_max = iter;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (iter->depth < hit_max->depth) {
|
|
|
|
|
|
hit_max = iter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-05-11 19:59:02 +10:00
|
|
|
|
}
|
2021-10-18 11:16:24 +11:00
|
|
|
|
/* In this case has only one hit. treat as ray-cast. */
|
2022-11-17 17:13:38 +01:00
|
|
|
|
if (hit_max == nullptr) {
|
2016-05-11 19:59:02 +10:00
|
|
|
|
hit_max = hit_min;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
}
|
2016-05-06 04:49:21 +10:00
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2016-05-11 19:59:02 +10:00
|
|
|
|
mid_v3_v3v3(r_loc, hit_min->co, hit_max->co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2016-05-11 19:59:02 +10:00
|
|
|
|
if (r_thickness) {
|
|
|
|
|
|
*r_thickness = hit_max->depth - hit_min->depth;
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* XXX, is there a correct normal in this case ???, for now just z up. */
|
2016-05-11 19:59:02 +10:00
|
|
|
|
r_no[0] = 0.0;
|
|
|
|
|
|
r_no[1] = 0.0;
|
|
|
|
|
|
r_no[2] = 1.0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2024-12-19 21:05:19 +01:00
|
|
|
|
LISTBASE_FOREACH_MUTABLE (SnapObjectHitDepth *, link, &depths_peel) {
|
|
|
|
|
|
MEM_delete(link);
|
|
|
|
|
|
}
|
2016-05-11 19:59:02 +10:00
|
|
|
|
return true;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
2016-05-11 19:59:02 +10:00
|
|
|
|
return false;
|
2009-03-20 18:00:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-28 09:32:59 -03:00
|
|
|
|
/** \} */
|
|
|
|
|
|
|
2019-10-28 09:51:53 -03:00
|
|
|
|
/* -------------------------------------------------------------------- */
|
2021-08-19 09:52:09 -03:00
|
|
|
|
/** \name snap Grid
|
2019-10-28 09:51:53 -03:00
|
|
|
|
* \{ */
|
|
|
|
|
|
|
2025-06-25 17:31:01 +02:00
|
|
|
|
static void snap_increment_apply(const TransInfo *t, const float loc[3], float r_out[3])
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
{
|
2025-06-25 17:31:01 +02:00
|
|
|
|
bool use_precision = (t->modifiers & MOD_PRECISION) != 0;
|
|
|
|
|
|
|
2024-03-09 23:25:40 +11:00
|
|
|
|
/* Relative snapping in fixed increments. */
|
2025-06-25 17:31:01 +02:00
|
|
|
|
for (int i = 0; i <= t->idx_max; i++) {
|
|
|
|
|
|
const float iter_fac = use_precision ? t->increment[i] * t->increment_precision :
|
|
|
|
|
|
t->increment[i];
|
2025-06-26 10:36:45 -03:00
|
|
|
|
if (iter_fac != 0.0f) {
|
|
|
|
|
|
r_out[i] = iter_fac * roundf(loc[i] / iter_fac);
|
|
|
|
|
|
}
|
2020-08-31 10:14:40 -03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2021-06-29 20:13:55 +10:00
|
|
|
|
bool transform_snap_increment_ex(const TransInfo *t, bool use_local_space, float *r_val)
|
2020-08-31 10:14:40 -03:00
|
|
|
|
{
|
2023-01-09 23:45:12 -03:00
|
|
|
|
if (!transform_snap_is_active(t)) {
|
2020-10-08 09:45:45 -03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-02 00:21:17 +02:00
|
|
|
|
if (t->spacetype == SPACE_SEQ) {
|
2025-04-29 09:02:49 +10:00
|
|
|
|
/* Sequencer has its own dedicated enum for snap_mode with increment snap bit overridden. */
|
2025-04-02 00:21:17 +02:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-23 16:58:16 -03:00
|
|
|
|
if (!(t->tsnap.mode & SCE_SNAP_TO_INCREMENT)) {
|
2020-08-31 10:14:40 -03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2020-08-31 10:14:40 -03:00
|
|
|
|
if (t->spacetype != SPACE_VIEW3D && validSnap(t)) {
|
|
|
|
|
|
/* Only do something if using absolute or incremental grid snapping
|
|
|
|
|
|
* and there is no valid snap point. */
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2021-01-10 20:24:46 -03:00
|
|
|
|
if (use_local_space) {
|
|
|
|
|
|
mul_m3_v3(t->spacemtx_inv, r_val);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-25 17:31:01 +02:00
|
|
|
|
snap_increment_apply(t, r_val, r_val);
|
2021-01-10 20:24:46 -03:00
|
|
|
|
|
|
|
|
|
|
if (use_local_space) {
|
|
|
|
|
|
mul_m3_v3(t->spacemtx, r_val);
|
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
2020-08-31 10:14:40 -03:00
|
|
|
|
return true;
|
2.5
Transform:
First working port of the transform code:
- Object mode only (other conversions need to be ported)
- Contraints (global and local only) working
- Snap (no edit mode, obviously) working
- Numinput working
- Gears (Ctrl and Shift) working
- Only grap, rotate, scale, shear, warp and to sphere have been added as hotkey, but the rest should work too once accessible
- No manipulator
- No drawn feedback other than moving stuff and header print (no constraint line, snap circle, ...)
- No NDOF support
I've only tested Scons support, though Makefil *should* work, I *think*.
Misc:
-QuatIsNull function in arith
-Exporting project_* and view[line|ray] functions from view3d
2008-12-29 01:41:28 +00:00
|
|
|
|
}
|
2019-10-28 09:32:59 -03:00
|
|
|
|
|
2021-06-29 20:13:55 +10:00
|
|
|
|
bool transform_snap_increment(const TransInfo *t, float *r_val)
|
2021-01-10 20:24:46 -03:00
|
|
|
|
{
|
|
|
|
|
|
return transform_snap_increment_ex(t, false, r_val);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-06 22:59:32 -03:00
|
|
|
|
float transform_snap_increment_get(const TransInfo *t)
|
|
|
|
|
|
{
|
2023-06-23 16:58:16 -03:00
|
|
|
|
if (transform_snap_is_active(t) && (t->tsnap.mode & (SCE_SNAP_TO_INCREMENT | SCE_SNAP_TO_GRID)))
|
2023-03-20 20:11:22 -03:00
|
|
|
|
{
|
2025-06-25 17:31:01 +02:00
|
|
|
|
return (t->modifiers & MOD_PRECISION) ? t->increment[0] * t->increment_precision :
|
|
|
|
|
|
t->increment[0];
|
2022-06-06 22:59:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
void tranform_snap_source_restore_context(TransInfo *t)
|
|
|
|
|
|
{
|
2024-03-12 14:29:46 -03:00
|
|
|
|
if (t->spacetype == SPACE_VIEW3D) {
|
|
|
|
|
|
snap_object_context_init(t);
|
|
|
|
|
|
}
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
snap_multipoints_free(t);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-28 09:32:59 -03:00
|
|
|
|
/** \} */
|
2020-06-22 09:07:51 -03:00
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
/** \name Generic callbacks
|
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
2022-12-20 15:51:47 -03:00
|
|
|
|
float transform_snap_distance_len_squared_fn(TransInfo * /*t*/,
|
2020-06-24 14:23:54 +10:00
|
|
|
|
const float p1[3],
|
|
|
|
|
|
const float p2[3])
|
2020-06-22 09:07:51 -03:00
|
|
|
|
{
|
|
|
|
|
|
return len_squared_v3v3(p1, p2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** \} */
|
2025-02-18 01:27:04 +01:00
|
|
|
|
|
|
|
|
|
|
} // namespace blender::ed::transform
|