37# pragma optimize("t", on)
50 if (
dot_v3v3(ray_dir, plane) > 0.0f) {
62 const float (*clip_plane)[4],
63 const int clip_plane_len,
83 if (dist_sq < nearest->dist_sq) {
92 const float (*clip_plane)[4],
93 const int clip_plane_len,
111 this->pmat_local = float4x4(sctx->runtime.rv3d->persmat) * obmat;
114 this->pmat_local = obmat;
120 this->nearest_point.index = -2;
127 bool skip_occlusion_plane)
130 if (!skip_occlusion_plane) {
151#ifdef TEST_CLIPPLANES_IN_BOUNDBOX
153 reinterpret_cast<const float(*)[4]
>(this->
clip_planes.data()),
154 this->clip_planes.size(),
175 reinterpret_cast<const float(*)[4]
>(this->
clip_planes.data()),
176 this->clip_planes.size(),
179 &
this->nearest_point))
190 reinterpret_cast<const float(*)[4]
>(this->
clip_planes.data()),
191 this->clip_planes.size(),
195 &
this->nearest_point))
206 float dist_px_sq_orig)
213 const float *v_pair[2];
219 this->nearest_precalc.ray_direction,
234 float range = 1.0f / (2 * e_mode_len - 1);
237 range *= e_mode_len - 1;
238 if ((range) < lambda && lambda < (1.0f - range)) {
250 float v_near[3], va_g[3], vb_g[3];
256 if (
IN_RANGE(lambda_perp, 0.0f, 1.0f)) {
268 if (lambda < (range) || (1.0f - range) < lambda) {
269 int v_id = lambda < 0.5f ? 0 : 1;
271 if (this->
snap_point(v_pair[v_id], vindex[v_id])) {
294 sctx->
ret.
ob = ob_eval;
304 r_nearest->
index = -2;
318 const bool is_in_front)
321 if (hit->
dist <= depth_max) {
329 sctx->
ret.
ob = ob_eval;
354 bool use_hide =
false;
356 switch (ob_eval->
type) {
374 mesh_eval = editmesh_eval;
379 *r_use_hide = use_hide;
381 return (
ID *)mesh_eval;
387 *r_use_hide = use_hide;
389 return (
ID *)ob_eval->
data;
402 bool is_object_active,
407 const Base *base_act,
425 const bool is_active = (base_act == base);
430 const bool is_in_object_mode = (base_act ==
nullptr) ||
433 if (is_in_object_mode) {
480 const bool is_object_active = (base == base_act);
488 if ((tmp = sob_callback(sctx,
501 bool use_hide =
false;
503 if ((tmp = sob_callback(
504 sctx, obj_eval, ob_data, obj_eval->object_to_world(), is_object_active, use_hide)) !=
552 data->raycast_callback(
data->bvhdata, index, ray, hit);
553 if (hit->
index != -1) {
560 depth = (hit->
dist +
data->len_diff) /
data->local_scale;
568 const float dir[3],
const float v0[3],
const float v1[3],
const float v2[3],
float no[3])
586 if (ob_data ==
nullptr) {
661 r_nearest->
index = -1;
694 if (r_nearest->
dist_sq <= original_distance) {
702 float3 delta = (curr_co - init_co) * step_scale_factor;
711 *r_nearest = nearest;
713 r_nearest->
dist_sq = original_distance;
734 if (ob_data ==
nullptr) {
788 const float (*clip_plane)[4],
789 const int clip_plane_len,
795 data->get_vert_co(index, &co);
798 data->copy_vert_no(index, nearest->
no);
799 nearest->
index = index;
806 const float (*clip_plane)[4],
807 const int clip_plane_len,
813 data->get_edge_verts_index(index, vindex);
815 const float *v_pair[2];
816 data->get_vert_co(vindex[0], &v_pair[0]);
817 data->get_vert_co(vindex[1], &v_pair[1]);
820 precalc, clip_plane, clip_plane_len,
data->is_persp, v_pair[0], v_pair[1], nearest))
823 nearest->
index = index;
888 bool is_object_active,
891 if (ob_data ==
nullptr && (ob_eval->
type ==
OB_MESH)) {
896 if (ob_data ==
nullptr) {
917 switch (ob_eval->
type) {
922 retval =
snapArmature(sctx, ob_eval, obmat, is_object_active);
927 retval =
snapCurve(sctx, ob_eval, obmat);
983 for (
int i = 0;
i < 4;
i++) {
1021 sctx->
scene = scene;
1032 bool (*test_vert_fn)(
BMVert *,
void *user_data),
1033 bool (*test_edge_fn)(
BMEdge *,
void *user_data),
1034 bool (*test_face_fn)(
BMFace *,
void *user_data),
1037 bool is_cache_dirty =
false;
1040 is_cache_dirty =
true;
1044 is_cache_dirty =
true;
1048 is_cache_dirty =
true;
1052 is_cache_dirty =
true;
1055 if (is_cache_dirty) {
1067 const float ray_start[3],
1068 const float ray_dir[3],
1069 const float ray_depth,
1070 const float mval[2],
1071 const float init_co[3],
1072 const float prev_co[3],
1073 const float dist_px_sq,
1144 if (
params->grid_size == 0.0f) {
1171 sctx->
ret.
ob =
nullptr;
1182 const float ray_start[3],
1183 const float ray_normal[3],
1189 float r_obmat[4][4])
1220 *r_ob = sctx->
ret.
ob;
1237 const float ray_start[3],
1238 const float ray_normal[3],
1282 const float ray_start[3],
1283 const float ray_normal[3],
1308 const float init_co[3],
1309 const float mval[2],
1310 const float prev_co[3],
1316 float r_obmat[4][4],
1317 float r_face_nor[3])
1321 bool use_occlusion_plane =
false;
1329 use_occlusion_plane =
true;
1361 use_occlusion_plane =
false;
1371 use_occlusion_plane ?
params->occlusion_test :
1386#ifdef DEBUG_SNAP_TIME
1394 bool has_hit =
false;
1426 if (use_occlusion_plane && has_hit) {
1464 retval = elem & snap_to_flag;
1480 *r_ob = sctx->
ret.
ob;
1494#ifdef DEBUG_SNAP_TIME
1495 duration_ += timeit::Clock::now() - start_;
1508 const float init_co[3],
1509 const float mval[2],
1510 const float prev_co[3],
1538 const float mval[2],
1543 float3 ray_start, ray_normal, ray_end;
1547 depsgraph, region, v3d, mval,
false,
nullptr, ray_normal, ray_start, ray_end))
1555 float ray_depth_max =
math::dot(ray_end - ray_start, ray_normal);
1556 if ((ray_depth == -1.0f) || (ray_depth > ray_depth_max)) {
1557 ray_depth = ray_depth_max;
1565#ifdef DEBUG_SNAP_TIME
1568 std::cout <<
"Average snapping time: ";
1569 std::cout << std::fixed << duration_.count() / 1.0e6 <<
" ms";
1572 duration_ = timeit::Nanoseconds::zero();
void free_object_duplilist(ListBase *lb)
ListBase * object_duplilist(Depsgraph *depsgraph, Scene *sce, Object *ob, blender::Set< const Object * > *include_objects=nullptr)
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
ListBase * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
General operations, lookup, etc. for blender objects.
const Mesh * BKE_object_get_editmesh_eval_cage(const Object *object)
bool BKE_object_is_in_editmode(const Object *ob)
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
const Mesh * BKE_object_get_editmesh_eval_final(const Object *object)
#define BVH_RAYCAST_DIST_MAX
void(*)(void *userdata, int index, const float co[3], BVHTreeNearest *nearest) BVHTree_NearestPointCallback
int BLI_bvhtree_find_nearest(const BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata)
#define LISTBASE_FOREACH(type, var, list)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void void BLI_listbase_sort(ListBase *listbase, int(*cmp)(const void *, const void *)) ATTR_NONNULL(1
MINLINE float max_ff(float a, float b)
MINLINE float square_f(float a)
#define BLI_ASSERT_UNIT_V3(v)
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
bool clip_segment_v3_plane_n(const float p1[3], const float p2[3], const float plane_array[][4], int plane_num, float r_p1[3], float r_p2[3])
bool isect_ray_plane_v3(const float ray_origin[3], const float ray_direction[3], const float plane[4], float *r_lambda, bool clip)
float dist_squared_to_projected_aabb(struct DistProjectedAABBPrecalc *data, const float bbmin[3], const float bbmax[3], bool r_axis_closest[3])
bool isect_ray_line_v3(const float ray_origin[3], const float ray_direction[3], const float v0[3], const float v1[3], float *r_lambda)
bool isect_point_planes_v3_negated(const float(*planes)[4], int totplane, const float p[3])
void cross_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
#define ISECT_AABB_PLANE_BEHIND_ANY
float closest_ray_to_segment_v3(const float ray_origin[3], const float ray_direction[3], const float v0[3], const float v1[3], float r_close[3])
void dist_squared_to_projected_aabb_precalc(struct DistProjectedAABBPrecalc *precalc, const float projmat[4][4], const float winsize[2], const float mval[2])
int isect_aabb_planes_v3(const float(*planes)[4], int totplane, const float bbmin[3], const float bbmax[3])
float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3])
void planes_from_projmat(const float mat[4][4], float left[4], float right[4], float bottom[4], float top[4], float near[4], float far[4])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
bool compare_m4m4(const float mat1[4][4], const float mat2[4][4], float limit)
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
MINLINE float mul_project_m4_v3_zfac(const float mat[4][4], const float co[3]) ATTR_WARN_UNUSED_RESULT
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE float dot_m4_v3_row_x(const float M[4][4], const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float dot_m4_v3_row_y(const float M[4][4], const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void negate_v4(float r[4])
#define IN_RANGE(a, b, c)
bool DEG_is_evaluated(const T *id)
ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
Scene * DEG_get_input_scene(const Depsgraph *graph)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ BA_TRANSFORM_LOCKED_IN_PLACE
@ BA_SNAP_FIX_DEPS_FIASCO
#define BASE_SELECTED(v3d, base)
@ SCE_SNAP_TARGET_NOT_ACTIVE
@ SCE_SNAP_TARGET_NOT_NONEDITED
@ SCE_SNAP_TARGET_ONLY_SELECTABLE
@ SCE_SNAP_TARGET_NOT_SELECTED
@ SCE_SNAP_TARGET_NOT_EDITED
#define BASE_SELECTABLE(v3d, base)
@ SCE_SNAP_INDIVIDUAL_NEAREST
@ SCE_SNAP_TO_EDGE_ENDPOINT
@ SCE_SNAP_TO_EDGE_MIDPOINT
@ SCE_SNAP_TO_EDGE_PERPENDICULAR
#define BASE_VISIBLE(v3d, base)
#define RV3D_VIEW_IS_AXIS(view)
#define ED_transform_snap_object_time_average_print()
#define XRAY_ENABLED(v3d)
float ED_view3d_grid_view_scale(const Scene *scene, const View3D *v3d, const ARegion *region, const char **r_grid_unit)
bool ED_view3d_win_to_ray_clipped_ex(Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const float mval[2], const bool do_clip_planes, float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], float r_ray_end[3])
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert * v2
BPy_StructRNA * depsgraph
static DBVT_INLINE btDbvtNode * sort(btDbvtNode *n, btDbvtNode *&r)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
bool object_has_geometry_set_instances(const Object &object)
T length_squared(const VecBase< T, Size > &a)
MatBase< T, NumCol, NumRow > transpose(const MatBase< T, NumRow, NumCol > &mat)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
CartesianBasis invert(const CartesianBasis &basis)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
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)
std::chrono::nanoseconds Nanoseconds
Clock::time_point TimePoint
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< float, 3 > float3
MeshRuntimeHandle * runtime
const c_style_mat & ptr() const
struct blender::ed::transform::SnapObjectContext::@023363036215051051114130033143317235151004224004 runtime
struct blender::ed::transform::SnapObjectContext::@252151137362251112213357331153135115250002101241 ret
struct blender::ed::transform::SnapObjectContext::@067317270346010157372337003264054373135063232165 grid
eSnapOcclusionTest occlusion_test_edit
float ray_depth_max_in_front
float4 occlusion_plane_in_front
bool(* test_edge_fn)(BMEdge *, void *user_data)
struct blender::ed::transform::SnapObjectContext::@204213351251212321145136124213325363323205155046::@105171171140051243320167151114070072015336343132 edit_mesh
bool(* test_face_fn)(BMFace *, void *user_data)
bool(* test_vert_fn)(BMVert *, void *user_data)
bool has_occlusion_plane_in_front
Map< const ID *, std::unique_ptr< SnapCache > > editmesh_caches
Vector< float4, MAX_CLIPPLANE_LEN > clip_planes
struct blender::ed::transform::SnapObjectContext::@204213351251212321145136124213325363323205155046 callbacks
const RegionView3D * rv3d