22# pragma optimize("t", on)
35 corner_tris_ = skip_hidden_ ? mesh_.bvh_corner_tris_no_hidden() : mesh_.bvh_corner_tris();
43 loose_edges_ = skip_hidden_ ? mesh_.bvh_loose_no_hidden_edges() : mesh_.bvh_loose_edges();
51 loose_verts_ = skip_hidden_ ? mesh_.bvh_loose_no_hidden_verts() : mesh_.bvh_loose_verts();
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]]],
81 if (dist >= 0 && dist < hit->dist) {
94 const Mesh *mesh_eval,
108 float local_scale, local_depth, len_diff = 0.0f;
116 local_depth = depth_max;
118 local_depth *= local_scale;
125 ray_start_local, ray_normal_local,
bounds->min,
bounds->max, &len_diff,
nullptr))
134 if (len_diff > 400.0f) {
136 len_diff -= local_scale;
137 madd_v3_v3fl(ray_start_local, ray_normal_local, len_diff);
138 local_depth -= len_diff;
146 const Span<int> tri_faces = mesh_eval->corner_tri_faces();
148 if (treedata.
tree ==
nullptr) {
156 data.bvhdata = &treedata;
159 data.len_diff = len_diff;
160 data.local_scale = local_scale;
161 data.ob_uuid = ob_index;
164 void *hit_last_prev =
data.hit_list->last();
168 retval = hit_last_prev !=
data.hit_list->last();
173 hit.
dist = local_depth;
180 sctx->
runtime.params.use_backface_culling ?
185 hit.
dist += len_diff;
186 hit.
dist /= local_scale;
187 if (hit.
dist <= depth_max) {
206 const Mesh *mesh_eval,
211 if (treedata.
tree ==
nullptr) {
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();
264 *r_co = this->vert_positions[
index];
270 r_v_index[0] = edge[0];
271 r_v_index[1] = edge[1];
281 const int start = this->face_offsets[face_index];
282 const int end = this->face_offsets[face_index + 1];
293 copy_v3_v3(r_no, this->face_normals[face_index]);
300 const float (*clip_plane)[4],
301 const int clip_plane_len,
307 data->get_edge_verts_index(
index, vindex);
309 for (
int i = 2; i--;) {
310 if (vindex[i] == nearest->
index) {
313 cb_snap_vert(userdata, vindex[i], precalc, clip_plane, clip_plane_len, nearest);
320 const float (*clip_plane)[4],
321 const int clip_plane_len,
327 const int *corner_verts =
data->corner_verts;
329 vindex[0] = corner_verts[tri[0]];
330 vindex[1] = corner_verts[tri[1]];
331 vindex[2] = corner_verts[tri[2]];
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]];
344 for (
int i = 3; i--;) {
345 if (vindex[i] == nearest->
index) {
348 cb_snap_vert(userdata, vindex[i], precalc, clip_plane, clip_plane_len, nearest);
355 const float (*clip_plane)[4],
356 const int clip_plane_len,
360 const int *corner_verts =
data->corner_verts;
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]]];
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) {
384 cb_snap_edge(userdata, eindex, precalc, clip_plane, clip_plane_len, nearest);
392 const float (*clip_plane)[4],
393 const int clip_plane_len,
398 const int *corner_verts =
data->corner_verts;
399 const int3 &tri =
data->corner_tris[tri_index];
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]]];
413 const int face_index =
data->corner_tri_faces[tri_index];
432 const Mesh *mesh_eval =
reinterpret_cast<const Mesh *
>(
id);
441 const IndexRange face = mesh_eval->faces()[face_index];
452 for (
int i = face.
size(); i--;) {
456 reinterpret_cast<float (*)[4]
>(nearest2d.
clip_planes.data()),
464 for (
int i = face.
size(); i--;) {
468 reinterpret_cast<float (*)[4]
>(nearest2d.
clip_planes.data()),
474 if (nearest.
index != -1) {
487 float dist_px_sq_orig,
504 if (
mesh->faces_num) {
508 else if (
mesh->edges_num) {
512 return snap_mode_supported;
517 const Mesh *mesh_eval,
543 const BVHTree *bvhtree[2] = {
nullptr};
559 int last_index = nearest.
index;
570 reinterpret_cast<float (*)[4]
>(nearest2d.
clip_planes.data()),
576 if (nearest.
index != -1) {
577 last_index = nearest.
index;
589 reinterpret_cast<float (*)[4]
>(nearest2d.
clip_planes.data()),
595 if (last_index != nearest.
index) {
596 last_index = nearest.
index;
609 reinterpret_cast<float (*)[4]
>(nearest2d.
clip_planes.data()),
623 reinterpret_cast<float (*)[4]
>(nearest2d.
clip_planes.data()),
630 if (last_index != nearest.
index) {
642 reinterpret_cast<float (*)[4]
>(nearest2d.
clip_planes.data()),
656 reinterpret_cast<float (*)[4]
>(nearest2d.
clip_planes.data()),
663 if (last_index != nearest.
index) {
668 if (nearest.
index != -1) {
688 const Mesh *mesh_eval =
reinterpret_cast<const Mesh *
>(
id);
691 elem =
snapMesh(sctx, ob_eval, mesh_eval, obmat, trees, is_editmesh, snap_to_flag);
698 if (
raycastMesh(sctx, ob_eval, mesh_eval, obmat, sctx->
runtime.object_index++, trees)) {
717 const bool skip_hidden)
720 return snap_object_mesh(sctx, ob_eval,
id, obmat, snap_to_flag, trees,
false);
#define BVH_RAYCAST_DIST_MAX
#define XRAY_FLAG_ENABLED(v3d)
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
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])
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])
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
float ray_depth_max_in_front
struct blender::ed::transform::SnapObjectContext::Output ret
struct blender::ed::transform::SnapObjectContext::@247331373256345130115246240121215056001150353127 runtime