Fix T85664: 3D Viewport issues with curve poly splines

Caused by cleanup in rBcdb3cbd64401, where an index
was used to index `float *` instead of `float[3]`.
This commit is contained in:
Hans Goudey 2021-02-16 21:40:16 -06:00
parent 5c523c6578
commit ab484ff22f
Notes: blender-bot 2023-02-14 02:27:51 +01:00
Referenced by issue #85725, when you convert to curve from mesh or import curves the curves are mesy
Referenced by issue #85664, 3D Viewport drawing issues with zero-width curves
1 changed files with 166 additions and 1 deletions

View File

@ -292,6 +292,170 @@ bool BKE_displist_surfindex_get(DispList *dl, int a, int *b, int *p1, int *p2, i
/* ICC with the optimization -02 causes crashes. */
# pragma intel optimization_level 1
#endif
// static void curve_to_displist(Curve *cu,
// ListBase *nubase,
// const bool for_render,
// ListBase *dispbase)
// {
// DispList *dl;
// BezTriple *bezt, *prevbezt;
// BPoint *bp;
// float *data;
// int a, len, resolu;
// const bool editmode = (!for_render && (cu->editnurb || cu->editfont));
// LISTBASE_FOREACH (Nurb *, nu, nubase) {
// if (nu->hide != 0 && editmode) {
// continue;
// }
// 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;
// }
// if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) {
// len++;
// }
// else {
// len += resolu;
// }
// if (a == 0 && (nu->flagu & CU_NURB_CYCLIC) == 0) {
// len++;
// }
// prevbezt = bezt;
// 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;
// }
// else {
// dl->type = DL_SEGM;
// a = nu->pntsu - 1;
// }
// prevbezt = nu->bezt;
// bezt = prevbezt + 1;
// while (a--) {
// if (a == 0 && dl->type == DL_POLY) {
// bezt = nu->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]));
// }
// 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));
// 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;
// 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;
// }
// a = len;
// bp = nu->bp;
// while (a--) {
// copy_v3_v3(data, bp->vec);
// bp++;
// data += 3;
// }
// }
// }
// }
static void curve_to_displist(const Curve *cu,
const ListBase *nubase,
const bool for_render,
@ -420,9 +584,10 @@ static void curve_to_displist(const Curve *cu,
dl->charidx = nu->charidx;
dl->type = (is_cyclic && (dl->nr != 2)) ? DL_POLY : DL_SEGM;
float(*coords)[3] = (float(*)[3])dl->verts;
for (int i = 0; i < len; i++) {
const BPoint *bp = &nu->bp[i];
copy_v3_v3(&dl->verts[i], bp->vec);
copy_v3_v3(coords[i], bp->vec);
}
}
}