forked from bartvdbraak/blender
fix for own bugs in curves.
- the number of segments was always 1 too many on cyclic curves. - [#17739] - normals were not being calculated when rendering curves. Replaced macro DL_SURFINDEX with a function. it that assumes variable names and could break from the loop that called it.
This commit is contained in:
parent
002725d72a
commit
6c2738ef48
@ -50,28 +50,6 @@
|
||||
#define DL_FRONT_CURVE 4
|
||||
#define DL_BACK_CURVE 8
|
||||
|
||||
#define DL_SURFINDEX(cyclu, cyclv, sizeu, sizev) \
|
||||
\
|
||||
if( (cyclv)==0 && a==(sizev)-1) break; \
|
||||
if(cyclu) { \
|
||||
p1= sizeu*a; \
|
||||
p2= p1+ sizeu-1; \
|
||||
p3= p1+ sizeu; \
|
||||
p4= p2+ sizeu; \
|
||||
b= 0; \
|
||||
} \
|
||||
else { \
|
||||
p2= sizeu*a; \
|
||||
p1= p2+1; \
|
||||
p4= p2+ sizeu; \
|
||||
p3= p1+ sizeu; \
|
||||
b= 1; \
|
||||
} \
|
||||
if( (cyclv) && a==sizev-1) { \
|
||||
p3-= sizeu*sizev; \
|
||||
p4-= sizeu*sizev; \
|
||||
}
|
||||
|
||||
|
||||
/* prototypes */
|
||||
|
||||
@ -114,6 +92,7 @@ extern void makeDispListMBall(struct Object *ob);
|
||||
extern void shadeDispList(struct Base *base);
|
||||
extern void shadeMeshMCol(struct Object *ob, struct Mesh *me);
|
||||
|
||||
int surfindex_displist(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4);
|
||||
void imagestodisplist(void);
|
||||
void reshadeall_displist(void);
|
||||
void filldisplist(struct ListBase *dispbase, struct ListBase *to);
|
||||
|
@ -832,7 +832,9 @@ void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radiu
|
||||
if(len==0) return;
|
||||
sum= (float *)MEM_callocN(sizeof(float)*len, "makeNurbcurve1");
|
||||
|
||||
resolu= (resolu*SEGMENTSU(nu))+1;
|
||||
resolu= (resolu*SEGMENTSU(nu));
|
||||
if((nu->flagu & CU_CYCLIC)==0) resolu++;
|
||||
|
||||
if(resolu==0) {
|
||||
MEM_freeN(sum);
|
||||
return;
|
||||
@ -842,7 +844,8 @@ void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radiu
|
||||
ustart= fp[nu->orderu-1];
|
||||
if(nu->flagu & CU_CYCLIC) uend= fp[nu->pntsu+nu->orderu-1];
|
||||
else uend= fp[nu->pntsu];
|
||||
ustep= (uend-ustart)/(resolu-1);
|
||||
ustep= (uend-ustart)/(resolu - ((nu->flagu & CU_CYCLIC) ? 0 : 1));
|
||||
|
||||
basisu= (float *)MEM_mallocN(sizeof(float)*KNOTSU(nu), "makeNurbcurve3");
|
||||
|
||||
if(nu->flagu & CU_CYCLIC) cycl= nu->orderu-1;
|
||||
@ -1678,7 +1681,9 @@ void makeBevelList(Object *ob)
|
||||
}
|
||||
else if((nu->type & 7)==CU_NURBS) {
|
||||
if(nu->pntsv==1) {
|
||||
len= (resolu*SEGMENTSU(nu))+1;
|
||||
len= (resolu*SEGMENTSU(nu));
|
||||
if((nu->flagu & CU_CYCLIC)==0) len++;
|
||||
|
||||
bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList3");
|
||||
BLI_addtail(&(cu->bev), bl);
|
||||
bl->nr= len;
|
||||
|
@ -206,8 +206,9 @@ void addnormalsDispList(Object *ob, ListBase *lb)
|
||||
ndata= dl->nors;
|
||||
|
||||
for(a=0; a<dl->parts; a++) {
|
||||
|
||||
DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
|
||||
|
||||
if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0)
|
||||
break;
|
||||
|
||||
v1= vdata+ 3*p1;
|
||||
n1= ndata+ 3*p1;
|
||||
@ -271,6 +272,33 @@ void count_displist(ListBase *lb, int *totvert, int *totface)
|
||||
}
|
||||
}
|
||||
|
||||
int surfindex_displist(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4)
|
||||
{
|
||||
if((dl->flag & DL_CYCL_V)==0 && a==(dl->parts)-1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(dl->flag & DL_CYCL_U) {
|
||||
(*p1)= dl->nr*a;
|
||||
(*p2)= (*p1)+ dl->nr-1;
|
||||
(*p3)= (*p1)+ dl->nr;
|
||||
(*p4)= (*p2)+ dl->nr;
|
||||
(*b)= 0;
|
||||
} else {
|
||||
(*p2)= dl->nr*a;
|
||||
(*p1)= (*p2)+1;
|
||||
(*p4)= (*p2)+ dl->nr;
|
||||
(*p3)= (*p1)+ dl->nr;
|
||||
(*b)= 1;
|
||||
}
|
||||
|
||||
if( (dl->flag & DL_CYCL_U) && a==dl->parts-1) { \
|
||||
(*p3)-= dl->nr*dl->parts; \
|
||||
(*p4)-= dl->nr*dl->parts; \
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ***************************** shade displist. note colors now are in rgb(a) order ******************** */
|
||||
|
||||
@ -858,12 +886,14 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase)
|
||||
}
|
||||
}
|
||||
else if((nu->type & 7)==CU_NURBS) {
|
||||
len= (resolu*SEGMENTSU(nu))+1;
|
||||
len= (resolu*SEGMENTSU(nu));
|
||||
if((nu->flagu & CU_CYCLIC)==0) len++;
|
||||
|
||||
dl= MEM_callocN(sizeof(DispList), "makeDispListsurf");
|
||||
dl->verts= MEM_callocN(len*3*sizeof(float), "dlverts");
|
||||
BLI_addtail(dispbase, dl);
|
||||
dl->parts= 1;
|
||||
|
||||
dl->nr= len;
|
||||
dl->col= nu->mat_nr;
|
||||
dl->charidx = nu->charidx;
|
||||
@ -1308,7 +1338,8 @@ static void displist_surf_indices(DispList *dl)
|
||||
|
||||
for(a=0; a<dl->parts; a++) {
|
||||
|
||||
DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
|
||||
if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0)
|
||||
break;
|
||||
|
||||
for(; b<dl->nr; b++, index+=4) {
|
||||
index[0]= p1;
|
||||
|
@ -2097,8 +2097,10 @@ static void displist_to_mesh(DispList *dlfirst)
|
||||
}
|
||||
|
||||
for(a=0; a<dl->parts; a++) {
|
||||
|
||||
DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
|
||||
|
||||
if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0)
|
||||
break;
|
||||
|
||||
p1+= startve;
|
||||
p2+= startve;
|
||||
p3+= startve;
|
||||
|
@ -2158,8 +2158,8 @@ static PyObject *new_NMesh_displist(ListBase *lb, Object *ob)
|
||||
|
||||
for(a=0; a<dl->parts; a++) {
|
||||
|
||||
DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
|
||||
|
||||
if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0)
|
||||
break;
|
||||
|
||||
for(; b<dl->nr; b++) {
|
||||
vidx[0] = p2 + ioffset;
|
||||
|
@ -2443,7 +2443,6 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar,
|
||||
VlakRen *vlr, *vlr1, *vlr2, *vlr3;
|
||||
Curve *cu= ob->data;
|
||||
float *data, n1[3];
|
||||
/*float flen; - as yet unused */
|
||||
int u, v, orcoret= 0;
|
||||
int p1, p2, p3, p4, a;
|
||||
int sizeu, nsizeu, sizev, nsizev;
|
||||
@ -2515,7 +2514,8 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar,
|
||||
vlr= RE_findOrAddVlak(obr, obr->totvlak++);
|
||||
vlr->v1= v1; vlr->v2= v2; vlr->v3= v3; vlr->v4= v4;
|
||||
|
||||
/* flen= CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, n1); - as yet unused */
|
||||
CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, n1);
|
||||
|
||||
VECCOPY(vlr->n, n1);
|
||||
|
||||
vlr->mat= matar[ dl->col];
|
||||
@ -2787,8 +2787,10 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset)
|
||||
for(a=0; a<dl->parts; a++) {
|
||||
|
||||
frontside= (a >= dl->nr/2);
|
||||
|
||||
DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
|
||||
|
||||
if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0)
|
||||
break;
|
||||
|
||||
p1+= startvert;
|
||||
p2+= startvert;
|
||||
p3+= startvert;
|
||||
|
Loading…
Reference in New Issue
Block a user