diff options
Diffstat (limited to 'source/blender/blenkernel/intern/pbvh.c')
-rw-r--r-- | source/blender/blenkernel/intern/pbvh.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 24f3097f9e3..1c6274ef35e 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -145,9 +145,14 @@ static void update_node_vb(PBVH *pbvh, PBVHNode *node) // BB_expand(&node->vb, co); //} -static bool face_materials_match(const MPoly *f1, const MPoly *f2) +static bool face_materials_match(const PBVH *pbvh, const int a, const int b) { - return ((f1->flag & ME_SMOOTH) == (f2->flag & ME_SMOOTH) && (f1->mat_nr == f2->mat_nr)); + if (pbvh->material_indices) { + if (pbvh->material_indices[a] != pbvh->material_indices[b]) { + return false; + } + } + return (pbvh->mpoly[a].flag & ME_SMOOTH) == (pbvh->mpoly[b].flag & ME_SMOOTH); } static bool grid_materials_match(const DMFlagMat *f1, const DMFlagMat *f2) @@ -180,30 +185,23 @@ static int partition_indices(int *prim_indices, int lo, int hi, int axis, float /* Returns the index of the first element on the right of the partition */ static int partition_indices_material(PBVH *pbvh, int lo, int hi) { - const MPoly *mpoly = pbvh->mpoly; const MLoopTri *looptri = pbvh->looptri; const DMFlagMat *flagmats = pbvh->grid_flag_mats; const int *indices = pbvh->prim_indices; - const void *first; int i = lo, j = hi; - if (pbvh->looptri) { - first = &mpoly[looptri[pbvh->prim_indices[lo]].poly]; - } - else { - first = &flagmats[pbvh->prim_indices[lo]]; - } - for (;;) { if (pbvh->looptri) { - for (; face_materials_match(first, &mpoly[looptri[indices[i]].poly]); i++) { + const int first = looptri[pbvh->prim_indices[lo]].poly; + for (; face_materials_match(pbvh, first, looptri[indices[i]].poly); i++) { /* pass */ } - for (; !face_materials_match(first, &mpoly[looptri[indices[j]].poly]); j--) { + for (; !face_materials_match(pbvh, first, looptri[indices[j]].poly); j--) { /* pass */ } } else { + const DMFlagMat *first = &flagmats[pbvh->prim_indices[lo]]; for (; grid_materials_match(first, &flagmats[indices[i]]); i++) { /* pass */ } @@ -424,12 +422,9 @@ static bool leaf_needs_material_split(PBVH *pbvh, int offset, int count) if (pbvh->looptri) { const MLoopTri *first = &pbvh->looptri[pbvh->prim_indices[offset]]; - const MPoly *mp = &pbvh->mpoly[first->poly]; - for (int i = offset + count - 1; i > offset; i--) { int prim = pbvh->prim_indices[i]; - const MPoly *mp_other = &pbvh->mpoly[pbvh->looptri[prim].poly]; - if (!face_materials_match(mp, mp_other)) { + if (!face_materials_match(pbvh, first->poly, pbvh->looptri[prim].poly)) { return true; } } @@ -557,6 +552,8 @@ void BKE_pbvh_build_mesh(PBVH *pbvh, pbvh->mesh = mesh; pbvh->header.type = PBVH_FACES; pbvh->mpoly = mpoly; + pbvh->material_indices = (const int *)CustomData_get_layer_named( + &mesh->pdata, CD_PROP_INT32, "material_index"); pbvh->mloop = mloop; pbvh->looptri = looptri; pbvh->verts = verts; |