Commit: c73a6b0d42f5ee16bb2af7d585035463854f4024
Author: Rohan Rathi
Date:   Wed Jun 20 22:29:44 2018 +0530
Branches: soc-2018-bevel
https://developer.blender.org/rBc73a6b0d42f5ee16bb2af7d585035463854f4024

Merge branch 'blender2.8' into soc-2018-bevel

===================================================================



===================================================================

diff --cc source/blender/bmesh/intern/bmesh_mesh.c
index 4d0f259b4e3,442cd9275ec..96707335081
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@@ -1062,468 -1041,6 +1062,415 @@@ void BM_edges_sharp_from_angle_set(BMes
        bm_mesh_edges_sharp_tag(bm, NULL, NULL, NULL, split_angle, true);
  }
  
 +void BM_lnorspacearr_store(BMesh *bm, float(*r_lnors)[3])
 +{
 +      BLI_assert(bm->lnor_spacearr != NULL);
 +
 +      if (!CustomData_has_layer(&bm->ldata, CD_CUSTOMLOOPNORMAL)) {
 +              BM_data_layer_add(bm, &bm->ldata, CD_CUSTOMLOOPNORMAL);
 +      }
 +
 +      int cd_loop_clnors_offset = CustomData_get_offset(&bm->ldata, 
CD_CUSTOMLOOPNORMAL);
 +
 +      BM_loops_calc_normal_vcos(
 +              bm, NULL, NULL, NULL, true, M_PI, r_lnors, bm->lnor_spacearr, 
NULL, cd_loop_clnors_offset, false);
 +      bm->spacearr_dirty &= ~(BM_SPACEARR_DIRTY | BM_SPACEARR_DIRTY_ALL);
 +}
 +
 +/* will change later */
 +#define CLEAR_SPACEARRAY_THRESHOLD(x) ((x) / 2)
 +
 +void BM_lnorspace_invalidate(BMesh *bm, const bool do_invalidate_all)
 +{
 +      if (bm->spacearr_dirty & BM_SPACEARR_DIRTY_ALL) {
 +              return;
 +      }
 +      if (do_invalidate_all || bm->totvertsel > 
CLEAR_SPACEARRAY_THRESHOLD(bm->totvert)) {
 +              bm->spacearr_dirty |= BM_SPACEARR_DIRTY_ALL;
 +              return;
 +      }
 +      if (bm->lnor_spacearr == NULL) {
 +              bm->spacearr_dirty |= BM_SPACEARR_DIRTY_ALL;
 +              return;
 +      }
 +
 +      BMVert *v;
 +      BMLoop *l;
 +      BMIter viter, liter;
 +      /* Note: we could use temp tag of BMItem for that, but probably better 
not use it in such a low-level func?
 +      * --mont29 */
 +      BLI_bitmap *done_verts = BLI_BITMAP_NEW(bm->totvert, __func__);
 +
 +      BM_mesh_elem_index_ensure(bm, BM_VERT);
 +
 +      /* When we affect a given vertex, we may affect following smooth fans:
 +      *     - all smooth fans of said vertex;
 +      *     - all smooth fans of all immediate loop-neighbors vertices;
 +      * This can be simplified as 'all loops of selected vertices and their 
immediate neighbors'
 +      * need to be tagged for update.
- */
- BM_ITER_MESH(v, &viter, bm, BM_VERTS_OF_MESH) {
-       if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
-               BM_ITER_ELEM(l, &liter, v, BM_LOOPS_OF_VERT) {
-                       BM_ELEM_API_FLAG_ENABLE(l, BM_LNORSPACE_UPDATE);
- 
-                       /* Note that we only handle unselected neighbor 
vertices here, main loop will take care of
-                       * selected ones. */
-                       if (!BM_elem_flag_test(l->prev->v, BM_ELEM_SELECT) &&
-                               !BLI_BITMAP_TEST(done_verts, 
BM_elem_index_get(l->prev->v)))
-                       {
-                               BMLoop *l_prev;
-                               BMIter liter_prev;
-                               BM_ITER_ELEM(l_prev, &liter_prev, l->prev->v, 
BM_LOOPS_OF_VERT) {
-                                       BM_ELEM_API_FLAG_ENABLE(l_prev, 
BM_LNORSPACE_UPDATE);
++      */
++      BM_ITER_MESH(v, &viter, bm, BM_VERTS_OF_MESH) {
++              if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
++                      BM_ITER_ELEM(l, &liter, v, BM_LOOPS_OF_VERT) {
++                              BM_ELEM_API_FLAG_ENABLE(l, BM_LNORSPACE_UPDATE);
++
++                              /* Note that we only handle unselected neighbor 
vertices here, main loop will take care of
++                              * selected ones. */
++                              if (!BM_elem_flag_test(l->prev->v, 
BM_ELEM_SELECT) &&
++                                      !BLI_BITMAP_TEST(done_verts, 
BM_elem_index_get(l->prev->v)))
++                              {
++                                      BMLoop *l_prev;
++                                      BMIter liter_prev;
++                                      BM_ITER_ELEM(l_prev, &liter_prev, 
l->prev->v, BM_LOOPS_OF_VERT) {
++                                              BM_ELEM_API_FLAG_ENABLE(l_prev, 
BM_LNORSPACE_UPDATE);
++                                      }
++                                      BLI_BITMAP_ENABLE(done_verts, 
BM_elem_index_get(l_prev->v));
 +                              }
-                               BLI_BITMAP_ENABLE(done_verts, 
BM_elem_index_get(l_prev->v));
-                       }
 +
-                       if (!BM_elem_flag_test(l->next->v, BM_ELEM_SELECT) &&
-                               !BLI_BITMAP_TEST(done_verts, 
BM_elem_index_get(l->next->v)))
-                       {
-                               BMLoop *l_next;
-                               BMIter liter_next;
-                               BM_ITER_ELEM(l_next, &liter_next, l->next->v, 
BM_LOOPS_OF_VERT) {
-                                       BM_ELEM_API_FLAG_ENABLE(l_next, 
BM_LNORSPACE_UPDATE);
++                              if (!BM_elem_flag_test(l->next->v, 
BM_ELEM_SELECT) &&
++                                      !BLI_BITMAP_TEST(done_verts, 
BM_elem_index_get(l->next->v)))
++                              {
++                                      BMLoop *l_next;
++                                      BMIter liter_next;
++                                      BM_ITER_ELEM(l_next, &liter_next, 
l->next->v, BM_LOOPS_OF_VERT) {
++                                              BM_ELEM_API_FLAG_ENABLE(l_next, 
BM_LNORSPACE_UPDATE);
++                                      }
++                                      BLI_BITMAP_ENABLE(done_verts, 
BM_elem_index_get(l_next->v));
 +                              }
-                               BLI_BITMAP_ENABLE(done_verts, 
BM_elem_index_get(l_next->v));
 +                      }
-               }
 +
-               BLI_BITMAP_ENABLE(done_verts, BM_elem_index_get(v));
++                      BLI_BITMAP_ENABLE(done_verts, BM_elem_index_get(v));
++              }
 +      }
- }
 +
- MEM_freeN(done_verts);
- bm->spacearr_dirty |= BM_SPACEARR_DIRTY;
++      MEM_freeN(done_verts);
++      bm->spacearr_dirty |= BM_SPACEARR_DIRTY;
 +}
 +
 +void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor)
 +{
 +      BLI_assert(bm->lnor_spacearr != NULL);
 +
 +      if (!(bm->spacearr_dirty & (BM_SPACEARR_DIRTY | 
BM_SPACEARR_DIRTY_ALL))) {
 +              return;
 +      }
 +      BMFace *f;
 +      BMLoop *l;
 +      BMIter fiter, liter;
 +
 +      float(*r_lnors)[3] = MEM_callocN(sizeof(*r_lnors) * bm->totloop, 
__func__);
 +      float(*oldnors)[3] = preserve_clnor ? MEM_mallocN(sizeof(*oldnors) * 
bm->totloop, __func__) : NULL;
 +
 +      int cd_loop_clnors_offset = CustomData_get_offset(&bm->ldata, 
CD_CUSTOMLOOPNORMAL);
 +
 +      BM_mesh_elem_index_ensure(bm, BM_LOOP);
 +
 +      if (preserve_clnor) {
 +              BLI_assert(bm->lnor_spacearr->lspacearr != NULL);
 +
 +              BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) {
 +                      BM_ITER_ELEM(l, &liter, f, BM_LOOPS_OF_FACE) {
 +                              if (BM_ELEM_API_FLAG_TEST(l, 
BM_LNORSPACE_UPDATE) || bm->spacearr_dirty & BM_SPACEARR_DIRTY_ALL) {
 +                                      short(*clnor)[2] = 
BM_ELEM_CD_GET_VOID_P(l, cd_loop_clnors_offset);
 +                                      int l_index = BM_elem_index_get(l);
 +
 +                                      
BKE_lnor_space_custom_data_to_normal(bm->lnor_spacearr->lspacearr[l_index], 
*clnor, oldnors[l_index]);
 +                              }
 +                      }
 +              }
 +      }
 +
 +      if (bm->spacearr_dirty & BM_SPACEARR_DIRTY_ALL) {
 +              BKE_lnor_spacearr_clear(bm->lnor_spacearr);
 +      }
 +      BM_loops_calc_normal_vcos(
 +              bm, NULL, NULL, NULL, true, M_PI, r_lnors, bm->lnor_spacearr, 
NULL, cd_loop_clnors_offset, true);
 +      MEM_freeN(r_lnors);
 +
 +      BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) {
 +              BM_ITER_ELEM(l, &liter, f, BM_LOOPS_OF_FACE) {
 +                      if (BM_ELEM_API_FLAG_TEST(l, BM_LNORSPACE_UPDATE) || 
bm->spacearr_dirty & BM_SPACEARR_DIRTY_ALL) {
 +                              if (preserve_clnor) {
 +                                      short(*clnor)[2] = 
BM_ELEM_CD_GET_VOID_P(l, cd_loop_clnors_offset);
 +                                      int l_index = BM_elem_index_get(l);
 +                                      
BKE_lnor_space_custom_normal_to_data(bm->lnor_spacearr->lspacearr[l_index], 
oldnors[l_index], *clnor);
 +                              }
 +                              BM_ELEM_API_FLAG_DISABLE(l, 
BM_LNORSPACE_UPDATE);
 +                      }
 +              }
 +      }
 +
 +      MEM_SAFE_FREE(oldnors);
 +      bm->spacearr_dirty &= ~(BM_SPACEARR_DIRTY | BM_SPACEARR_DIRTY_ALL);
 +
 +#ifndef NDEBUG
 +      BM_lnorspace_err(bm);
 +#endif
 +}
 +
 +void BM_lnorspace_update(BMesh *bm)
 +{
 +      if (bm->lnor_spacearr == NULL) {
 +              bm->lnor_spacearr = MEM_callocN(sizeof(*bm->lnor_spacearr), 
__func__);
 +      }
 +      if (bm->lnor_spacearr->lspacearr == NULL) {
 +              float(*lnors)[3] = MEM_callocN(sizeof(*lnors) * bm->totloop, 
__func__);
 +
 +              BM_lnorspacearr_store(bm, lnors);
 +
 +              MEM_freeN(lnors);
 +      }
 +      else if (bm->spacearr_dirty & (BM_SPACEARR_DIRTY | 
BM_SPACEARR_DIRTY_ALL)) {
 +              BM_lnorspace_rebuild(bm, false);
 +      }
 +}
 +
 +void BM_normals_loops_edges_tag(BMesh *bm, const bool do_edges)
 +{
 +      BMFace *f;
 +      BMEdge *e;
 +      BMIter fiter, eiter;
 +      BMLoop *l_curr, *l_first;
 +
 +      if (do_edges) {
 +              int index_edge;
 +              BM_ITER_MESH_INDEX(e, &eiter, bm, BM_EDGES_OF_MESH, index_edge) 
{
 +                      BMLoop *l_a, *l_b;
 +
 +                      BM_elem_index_set(e, index_edge);  /* set_inline */
 +                      BM_elem_flag_disable(e, BM_ELEM_TAG);
 +                      if (BM_edge_loop_pair(e, &l_a, &l_b)) {
 +                              if (BM_elem_flag_test(e, BM_ELEM_SMOOTH) && 
l_a->v != l_b->v) {
 +                                      BM_elem_flag_enable(e, BM_ELEM_TAG);
 +                              }
 +                      }
 +              }
 +              bm->elem_index_dirty &= ~BM_EDGE;
 +      }
 +
 +      int index_face, index_loop = 0;
 +      BM_ITER_MESH_INDEX(f, &fiter, bm, BM_FACES_OF_MESH, index_face) {
 +              BM_elem_index_set(f, index_face);  /* set_inline */
 +              l_curr = l_first = BM_FACE_FIRST_LOOP(f);
 +              do {
 +                      BM_elem_index_set(l_curr, index_loop++);  /* set_inline 
*/
 +                      BM_elem_flag_disable(l_curr, BM_ELEM_TAG);
 +              } while ((l_curr = l_curr->next) != l_first);
 +      }
 +      bm->elem_index_dirty &= ~(BM_FACE | BM_LOOP);
 +}
 +
 +/**
 +* Auxillary function only used by rebuild to detect if any spaces were not 
marked as invalid.
 +* Reports error if any of the lnor spaces change after rebuilding, meaning 
that all the possible
 +* lnor spaces to be rebuilt were not correctly marked.
 +*/
 +#ifndef NDEBUG
 +void BM_lnorspace_err(BMesh *bm)
 +{
 +      bm->spacearr_dirty |= BM_SPACEARR_DIRTY_ALL;
 +      bool clear = true;
 +
 +      MLoopNorSpaceArray *temp = MEM_callocN(sizeof(*temp), __func__);
 +      temp->lspacearr = NULL;
 +
 +      BKE_lnor_spacearr_init(temp, bm->totloop, MLNOR_SPACEARR_BMLOOP_PTR);
 +
 +      int cd_loop_clnors_offset = CustomData_get_offset(&bm->ldata, 
CD_CUSTOMLOOPNORMAL);
 +      float(*lnors)[3] = MEM_callocN(sizeof(*lnors) * bm->totloop, __func__);
 +      BM_loops_calc_normal_vcos(bm, NULL, NULL, NULL, true, M_PI, lnors, 
temp, NULL, cd_loop_clnors_offset, true);
 +
 +      for (int i = 0; i < bm->totloop; i++) {
 +              int j = 0;
 +              j += compare_ff(temp->lspacearr[i]->ref_alpha, 
bm->lnor_spacearr->lspacearr[i]->ref_alpha, 1e-4f);
 +              j += compare_ff(temp->lspacearr[i]->ref_beta, 
bm->lnor_spacearr->lspacearr[i]->ref_beta, 1e-4f);
 +              j += compare_v3v3(temp->lspacearr[i]->vec_lnor, 
bm->lnor_spacearr->lspacearr[i]->vec_lnor, 1e-4f);
 +              j += compare_v3v3(temp->lspacearr[i]->vec_ortho, 
bm->lnor_spacearr->lspacearr[i]->vec_ortho, 1e-4f);
 +              j += compare_v3v3(temp->lspacearr[i]->vec_ref, 
bm->lnor_spacearr->lspacearr[i]->vec_ref, 1e-4f);
 +
 +              if (j != 5) {
 +                      clear = false;
 +                      break;
 +              }
 +      }
 +      BKE_lnor_spacearr_free(temp);
 +      MEM_freeN(temp);
 +      MEM_freeN(lnors);
 +      BLI_assert(clear);
 +
 +      bm->spacearr_dirty &= ~BM_SPACEARR_DIRTY_ALL;
 +}
 +#endif
 +
 +static void bm_loop_normal_mark_indiv_do_loop(
 +      BMLoop *l, BLI_bitmap *loops, MLoopNorSpaceArray *lnor_spacearr, int 
*totloopsel)
 +{
 +      if (l != NULL) {
 +              const int l_idx = BM_elem_index_get(l);
 +
 +              if (!BLI_BITMAP_TEST(loops, BM_elem_index_get(l))) {
 +                      /* If vert and face selected share a loop, mark it for 
editing. */
 +                      BLI_BITMAP_ENABLE(loops, l_idx);
 +                      (*totloopsel)++;
 +
 +                      /* Mark all loops in same loop normal s

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to