BMesh: avoid copying by value for BMLoop triangles
Caused by [0] which made BMLoop[3] variables & arguments copy by value.
[0]: 3805974b6f
This commit is contained in:
@@ -189,7 +189,7 @@ BVHTree *BKE_bmbvh_tree_get(BMBVHTree *bmtree)
|
||||
* Return the coords from a triangle.
|
||||
*/
|
||||
static void bmbvh_tri_from_face(const float *cos[3],
|
||||
const std::array<BMLoop *, 3> ltri,
|
||||
const std::array<BMLoop *, 3> <ri,
|
||||
const float (*cos_cage)[3])
|
||||
{
|
||||
if (cos_cage == nullptr) {
|
||||
@@ -227,7 +227,7 @@ static BMFace *bmbvh_ray_cast_handle_hit(BMBVHTree *bmtree,
|
||||
{
|
||||
if (r_hitout) {
|
||||
if (bmtree->flag & BMBVH_RETURN_ORIG) {
|
||||
std::array<BMLoop *, 3> ltri = bmtree->looptris[hit->index];
|
||||
const std::array<BMLoop *, 3> <ri = bmtree->looptris[hit->index];
|
||||
interp_v3_v3v3v3_uv(r_hitout, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, bmcb_data->uv);
|
||||
}
|
||||
else {
|
||||
@@ -249,7 +249,7 @@ static BMFace *bmbvh_ray_cast_handle_hit(BMBVHTree *bmtree,
|
||||
static void bmbvh_ray_cast_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
|
||||
{
|
||||
RayCastUserData *bmcb_data = static_cast<RayCastUserData *>(userdata);
|
||||
const std::array<BMLoop *, 3> ltri = bmcb_data->looptris[index];
|
||||
const std::array<BMLoop *, 3> <ri = bmcb_data->looptris[index];
|
||||
float dist, uv[2];
|
||||
const float *tri_cos[3];
|
||||
bool isect;
|
||||
@@ -338,7 +338,7 @@ static void bmbvh_ray_cast_cb_filter(void *userdata,
|
||||
{
|
||||
RayCastUserData_Filter *bmcb_data_filter = static_cast<RayCastUserData_Filter *>(userdata);
|
||||
RayCastUserData *bmcb_data = &bmcb_data_filter->bmcb_data;
|
||||
const std::array<BMLoop *, 3> ltri = bmcb_data->looptris[index];
|
||||
const std::array<BMLoop *, 3> <ri = bmcb_data->looptris[index];
|
||||
if (bmcb_data_filter->filter_cb(ltri[0]->f, bmcb_data_filter->filter_userdata)) {
|
||||
bmbvh_ray_cast_cb(bmcb_data, index, ray, hit);
|
||||
}
|
||||
@@ -402,7 +402,7 @@ static void bmbvh_find_vert_closest_cb(void *userdata,
|
||||
BVHTreeNearest *hit)
|
||||
{
|
||||
VertSearchUserData *bmcb_data = static_cast<VertSearchUserData *>(userdata);
|
||||
const std::array<BMLoop *, 3> ltri = bmcb_data->looptris[index];
|
||||
const std::array<BMLoop *, 3> <ri = bmcb_data->looptris[index];
|
||||
const float dist_max_sq = bmcb_data->dist_max_sq;
|
||||
|
||||
const float *tri_cos[3];
|
||||
@@ -440,7 +440,7 @@ BMVert *BKE_bmbvh_find_vert_closest(BMBVHTree *bmtree, const float co[3], const
|
||||
|
||||
BLI_bvhtree_find_nearest(bmtree->tree, co, &hit, bmbvh_find_vert_closest_cb, &bmcb_data);
|
||||
if (hit.index != -1) {
|
||||
const std::array<BMLoop *, 3> ltri = bmtree->looptris[hit.index];
|
||||
const std::array<BMLoop *, 3> <ri = bmtree->looptris[hit.index];
|
||||
return ltri[bmcb_data.index_tri]->v;
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ static void bmbvh_find_face_closest_cb(void *userdata,
|
||||
BVHTreeNearest *hit)
|
||||
{
|
||||
FaceSearchUserData *bmcb_data = static_cast<FaceSearchUserData *>(userdata);
|
||||
const std::array<BMLoop *, 3> ltri = bmcb_data->looptris[index];
|
||||
const std::array<BMLoop *, 3> <ri = bmcb_data->looptris[index];
|
||||
const float dist_max_sq = bmcb_data->dist_max_sq;
|
||||
|
||||
const float *tri_cos[3];
|
||||
@@ -499,7 +499,7 @@ BMFace *BKE_bmbvh_find_face_closest(BMBVHTree *bmtree, const float co[3], const
|
||||
|
||||
BLI_bvhtree_find_nearest(bmtree->tree, co, &hit, bmbvh_find_face_closest_cb, &bmcb_data);
|
||||
if (hit.index != -1) {
|
||||
const std::array<BMLoop *, 3> ltri = bmtree->looptris[hit.index];
|
||||
const std::array<BMLoop *, 3> <ri = bmtree->looptris[hit.index];
|
||||
return ltri[0]->f;
|
||||
}
|
||||
|
||||
@@ -520,8 +520,8 @@ static bool bmbvh_overlap_cb(void *userdata, int index_a, int index_b, int /*thr
|
||||
const BMBVHTree *bmtree_a = data->tree_pair[0];
|
||||
const BMBVHTree *bmtree_b = data->tree_pair[1];
|
||||
|
||||
const std::array<BMLoop *, 3> tri_a = bmtree_a->looptris[index_a];
|
||||
const std::array<BMLoop *, 3> tri_b = bmtree_b->looptris[index_b];
|
||||
const std::array<BMLoop *, 3> &tri_a = bmtree_a->looptris[index_a];
|
||||
const std::array<BMLoop *, 3> &tri_b = bmtree_b->looptris[index_b];
|
||||
const float *tri_a_co[3] = {tri_a[0]->v->co, tri_a[1]->v->co, tri_a[2]->v->co};
|
||||
const float *tri_b_co[3] = {tri_b[0]->v->co, tri_b[1]->v->co, tri_b[2]->v->co};
|
||||
float ix_pair[2][3];
|
||||
|
||||
@@ -59,12 +59,12 @@ struct SGLSLEditMeshToTangent {
|
||||
const BMLoop *GetLoop(const uint face_num, uint vert_index)
|
||||
{
|
||||
// BLI_assert(vert_index >= 0 && vert_index < 4);
|
||||
std::array<BMLoop *, 3> lt;
|
||||
BMLoop *const *lt;
|
||||
const BMLoop *l;
|
||||
|
||||
#ifdef USE_LOOPTRI_DETECT_QUADS
|
||||
if (face_as_quad_map) {
|
||||
lt = looptris[face_as_quad_map[face_num]];
|
||||
lt = looptris[face_as_quad_map[face_num]].data();
|
||||
if (lt[0]->f->len == 4) {
|
||||
l = BM_FACE_FIRST_LOOP(lt[0]->f);
|
||||
while (vert_index--) {
|
||||
@@ -75,10 +75,10 @@ struct SGLSLEditMeshToTangent {
|
||||
/* fall through to regular triangle */
|
||||
}
|
||||
else {
|
||||
lt = looptris[face_num];
|
||||
lt = looptris[face_num].data();
|
||||
}
|
||||
#else
|
||||
lt = looptris[face_num];
|
||||
lt = looptris[face_num].data();
|
||||
#endif
|
||||
return lt[vert_index];
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ static void extract_tris_iter_face_bm(const MeshRenderData &mr,
|
||||
Span<std::array<BMLoop *, 3>> looptris = mr.edit_bmesh->looptris;
|
||||
int tri_len = f->len - 2;
|
||||
for (int offs = 0; offs < tri_len; offs++) {
|
||||
const std::array<BMLoop *, 3> elt = looptris[tri_first_index_real + offs];
|
||||
const std::array<BMLoop *, 3> &elt = looptris[tri_first_index_real + offs];
|
||||
int tri_index = tri_offset + offs;
|
||||
GPU_indexbuf_set_tri_verts(elb,
|
||||
tri_index,
|
||||
|
||||
@@ -1313,7 +1313,7 @@ static void knife_bvh_raycast_cb(void *userdata,
|
||||
}
|
||||
|
||||
KnifeTool_OpData *kcd = static_cast<KnifeTool_OpData *>(userdata);
|
||||
std::array<BMLoop *, 3> ltri;
|
||||
BMLoop *const *ltri = nullptr;
|
||||
Object *ob;
|
||||
BMEditMesh *em;
|
||||
|
||||
@@ -1329,10 +1329,11 @@ static void knife_bvh_raycast_cb(void *userdata,
|
||||
em = BKE_editmesh_from_object(ob);
|
||||
tottri = em->looptris.size();
|
||||
if (index < tottri) {
|
||||
ltri = em->looptris[index];
|
||||
ltri = em->looptris[index].data();
|
||||
break;
|
||||
}
|
||||
}
|
||||
BLI_assert(ltri != nullptr);
|
||||
|
||||
if (kcd->bvh.filter_cb) {
|
||||
if (!kcd->bvh.filter_cb(ltri[0]->f, kcd->bvh.filter_data)) {
|
||||
@@ -2505,7 +2506,6 @@ static bool knife_ray_intersect_face(KnifeTool_OpData *kcd,
|
||||
float tri_norm[3], tri_plane[4];
|
||||
float se1[2], se2[2];
|
||||
float d, lambda;
|
||||
std::array<BMLoop *, 3> tri;
|
||||
ListBase *list;
|
||||
KnifeEdge *kfe;
|
||||
|
||||
@@ -2519,7 +2519,7 @@ static bool knife_ray_intersect_face(KnifeTool_OpData *kcd,
|
||||
float tri_cos[3][3];
|
||||
float ray_tri_uv[2];
|
||||
|
||||
tri = em->looptris[tri_i];
|
||||
const std::array<BMLoop *, 3> &tri = em->looptris[tri_i];
|
||||
if (tri[0]->f != f) {
|
||||
break;
|
||||
}
|
||||
@@ -2818,7 +2818,6 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
|
||||
{
|
||||
float v1[3], v2[3], v3[3], v4[3], s1[2], s2[2];
|
||||
int *results, *result;
|
||||
std::array<BMLoop *, 3> ls;
|
||||
ListBase *list;
|
||||
KnifeLineHit *linehits = nullptr;
|
||||
BLI_array_declare(linehits);
|
||||
@@ -2902,16 +2901,17 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
|
||||
|
||||
for (i = 0, result = results; i < tot; i++, result++) {
|
||||
uint ob_index = 0;
|
||||
BMLoop *const *ls = nullptr;
|
||||
for (ob_index = 0; ob_index < kcd->objects.size(); ob_index++) {
|
||||
ob = kcd->objects[ob_index];
|
||||
em = BKE_editmesh_from_object(ob);
|
||||
if (*result >= 0 && *result < em->looptris.size()) {
|
||||
ls = em->looptris[*result];
|
||||
ls = em->looptris[*result].data();
|
||||
break;
|
||||
}
|
||||
*result -= em->looptris.size();
|
||||
}
|
||||
|
||||
BLI_assert(ls != nullptr);
|
||||
BMFace *f = ls[0]->f;
|
||||
set_lowest_face_tri(kcd, em, f, *result);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user