38# pragma optimize("t", on)
51 if (
dot_v3v3(ray_dir, plane) > 0.0f) {
63 const float (*clip_plane)[4],
64 const int clip_plane_len,
84 if (dist_sq < nearest->dist_sq) {
93 const float (*clip_plane)[4],
94 const int clip_plane_len,
112 this->pmat_local = float4x4(sctx->runtime.rv3d->persmat) * obmat;
115 this->pmat_local = obmat;
121 this->nearest_point.index = -2;
128 bool skip_occlusion_plane)
131 if (!skip_occlusion_plane) {
152#ifdef TEST_CLIPPLANES_IN_BOUNDBOX
154 reinterpret_cast<const float (*)[4]
>(this->
clip_planes.data()),
155 this->clip_planes.size(),
176 reinterpret_cast<const float (*)[4]
>(this->
clip_planes.data()),
177 this->clip_planes.size(),
180 &this->nearest_point))
191 reinterpret_cast<const float (*)[4]
>(this->
clip_planes.data()),
192 this->clip_planes.size(),
196 &this->nearest_point))
207 float dist_px_sq_orig)
214 const float *v_pair[2];
220 this->nearest_precalc.ray_direction,
235 float range = 1.0f / (2 * e_mode_len - 1);
238 range *= e_mode_len - 1;
239 if ((range) < lambda && lambda < (1.0f - range)) {
251 float v_near[3], va_g[3], vb_g[3];
257 if (
IN_RANGE(lambda_perp, 0.0f, 1.0f)) {
269 if (lambda < (range) || (1.0f - range) < lambda) {
270 int v_id = lambda < 0.5f ? 0 : 1;
272 if (this->
snap_point(v_pair[v_id], vindex[v_id])) {
295 sctx->
ret.
ob = ob_eval;
305 r_nearest->
index = -2;
319 const bool is_in_front)
322 if (hit->
dist <= depth_max) {
330 sctx->
ret.
ob = ob_eval;
378 return &editmesh_eval->
id;
387 return static_cast<const ID *
>(ob_eval->
data);
393 return &mesh_eval->id;
396 return static_cast<const ID *
>(ob_eval->
data);
406 Mesh *
mesh = blender::id_cast<Mesh *>(ob_data);
422 bool is_object_active,
427 const Base *base_act,
443 const bool is_active = (base_act == base);
448 const bool is_in_object_mode = (base_act ==
nullptr) ||
451 if (is_in_object_mode) {
499 const bool is_object_active = (base == base_act);
508 if ((tmp = sob_callback(
509 sctx, dupli_ob.ob, ob_data,
float4x4(dupli_ob.mat), is_object_active,
false)) !=
518 bool use_hide =
false;
520 if ((tmp = sob_callback(
521 sctx, obj_eval, ob_data, obj_eval->object_to_world(), is_object_active, use_hide)) !=
569 data->raycast_callback(
data->bvhdata, index, ray, hit);
570 if (hit->
index != -1) {
577 depth = (hit->
dist +
data->len_diff) /
data->local_scale;
585 const float dir[3],
const float v0[3],
const float v1[3],
const float v2[3],
float no[3])
608 if (ob_data ==
nullptr) {
683 r_nearest->
index = -1;
716 if (r_nearest->
dist_sq <= original_distance) {
724 float3 delta = (curr_co - init_co) * step_scale_factor;
733 *r_nearest = nearest;
735 r_nearest->
dist_sq = original_distance;
756 if (ob_data ==
nullptr) {
810 const float (*clip_plane)[4],
811 const int clip_plane_len,
817 data->get_vert_co(index, &co);
820 data->copy_vert_no(index, nearest->
no);
821 nearest->
index = index;
828 const float (*clip_plane)[4],
829 const int clip_plane_len,
835 data->get_edge_verts_index(index, vindex);
837 const float *v_pair[2];
838 data->get_vert_co(vindex[0], &v_pair[0]);
839 data->get_vert_co(vindex[1], &v_pair[1]);
842 precalc, clip_plane, clip_plane_len,
data->is_persp, v_pair[0], v_pair[1], nearest))
845 nearest->
index = index;
910 bool is_object_active,
913 if (ob_data ==
nullptr && (ob_eval->
type ==
OB_MESH)) {
918 if (ob_data ==
nullptr) {
940 switch (ob_eval->
type) {
945 retval =
snapArmature(sctx, ob_eval, obmat, is_object_active);
950 retval =
snapCurve(sctx, ob_eval, obmat);
1006 for (
int i = 0;
i < 4;
i++) {
1044 sctx->
scene = scene;
1055 bool (*test_vert_fn)(
BMVert *,
void *user_data),
1056 bool (*test_edge_fn)(
BMEdge *,
void *user_data),
1057 bool (*test_face_fn)(
BMFace *,
void *user_data),
1060 bool is_cache_dirty =
false;
1063 is_cache_dirty =
true;
1067 is_cache_dirty =
true;
1071 is_cache_dirty =
true;
1075 is_cache_dirty =
true;
1078 if (is_cache_dirty) {
1090 const float ray_start[3],
1091 const float ray_dir[3],
1092 const float ray_depth,
1093 const float mval[2],
1094 const float init_co[3],
1095 const float prev_co[3],
1096 const float dist_px_sq,
1167 if (
params->grid_size == 0.0f) {
1194 sctx->
ret.
ob =
nullptr;
1205 const float ray_start[3],
1206 const float ray_normal[3],
1212 float r_obmat[4][4])
1243 *r_ob = sctx->
ret.
ob;
1260 const float ray_start[3],
1261 const float ray_normal[3],
1305 const float ray_start[3],
1306 const float ray_normal[3],
1331 const float init_co[3],
1332 const float mval[2],
1333 const float prev_co[3],
1339 float r_obmat[4][4],
1340 float r_face_nor[3])
1344 bool use_occlusion_plane =
false;
1352 use_occlusion_plane =
true;
1384 use_occlusion_plane =
false;
1394 use_occlusion_plane ?
params->occlusion_test :
1409#ifdef DEBUG_SNAP_TIME
1417 bool has_hit =
false;
1456 ret_bak = sctx->
ret;
1459 if (use_occlusion_plane && has_hit) {
1496 if (!(elem & snap_to_flag)) {
1499 sctx->
ret = ret_bak;
1504 retval = elem & snap_to_flag;
1520 *r_ob = sctx->
ret.
ob;
1534#ifdef DEBUG_SNAP_TIME
1535 duration_ += timeit::Clock::now() - start_;
1548 const float init_co[3],
1549 const float mval[2],
1550 const float prev_co[3],
1578 const float mval[2],
1583 float3 ray_start, ray_normal, ray_end;
1587 depsgraph, region, v3d, mval,
false,
nullptr, ray_normal, ray_start, ray_end))
1595 float ray_depth_max =
math::dot(ray_end - ray_start, ray_normal);
1596 if ((ray_depth == -1.0f) || (ray_depth > ray_depth_max)) {
1597 ray_depth = ray_depth_max;
1605#ifdef DEBUG_SNAP_TIME
1608 std::cout <<
"Average snapping time: ";
1609 std::cout << std::fixed << duration_.count() / 1.0e6 <<
" ms";
1612 duration_ = timeit::Nanoseconds::zero();
blender::VectorList< DupliObject > DupliList
void object_duplilist(Depsgraph *depsgraph, Scene *sce, Object *ob, blender::Set< const Object * > *include_objects, DupliList &r_duplilist)
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)
Mesh * BKE_mesh_wrapper_ensure_subdivision(Mesh *mesh)
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_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
float ray_depth_max_in_front
struct blender::ed::transform::SnapObjectContext::@170374026073064374202114033260227063176045253050 runtime
struct blender::ed::transform::SnapObjectContext::@261131034374131144046074012251042111150012050144 grid
struct blender::ed::transform::SnapObjectContext::Output ret
eSnapOcclusionTest occlusion_test_edit
float4 occlusion_plane_in_front
bool(* test_edge_fn)(BMEdge *, void *user_data)
bool(* test_face_fn)(BMFace *, void *user_data)
bool(* test_vert_fn)(BMVert *, void *user_data)
struct blender::ed::transform::SnapObjectContext::@057303224201065302154130247374246316157207360104 callbacks
bool has_occlusion_plane_in_front
Map< const ID *, std::unique_ptr< SnapCache > > editmesh_caches
struct blender::ed::transform::SnapObjectContext::@057303224201065302154130247374246316157207360104::@052144141244060360354325332176274005342203076127 edit_mesh
Vector< float4, MAX_CLIPPLANE_LEN > clip_planes
const RegionView3D * rv3d