Cleanup: Use Vector and Matrices types in C++

This commit is contained in:
Germano Cavalcante
2023-07-03 16:01:18 -03:00
parent bc3ec100c2
commit 5ea561b51c
7 changed files with 112 additions and 137 deletions

View File

@@ -119,8 +119,8 @@ SnapData::SnapData(SnapObjectContext *sctx, const float4x4 &obmat)
void SnapData::clip_planes_enable(SnapObjectContext *sctx, bool skip_occlusion_plane)
{
float(*clip_planes)[4] = sctx->runtime.clip_plane;
int clip_plane_len = sctx->runtime.clip_plane_len;
float(*clip_planes)[4] = reinterpret_cast<float(*)[4]>(sctx->runtime.clip_planes.data());
int clip_plane_len = sctx->runtime.clip_planes.size();
if (skip_occlusion_plane && sctx->runtime.has_occlusion_plane) {
/* We snap to vertices even if occluded. */
@@ -283,15 +283,14 @@ void SnapData::register_result(SnapObjectContext *sctx,
copy_v3_v3(sctx->ret.loc, r_nearest->co);
copy_v3_v3(sctx->ret.no, r_nearest->no);
sctx->ret.index = r_nearest->index;
copy_m4_m4(sctx->ret.obmat, obmat.ptr());
sctx->ret.obmat = obmat;
sctx->ret.ob = ob_eval;
sctx->ret.data = id_eval;
sctx->ret.dist_px_sq = r_nearest->dist_sq;
/* Global space. */
mul_m4_v3(obmat.ptr(), sctx->ret.loc);
mul_mat3_m4_v3(obmat.ptr(), sctx->ret.no);
normalize_v3(sctx->ret.no);
sctx->ret.loc = math::transform_point(obmat, sctx->ret.loc);
sctx->ret.no = math::normalize(math::transform_direction(obmat, sctx->ret.no));
#ifdef DEBUG
/* Make sure this is only called once. */
@@ -368,7 +367,7 @@ static ID *data_for_snap(Object *ob_eval, eSnapEditType edit_mode_type, bool *r_
using IterSnapObjsCallback = eSnapMode (*)(SnapObjectContext *sctx,
Object *ob_eval,
ID *ob_data,
const float obmat[4][4],
const float4x4 &obmat,
bool is_object_active,
bool use_hide);
@@ -454,9 +453,12 @@ static eSnapMode iter_snap_objects(SnapObjectContext *sctx, IterSnapObjsCallback
ListBase *lb = object_duplilist(sctx->runtime.depsgraph, sctx->scene, obj_eval);
LISTBASE_FOREACH (DupliObject *, dupli_ob, lb) {
BLI_assert(DEG_is_evaluated_object(dupli_ob->ob));
if ((tmp = sob_callback(
sctx, dupli_ob->ob, dupli_ob->ob_data, dupli_ob->mat, is_object_active, false)) !=
SCE_SNAP_TO_NONE)
if ((tmp = sob_callback(sctx,
dupli_ob->ob,
dupli_ob->ob_data,
float4x4(dupli_ob->mat),
is_object_active,
false)) != SCE_SNAP_TO_NONE)
{
ret = tmp;
}
@@ -466,9 +468,12 @@ static eSnapMode iter_snap_objects(SnapObjectContext *sctx, IterSnapObjsCallback
bool use_hide = false;
ID *ob_data = data_for_snap(obj_eval, sctx->runtime.params.edit_mode_type, &use_hide);
if ((tmp = sob_callback(
sctx, obj_eval, ob_data, obj_eval->object_to_world, is_object_active, use_hide)) !=
SCE_SNAP_TO_NONE)
if ((tmp = sob_callback(sctx,
obj_eval,
ob_data,
float4x4(obj_eval->object_to_world),
is_object_active,
use_hide)) != SCE_SNAP_TO_NONE)
{
ret = tmp;
}
@@ -543,7 +548,7 @@ bool raycast_tri_backface_culling_test(
static eSnapMode raycast_obj_fn(SnapObjectContext *sctx,
Object *ob_eval,
ID *ob_data,
const float obmat[4][4],
const float4x4 &obmat,
bool is_object_active,
bool use_hide)
{
@@ -578,7 +583,7 @@ static eSnapMode raycast_obj_fn(SnapObjectContext *sctx,
}
if (retval) {
copy_m4_m4(sctx->ret.obmat, obmat);
sctx->ret.obmat = obmat;
sctx->ret.ob = ob_eval;
sctx->ret.data = ob_data;
return SCE_SNAP_TO_FACE;
@@ -671,7 +676,7 @@ bool nearest_world_tree(SnapObjectContext *sctx,
static eSnapMode nearest_world_object_fn(SnapObjectContext *sctx,
Object *ob_eval,
ID *ob_data,
const float obmat[4][4],
const float4x4 &obmat,
bool is_object_active,
bool use_hide)
{
@@ -815,7 +820,7 @@ static eSnapMode snap_edge_points(SnapObjectContext *sctx, const float dist_px_s
/* May extend later (for now just snaps to empty or camera center). */
eSnapMode snap_object_center(SnapObjectContext *sctx,
Object *ob_eval,
const float obmat[4][4],
const float4x4 &obmat,
eSnapMode snap_to_flag)
{
if (ob_eval->transflag & OB_DUPLI) {
@@ -827,7 +832,7 @@ eSnapMode snap_object_center(SnapObjectContext *sctx,
return SCE_SNAP_TO_NONE;
}
SnapData nearest2d(sctx, float4x4(obmat));
SnapData nearest2d(sctx, obmat);
nearest2d.clip_planes_enable(sctx);
@@ -845,7 +850,7 @@ eSnapMode snap_object_center(SnapObjectContext *sctx,
static eSnapMode snap_obj_fn(SnapObjectContext *sctx,
Object *ob_eval,
ID *ob_data,
const float obmat[4][4],
const float4x4 &obmat,
bool is_object_active,
bool use_hide)
{
@@ -1030,29 +1035,25 @@ static bool snap_object_context_runtime_init(SnapObjectContext *sctx,
sctx->runtime.win_size[0] = region->winx;
sctx->runtime.win_size[1] = region->winy;
sctx->runtime.clip_planes.resize(2);
planes_from_projmat(rv3d->persmat,
nullptr,
nullptr,
nullptr,
nullptr,
sctx->runtime.clip_plane[0],
sctx->runtime.clip_plane[1]);
sctx->runtime.clip_plane_len = 2;
sctx->runtime.clip_planes[0],
sctx->runtime.clip_planes[1]);
if (rv3d->rflag & RV3D_CLIPPING) {
memcpy(&sctx->runtime.clip_plane[2], rv3d->clip, 4 * sizeof(rv3d->clip[0]));
sctx->runtime.clip_plane_len = 6;
sctx->runtime.clip_planes.extend_unchecked(reinterpret_cast<const float4 *>(rv3d->clip), 4);
}
sctx->runtime.rv3d = rv3d;
}
sctx->ret.ray_depth_max = ray_depth;
zero_v3(sctx->ret.loc);
zero_v3(sctx->ret.no);
sctx->ret.index = -1;
zero_m4(sctx->ret.obmat);
sctx->ret.hit_list = hit_list;
sctx->ret.ob = nullptr;
sctx->ret.data = nullptr;
@@ -1106,7 +1107,7 @@ bool ED_transform_snap_object_project_ray_ex(SnapObjectContext *sctx,
*r_ob = sctx->ret.ob;
}
if (r_obmat) {
copy_m4_m4(r_obmat, sctx->ret.obmat);
copy_m4_m4(r_obmat, sctx->ret.obmat.ptr());
}
if (ray_depth) {
*ray_depth = sctx->ret.ray_depth_max;
@@ -1273,7 +1274,7 @@ eSnapMode ED_transform_snap_object_project_view3d_ex(SnapObjectContext *sctx,
*r_ob = sctx->ret.ob;
}
if (r_obmat) {
copy_m4_m4(r_obmat, sctx->ret.obmat);
copy_m4_m4(r_obmat, sctx->ret.obmat.ptr());
}
if (r_index) {
*r_index = sctx->ret.index;
@@ -1300,7 +1301,7 @@ eSnapMode ED_transform_snap_object_project_view3d_ex(SnapObjectContext *sctx,
*r_ob = sctx->ret.ob;
}
if (r_obmat) {
copy_m4_m4(r_obmat, sctx->ret.obmat);
copy_m4_m4(r_obmat, sctx->ret.obmat.ptr());
}
if (r_index) {
*r_index = sctx->ret.index;
@@ -1338,11 +1339,7 @@ eSnapMode ED_transform_snap_object_project_view3d_ex(SnapObjectContext *sctx,
}
/* Add the new clip plane to the beginning of the list. */
for (int i = sctx->runtime.clip_plane_len; i != 0; i--) {
copy_v4_v4(sctx->runtime.clip_plane[i], sctx->runtime.clip_plane[i - 1]);
}
copy_v4_v4(sctx->runtime.clip_plane[0], new_clipplane);
sctx->runtime.clip_plane_len++;
sctx->runtime.clip_planes.prepend(new_clipplane);
sctx->runtime.has_occlusion_plane = true;
}
@@ -1366,13 +1363,15 @@ eSnapMode ED_transform_snap_object_project_view3d_ex(SnapObjectContext *sctx,
*r_ob = sctx->ret.ob;
}
if (r_obmat) {
copy_m4_m4(r_obmat, sctx->ret.obmat);
copy_m4_m4(r_obmat, sctx->ret.obmat.ptr());
}
if (r_index) {
*r_index = sctx->ret.index;
}
*dist_px = blender::math::sqrt(sctx->ret.dist_px_sq);
if (dist_px) {
*dist_px = math::sqrt(sctx->ret.dist_px_sq);
}
}
}

View File

@@ -14,8 +14,6 @@
(SCE_SNAP_TO_EDGE | SCE_SNAP_TO_EDGE_ENDPOINT | SCE_SNAP_TO_EDGE_MIDPOINT | \
SCE_SNAP_TO_EDGE_PERPENDICULAR)
struct SnapCache_EditMesh;
struct SnapObjectContext {
struct Scene *scene;
@@ -42,16 +40,16 @@ struct SnapObjectContext {
eSnapMode snap_to_flag;
SnapObjectParams params;
float ray_start[3];
float ray_dir[3];
float mval[2];
blender::float3 ray_start;
blender::float3 ray_dir;
float init_co[3];
float curr_co[3];
blender::float3 init_co;
blender::float3 curr_co;
float win_size[2]; /* win x and y */
float clip_plane[MAX_CLIPPLANE_LEN][4];
int clip_plane_len;
blender::float2 win_size; /* win x and y */
blender::float2 mval;
blender::Vector<blender::float4, MAX_CLIPPLANE_LEN> clip_planes;
/* read/write */
uint object_index;
@@ -63,13 +61,13 @@ struct SnapObjectContext {
/* Output. */
struct {
/* Location of snapped point on target surface. */
float loc[3];
blender::float3 loc;
/* Normal of snapped point on target surface. */
float no[3];
blender::float3 no;
/* Index of snapped element on target object (-1 when no valid index is found). */
int index;
/* Matrix of target object (may not be #Object.object_to_world with dupli-instances). */
float obmat[4][4];
blender::float4x4 obmat;
/* List of #SnapObjectHitDepth (caller must free). */
ListBase *hit_list;
/* Snapped object. */
@@ -88,7 +86,7 @@ struct RayCastAll_Data {
/* internal vars for adding depths */
BVHTree_RayCastCallback raycast_callback;
const float (*obmat)[4];
const blender::float4x4 *obmat;
float len_diff;
float local_scale;
@@ -165,47 +163,47 @@ bool nearest_world_tree(SnapObjectContext *sctx,
eSnapMode snap_object_center(SnapObjectContext *sctx,
Object *ob_eval,
const float obmat[4][4],
const blender::float4x4 &obmat,
eSnapMode snap_to_flag);
/* transform_snap_object_armature.cc */
eSnapMode snapArmature(SnapObjectContext *sctx,
Object *ob_eval,
const float obmat[4][4],
const blender::float4x4 &obmat,
bool is_object_active);
/* transform_snap_object_camera.cc */
eSnapMode snapCamera(SnapObjectContext *sctx,
Object *object,
const float obmat[4][4],
const blender::float4x4 &obmat,
eSnapMode snap_to_flag);
/* transform_snap_object_curve.cc */
eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const float obmat[4][4]);
eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const blender::float4x4 &obmat);
/* transform_snap_object_editmesh.cc */
eSnapMode snap_object_editmesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID *id,
const float obmat[4][4],
const blender::float4x4 &obmat,
eSnapMode snap_to_flag,
bool use_hide);
eSnapMode snap_polygon_editmesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID *id,
const float obmat[4][4],
const blender::float4x4 &obmat,
eSnapMode snap_to_flag,
int polygon);
eSnapMode snap_edge_points_editmesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID *id,
const float obmat[4][4],
const blender::float4x4 &obmat,
float dist_px_sq_orig,
int edge);
@@ -214,20 +212,20 @@ eSnapMode snap_edge_points_editmesh(SnapObjectContext *sctx,
eSnapMode snap_object_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID *id,
const float obmat[4][4],
const blender::float4x4 &obmat,
eSnapMode snap_to_flag,
bool use_hide);
eSnapMode snap_polygon_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID *id,
const float obmat[4][4],
const blender::float4x4 &obmat,
eSnapMode snap_to_flag,
int polygon);
eSnapMode snap_edge_points_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID *id,
const float obmat[4][4],
const blender::float4x4 &obmat,
float dist_px_sq_orig,
int edge);

View File

@@ -22,7 +22,7 @@ using blender::float4x4;
eSnapMode snapArmature(SnapObjectContext *sctx,
Object *ob_eval,
const float obmat[4][4],
const float4x4 &obmat,
bool is_object_active)
{
eSnapMode retval = SCE_SNAP_TO_NONE;
@@ -34,7 +34,7 @@ eSnapMode snapArmature(SnapObjectContext *sctx,
bArmature *arm = static_cast<bArmature *>(ob_eval->data);
SnapData nearest2d(sctx, float4x4(obmat));
SnapData nearest2d(sctx, obmat);
const bool is_editmode = arm->edbo != nullptr;

View File

@@ -18,9 +18,11 @@
#include "transform_snap_object.hh"
using namespace blender;
eSnapMode snapCamera(SnapObjectContext *sctx,
Object *object,
const float obmat[4][4],
const float4x4 &obmat,
eSnapMode snap_to_flag)
{
eSnapMode retval = SCE_SNAP_TO_NONE;
@@ -40,42 +42,40 @@ eSnapMode snapCamera(SnapObjectContext *sctx,
return retval;
}
float orig_camera_mat[4][4], orig_camera_imat[4][4];
BKE_tracking_get_camera_object_matrix(object, orig_camera_mat);
float4x4 orig_camera_mat;
BKE_tracking_get_camera_object_matrix(object, orig_camera_mat.ptr());
float4x4 orig_camera_imat = math::invert(orig_camera_mat);
invert_m4_m4(orig_camera_imat, orig_camera_mat);
SnapData nearest2d(sctx);
nearest2d.clip_planes_enable(sctx);
MovieTracking *tracking = &clip->tracking;
LISTBASE_FOREACH (MovieTrackingObject *, tracking_object, &tracking->objects) {
float reconstructed_camera_mat[4][4], reconstructed_camera_imat[4][4];
const float(*vertex_obmat)[4];
float4x4 reconstructed_camera_imat;
if ((tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0) {
float4x4 reconstructed_camera_mat;
BKE_tracking_camera_get_reconstructed_interpolate(
tracking, tracking_object, scene->r.cfra, reconstructed_camera_mat);
tracking, tracking_object, scene->r.cfra, reconstructed_camera_mat.ptr());
invert_m4_m4(reconstructed_camera_imat, reconstructed_camera_mat);
reconstructed_camera_imat = math::invert(reconstructed_camera_mat) * obmat;
}
LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking_object->tracks) {
float bundle_pos[3];
float3 bundle_pos;
if ((track->flag & TRACK_HAS_BUNDLE) == 0) {
continue;
}
copy_v3_v3(bundle_pos, track->bundle_pos);
if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
vertex_obmat = orig_camera_mat;
bundle_pos = math::transform_point(orig_camera_mat, float3(track->bundle_pos));
}
else {
mul_m4_v3(reconstructed_camera_imat, bundle_pos);
vertex_obmat = obmat;
bundle_pos = math::transform_point(reconstructed_camera_imat, float3(track->bundle_pos));
}
mul_m4_v3(vertex_obmat, bundle_pos);
if (nearest2d.snap_point(bundle_pos)) {
retval = SCE_SNAP_TO_POINT;
}

View File

@@ -22,7 +22,7 @@
using blender::float4x4;
eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const float obmat[4][4])
eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const float4x4 &obmat)
{
bool has_snap = false;
@@ -33,7 +33,7 @@ eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const float obmat[
Curve *cu = static_cast<Curve *>(ob_eval->data);
SnapData nearest2d(sctx, float4x4(obmat));
SnapData nearest2d(sctx, obmat);
const bool use_obedit = BKE_object_is_in_editmode(ob_eval);

View File

@@ -291,25 +291,19 @@ static void editmesh_looptri_raycast_backface_culling_cb(void *userdata,
static bool raycastEditMesh(SnapCache_EditMesh *em_cache,
SnapObjectContext *sctx,
BMEditMesh *em,
const float obmat[4][4],
const float4x4 &obmat,
const uint ob_index)
{
bool retval = false;
float imat[4][4];
float ray_start_local[3], ray_normal_local[3];
float4x4 imat = math::invert(obmat);
float3 ray_start_local = math::transform_point(imat, sctx->runtime.ray_start);
float3 ray_normal_local = math::transform_direction(imat, sctx->runtime.ray_dir);
float local_scale, local_depth, len_diff = 0.0f;
invert_m4_m4(imat, obmat);
copy_v3_v3(ray_start_local, sctx->runtime.ray_start);
copy_v3_v3(ray_normal_local, sctx->runtime.ray_dir);
mul_m4_v3(imat, ray_start_local);
mul_mat3_m4_v3(imat, ray_normal_local);
/* local scale in normal direction */
local_scale = normalize_v3(ray_normal_local);
ray_normal_local = math::normalize_and_get_length(ray_normal_local, local_scale);
local_depth = sctx->ret.ray_depth_max;
if (local_depth != BVH_RAYCAST_DIST_MAX) {
local_depth *= local_scale;
@@ -345,7 +339,7 @@ static bool raycastEditMesh(SnapCache_EditMesh *em_cache,
data.bvhdata = em;
data.raycast_callback = em_cache->raycast_callback;
data.obmat = obmat;
data.obmat = &obmat;
data.len_diff = len_diff;
data.local_scale = local_scale;
data.ob_uuid = ob_index;
@@ -380,13 +374,8 @@ static bool raycastEditMesh(SnapCache_EditMesh *em_cache,
hit.dist += len_diff;
hit.dist /= local_scale;
if (hit.dist <= sctx->ret.ray_depth_max) {
copy_v3_v3(sctx->ret.loc, hit.co);
copy_v3_v3(sctx->ret.no, hit.no);
mul_m4_v3(obmat, sctx->ret.loc);
mul_transposed_mat3_m4_v3(imat, sctx->ret.no);
normalize_v3(sctx->ret.no);
sctx->ret.loc = math::transform_point(obmat, float3(hit.co));
sctx->ret.no = math::normalize(math::transform_direction(obmat, float3(hit.no)));
sctx->ret.ray_depth_max = hit.dist;
@@ -472,14 +461,14 @@ class SnapData_EditMesh : public SnapData {
eSnapMode snap_polygon_editmesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID * /*id*/,
const float obmat[4][4],
const float4x4 &obmat,
eSnapMode snap_to_flag,
int polygon)
{
eSnapMode elem = SCE_SNAP_TO_NONE;
BMEditMesh *em = BKE_editmesh_from_object(ob_eval);
SnapData_EditMesh nearest2d(sctx, em->bm, float4x4(obmat));
SnapData_EditMesh nearest2d(sctx, em->bm, obmat);
nearest2d.clip_planes_enable(sctx);
BVHTreeNearest nearest{};
@@ -529,12 +518,12 @@ eSnapMode snap_polygon_editmesh(SnapObjectContext *sctx,
eSnapMode snap_edge_points_editmesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID * /*id*/,
const float obmat[4][4],
const float4x4 &obmat,
float dist_pex_sq_orig,
int edge)
{
BMEditMesh *em = BKE_editmesh_from_object(ob_eval);
SnapData_EditMesh nearest2d(sctx, em->bm, float4x4(obmat));
SnapData_EditMesh nearest2d(sctx, em->bm, obmat);
eSnapMode elem = nearest2d.snap_edge_points_impl(sctx, edge, dist_pex_sq_orig);
if (nearest2d.nearest_point.index != -2) {
nearest2d.register_result(sctx, ob_eval, nullptr);
@@ -546,12 +535,12 @@ static eSnapMode snapEditMesh(SnapCache_EditMesh *em_cache,
SnapObjectContext *sctx,
Object *ob_eval,
BMEditMesh *em,
const float obmat[4][4],
const float4x4 &obmat,
eSnapMode snap_to_flag)
{
BLI_assert(snap_to_flag != SCE_SNAP_TO_FACE);
SnapData_EditMesh nearest2d(sctx, em->bm, float4x4(obmat));
SnapData_EditMesh nearest2d(sctx, em->bm, obmat);
/* Was BKE_boundbox_ray_hit_check, see: cf6ca226fa58. */
if (!nearest2d.snap_boundbox(em_cache->min, em_cache->max)) {
@@ -681,7 +670,7 @@ static eSnapMode snapEditMesh(SnapCache_EditMesh *em_cache,
eSnapMode snap_object_editmesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID * /*id*/,
const float obmat[4][4],
const float4x4 &obmat,
eSnapMode snap_to_flag,
bool /*use_hide*/)
{
@@ -708,7 +697,7 @@ eSnapMode snap_object_editmesh(SnapObjectContext *sctx,
}
if (snap_mode_used & SCE_SNAP_INDIVIDUAL_NEAREST) {
if (nearest_world_editmesh(em_cache, sctx, ob_eval, em, float4x4(obmat))) {
if (nearest_world_editmesh(em_cache, sctx, ob_eval, em, obmat)) {
return SCE_SNAP_INDIVIDUAL_NEAREST;
}
}

View File

@@ -90,7 +90,7 @@ static void mesh_looptri_raycast_backface_culling_cb(void *userdata,
static bool raycastMesh(SnapObjectContext *sctx,
Object *ob_eval,
const Mesh *me_eval,
const float obmat[4][4],
const float4x4 &obmat,
const uint ob_index,
bool use_hide)
{
@@ -100,20 +100,14 @@ static bool raycastMesh(SnapObjectContext *sctx,
return retval;
}
float imat[4][4];
float ray_start_local[3], ray_normal_local[3];
float4x4 imat = math::invert(obmat);
float3 ray_start_local = math::transform_point(imat, sctx->runtime.ray_start);
float3 ray_normal_local = math::transform_direction(imat, sctx->runtime.ray_dir);
float local_scale, local_depth, len_diff = 0.0f;
invert_m4_m4(imat, obmat);
copy_v3_v3(ray_start_local, sctx->runtime.ray_start);
copy_v3_v3(ray_normal_local, sctx->runtime.ray_dir);
mul_m4_v3(imat, ray_start_local);
mul_mat3_m4_v3(imat, ray_normal_local);
/* local scale in normal direction */
local_scale = normalize_v3(ray_normal_local);
ray_normal_local = math::normalize_and_get_length(ray_normal_local, local_scale);
local_depth = sctx->ret.ray_depth_max;
if (local_depth != BVH_RAYCAST_DIST_MAX) {
local_depth *= local_scale;
@@ -160,7 +154,7 @@ static bool raycastMesh(SnapObjectContext *sctx,
data.bvhdata = &treedata;
data.raycast_callback = treedata.raycast_callback;
data.obmat = obmat;
data.obmat = &obmat;
data.len_diff = len_diff;
data.local_scale = local_scale;
data.ob_uuid = ob_index;
@@ -195,13 +189,8 @@ static bool raycastMesh(SnapObjectContext *sctx,
hit.dist += len_diff;
hit.dist /= local_scale;
if (hit.dist <= sctx->ret.ray_depth_max) {
copy_v3_v3(sctx->ret.loc, hit.co);
copy_v3_v3(sctx->ret.no, hit.no);
mul_m4_v3(obmat, sctx->ret.loc);
mul_transposed_mat3_m4_v3(imat, sctx->ret.no);
normalize_v3(sctx->ret.no);
sctx->ret.loc = math::transform_point(obmat, float3(hit.co));
sctx->ret.no = math::normalize(math::transform_direction(obmat, float3(hit.no)));
sctx->ret.ray_depth_max = hit.dist;
sctx->ret.index = looptri_polys[hit.index];
@@ -222,7 +211,7 @@ static bool raycastMesh(SnapObjectContext *sctx,
static bool nearest_world_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const Mesh *me_eval,
const float4x4 obmat,
const float4x4 &obmat,
bool use_hide)
{
BVHTreeFromMesh treedata;
@@ -391,7 +380,7 @@ static void cb_snap_tri_edges(void *userdata,
eSnapMode snap_polygon_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID *id,
const float obmat[4][4],
const float4x4 &obmat,
eSnapMode snap_to_flag,
int polygon)
{
@@ -399,7 +388,7 @@ eSnapMode snap_polygon_mesh(SnapObjectContext *sctx,
const Mesh *mesh_eval = reinterpret_cast<const Mesh *>(id);
SnapData_Mesh nearest2d(sctx, mesh_eval, float4x4(obmat));
SnapData_Mesh nearest2d(sctx, mesh_eval, obmat);
nearest2d.clip_planes_enable(sctx);
BVHTreeNearest nearest{};
@@ -446,11 +435,11 @@ eSnapMode snap_polygon_mesh(SnapObjectContext *sctx,
eSnapMode snap_edge_points_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID *id,
const float obmat[4][4],
const float4x4 &obmat,
float dist_pex_sq_orig,
int edge)
{
SnapData_Mesh nearest2d(sctx, reinterpret_cast<const Mesh *>(id), float4x4(obmat));
SnapData_Mesh nearest2d(sctx, reinterpret_cast<const Mesh *>(id), obmat);
eSnapMode elem = nearest2d.snap_edge_points_impl(sctx, edge, dist_pex_sq_orig);
if (nearest2d.nearest_point.index != -2) {
nearest2d.register_result(sctx, ob_eval, id);
@@ -474,12 +463,12 @@ static eSnapMode mesh_snap_mode_supported(const Mesh *mesh)
static eSnapMode snapMesh(SnapObjectContext *sctx,
Object *ob_eval,
const Mesh *me_eval,
const float obmat[4][4],
const float4x4 &obmat,
bool use_hide,
eSnapMode snap_to)
{
BLI_assert(snap_to != SCE_SNAP_TO_FACE);
SnapData_Mesh nearest2d(sctx, me_eval, float4x4(obmat));
SnapData_Mesh nearest2d(sctx, me_eval, obmat);
if (ob_eval->data == me_eval) {
const BoundBox *bb = BKE_mesh_boundbox_get(ob_eval);
@@ -607,7 +596,7 @@ static eSnapMode snapMesh(SnapObjectContext *sctx,
eSnapMode snap_object_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const ID *id,
const float obmat[4][4],
const float4x4 &obmat,
eSnapMode snap_to_flag,
bool use_hide)
{
@@ -628,7 +617,7 @@ eSnapMode snap_object_mesh(SnapObjectContext *sctx,
}
if (snap_to_flag & SCE_SNAP_INDIVIDUAL_NEAREST) {
if (nearest_world_mesh(sctx, ob_eval, mesh_eval, float4x4(obmat), use_hide)) {
if (nearest_world_mesh(sctx, ob_eval, mesh_eval, obmat, use_hide)) {
return SCE_SNAP_INDIVIDUAL_NEAREST;
}
}