22# pragma optimize("t", on)
38 *r_treedata = mesh_eval->bvh_corner_tris_no_hidden();
41 *r_treedata = mesh_eval->bvh_corner_tris();
62 const int3 &tri =
data->corner_tris[index];
63 const float *vtri_co[3] = {
64 positions[
data->corner_verts[tri[0]]],
65 positions[
data->corner_verts[tri[1]]],
66 positions[
data->corner_verts[tri[2]]],
70 if (dist >= 0 && dist < hit->dist) {
83 const Mesh *mesh_eval,
97 float local_scale, local_depth, len_diff = 0.0f;
105 local_depth = depth_max;
107 local_depth *= local_scale;
111 if (std::optional<
Bounds<float3>> bounds = mesh_eval->bounds_min_max()) {
114 ray_start_local, ray_normal_local, bounds->min, bounds->max, &len_diff,
nullptr))
123 if (len_diff > 400.0f) {
125 len_diff -= local_scale;
126 madd_v3_v3fl(ray_start_local, ray_normal_local, len_diff);
127 local_depth -= len_diff;
136 const Span<int> tri_faces = mesh_eval->corner_tri_faces();
138 if (treedata.
tree ==
nullptr) {
149 data.len_diff = len_diff;
150 data.local_scale = local_scale;
151 data.ob_uuid = ob_index;
154 void *hit_last_prev =
data.hit_list->
last;
158 retval = hit_last_prev !=
data.hit_list->last;
163 hit.dist = local_depth;
175 hit.dist += len_diff;
176 hit.dist /= local_scale;
177 if (hit.dist <= depth_max) {
178 hit.index = tri_faces[hit.index];
196 const Mesh *mesh_eval,
202 if (treedata.
tree ==
nullptr) {
235 this->vert_positions = mesh_eval->vert_positions().data();
236 this->vert_normals = mesh_eval->vert_normals().data();
237 this->edges = mesh_eval->edges().data();
238 this->corner_verts = mesh_eval->corner_verts().data();
239 this->corner_edges = mesh_eval->corner_edges().data();
240 this->corner_tris = mesh_eval->corner_tris().data();
245 *r_co = this->vert_positions[index];
250 const int2 &edge = this->edges[index];
251 r_v_index[0] = edge[0];
252 r_v_index[1] = edge[1];
264 const float (*clip_plane)[4],
265 const int clip_plane_len,
273 for (
int i = 2; i--;) {
274 if (vindex[i] == nearest->
index) {
277 cb_snap_vert(userdata, vindex[i], precalc, clip_plane, clip_plane_len, nearest);
284 const float (*clip_plane)[4],
285 const int clip_plane_len,
292 const int3 &tri =
data->corner_tris[index];
293 vindex[0] = corner_verts[tri[0]];
294 vindex[1] = corner_verts[tri[1]];
295 vindex[2] = corner_verts[tri[2]];
297 if (
data->use_backface_culling) {
298 const float3 *vert_positions =
data->vert_positions;
299 const float3 &t0 = vert_positions[vindex[0]];
300 const float3 &t1 = vert_positions[vindex[1]];
301 const float3 &t2 = vert_positions[vindex[2]];
308 for (
int i = 3; i--;) {
309 if (vindex[i] == nearest->
index) {
312 cb_snap_vert(userdata, vindex[i], precalc, clip_plane, clip_plane_len, nearest);
319 const float (*clip_plane)[4],
320 const int clip_plane_len,
325 const int3 &tri =
data->corner_tris[index];
327 if (
data->use_backface_culling) {
328 const float3 *vert_positions =
data->vert_positions;
329 const float3 &t0 = vert_positions[corner_verts[tri[0]]];
330 const float3 &t1 = vert_positions[corner_verts[tri[1]]];
331 const float3 &t2 = vert_positions[corner_verts[tri[2]]];
339 const int *corner_edges =
data->corner_edges;
340 for (
int j = 2, j_next = 0; j_next < 3; j = j_next++) {
341 int eindex = corner_edges[tri[j]];
342 const int2 &edge = edges[eindex];
343 const int2 tri_edge = {corner_verts[tri[j]], corner_verts[tri[j_next]]};
344 if (
ELEM(edge[0], tri_edge[0], tri_edge[1]) &&
ELEM(edge[1], tri_edge[0], tri_edge[1])) {
345 if (eindex == nearest->
index) {
348 cb_snap_edge(userdata, eindex, precalc, clip_plane, clip_plane_len, nearest);
368 const Mesh *mesh_eval =
reinterpret_cast<const Mesh *
>(id);
377 const IndexRange face = mesh_eval->faces()[face_index];
388 for (
int i = face.
size(); i--;) {
392 reinterpret_cast<float(*)[4]
>(nearest2d.
clip_planes.data()),
400 for (
int i = face.
size(); i--;) {
404 reinterpret_cast<float(*)[4]
>(nearest2d.
clip_planes.data()),
410 if (nearest.index != -1) {
423 float dist_px_sq_orig,
448 return snap_mode_supported;
453 const Mesh *mesh_eval,
465 if (std::optional<
Bounds<float3>> bounds = mesh_eval->bounds_min_max()) {
480 const BVHTree *bvhtree[2] = {
nullptr};
481 bvhtree[0] = skip_hidden ? mesh_eval->bvh_loose_no_hidden_edges().tree :
482 mesh_eval->bvh_loose_edges().tree;
484 bvhtree[1] = skip_hidden ? mesh_eval->bvh_loose_no_hidden_verts().tree :
485 mesh_eval->bvh_loose_verts().tree;
498 int last_index = nearest.index;
508 reinterpret_cast<float(*)[4]
>(nearest2d.
clip_planes.data()),
514 if (nearest.index != -1) {
515 last_index = nearest.index;
528 reinterpret_cast<float(*)[4]
>(nearest2d.
clip_planes.data()),
542 reinterpret_cast<float(*)[4]
>(nearest2d.
clip_planes.data()),
549 if (last_index != nearest.index) {
561 reinterpret_cast<float(*)[4]
>(nearest2d.
clip_planes.data()),
575 reinterpret_cast<float(*)[4]
>(nearest2d.
clip_planes.data()),
582 if (last_index != nearest.index) {
587 if (nearest.index != -1) {
607 const Mesh *mesh_eval =
reinterpret_cast<const Mesh *
>(id);
610 elem =
snapMesh(sctx, ob_eval, mesh_eval, obmat, skip_hidden, is_editmesh, snap_to_flag);
#define BVH_RAYCAST_DIST_MAX
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)
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)
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)
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)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
@ SCE_SNAP_INDIVIDUAL_NEAREST
@ SCE_SNAP_TO_EDGE_ENDPOINT
@ SCE_SNAP_TO_EDGE_MIDPOINT
@ SCE_SNAP_TO_EDGE_PERPENDICULAR
#define XRAY_FLAG_ENABLED(v3d)
constexpr int64_t size() const
constexpr int64_t start() const
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)
const c_style_mat & ptr() const
BVHTree_NearestPointCallback nearest_callback
BVHTree_RayCastCallback raycast_callback
float ray_depth_max_in_front
struct blender::ed::transform::SnapObjectContext::@516 runtime
struct blender::ed::transform::SnapObjectContext::@517 ret