Blender V5.0
transform_snap_object.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "DNA_scene_types.h"
12
13#include "BLI_kdopbvh.hh"
14#include "BLI_map.hh"
15#include "BLI_math_geom.h"
18
20
21#define MAX_CLIPPLANE_LEN 6
22
23#define SNAP_TO_EDGE_ELEMENTS \
24 (SCE_SNAP_TO_EDGE | SCE_SNAP_TO_EDGE_ENDPOINT | SCE_SNAP_TO_EDGE_MIDPOINT | \
25 SCE_SNAP_TO_EDGE_PERPENDICULAR)
26
27struct BMEdge;
28struct BMFace;
29struct BMVert;
30struct Depsgraph;
31struct ID;
32struct ListBase;
33struct Object;
34struct RegionView3D;
35struct Scene;
36struct View3D;
37
38namespace blender::ed::transform {
39
42
43 struct SnapCache {
44 virtual ~SnapCache() = default;
45 };
47
48 /* Filter data, returns true to check this value. */
49 struct {
50 struct {
51 bool (*test_vert_fn)(BMVert *, void *user_data);
52 bool (*test_edge_fn)(BMEdge *, void *user_data);
53 bool (*test_face_fn)(BMFace *, void *user_data);
54 void *user_data;
57
58 struct {
59 /* Compare with #RegionView3D::persmat to update. */
62 float size;
65
66 struct {
67 Depsgraph *depsgraph;
69 const View3D *v3d;
70
73
76
79
80 float2 win_size; /* Win x and y. */
82
86
87 /* Read/write. */
89 /* List of #SnapObjectHitDepth (caller must free). */
91
93
97
98 /* Output. */
99 struct Output {
100 /* Location of snapped point on target surface. */
102 /* Normal of snapped point on target surface. */
104 /* Index of snapped element on target object (-1 when no valid index is found). */
105 int index;
106 /* Matrix of target object (may not be #Object.object_to_world with dupli-instances). */
108 /* Snapped object. */
109 const Object *ob;
110 /* Snapped data. */
111 const ID *data;
112
115 union {
118 };
120};
121
123 void *bvhdata;
124
125 /* Internal vars for adding depths. */
127
129
130 float len_diff;
132
134
135 /* Output data. */
137};
138
139class SnapData {
140 public:
141 /* Read-only. */
146 const bool is_persp;
148
149 /* Read and write. */
151
152 /* Constructor. */
153 SnapData(SnapObjectContext *sctx, const float4x4 &obmat = float4x4::identity());
154
156 const Object *ob_eval,
157 bool skip_occlusion_plane = false);
158 bool snap_boundbox(const float3 &min, const float3 &max);
159 bool snap_point(const float3 &co, int index = -1);
160 bool snap_edge(const float3 &va, const float3 &vb, int edge_index = -1);
161 eSnapMode snap_edge_points_impl(SnapObjectContext *sctx, int edge_index, float dist_px_sq_orig);
162 static void register_result(SnapObjectContext *sctx,
163 const Object *ob_eval,
164 const ID *id_eval,
165 const float4x4 &obmat,
166 BVHTreeNearest *r_nearest);
167 void register_result(SnapObjectContext *sctx, const Object *ob_eval, const ID *id_eval);
169 const Object *ob_eval,
170 const ID *id_eval,
171 const float4x4 &obmat,
172 const BVHTreeRayHit *hit,
173 const bool is_in_front);
174
175 virtual void get_vert_co(const int /*index*/, const float ** /*r_co*/) {};
176 virtual void get_edge_verts_index(const int /*index*/, int /*r_v_index*/[2]) {};
177 virtual void copy_vert_no(const int /*index*/, float /*r_no*/[3]) {};
178};
179
180/* `transform_snap_object.cc` */
181
182void raycast_all_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit);
183
185 const float dir[3], const float v0[3], const float v1[3], const float v2[3], float no[3]);
186
187void cb_snap_vert(void *userdata,
188 int index,
189 const DistProjectedAABBPrecalc *precalc,
190 const float (*clip_plane)[4],
191 const int clip_plane_len,
192 BVHTreeNearest *nearest);
193
194void cb_snap_edge(void *userdata,
195 int index,
196 const DistProjectedAABBPrecalc *precalc,
197 const float (*clip_plane)[4],
198 const int clip_plane_len,
199 BVHTreeNearest *nearest);
200
201bool nearest_world_tree(SnapObjectContext *sctx,
202 const BVHTree *tree,
204 const float4x4 &obmat,
205 void *treedata,
206 BVHTreeNearest *r_nearest);
207
208eSnapMode snap_object_center(SnapObjectContext *sctx,
209 const Object *ob_eval,
210 const float4x4 &obmat,
211 eSnapMode snap_to_flag);
212
213/* `transform_snap_object_armature.cc` */
214
215eSnapMode snapArmature(SnapObjectContext *sctx,
216 const Object *ob_eval,
217 const float4x4 &obmat,
218 bool is_object_active);
219
220/* `transform_snap_object_camera.cc` */
221
222eSnapMode snapCamera(SnapObjectContext *sctx,
223 const Object *object,
224 const float4x4 &obmat,
225 eSnapMode snap_to_flag);
226
227/* `transform_snap_object_curve.cc` */
228
229eSnapMode snapCurve(SnapObjectContext *sctx, const Object *ob_eval, const float4x4 &obmat);
230
231/* `transform_snap_object_editmesh.cc` */
232
233eSnapMode snap_object_editmesh(SnapObjectContext *sctx,
234 const Object *ob_eval,
235 const ID *id,
236 const float4x4 &obmat,
237 eSnapMode snap_to_flag,
238 bool use_hide);
239
240/* `transform_snap_object_mesh.cc` */
241
242eSnapMode snap_object_mesh(SnapObjectContext *sctx,
243 const Object *ob_eval,
244 const ID *id,
245 const float4x4 &obmat,
246 eSnapMode snap_to_flag,
247 bool skip_hidden,
248 bool is_editmesh = false);
249
250eSnapMode snap_polygon_mesh(SnapObjectContext *sctx,
251 const Object *ob_eval,
252 const ID *id,
253 const float4x4 &obmat,
254 eSnapMode snap_to_flag,
255 int face_index);
256
257eSnapMode snap_edge_points_mesh(SnapObjectContext *sctx,
258 const Object *ob_eval,
259 const ID *id,
260 const float4x4 &obmat,
261 float dist_px_sq_orig,
262 int edge_index);
263
264} // namespace blender::ed::transform
void(*)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) BVHTree_RayCastCallback
void(*)(void *userdata, int index, const float co[3], BVHTreeNearest *nearest) BVHTree_NearestPointCallback
unsigned int uint
ATTR_WARN_UNUSED_RESULT const BMVert * v2
virtual void get_edge_verts_index(const int, int[2])
void clip_planes_enable(SnapObjectContext *sctx, const Object *ob_eval, bool skip_occlusion_plane=false)
Vector< float4, MAX_CLIPPLANE_LEN+1 > clip_planes
bool snap_edge(const float3 &va, const float3 &vb, int edge_index=-1)
virtual void copy_vert_no(const int, float[3])
SnapData(SnapObjectContext *sctx, const float4x4 &obmat=float4x4::identity())
virtual void get_vert_co(const int, const float **)
static void register_result_raycast(SnapObjectContext *sctx, const Object *ob_eval, const ID *id_eval, const float4x4 &obmat, const BVHTreeRayHit *hit, const bool is_in_front)
eSnapMode snap_edge_points_impl(SnapObjectContext *sctx, int edge_index, float dist_px_sq_orig)
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)
KDTree_3d * tree
bool nearest_world_tree(SnapObjectContext *sctx, const BVHTree *tree, BVHTree_NearestPointCallback nearest_cb, const blender::float4x4 &obmat, void *treedata, BVHTreeNearest *r_nearest)
void raycast_all_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
eSnapMode snapArmature(SnapObjectContext *sctx, const Object *ob_eval, const float4x4 &obmat, bool is_object_active)
eSnapMode snapCamera(SnapObjectContext *sctx, const Object *object, const float4x4 &obmat, eSnapMode snap_to_flag)
eSnapMode snap_object_mesh(SnapObjectContext *sctx, const Object *ob_eval, const ID *id, const float4x4 &obmat, eSnapMode snap_to_flag, bool skip_hidden, bool is_editmesh=false)
bool raycast_tri_backface_culling_test(const float dir[3], const float v0[3], const float v1[3], const float v2[3], float no[3])
eSnapMode snapCurve(SnapObjectContext *sctx, const Object *ob_eval, const float4x4 &obmat)
eSnapMode snap_edge_points_mesh(SnapObjectContext *sctx, const Object *ob_eval, const ID *id, const float4x4 &obmat, float dist_px_sq_orig, int edge_index)
void cb_snap_vert(void *userdata, int index, const DistProjectedAABBPrecalc *precalc, const float(*clip_plane)[4], const int clip_plane_len, BVHTreeNearest *nearest)
void cb_snap_edge(void *userdata, int index, const DistProjectedAABBPrecalc *precalc, const float(*clip_plane)[4], const int clip_plane_len, BVHTreeNearest *nearest)
eSnapMode snap_object_editmesh(SnapObjectContext *sctx, const Object *ob_eval, const ID *id, const float4x4 &obmat, eSnapMode snap_to_flag, bool use_hide)
eSnapMode snap_polygon_mesh(SnapObjectContext *sctx, const Object *ob_eval, const ID *id, const float4x4 &obmat, eSnapMode snap_to_flag, int face_index)
eSnapMode snap_object_center(SnapObjectContext *sctx, const Object *ob_eval, const float4x4 &obmat, eSnapMode snap_to_flag)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< float, 2 > float2
VecBase< float, 3 > float3
return ret
Definition DNA_ID.h:414
struct blender::ed::transform::SnapObjectContext::@170374026073064374202114033260227063176045253050 runtime
struct blender::ed::transform::SnapObjectContext::@261131034374131144046074012251042111150012050144 grid
bool(* test_edge_fn)(BMEdge *, void *user_data)
bool(* test_face_fn)(BMFace *, void *user_data)
bool(* test_vert_fn)(BMVert *, void *user_data)
struct blender::ed::transform::SnapObjectContext::@057303224201065302154130247374246316157207360104 callbacks
Map< const ID *, std::unique_ptr< SnapCache > > editmesh_caches
struct blender::ed::transform::SnapObjectContext::@057303224201065302154130247374246316157207360104::@052144141244060360354325332176274005342203076127 edit_mesh
Vector< float4, MAX_CLIPPLANE_LEN > clip_planes