Blender V4.3
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
9#pragma once
10
11#include "BLI_map.hh"
12#include "BLI_math_geom.h"
13
14#define MAX_CLIPPLANE_LEN 6
15
16#define SNAP_TO_EDGE_ELEMENTS \
17 (SCE_SNAP_TO_EDGE | SCE_SNAP_TO_EDGE_ENDPOINT | SCE_SNAP_TO_EDGE_MIDPOINT | \
18 SCE_SNAP_TO_EDGE_PERPENDICULAR)
19
22
23 struct SnapCache {
24 virtual ~SnapCache(){};
25 };
27
28 /* Filter data, returns true to check this value. */
29 struct {
30 struct {
31 bool (*test_vert_fn)(BMVert *, void *user_data);
32 bool (*test_edge_fn)(BMEdge *, void *user_data);
33 bool (*test_face_fn)(BMFace *, void *user_data);
34 void *user_data;
37
38 struct {
39 /* Compare with #RegionView3D::persmat to update. */
41 blender::float4 planes[4];
42 float size;
45
46 struct {
47 Depsgraph *depsgraph;
49 const View3D *v3d;
50
53
56
59
60 blender::float2 win_size; /* Win x and y. */
62
66
67 /* Read/write. */
69
71
75
76 /* Output. */
77 struct {
78 /* Location of snapped point on target surface. */
80 /* Normal of snapped point on target surface. */
82 /* Index of snapped element on target object (-1 when no valid index is found). */
83 int index;
84 /* Matrix of target object (may not be #Object.object_to_world with dupli-instances). */
86 /* List of #SnapObjectHitDepth (caller must free). */
88 /* Snapped object. */
89 const Object *ob;
90 /* Snapped data. */
91 const ID *data;
92
95 union {
98 };
99 } ret;
100};
101
103 void *bvhdata;
104
105 /* Internal vars for adding depths. */
107
109
110 float len_diff;
112
114
115 /* Output data. */
117};
118
119class SnapData {
120 public:
121 /* Read-only. */
126 const bool is_persp;
128
129 /* Read and write. */
131
132 public:
133 /* Constructor. */
136
138 const Object *ob_eval,
139 bool skip_occlusion_plane = false);
140 bool snap_boundbox(const blender::float3 &min, const blender::float3 &max);
141 bool snap_point(const blender::float3 &co, int index = -1);
142 bool snap_edge(const blender::float3 &va, const blender::float3 &vb, int edge_index = -1);
143 eSnapMode snap_edge_points_impl(SnapObjectContext *sctx, int edge_index, float dist_px_sq_orig);
144 static void register_result(SnapObjectContext *sctx,
145 const Object *ob_eval,
146 const ID *id_eval,
147 const blender::float4x4 &obmat,
148 BVHTreeNearest *r_nearest);
149 void register_result(SnapObjectContext *sctx, const Object *ob_eval, const ID *id_eval);
151 const Object *ob_eval,
152 const ID *id_eval,
153 const blender::float4x4 &obmat,
154 const BVHTreeRayHit *hit,
155 const bool is_in_front);
156
157 virtual void get_vert_co(const int /*index*/, const float ** /*r_co*/){};
158 virtual void get_edge_verts_index(const int /*index*/, int /*r_v_index*/[2]){};
159 virtual void copy_vert_no(const int /*index*/, float /*r_no*/[3]){};
160};
161
162/* `transform_snap_object.cc` */
163
164void raycast_all_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit);
165
167 const float dir[3], const float v0[3], const float v1[3], const float v2[3], float no[3]);
168
169void cb_snap_vert(void *userdata,
170 int index,
171 const DistProjectedAABBPrecalc *precalc,
172 const float (*clip_plane)[4],
173 const int clip_plane_len,
174 BVHTreeNearest *nearest);
175
176void cb_snap_edge(void *userdata,
177 int index,
178 const DistProjectedAABBPrecalc *precalc,
179 const float (*clip_plane)[4],
180 const int clip_plane_len,
181 BVHTreeNearest *nearest);
182
184 BVHTree *tree,
186 const blender::float4x4 &obmat,
187 void *treedata,
188 BVHTreeNearest *r_nearest);
189
191 const Object *ob_eval,
192 const blender::float4x4 &obmat,
193 eSnapMode snap_to_flag);
194
195/* `transform_snap_object_armature.cc` */
196
198 const Object *ob_eval,
199 const blender::float4x4 &obmat,
200 bool is_object_active);
201
202/* `transform_snap_object_camera.cc` */
203
205 const Object *object,
206 const blender::float4x4 &obmat,
207 eSnapMode snap_to_flag);
208
209/* `transform_snap_object_curve.cc` */
210
212 const Object *ob_eval,
213 const blender::float4x4 &obmat);
214
215/* `transform_snap_object_editmesh.cc` */
216
218 const Object *ob_eval,
219 const ID *id,
220 const blender::float4x4 &obmat,
221 eSnapMode snap_to_flag,
222 bool use_hide);
223
224/* `transform_snap_object_mesh.cc` */
225
227 const Object *ob_eval,
228 const ID *id,
229 const blender::float4x4 &obmat,
230 eSnapMode snap_to_flag,
231 bool skip_hidden,
232 bool is_editmesh = false);
233
235 const Object *ob_eval,
236 const ID *id,
237 const blender::float4x4 &obmat,
238 eSnapMode snap_to_flag,
239 int face_index);
240
242 const Object *ob_eval,
243 const ID *id,
244 const blender::float4x4 &obmat,
245 float dist_px_sq_orig,
246 int edge_index);
void(* BVHTree_RayCastCallback)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
void(* BVHTree_NearestPointCallback)(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
Definition BLI_kdopbvh.h:97
unsigned int uint
ATTR_WARN_UNUSED_RESULT const BMVert * v2
blender::Vector< blender::float4, MAX_CLIPPLANE_LEN+1 > clip_planes
void clip_planes_enable(SnapObjectContext *sctx, const Object *ob_eval, bool skip_occlusion_plane=false)
blender::float4x4 pmat_local
bool snap_point(const blender::float3 &co, int index=-1)
static void register_result_raycast(SnapObjectContext *sctx, const Object *ob_eval, const ID *id_eval, const blender::float4x4 &obmat, const BVHTreeRayHit *hit, const bool is_in_front)
SnapData(SnapObjectContext *sctx, const blender::float4x4 &obmat=blender::float4x4::identity())
static void register_result(SnapObjectContext *sctx, const Object *ob_eval, const ID *id_eval, const blender::float4x4 &obmat, BVHTreeNearest *r_nearest)
virtual void copy_vert_no(const int, float[3])
blender::float4x4 obmat_
DistProjectedAABBPrecalc nearest_precalc
BVHTreeNearest nearest_point
eSnapMode snap_edge_points_impl(SnapObjectContext *sctx, int edge_index, float dist_px_sq_orig)
virtual void get_vert_co(const int, const float **)
bool snap_boundbox(const blender::float3 &min, const blender::float3 &max)
virtual void get_edge_verts_index(const int, int[2])
bool snap_edge(const blender::float3 &va, const blender::float3 &vb, int edge_index=-1)
KDTree_3d * tree
#define min(a, b)
Definition sort.c:32
Definition DNA_ID.h:413
BVHTree_RayCastCallback raycast_callback
const blender::float4x4 * obmat
struct SnapObjectContext::@587::@591 edit_mesh
blender::float4x4 obmat
blender::float4 occlusion_plane_in_front
struct SnapObjectContext::@588 grid
const RegionView3D * rv3d
blender::Vector< blender::float4, MAX_CLIPPLANE_LEN > clip_planes
struct SnapObjectContext::@590 ret
bool(* test_face_fn)(BMFace *, void *user_data)
bool(* test_edge_fn)(BMEdge *, void *user_data)
blender::Map< const ID *, std::unique_ptr< SnapCache > > editmesh_caches
bool(* test_vert_fn)(BMVert *, void *user_data)
eSnapOcclusionTest occlusion_test_edit
struct SnapObjectContext::@589 runtime
blender::float4 occlusion_plane
blender::float4x4 persmat
struct SnapObjectContext::@587 callbacks
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 blender::float4x4 &obmat, eSnapMode snap_to_flag, bool use_hide)
void cb_snap_vert(void *userdata, int index, const DistProjectedAABBPrecalc *precalc, const float(*clip_plane)[4], const int clip_plane_len, BVHTreeNearest *nearest)
eSnapMode snap_object_center(SnapObjectContext *sctx, const Object *ob_eval, const blender::float4x4 &obmat, eSnapMode snap_to_flag)
bool nearest_world_tree(SnapObjectContext *sctx, BVHTree *tree, BVHTree_NearestPointCallback nearest_cb, const blender::float4x4 &obmat, void *treedata, BVHTreeNearest *r_nearest)
eSnapMode snapArmature(SnapObjectContext *sctx, const Object *ob_eval, const blender::float4x4 &obmat, bool is_object_active)
eSnapMode snapCurve(SnapObjectContext *sctx, const Object *ob_eval, const blender::float4x4 &obmat)
eSnapMode snap_edge_points_mesh(SnapObjectContext *sctx, const Object *ob_eval, const ID *id, const blender::float4x4 &obmat, float dist_px_sq_orig, int edge_index)
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 snap_polygon_mesh(SnapObjectContext *sctx, const Object *ob_eval, const ID *id, const blender::float4x4 &obmat, eSnapMode snap_to_flag, int face_index)
void raycast_all_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
eSnapMode snapCamera(SnapObjectContext *sctx, const Object *object, const blender::float4x4 &obmat, eSnapMode snap_to_flag)
eSnapMode snap_object_mesh(SnapObjectContext *sctx, const Object *ob_eval, const ID *id, const blender::float4x4 &obmat, eSnapMode snap_to_flag, bool skip_hidden, bool is_editmesh=false)