Blender V5.3
transform_snap_object_lattice.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_span.hh"
10
11#include "BKE_lattice.hh"
12#include "BKE_object.hh"
13
14#include "DNA_curve_types.h"
15#include "DNA_lattice_types.h"
16
18
20
21namespace blender::ed::transform {
22
23eSnapMode snapLattice(SnapObjectContext *sctx, const Object *ob_eval, const float4x4 &obmat)
24{
25 bool has_snap = false;
26
27 /* Only vertex snapping is supported for now. */
28 if ((sctx->runtime.snap_to_flag & SCE_SNAP_TO_POINT) == 0) {
29 return SCE_SNAP_TO_NONE;
30 }
31
32 Lattice *lt_id = id_cast<Lattice *>(ob_eval->data);
33
34 SnapData nearest2d(sctx, obmat);
35
36 const bool use_obedit = BKE_object_is_in_editmode(ob_eval);
37 Lattice *lt = use_obedit ? lt_id->editlatt->latt : lt_id;
38
39 if (!use_obedit) {
40 std::optional<Bounds<float3>> bounds = BKE_lattice_minmax(lt);
41 if (bounds && !nearest2d.snap_boundbox(bounds->min, bounds->max)) {
42 return SCE_SNAP_TO_NONE;
43 }
44 }
45
46 nearest2d.clip_planes_enable(sctx, ob_eval, true);
47
48 bool skip_selected = (sctx->runtime.params.snap_target_select & SCE_SNAP_TARGET_NOT_SELECTED) !=
49 0;
50
51 const int totpoint = lt->pntsu * lt->pntsv * lt->pntsw;
52 Span<BPoint> points(lt->def, totpoint);
53
54 for (const BPoint &bp : points) {
55 if (use_obedit) {
56 if (bp.hide) {
57 continue;
58 }
59
60 bool is_selected = (bp.f1 & SELECT) != 0;
61 if (is_selected && skip_selected) {
62 continue;
63 }
64 }
65 has_snap |= nearest2d.snap_point(bp.vec);
66 }
67
68 if (has_snap) {
69 nearest2d.register_result(sctx, ob_eval, &lt->id);
70 return SCE_SNAP_TO_POINT;
71 }
72 return SCE_SNAP_TO_NONE;
73}
74
75} // namespace blender::ed::transform
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for blender objects.
void clip_planes_enable(SnapObjectContext *sctx, const Object *ob_eval, bool skip_occlusion_plane=false)
bool snap_point(const float3 &co, int index=-1)
static void register_result(SnapObjectContext *sctx, const Object *ob_eval, const ID *id_eval, const float4x4 &obmat, BVHTreeNearest *r_nearest)
bool snap_boundbox(const float3 &min, const float3 &max)
eSnapMode snapLattice(SnapObjectContext *sctx, const Object *ob_eval, const float4x4 &obmat)
std::optional< Bounds< float3 > > BKE_lattice_minmax(const Lattice *lt)
Definition lattice.cc:625
MatBase< float, 4, 4 > float4x4
@ SCE_SNAP_TARGET_NOT_SELECTED
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
struct Lattice * latt
struct EditLatt * editlatt
struct BPoint * def
struct blender::ed::transform::SnapObjectContext::@247331373256345130115246240121215056001150353127 runtime