Cleanup: Transform Snap Object Code

Transform: remove unused members from 'SnapObjectHitDepth'

Also move the `short face_nearest_steps` member before the bit field.

And move 'void SnapData_EditMesh::clear()' definition to the source.

Pull Request: https://projects.blender.org/blender/blender/pulls/109132
This commit is contained in:
Germano Cavalcante
2023-06-19 19:03:08 +02:00
committed by Germano Cavalcante
parent 93e2e749da
commit 7764c87528
5 changed files with 46 additions and 86 deletions

View File

@@ -41,11 +41,6 @@ struct SnapObjectHitDepth {
float depth;
float co[3];
float no[3];
int index;
struct Object *ob_eval;
float obmat[4][4];
/* needed to tell which ray-cast this was part of,
* the same object may be part of many ray-casts when dupli's are used. */
@@ -58,12 +53,12 @@ struct SnapObjectParams {
eSnapTargetOP snap_target_select;
/* Geometry for snapping in edit mode. */
eSnapEditType edit_mode_type;
/* Break nearest face snapping into steps to improve transformations across U-shaped targets. */
short face_nearest_steps;
/* snap to the closest element, use when using more than one snap type */
bool use_occlusion_test : 1;
/* exclude back facing geometry from snapping */
bool use_backface_culling : 1;
/* Break nearest face snapping into steps to improve transformations across U-shaped targets. */
short face_nearest_steps;
/* Enable to force nearest face snapping to snap to target the source was initially near. */
bool keep_on_same_target : 1;
};

View File

@@ -215,23 +215,12 @@ static eSnapMode iter_snap_objects(SnapObjectContext *sctx, IterSnapObjsCallback
/* Store all ray-hits
* Support for storing all depths, not just the first (ray-cast 'all'). */
static SnapObjectHitDepth *hit_depth_create(const float depth,
const float co[3],
const float no[3],
int index,
Object *ob_eval,
const float obmat[4][4],
uint ob_uuid)
static SnapObjectHitDepth *hit_depth_create(const float depth, const float co[3], uint ob_uuid)
{
SnapObjectHitDepth *hit = MEM_new<SnapObjectHitDepth>(__func__);
hit->depth = depth;
copy_v3_v3(hit->co, co);
copy_v3_v3(hit->no, no);
hit->index = index;
hit->ob_eval = ob_eval;
copy_m4_m4(hit->obmat, (float(*)[4])obmat);
hit->ob_uuid = ob_uuid;
return hit;
@@ -259,20 +248,14 @@ void raycast_all_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRay
data->raycast_callback(data->bvhdata, index, ray, hit);
if (hit->index != -1) {
/* Get all values in world-space. */
float location[3], normal[3];
float location[3];
float depth;
/* World-space location. */
mul_v3_m4v3(location, (float(*)[4])data->obmat, hit->co);
depth = (hit->dist + data->len_diff) / data->local_scale;
/* World-space normal. */
copy_v3_v3(normal, hit->no);
mul_m3_v3((float(*)[3])data->timat, normal);
normalize_v3(normal);
SnapObjectHitDepth *hit_item = hit_depth_create(
depth, location, normal, hit->index, data->ob_eval, data->obmat, data->ob_uuid);
SnapObjectHitDepth *hit_item = hit_depth_create(depth, location, data->ob_uuid);
BLI_addtail(data->hit_list, hit_item);
}
}

View File

@@ -10,44 +10,7 @@
#define MAX_CLIPPLANE_LEN 3
/* -------------------------------------------------------------------- */
/** \name Internal Data Types
* \{ */
/** #SnapObjectContext.editmesh_caches */
struct SnapData_EditMesh {
/* Verts, Edges. */
BVHTree *bvhtree[2];
bool cached[2];
/* BVH tree from #BMEditMesh.looptris. */
BVHTreeFromEditMesh treedata_editmesh;
blender::bke::MeshRuntime *mesh_runtime;
float min[3], max[3];
void clear()
{
for (int i = 0; i < ARRAY_SIZE(this->bvhtree); i++) {
if (!this->cached[i]) {
BLI_bvhtree_free(this->bvhtree[i]);
}
this->bvhtree[i] = nullptr;
}
free_bvhtree_from_editmesh(&this->treedata_editmesh);
}
~SnapData_EditMesh()
{
this->clear();
}
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("SnapData_EditMesh")
#endif
};
/** \} */
struct SnapData_EditMesh;
struct SnapObjectContext {
struct Scene *scene;
@@ -123,17 +86,14 @@ struct RayCastAll_Data {
BVHTree_RayCastCallback raycast_callback;
const float (*obmat)[4];
const float (*timat)[3];
float len_diff;
float local_scale;
Object *ob_eval;
uint ob_uuid;
/* output data */
ListBase *hit_list;
bool retval;
};
struct Nearest2dUserData;
@@ -222,6 +182,29 @@ bool nearest_world_tree(SnapObjectContext *sctx,
/* transform_snap_object_editmesh.cc */
struct SnapData_EditMesh {
/* Verts, Edges. */
BVHTree *bvhtree[2];
bool cached[2];
/* BVH tree from #BMEditMesh.looptris. */
BVHTreeFromEditMesh treedata_editmesh;
blender::bke::MeshRuntime *mesh_runtime;
float min[3], max[3];
void clear();
~SnapData_EditMesh()
{
this->clear();
}
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("SnapData_EditMesh")
#endif
};
eSnapMode snap_object_editmesh(SnapObjectContext *sctx,
Object *ob_eval,
ID *id,

View File

@@ -25,6 +25,17 @@
/** \name Snap Object Data
* \{ */
void SnapData_EditMesh::clear()
{
for (int i = 0; i < ARRAY_SIZE(this->bvhtree); i++) {
if (!this->cached[i]) {
BLI_bvhtree_free(this->bvhtree[i]);
}
this->bvhtree[i] = nullptr;
}
free_bvhtree_from_editmesh(&this->treedata_editmesh);
}
/**
* Calculate the minimum and maximum coordinates of the box that encompasses this mesh.
*/
@@ -257,7 +268,6 @@ static void editmesh_looptri_raycast_backface_culling_cb(void *userdata,
static bool raycastEditMesh(SnapData_EditMesh *sod,
SnapObjectContext *sctx,
Object *ob_eval,
BMEditMesh *em,
const float obmat[4][4],
const uint ob_index,
@@ -316,23 +326,18 @@ static bool raycastEditMesh(SnapData_EditMesh *sod,
return retval;
}
float timat[3][3]; /* transpose inverse matrix for normals */
transpose_m3_m4(timat, imat);
if (r_hit_list) {
RayCastAll_Data data;
data.bvhdata = treedata;
data.raycast_callback = treedata->raycast_callback;
data.obmat = obmat;
data.timat = timat;
data.len_diff = len_diff;
data.local_scale = local_scale;
data.ob_eval = ob_eval;
data.ob_uuid = ob_index;
data.hit_list = r_hit_list;
data.retval = retval;
void *hit_last_prev = data.hit_list->last;
BLI_bvhtree_ray_cast_all(treedata->tree,
ray_start_local,
ray_normal_local,
@@ -341,7 +346,7 @@ static bool raycastEditMesh(SnapData_EditMesh *sod,
raycast_all_cb,
&data);
retval = data.retval;
retval = hit_last_prev != data.hit_list->last;
}
else {
BVHTreeRayHit hit{};
@@ -369,7 +374,7 @@ static bool raycastEditMesh(SnapData_EditMesh *sod,
if (r_no) {
copy_v3_v3(r_no, hit.no);
mul_m3_v3(timat, r_no);
mul_transposed_mat3_m4_v3(imat, r_no);
normalize_v3(r_no);
}
@@ -759,7 +764,6 @@ eSnapMode snap_object_editmesh(SnapObjectContext *sctx,
if (snap_mode_used & SCE_SNAP_MODE_FACE) {
if (raycastEditMesh(sod,
sctx,
ob_eval,
em,
obmat,
sctx->runtime.object_index++,

View File

@@ -156,9 +156,6 @@ static bool raycastMesh(SnapObjectContext *sctx,
return retval;
}
float timat[3][3]; /* transpose inverse matrix for normals */
transpose_m3_m4(timat, imat);
BLI_assert(treedata.raycast_callback != nullptr);
if (r_hit_list) {
RayCastAll_Data data;
@@ -166,18 +163,16 @@ static bool raycastMesh(SnapObjectContext *sctx,
data.bvhdata = &treedata;
data.raycast_callback = treedata.raycast_callback;
data.obmat = obmat;
data.timat = timat;
data.len_diff = len_diff;
data.local_scale = local_scale;
data.ob_eval = ob_eval;
data.ob_uuid = ob_index;
data.hit_list = r_hit_list;
data.retval = retval;
void *hit_last_prev = data.hit_list->last;
BLI_bvhtree_ray_cast_all(
treedata.tree, ray_start_local, ray_normal_local, 0.0f, *ray_depth, raycast_all_cb, &data);
retval = data.retval;
retval = hit_last_prev != data.hit_list->last;
}
else {
BVHTreeRayHit hit{};
@@ -205,7 +200,7 @@ static bool raycastMesh(SnapObjectContext *sctx,
if (r_no) {
copy_v3_v3(r_no, hit.no);
mul_m3_v3(timat, r_no);
mul_transposed_mat3_m4_v3(imat, r_no);
normalize_v3(r_no);
}