Blender V5.3
transform_snap_object_mesh.cc
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#include "BLI_math_matrix.hh"
10#include "BLI_math_vector_c.hh"
11
12#include "BKE_bvhutils.hh"
13#include "BKE_mesh.hh"
14
16#include "ED_view3d.hh"
17
19
20#ifdef DEBUG_SNAP_TIME
21# if WIN32 and NDEBUG
22# pragma optimize("t", on)
23# endif
24#endif
25
26namespace blender::ed::transform {
27
28/* -------------------------------------------------------------------- */
31
33{
34 if (!corner_tris_) {
35 corner_tris_ = skip_hidden_ ? mesh_.bvh_corner_tris_no_hidden() : mesh_.bvh_corner_tris();
36 }
37 return *corner_tris_;
38}
39
41{
42 if (!loose_edges_) {
43 loose_edges_ = skip_hidden_ ? mesh_.bvh_loose_no_hidden_edges() : mesh_.bvh_loose_edges();
44 }
45 return *loose_edges_;
46}
47
49{
50 if (!loose_verts_) {
51 loose_verts_ = skip_hidden_ ? mesh_.bvh_loose_no_hidden_verts() : mesh_.bvh_loose_verts();
52 }
53 return *loose_verts_;
54}
55
57
58/* -------------------------------------------------------------------- */
61
62/* Store all ray-hits
63 * Support for storing all depths, not just the first (ray-cast 'all'). */
64
65/* Callback to ray-cast with back-face culling (#Mesh). */
67 int index,
68 const BVHTreeRay *ray,
69 BVHTreeRayHit *hit)
70{
71 const bke::BVHTreeFromMesh *data = static_cast<bke::BVHTreeFromMesh *>(userdata);
72 const Span<float3> positions = data->vert_positions;
73 const int3 &tri = data->corner_tris[index];
74 const float *vtri_co[3] = {
75 positions[data->corner_verts[tri[0]]],
76 positions[data->corner_verts[tri[1]]],
77 positions[data->corner_verts[tri[2]]],
78 };
79 float dist = bke::bvhtree_ray_tri_intersection(ray, hit->dist, UNPACK3(vtri_co));
80
81 if (dist >= 0 && dist < hit->dist) {
82 float no[3];
83 if (raycast_tri_backface_culling_test(ray->direction, UNPACK3(vtri_co), no)) {
84 hit->index = index;
85 hit->dist = dist;
86 madd_v3_v3v3fl(hit->co, ray->origin, ray->direction, dist);
87 normalize_v3_v3(hit->no, no);
88 }
89 }
90}
91
93 const Object *ob_eval,
94 const Mesh *mesh_eval,
95 const float4x4 &obmat,
96 const uint ob_index,
97 SnapTargetTrees &trees)
98{
99 bool retval = false;
100
101 if (mesh_eval->faces_num == 0) {
102 return retval;
103 }
104
105 float4x4 imat = math::invert(obmat);
106 float3 ray_start_local = math::transform_point(imat, sctx->runtime.ray_start);
107 float3 ray_normal_local = math::transform_direction(imat, sctx->runtime.ray_dir);
108 float local_scale, local_depth, len_diff = 0.0f;
109
110 /* Local scale in normal direction. */
111 ray_normal_local = math::normalize_and_get_length(ray_normal_local, local_scale);
112
113 const bool is_in_front = (sctx->runtime.params.occlusion_test == SNAP_OCCLUSION_AS_SEEM) &&
114 (ob_eval->dtx & OB_DRAW_IN_FRONT);
115 const float depth_max = is_in_front ? sctx->ret.ray_depth_max_in_front : sctx->ret.ray_depth_max;
116 local_depth = depth_max;
117 if (local_depth != BVH_RAYCAST_DIST_MAX) {
118 local_depth *= local_scale;
119 }
120
121 /* Test bounding box. */
122 if (std::optional<Bounds<float3>> bounds = mesh_eval->bounds_min_max()) {
123 /* Was #BKE_boundbox_ray_hit_check, see: cf6ca226fa58 */
125 ray_start_local, ray_normal_local, bounds->min, bounds->max, &len_diff, nullptr))
126 {
127 return retval;
128 }
129 }
130
131 /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with
132 * very far away ray_start values (as returned in case of ortho view3d), see #50486, #38358.
133 */
134 if (len_diff > 400.0f) {
135 /* Make temporary start point a bit away from bounding-box hit point. */
136 len_diff -= local_scale;
137 madd_v3_v3fl(ray_start_local, ray_normal_local, len_diff);
138 local_depth -= len_diff;
139 }
140 else {
141 len_diff = 0.0f;
142 }
143
144 bke::BVHTreeFromMesh &treedata = trees.corner_tris();
145
146 const Span<int> tri_faces = mesh_eval->corner_tri_faces();
147
148 if (treedata.tree == nullptr) {
149 return retval;
150 }
151
152 BLI_assert(treedata.raycast_callback != nullptr);
153 if (sctx->runtime.hit_list) {
155
156 data.bvhdata = &treedata;
157 data.raycast_callback = treedata.raycast_callback;
158 data.obmat = &obmat;
159 data.len_diff = len_diff;
160 data.local_scale = local_scale;
161 data.ob_uuid = ob_index;
162 data.hit_list = sctx->runtime.hit_list;
163
164 void *hit_last_prev = data.hit_list->last();
166 treedata.tree, ray_start_local, ray_normal_local, 0.0f, depth_max, raycast_all_cb, &data);
167
168 retval = hit_last_prev != data.hit_list->last();
169 }
170 else {
171 BVHTreeRayHit hit{};
172 hit.index = -1;
173 hit.dist = local_depth;
174
175 if (BLI_bvhtree_ray_cast(treedata.tree,
176 ray_start_local,
177 ray_normal_local,
178 0.0f,
179 &hit,
180 sctx->runtime.params.use_backface_culling ?
182 treedata.raycast_callback,
183 &treedata) != -1)
184 {
185 hit.dist += len_diff;
186 hit.dist /= local_scale;
187 if (hit.dist <= depth_max) {
188 hit.index = tri_faces[hit.index];
189 retval = true;
190 }
191 SnapData::register_result_raycast(sctx, ob_eval, &mesh_eval->id, obmat, &hit, is_in_front);
192 }
193 }
194
195 return retval;
196}
197
199
200/* -------------------------------------------------------------------- */
203
205 const Object *ob_eval,
206 const Mesh *mesh_eval,
207 const float4x4 &obmat,
208 SnapTargetTrees &trees)
209{
210 bke::BVHTreeFromMesh &treedata = trees.corner_tris();
211 if (treedata.tree == nullptr) {
212 return false;
213 }
214
215 BVHTreeNearest nearest{};
216 nearest.dist_sq = sctx->ret.dist_nearest_sq;
218 sctx, treedata.tree, treedata.nearest_callback, obmat, &treedata, &nearest))
219 {
220 SnapData::register_result(sctx, ob_eval, &mesh_eval->id, obmat, &nearest);
221 return true;
222 }
223 return false;
224}
225
227
228/* -------------------------------------------------------------------- */
231
232class SnapData_Mesh : public SnapData {
233 public:
236 const int2 *edges; /* Only used for #BVHTreeFromMeshEdges. */
237 const int *corner_verts;
238 const int *corner_edges;
242 const int *face_offsets;
245
246 SnapData_Mesh(SnapObjectContext *sctx, const Mesh *mesh_eval, const float4x4 &obmat)
247 : SnapData(sctx, obmat)
248 {
249 this->vert_positions = mesh_eval->vert_positions().data();
250 this->vert_normals = mesh_eval->vert_normals().data();
251 this->edges = mesh_eval->edges().data();
252 this->corner_verts = mesh_eval->corner_verts().data();
253 this->corner_edges = mesh_eval->corner_edges().data();
254 this->corner_tris = mesh_eval->corner_tris().data();
255 this->corner_tri_faces = mesh_eval->corner_tri_faces().data();
256 this->face_normals = mesh_eval->face_normals().data();
257 this->face_offsets = mesh_eval->face_offsets().data();
258 this->verts_num = mesh_eval->verts_num;
259 this->corners_num = mesh_eval->corners_num;
260 };
261
262 void get_vert_co(const int index, const float **r_co) override
263 {
264 *r_co = this->vert_positions[index];
265 }
266
267 void get_edge_verts_index(const int index, int r_v_index[2]) override
268 {
269 const int2 &edge = this->edges[index];
270 r_v_index[0] = edge[0];
271 r_v_index[1] = edge[1];
272 }
273
274 void copy_vert_no(const int index, float r_no[3]) override
275 {
276 copy_v3_v3(r_no, this->vert_normals[index]);
277 }
278
279 void get_face_center(const int face_index, float3 &r_center) override
280 {
281 const int start = this->face_offsets[face_index];
282 const int end = this->face_offsets[face_index + 1];
283 const IndexRange face = IndexRange::from_begin_end(start, end);
284
285 const Span<int> face_verts = Span<int>(corner_verts, corners_num).slice(face);
286 const Span<float3> positions(vert_positions, verts_num);
287
288 r_center = bke::mesh::face_center_calc(positions, face_verts);
289 }
290
291 void copy_face_no(const int face_index, float r_no[3]) override
292 {
293 copy_v3_v3(r_no, this->face_normals[face_index]);
294 }
295};
296
297static void cb_snap_edge_verts(void *userdata,
298 int index,
299 const DistProjectedAABBPrecalc *precalc,
300 const float (*clip_plane)[4],
301 const int clip_plane_len,
302 BVHTreeNearest *nearest)
303{
304 SnapData_Mesh *data = static_cast<SnapData_Mesh *>(userdata);
305
306 int vindex[2];
307 data->get_edge_verts_index(index, vindex);
308
309 for (int i = 2; i--;) {
310 if (vindex[i] == nearest->index) {
311 continue;
312 }
313 cb_snap_vert(userdata, vindex[i], precalc, clip_plane, clip_plane_len, nearest);
314 }
315}
316
317static void cb_snap_tri_verts(void *userdata,
318 int index,
319 const DistProjectedAABBPrecalc *precalc,
320 const float (*clip_plane)[4],
321 const int clip_plane_len,
322 BVHTreeNearest *nearest)
323{
324 SnapData_Mesh *data = static_cast<SnapData_Mesh *>(userdata);
325
326 int vindex[3];
327 const int *corner_verts = data->corner_verts;
328 const int3 &tri = data->corner_tris[index];
329 vindex[0] = corner_verts[tri[0]];
330 vindex[1] = corner_verts[tri[1]];
331 vindex[2] = corner_verts[tri[2]];
332
333 if (data->use_backface_culling) {
334 const float3 *vert_positions = data->vert_positions;
335 const float3 &t0 = vert_positions[vindex[0]];
336 const float3 &t1 = vert_positions[vindex[1]];
337 const float3 &t2 = vert_positions[vindex[2]];
338 float dummy[3];
339 if (raycast_tri_backface_culling_test(precalc->ray_direction, t0, t1, t2, dummy)) {
340 return;
341 }
342 }
343
344 for (int i = 3; i--;) {
345 if (vindex[i] == nearest->index) {
346 continue;
347 }
348 cb_snap_vert(userdata, vindex[i], precalc, clip_plane, clip_plane_len, nearest);
349 }
350}
351
352static void cb_snap_tri_edges(void *userdata,
353 int index,
354 const DistProjectedAABBPrecalc *precalc,
355 const float (*clip_plane)[4],
356 const int clip_plane_len,
357 BVHTreeNearest *nearest)
358{
359 SnapData_Mesh *data = static_cast<SnapData_Mesh *>(userdata);
360 const int *corner_verts = data->corner_verts;
361 const int3 &tri = data->corner_tris[index];
362
363 if (data->use_backface_culling) {
364 const float3 *vert_positions = data->vert_positions;
365 const float3 &t0 = vert_positions[corner_verts[tri[0]]];
366 const float3 &t1 = vert_positions[corner_verts[tri[1]]];
367 const float3 &t2 = vert_positions[corner_verts[tri[2]]];
368 float dummy[3];
369 if (raycast_tri_backface_culling_test(precalc->ray_direction, t0, t1, t2, dummy)) {
370 return;
371 }
372 }
373
374 const int2 *edges = data->edges;
375 const int *corner_edges = data->corner_edges;
376 for (int j = 2, j_next = 0; j_next < 3; j = j_next++) {
377 int eindex = corner_edges[tri[j]];
378 const int2 &edge = edges[eindex];
379 const int2 tri_edge = {corner_verts[tri[j]], corner_verts[tri[j_next]]};
380 if (ELEM(edge[0], tri_edge[0], tri_edge[1]) && ELEM(edge[1], tri_edge[0], tri_edge[1])) {
381 if (eindex == nearest->index) {
382 continue;
383 }
384 cb_snap_edge(userdata, eindex, precalc, clip_plane, clip_plane_len, nearest);
385 }
386 }
387}
388
389static void cb_snap_tri_faces_midpoint(void *userdata,
390 const int tri_index,
391 const DistProjectedAABBPrecalc *precalc,
392 const float (*clip_plane)[4],
393 const int clip_plane_len,
394 BVHTreeNearest *nearest)
395{
396 SnapData_Mesh *data = static_cast<SnapData_Mesh *>(userdata);
397
398 const int *corner_verts = data->corner_verts;
399 const int3 &tri = data->corner_tris[tri_index];
400
401 if (data->use_backface_culling) {
402 const float3 *positions = data->vert_positions;
403 const float3 &t0 = positions[corner_verts[tri[0]]];
404 const float3 &t1 = positions[corner_verts[tri[1]]];
405 const float3 &t2 = positions[corner_verts[tri[2]]];
406
407 float dummy[3];
408 if (raycast_tri_backface_culling_test(precalc->ray_direction, t0, t1, t2, dummy)) {
409 return;
410 }
411 }
412
413 const int face_index = data->corner_tri_faces[tri_index];
414 cb_snap_face_midpoint(userdata, face_index, precalc, clip_plane, clip_plane_len, nearest);
415}
416
418
419/* -------------------------------------------------------------------- */
422
424 const Object *ob_eval,
425 const ID *id,
426 const float4x4 &obmat,
427 eSnapMode snap_to_flag,
428 int face_index)
429{
431
432 const Mesh *mesh_eval = reinterpret_cast<const Mesh *>(id);
433
434 SnapData_Mesh nearest2d(sctx, mesh_eval, obmat);
435 nearest2d.clip_planes_enable(sctx, ob_eval);
436
437 BVHTreeNearest nearest{};
438 nearest.index = -1;
439 nearest.dist_sq = sctx->ret.dist_px_sq;
440
441 const IndexRange face = mesh_eval->faces()[face_index];
442
443 if (snap_to_flag &
445 {
446 /* We return "Snap to Edge" even if the intent is "Snap to Edge Midpoint" or
447 * "Snap to Edge Perpendicular".
448 * This avoids complexity. These snap points will be tested in `snap_edge_points`. */
449 elem = SCE_SNAP_TO_EDGE;
450 BLI_assert(nearest2d.edges != nullptr);
451 const int *face_edges = &nearest2d.corner_edges[face.start()];
452 for (int i = face.size(); i--;) {
453 cb_snap_edge(&nearest2d,
454 face_edges[i],
455 &nearest2d.nearest_precalc,
456 reinterpret_cast<float (*)[4]>(nearest2d.clip_planes.data()),
457 nearest2d.clip_planes.size(),
458 &nearest);
459 }
460 }
461 else {
463 const int *face_verts = &nearest2d.corner_verts[face.start()];
464 for (int i = face.size(); i--;) {
465 cb_snap_vert(&nearest2d,
466 face_verts[i],
467 &nearest2d.nearest_precalc,
468 reinterpret_cast<float (*)[4]>(nearest2d.clip_planes.data()),
469 nearest2d.clip_planes.size(),
470 &nearest);
471 }
472 }
473
474 if (nearest.index != -1) {
475 nearest2d.nearest_point = nearest;
476 nearest2d.register_result(sctx, ob_eval, id);
477 return elem;
478 }
479
480 return SCE_SNAP_TO_NONE;
481}
482
484 const Object *ob_eval,
485 const ID *id,
486 const float4x4 &obmat,
487 float dist_px_sq_orig,
488 int edge_index)
489{
490 SnapData_Mesh nearest2d(sctx, reinterpret_cast<const Mesh *>(id), obmat);
491 eSnapMode elem = nearest2d.snap_edge_points_impl(sctx, edge_index, dist_px_sq_orig);
492 if (nearest2d.nearest_point.index != -2) {
493 nearest2d.register_result(sctx, ob_eval, id);
494 }
495 return elem;
496}
497
499{
500 /* Whether anything can be snapped to with #SCE_SNAP_TO_POINT isn't known until
501 * #SnapTargetTrees::loose_verts is built, and that doesn't directly correspond to
502 * #Mesh::loose_verts(). */
503 eSnapMode snap_mode_supported = SCE_SNAP_TO_POINT;
504 if (mesh->faces_num) {
505 snap_mode_supported |= SCE_SNAP_TO_FACE | SCE_SNAP_TO_FACE_MIDPOINT |
507 }
508 else if (mesh->edges_num) {
509 snap_mode_supported |= SNAP_TO_EDGE_ELEMENTS;
510 }
511
512 return snap_mode_supported;
513}
514
516 const Object *ob_eval,
517 const Mesh *mesh_eval,
518 const float4x4 &obmat,
519 SnapTargetTrees &trees,
520 bool is_editmesh,
521 eSnapMode snap_to)
522{
523 BLI_assert(snap_to != SCE_SNAP_TO_FACE);
524 SnapData_Mesh nearest2d(sctx, mesh_eval, obmat);
525 if (is_editmesh) {
526 nearest2d.use_backface_culling = false;
527 }
528
529 if (std::optional<Bounds<float3>> bounds = mesh_eval->bounds_min_max()) {
530 if (!nearest2d.snap_boundbox(bounds->min, bounds->max)) {
531 return SCE_SNAP_TO_NONE;
532 }
533 }
534
535 snap_to &= mesh_snap_mode_supported(mesh_eval) &
537 if (snap_to == SCE_SNAP_TO_NONE) {
538 return SCE_SNAP_TO_NONE;
539 }
540
541 const bke::BVHTreeFromMesh &treedata = trees.corner_tris();
542
543 const BVHTree *bvhtree[2] = {nullptr};
544 bvhtree[0] = trees.loose_edges().tree;
545 if (snap_to & SCE_SNAP_TO_POINT) {
546 bvhtree[1] = trees.loose_verts().tree;
547 }
548
549 /* #XRAY_ENABLED can return false even with the XRAY flag enabled, this happens because the
550 * alpha is 1.0 in this case. But even with the alpha being 1.0, the edit mesh is still not
551 * occluded. */
552 const bool skip_occlusion_plane = is_editmesh && XRAY_FLAG_ENABLED(sctx->runtime.v3d);
553 nearest2d.clip_planes_enable(sctx, ob_eval, skip_occlusion_plane);
554
555 BVHTreeNearest nearest{};
556 nearest.index = -1;
557 nearest.dist_sq = sctx->ret.dist_px_sq;
558
559 int last_index = nearest.index;
561
562 if (bvhtree[1]) {
563 BLI_assert(snap_to & SCE_SNAP_TO_POINT);
564 /* Snap to loose verts. */
566 bvhtree[1],
567 nearest2d.pmat_local.ptr(),
568 sctx->runtime.win_size,
569 sctx->runtime.mval,
570 reinterpret_cast<float (*)[4]>(nearest2d.clip_planes.data()),
571 nearest2d.clip_planes.size(),
572 &nearest,
574 &nearest2d);
575
576 if (nearest.index != -1) {
577 last_index = nearest.index;
578 elem = SCE_SNAP_TO_POINT;
579 }
580 }
581
582 if (snap_to & SCE_SNAP_TO_FACE_MIDPOINT) {
583 if (treedata.tree) {
585 treedata.tree,
586 nearest2d.pmat_local.ptr(),
587 sctx->runtime.win_size,
588 sctx->runtime.mval,
589 reinterpret_cast<float (*)[4]>(nearest2d.clip_planes.data()),
590 nearest2d.clip_planes.size(),
591 &nearest,
593 &nearest2d);
594 }
595 if (last_index != nearest.index) {
596 last_index = nearest.index;
598 }
599 }
600
602 if (bvhtree[0]) {
603 /* Snap to loose edges. */
605 bvhtree[0],
606 nearest2d.pmat_local.ptr(),
607 sctx->runtime.win_size,
608 sctx->runtime.mval,
609 reinterpret_cast<float (*)[4]>(nearest2d.clip_planes.data()),
610 nearest2d.clip_planes.size(),
611 &nearest,
613 &nearest2d);
614 }
615
616 if (treedata.tree) {
617 /* Snap to corner_tris. */
619 treedata.tree,
620 nearest2d.pmat_local.ptr(),
621 sctx->runtime.win_size,
622 sctx->runtime.mval,
623 reinterpret_cast<float (*)[4]>(nearest2d.clip_planes.data()),
624 nearest2d.clip_planes.size(),
625 &nearest,
627 &nearest2d);
628 }
629
630 if (last_index != nearest.index) {
631 elem = SCE_SNAP_TO_EDGE;
632 }
633 }
634 else if (snap_to & SCE_SNAP_TO_EDGE_ENDPOINT) {
635 if (bvhtree[0]) {
636 /* Snap to loose edges verts. */
638 bvhtree[0],
639 nearest2d.pmat_local.ptr(),
640 sctx->runtime.win_size,
641 sctx->runtime.mval,
642 reinterpret_cast<float (*)[4]>(nearest2d.clip_planes.data()),
643 nearest2d.clip_planes.size(),
644 &nearest,
646 &nearest2d);
647 }
648
649 if (treedata.tree) {
650 /* Snap to corner_tris verts. */
652 treedata.tree,
653 nearest2d.pmat_local.ptr(),
654 sctx->runtime.win_size,
655 sctx->runtime.mval,
656 reinterpret_cast<float (*)[4]>(nearest2d.clip_planes.data()),
657 nearest2d.clip_planes.size(),
658 &nearest,
660 &nearest2d);
661 }
662
663 if (last_index != nearest.index) {
665 }
666 }
667
668 if (nearest.index != -1) {
669 nearest2d.nearest_point = nearest;
670 nearest2d.register_result(sctx, ob_eval, &mesh_eval->id);
671 return elem;
672 }
673
674 return SCE_SNAP_TO_NONE;
675}
676
678
680 const Object *ob_eval,
681 const ID *id,
682 const float4x4 &obmat,
683 eSnapMode snap_to_flag,
684 SnapTargetTrees &trees,
685 bool is_editmesh)
686{
688 const Mesh *mesh_eval = reinterpret_cast<const Mesh *>(id);
689
691 elem = snapMesh(sctx, ob_eval, mesh_eval, obmat, trees, is_editmesh, snap_to_flag);
692 if (elem) {
693 return elem;
694 }
695 }
696
697 if (snap_to_flag & SCE_SNAP_TO_FACE) {
698 if (raycastMesh(sctx, ob_eval, mesh_eval, obmat, sctx->runtime.object_index++, trees)) {
699 return SCE_SNAP_TO_FACE;
700 }
701 }
702
703 if (snap_to_flag & SCE_SNAP_INDIVIDUAL_NEAREST) {
704 if (nearest_world_mesh(sctx, ob_eval, mesh_eval, obmat, trees)) {
706 }
707 }
708
709 return SCE_SNAP_TO_NONE;
710}
711
713 const Object *ob_eval,
714 const ID *id,
715 const float4x4 &obmat,
716 eSnapMode snap_to_flag,
717 const bool skip_hidden)
718{
719 SnapTargetTreesMesh trees(*id_cast<const Mesh *>(id), skip_hidden);
720 return snap_object_mesh(sctx, ob_eval, id, obmat, snap_to_flag, trees, false);
721}
722
723} // namespace blender::ed::transform
#define BVH_RAYCAST_DIST_MAX
#define XRAY_FLAG_ENABLED(v3d)
#define UNPACK3(a)
#define ELEM(...)
constexpr int64_t size() const
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
constexpr int64_t start() const
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
void copy_face_no(const int face_index, float r_no[3]) override
void copy_vert_no(const int index, float r_no[3]) override
SnapData_Mesh(SnapObjectContext *sctx, const Mesh *mesh_eval, const float4x4 &obmat)
void get_edge_verts_index(const int index, int r_v_index[2]) override
void get_vert_co(const int index, const float **r_co) override
void get_face_center(const int face_index, float3 &r_center) override
void clip_planes_enable(SnapObjectContext *sctx, const Object *ob_eval, bool skip_occlusion_plane=false)
Vector< float4, MAX_CLIPPLANE_LEN+1 > clip_planes
SnapData(SnapObjectContext *sctx, const float4x4 &obmat=float4x4::identity())
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)
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)
virtual bke::BVHTreeFromMesh & loose_edges()=0
virtual bke::BVHTreeFromMesh & loose_verts()=0
virtual bke::BVHTreeFromMesh & corner_tris()=0
float3 face_center_calc(Span< float3 > vert_positions, Span< int > face_verts)
float bvhtree_ray_tri_intersection(const BVHTreeRay *ray, float m_dist, const float v0[3], const float v1[3], const float v2[3])
Definition bvhutils.cc:30
static eSnapMode mesh_snap_mode_supported(const Mesh *mesh)
static bool raycastMesh(SnapObjectContext *sctx, const Object *ob_eval, const Mesh *mesh_eval, const float4x4 &obmat, const uint ob_index, SnapTargetTrees &trees)
void raycast_all_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
static void cb_snap_edge_verts(void *userdata, int index, const DistProjectedAABBPrecalc *precalc, const float(*clip_plane)[4], const int clip_plane_len, BVHTreeNearest *nearest)
bool nearest_world_tree(SnapObjectContext *sctx, const BVHTree *tree, BVHTree_NearestPointCallback nearest_cb, const float4x4 &obmat, void *treedata, BVHTreeNearest *r_nearest)
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_edge_points_mesh(SnapObjectContext *sctx, const Object *ob_eval, const ID *id, const float4x4 &obmat, float dist_px_sq_orig, int edge_index)
static bool nearest_world_mesh(SnapObjectContext *sctx, const Object *ob_eval, const Mesh *mesh_eval, const float4x4 &obmat, SnapTargetTrees &trees)
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)
static void mesh_corner_tris_raycast_backface_culling_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
eSnapMode snap_object_mesh(SnapObjectContext *sctx, const Object *ob_eval, const ID *id, const float4x4 &obmat, eSnapMode snap_to_flag, bool skip_hidden)
void cb_snap_face_midpoint(void *userdata, const int face_index, const DistProjectedAABBPrecalc *precalc, const float(*clip_plane)[4], const int clip_plane_len, BVHTreeNearest *nearest)
static eSnapMode snapMesh(SnapObjectContext *sctx, const Object *ob_eval, const Mesh *mesh_eval, const float4x4 &obmat, SnapTargetTrees &trees, bool is_editmesh, eSnapMode snap_to)
static void cb_snap_tri_verts(void *userdata, int index, const DistProjectedAABBPrecalc *precalc, const float(*clip_plane)[4], const int clip_plane_len, BVHTreeNearest *nearest)
static void cb_snap_tri_edges(void *userdata, int index, const DistProjectedAABBPrecalc *precalc, const float(*clip_plane)[4], const int clip_plane_len, BVHTreeNearest *nearest)
eSnapMode snap_polygon_mesh(SnapObjectContext *sctx, const Object *ob_eval, const ID *id, const float4x4 &obmat, eSnapMode snap_to_flag, int face_index)
static void cb_snap_tri_faces_midpoint(void *userdata, const int tri_index, const DistProjectedAABBPrecalc *precalc, const float(*clip_plane)[4], const int clip_plane_len, BVHTreeNearest *nearest)
QuaternionBase< T > normalize_and_get_length(const QuaternionBase< T > &q, T &out_length)
CartesianBasis invert(const CartesianBasis &basis)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
MatBase< float, 4, 4 > float4x4
bool isect_ray_aabb_v3_simple(const float orig[3], const float dir[3], const float bb_min[3], const float bb_max[3], float *tmin, float *tmax)
int BLI_bvhtree_ray_cast(const BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
BMesh const char void * data
@ SCE_SNAP_TO_EDGE_MIDPOINT
@ SCE_SNAP_TO_EDGE_PERPENDICULAR
@ SCE_SNAP_TO_FACE_MIDPOINT
@ SCE_SNAP_INDIVIDUAL_NEAREST
@ SCE_SNAP_TO_EDGE_ENDPOINT
void BLI_bvhtree_ray_cast_all(const BVHTree *tree, const float co[3], const float dir[3], float radius, float hit_dist, BVHTree_RayCastCallback callback, void *userdata)
MINLINE float normalize_v3_v3(float r[3], const float a[3])
VecBase< float, 3 > float3
int BLI_bvhtree_find_nearest_projected(const BVHTree *tree, float projmat[4][4], float winsize[2], float mval[2], float(*clip_planes)[4], int clip_plane_len, BVHTreeNearest *nearest, BVHTree_NearestProjectedCallback callback, void *userdata)
const c_style_mat & ptr() const
eObject_DrawExtraFlag dtx
BVHTree_NearestPointCallback nearest_callback
BVHTree_RayCastCallback raycast_callback
struct blender::ed::transform::SnapObjectContext::Output ret
struct blender::ed::transform::SnapObjectContext::@247331373256345130115246240121215056001150353127 runtime
#define SNAP_TO_EDGE_ELEMENTS