diff options
Diffstat (limited to 'source/blender/blenkernel/intern/displist.c')
-rw-r--r-- | source/blender/blenkernel/intern/displist.c | 423 |
1 files changed, 197 insertions, 226 deletions
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index bcb467e1230..f5257eb12ab 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -92,17 +92,13 @@ void BKE_displist_free(ListBase *lb) DispList *BKE_displist_find_or_create(ListBase *lb, int type) { - DispList *dl; - - dl = lb->first; - while (dl) { + LISTBASE_FOREACH (DispList *, dl, lb) { if (dl->type == type) { return dl; } - dl = dl->next; } - dl = MEM_callocN(sizeof(DispList), "find_disp"); + DispList *dl = MEM_callocN(sizeof(DispList), "find_disp"); dl->type = type; BLI_addtail(lb, dl); @@ -111,14 +107,10 @@ DispList *BKE_displist_find_or_create(ListBase *lb, int type) DispList *BKE_displist_find(ListBase *lb, int type) { - DispList *dl; - - dl = lb->first; - while (dl) { + LISTBASE_FOREACH (DispList *, dl, lb) { if (dl->type == type) { return dl; } - dl = dl->next; } return NULL; @@ -126,9 +118,7 @@ DispList *BKE_displist_find(ListBase *lb, int type) bool BKE_displist_has_faces(ListBase *lb) { - DispList *dl; - - for (dl = lb->first; dl; dl = dl->next) { + LISTBASE_FOREACH (DispList *, dl, lb) { if (ELEM(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF)) { return true; } @@ -139,13 +129,10 @@ bool BKE_displist_has_faces(ListBase *lb) void BKE_displist_copy(ListBase *lbn, ListBase *lb) { - DispList *dln, *dl; - BKE_displist_free(lbn); - dl = lb->first; - while (dl) { - dln = MEM_dupallocN(dl); + LISTBASE_FOREACH (const DispList *, dl, lb) { + DispList *dln = MEM_dupallocN(dl); BLI_addtail(lbn, dln); dln->verts = MEM_dupallocN(dl->verts); dln->nors = MEM_dupallocN(dl->nors); @@ -154,22 +141,17 @@ void BKE_displist_copy(ListBase *lbn, ListBase *lb) if (dl->bevel_split) { dln->bevel_split = MEM_dupallocN(dl->bevel_split); } - - dl = dl->next; } } void BKE_displist_normals_add(ListBase *lb) { - DispList *dl = NULL; float *vdata, *ndata, nor[3]; float *v1, *v2, *v3, *v4; float *n1, *n2, *n3, *n4; int a, b, p1, p2, p3, p4; - dl = lb->first; - - while (dl) { + LISTBASE_FOREACH (DispList *, dl, lb) { if (dl->type == DL_INDEX3) { if (dl->nors == NULL) { dl->nors = MEM_callocN(sizeof(float[3]), "dlnors"); @@ -230,15 +212,12 @@ void BKE_displist_normals_add(ListBase *lb) } } } - dl = dl->next; } } void BKE_displist_count(ListBase *lb, int *totvert, int *totface, int *tottri) { - DispList *dl; - - for (dl = lb->first; dl; dl = dl->next) { + LISTBASE_FOREACH (DispList *, dl, lb) { int vert_tot = 0; int face_tot = 0; int tri_tot = 0; @@ -318,7 +297,6 @@ static void curve_to_displist(Curve *cu, ListBase *dispbase, const bool for_render) { - Nurb *nu; DispList *dl; BezTriple *bezt, *prevbezt; BPoint *bp; @@ -326,154 +304,154 @@ static void curve_to_displist(Curve *cu, int a, len, resolu; const bool editmode = (!for_render && (cu->editnurb || cu->editfont)); - nu = nubase->first; - while (nu) { - if (nu->hide == 0 || editmode == false) { - if (for_render && cu->resolu_ren != 0) { - resolu = cu->resolu_ren; - } - else { - resolu = nu->resolu; - } - - if (!BKE_nurb_check_valid_u(nu)) { - /* pass */ - } - else if (nu->type == CU_BEZIER) { - /* count */ - len = 0; - a = nu->pntsu - 1; - if (nu->flagu & CU_NURB_CYCLIC) { - a++; - } - - prevbezt = nu->bezt; - bezt = prevbezt + 1; - while (a--) { - if (a == 0 && (nu->flagu & CU_NURB_CYCLIC)) { - bezt = nu->bezt; - } + LISTBASE_FOREACH (Nurb *, nu, nubase) { + if (nu->hide != 0 && editmode) { + continue; + } - if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) { - len++; - } - else { - len += resolu; - } + if (for_render && cu->resolu_ren != 0) { + resolu = cu->resolu_ren; + } + else { + resolu = nu->resolu; + } - if (a == 0 && (nu->flagu & CU_NURB_CYCLIC) == 0) { - len++; - } + if (!BKE_nurb_check_valid_u(nu)) { + /* pass */ + } + else if (nu->type == CU_BEZIER) { + /* count */ + len = 0; + a = nu->pntsu - 1; + if (nu->flagu & CU_NURB_CYCLIC) { + a++; + } - prevbezt = bezt; - bezt++; + prevbezt = nu->bezt; + bezt = prevbezt + 1; + while (a--) { + if (a == 0 && (nu->flagu & CU_NURB_CYCLIC)) { + bezt = nu->bezt; } - dl = MEM_callocN(sizeof(DispList), "makeDispListbez"); - /* len+1 because of 'forward_diff_bezier' function */ - dl->verts = MEM_mallocN((len + 1) * sizeof(float[3]), "dlverts"); - BLI_addtail(dispbase, dl); - dl->parts = 1; - dl->nr = len; - dl->col = nu->mat_nr; - dl->charidx = nu->charidx; - - data = dl->verts; - - /* check that (len != 2) so we don't immediately loop back on ourselves */ - if (nu->flagu & CU_NURB_CYCLIC && (dl->nr != 2)) { - dl->type = DL_POLY; - a = nu->pntsu; + if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) { + len++; } else { - dl->type = DL_SEGM; - a = nu->pntsu - 1; + len += resolu; } - prevbezt = nu->bezt; - bezt = prevbezt + 1; + if (a == 0 && (nu->flagu & CU_NURB_CYCLIC) == 0) { + len++; + } - while (a--) { - if (a == 0 && dl->type == DL_POLY) { - bezt = nu->bezt; - } + prevbezt = bezt; + bezt++; + } - if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) { - copy_v3_v3(data, prevbezt->vec[1]); - data += 3; - } - else { - int j; - for (j = 0; j < 3; j++) { - BKE_curve_forward_diff_bezier(prevbezt->vec[1][j], - prevbezt->vec[2][j], - bezt->vec[0][j], - bezt->vec[1][j], - data + j, - resolu, - sizeof(float[3])); - } + dl = MEM_callocN(sizeof(DispList), "makeDispListbez"); + /* len+1 because of 'forward_diff_bezier' function */ + dl->verts = MEM_mallocN((len + 1) * sizeof(float[3]), "dlverts"); + BLI_addtail(dispbase, dl); + dl->parts = 1; + dl->nr = len; + dl->col = nu->mat_nr; + dl->charidx = nu->charidx; + + data = dl->verts; + + /* check that (len != 2) so we don't immediately loop back on ourselves */ + if (nu->flagu & CU_NURB_CYCLIC && (dl->nr != 2)) { + dl->type = DL_POLY; + a = nu->pntsu; + } + else { + dl->type = DL_SEGM; + a = nu->pntsu - 1; + } - data += 3 * resolu; - } + prevbezt = nu->bezt; + bezt = prevbezt + 1; + + while (a--) { + if (a == 0 && dl->type == DL_POLY) { + bezt = nu->bezt; + } - if (a == 0 && dl->type == DL_SEGM) { - copy_v3_v3(data, bezt->vec[1]); + if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) { + copy_v3_v3(data, prevbezt->vec[1]); + data += 3; + } + else { + int j; + for (j = 0; j < 3; j++) { + BKE_curve_forward_diff_bezier(prevbezt->vec[1][j], + prevbezt->vec[2][j], + bezt->vec[0][j], + bezt->vec[1][j], + data + j, + resolu, + sizeof(float[3])); } - prevbezt = bezt; - bezt++; + data += 3 * resolu; } + + if (a == 0 && dl->type == DL_SEGM) { + copy_v3_v3(data, bezt->vec[1]); + } + + prevbezt = bezt; + bezt++; } - else if (nu->type == CU_NURBS) { - len = (resolu * SEGMENTSU(nu)); + } + else if (nu->type == CU_NURBS) { + len = (resolu * SEGMENTSU(nu)); - dl = MEM_callocN(sizeof(DispList), "makeDispListsurf"); - dl->verts = MEM_mallocN(len * sizeof(float[3]), "dlverts"); - BLI_addtail(dispbase, dl); - dl->parts = 1; + dl = MEM_callocN(sizeof(DispList), "makeDispListsurf"); + dl->verts = MEM_mallocN(len * sizeof(float[3]), "dlverts"); + BLI_addtail(dispbase, dl); + dl->parts = 1; - dl->nr = len; - dl->col = nu->mat_nr; - dl->charidx = nu->charidx; + dl->nr = len; + dl->col = nu->mat_nr; + dl->charidx = nu->charidx; - data = dl->verts; - if (nu->flagu & CU_NURB_CYCLIC) { - dl->type = DL_POLY; - } - else { - dl->type = DL_SEGM; - } - BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, sizeof(float[3])); + data = dl->verts; + if (nu->flagu & CU_NURB_CYCLIC) { + dl->type = DL_POLY; + } + else { + dl->type = DL_SEGM; + } + BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, sizeof(float[3])); + } + else if (nu->type == CU_POLY) { + len = nu->pntsu; + dl = MEM_callocN(sizeof(DispList), "makeDispListpoly"); + dl->verts = MEM_mallocN(len * sizeof(float[3]), "dlverts"); + BLI_addtail(dispbase, dl); + dl->parts = 1; + dl->nr = len; + dl->col = nu->mat_nr; + dl->charidx = nu->charidx; + + data = dl->verts; + if ((nu->flagu & CU_NURB_CYCLIC) && (dl->nr != 2)) { + dl->type = DL_POLY; + } + else { + dl->type = DL_SEGM; } - else if (nu->type == CU_POLY) { - len = nu->pntsu; - dl = MEM_callocN(sizeof(DispList), "makeDispListpoly"); - dl->verts = MEM_mallocN(len * sizeof(float[3]), "dlverts"); - BLI_addtail(dispbase, dl); - dl->parts = 1; - dl->nr = len; - dl->col = nu->mat_nr; - dl->charidx = nu->charidx; - - data = dl->verts; - if ((nu->flagu & CU_NURB_CYCLIC) && (dl->nr != 2)) { - dl->type = DL_POLY; - } - else { - dl->type = DL_SEGM; - } - a = len; - bp = nu->bp; - while (a--) { - copy_v3_v3(data, bp->vec); - bp++; - data += 3; - } + a = len; + bp = nu->bp; + while (a--) { + copy_v3_v3(data, bp->vec); + bp++; + data += 3; } } - nu = nu->next; } } @@ -491,7 +469,7 @@ void BKE_displist_fill(ListBase *dispbase, ScanFillVert *sf_vert, *sf_vert_new, *sf_vert_last; ScanFillFace *sf_tri; MemArena *sf_arena; - DispList *dlnew = NULL, *dl; + DispList *dlnew = NULL; float *f1; int colnr = 0, charidx = 0, cont = 1, tot, a, *index, nextcol = 0; int totvert; @@ -515,8 +493,7 @@ void BKE_displist_fill(ListBase *dispbase, BLI_scanfill_begin_arena(&sf_ctx, sf_arena); - dl = dispbase->first; - while (dl) { + LISTBASE_FOREACH (DispList *, dl, dispbase) { if (dl->type == DL_POLY) { if (charidx < dl->charidx) { cont = 1; @@ -558,7 +535,6 @@ void BKE_displist_fill(ListBase *dispbase, } dl_flag_accum |= dl->flag; } - dl = dl->next; } /* XXX (obedit && obedit->actcol) ? (obedit->actcol - 1) : 0)) { */ @@ -627,19 +603,17 @@ static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase) { const float z_up[3] = {0.0f, 0.0f, -1.0f}; ListBase front, back; - DispList *dl, *dlnew; float *fp, *fp1; int a, dpoly; BLI_listbase_clear(&front); BLI_listbase_clear(&back); - dl = dispbase->first; - while (dl) { + LISTBASE_FOREACH (DispList *, dl, dispbase) { if (dl->type == DL_SURF) { if ((dl->flag & DL_CYCL_V) && (dl->flag & DL_CYCL_U) == 0) { if ((cu->flag & CU_BACK) && (dl->flag & DL_BACK_CURVE)) { - dlnew = MEM_callocN(sizeof(DispList), "filldisp"); + DispList *dlnew = MEM_callocN(sizeof(DispList), "filldisp"); BLI_addtail(&front, dlnew); dlnew->verts = fp1 = MEM_mallocN(sizeof(float[3]) * dl->parts, "filldisp1"); dlnew->nr = dl->parts; @@ -660,7 +634,7 @@ static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase) } } if ((cu->flag & CU_FRONT) && (dl->flag & DL_FRONT_CURVE)) { - dlnew = MEM_callocN(sizeof(DispList), "filldisp"); + DispList *dlnew = MEM_callocN(sizeof(DispList), "filldisp"); BLI_addtail(&back, dlnew); dlnew->verts = fp1 = MEM_mallocN(sizeof(float[3]) * dl->parts, "filldisp1"); dlnew->nr = dl->parts; @@ -682,7 +656,6 @@ static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase) } } } - dl = dl->next; } BKE_displist_fill(&front, dispbase, z_up, true); @@ -939,18 +912,17 @@ static bool curve_calc_modifiers_pre( static float (*displist_vert_coords_alloc(ListBase *dispbase, int *r_vert_len))[3] { - DispList *dl; float(*allverts)[3], *fp; *r_vert_len = 0; - for (dl = dispbase->first; dl; dl = dl->next) { + LISTBASE_FOREACH (DispList *, dl, dispbase) { *r_vert_len += (dl->type == DL_INDEX3) ? dl->nr : dl->parts * dl->nr; } allverts = MEM_mallocN(sizeof(float[3]) * (*r_vert_len), "displist_vert_coords_alloc allverts"); fp = (float *)allverts; - for (dl = dispbase->first; dl; dl = dl->next) { + LISTBASE_FOREACH (DispList *, dl, dispbase) { int offs = 3 * ((dl->type == DL_INDEX3) ? dl->nr : dl->parts * dl->nr); memcpy(fp, dl->verts, sizeof(float) * offs); fp += offs; @@ -961,11 +933,10 @@ static float (*displist_vert_coords_alloc(ListBase *dispbase, int *r_vert_len))[ static void displist_vert_coords_apply(ListBase *dispbase, float (*allverts)[3]) { - DispList *dl; const float *fp; fp = (float *)allverts; - for (dl = dispbase->first; dl; dl = dl->next) { + LISTBASE_FOREACH (DispList *, dl, dispbase) { int offs = 3 * ((dl->type == DL_INDEX3) ? dl->nr : dl->parts * dl->nr); memcpy(dl->verts, fp, sizeof(float) * offs); fp += offs; @@ -1218,7 +1189,6 @@ void BKE_displist_make_surf(Depsgraph *depsgraph, const bool for_orco) { ListBase nubase = {NULL, NULL}; - Nurb *nu; Curve *cu = ob->data; DispList *dl; float *data; @@ -1236,76 +1206,78 @@ void BKE_displist_make_surf(Depsgraph *depsgraph, force_mesh_conversion = curve_calc_modifiers_pre(depsgraph, scene, ob, &nubase, for_render); } - for (nu = nubase.first; nu; nu = nu->next) { - if ((for_render || nu->hide == 0) && BKE_nurb_check_valid_uv(nu)) { - int resolu = nu->resolu, resolv = nu->resolv; + LISTBASE_FOREACH (Nurb *, nu, &nubase) { + if (!(for_render || nu->hide == 0) || !BKE_nurb_check_valid_uv(nu)) { + continue; + } + + int resolu = nu->resolu, resolv = nu->resolv; - if (for_render) { - if (cu->resolu_ren) { - resolu = cu->resolu_ren; - } - if (cu->resolv_ren) { - resolv = cu->resolv_ren; - } + if (for_render) { + if (cu->resolu_ren) { + resolu = cu->resolu_ren; + } + if (cu->resolv_ren) { + resolv = cu->resolv_ren; } + } - if (nu->pntsv == 1) { - len = SEGMENTSU(nu) * resolu; + if (nu->pntsv == 1) { + len = SEGMENTSU(nu) * resolu; - dl = MEM_callocN(sizeof(DispList), "makeDispListsurf"); - dl->verts = MEM_mallocN(len * sizeof(float[3]), "dlverts"); + dl = MEM_callocN(sizeof(DispList), "makeDispListsurf"); + dl->verts = MEM_mallocN(len * sizeof(float[3]), "dlverts"); - BLI_addtail(dispbase, dl); - dl->parts = 1; - dl->nr = len; - dl->col = nu->mat_nr; - dl->charidx = nu->charidx; + BLI_addtail(dispbase, dl); + dl->parts = 1; + dl->nr = len; + dl->col = nu->mat_nr; + dl->charidx = nu->charidx; - /* dl->rt will be used as flag for render face and */ - /* CU_2D conflicts with R_NOPUNOFLIP */ - dl->rt = nu->flag & ~CU_2D; + /* dl->rt will be used as flag for render face and */ + /* CU_2D conflicts with R_NOPUNOFLIP */ + dl->rt = nu->flag & ~CU_2D; - data = dl->verts; - if (nu->flagu & CU_NURB_CYCLIC) { - dl->type = DL_POLY; - } - else { - dl->type = DL_SEGM; - } - - BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, sizeof(float[3])); + data = dl->verts; + if (nu->flagu & CU_NURB_CYCLIC) { + dl->type = DL_POLY; } else { - len = (nu->pntsu * resolu) * (nu->pntsv * resolv); + dl->type = DL_SEGM; + } - dl = MEM_callocN(sizeof(DispList), "makeDispListsurf"); - dl->verts = MEM_mallocN(len * sizeof(float[3]), "dlverts"); - BLI_addtail(dispbase, dl); + BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, sizeof(float[3])); + } + else { + len = (nu->pntsu * resolu) * (nu->pntsv * resolv); - dl->col = nu->mat_nr; - dl->charidx = nu->charidx; + dl = MEM_callocN(sizeof(DispList), "makeDispListsurf"); + dl->verts = MEM_mallocN(len * sizeof(float[3]), "dlverts"); + BLI_addtail(dispbase, dl); - /* dl->rt will be used as flag for render face and */ - /* CU_2D conflicts with R_NOPUNOFLIP */ - dl->rt = nu->flag & ~CU_2D; + dl->col = nu->mat_nr; + dl->charidx = nu->charidx; - data = dl->verts; - dl->type = DL_SURF; + /* dl->rt will be used as flag for render face and */ + /* CU_2D conflicts with R_NOPUNOFLIP */ + dl->rt = nu->flag & ~CU_2D; - dl->parts = (nu->pntsu * resolu); /* in reverse, because makeNurbfaces works that way */ - dl->nr = (nu->pntsv * resolv); - if (nu->flagv & CU_NURB_CYCLIC) { - dl->flag |= DL_CYCL_U; /* reverse too! */ - } - if (nu->flagu & CU_NURB_CYCLIC) { - dl->flag |= DL_CYCL_V; - } + data = dl->verts; + dl->type = DL_SURF; - BKE_nurb_makeFaces(nu, data, 0, resolu, resolv); - - /* gl array drawing: using indices */ - displist_surf_indices(dl); + dl->parts = (nu->pntsu * resolu); /* in reverse, because makeNurbfaces works that way */ + dl->nr = (nu->pntsv * resolv); + if (nu->flagv & CU_NURB_CYCLIC) { + dl->flag |= DL_CYCL_U; /* reverse too! */ + } + if (nu->flagu & CU_NURB_CYCLIC) { + dl->flag |= DL_CYCL_V; } + + BKE_nurb_makeFaces(nu, data, 0, resolu, resolv); + + /* gl array drawing: using indices */ + displist_surf_indices(dl); } } @@ -1851,12 +1823,11 @@ void BKE_displist_make_curveTypes_forRender(Depsgraph *depsgraph, void BKE_displist_minmax(ListBase *dispbase, float min[3], float max[3]) { - DispList *dl; const float *vert; int a, tot = 0; int doit = 0; - for (dl = dispbase->first; dl; dl = dl->next) { + LISTBASE_FOREACH (DispList *, dl, dispbase) { tot = (dl->type == DL_INDEX3) ? dl->nr : dl->nr * dl->parts; vert = dl->verts; for (a = 0; a < tot; a++, vert += 3) { |