- remove some silly array copying code for nurb displist generation

- converted dl->flag to use consistent defines for cyclic U/V
This commit is contained in:
Daniel Dunbar 2005-08-11 22:27:53 +00:00
parent 841ddb4680
commit 5afdfc6ac1
11 changed files with 44 additions and 269 deletions

@ -46,7 +46,6 @@ struct BevList;
#define KNOTSV(nu) ( (nu)->orderv+ (nu)->pntsv+ (nu->orderv-1)*((nu)->flagv & 1) )
int copyintoExtendedArray(float *old, int oldx, int oldy, float *newp, int newx, int newy);
void unlink_curve( struct Curve *cu);
void free_curve( struct Curve *cu);
struct Curve *add_curve(int type);
@ -66,7 +65,7 @@ void calcknots(float *knots, short aantal, short order, short type);
void makecyclicknots(float *knots, short pnts, short order);
void makeknots( struct Nurb *nu, short uv, short type);
void basisNurb(float t, short order, short pnts, float *knots, float *basis, int *start, int *end);
void makeNurbfaces( struct Nurb *nu, float *data);
void makeNurbfaces( struct Nurb *nu, float *data, int rowstride);
void makeNurbcurve_forw(struct Nurb *nu, float *data);
void makeNurbcurve( struct Nurb *nu, float *data, int dim);
void forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride);

@ -580,7 +580,7 @@ void armature_deform_verts(Object *armOb, Object *target, float (*vertexCos)[3],
VecAddf(co, vec, co);
Mat4MulVecfl(postmat, co);
}
if (defnrToPC) MEM_freeN(defnrToPC);
}

@ -33,8 +33,6 @@
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#define STRUBI hack
#include <math.h> // floor
#include <string.h>
#include <stdlib.h>
@ -79,43 +77,6 @@ int cu_isectLL(float *v1, float *v2, float *v3, float *v4,
short cox, short coy,
float *labda, float *mu, float *vec);
#ifdef STRUBI
/* hotfix; copies x*y array into extended (x+dx)*(y+dy) array
old[] and new[] can be the same ! */
int copyintoExtendedArray(float *old, int oldx, int oldy, float *new, int newx, int newy)
{
int x, y, ttt, ooo;
float *oldp, *newp;
if (newx < oldx || newy < oldy) return 0;
for (y = newy - 1; y >= oldy; y--) {
ttt = y * newx;
for (x = newx - 1; x >= 0; x--) {
newp = new + 3 * (ttt + x);
newp[0] = 0.0; newp[1] = 0.0; newp[2] = 0.0;
}
}
for (; y >= 0; y--) {
ttt = y * newx;
ooo = y * oldx;
for (x = newx - 1; x >= oldx; x--) {
newp = new + 3 * (ttt + x);
newp[0] = 0.0; newp[1] = 0.0; newp[2] = 0.0;
}
for (; x >= 0; x--) {
oldp = old + 3 * (ooo + x);
newp = new + 3 * (ttt + x);
VECCOPY(newp, oldp);
}
}
return 1;
}
#endif
void unlink_curve(Curve *cu)
{
int a;
@ -718,7 +679,7 @@ void basisNurb(float t, short order, short pnts, float *knots, float *basis, int
}
void makeNurbfaces(Nurb *nu, float *data)
void makeNurbfaces(Nurb *nu, float *data, int rowstride)
/* data has to be 3*4*resolu*resolv in size, and zero-ed */
{
BPoint *bp;
@ -863,6 +824,7 @@ void makeNurbfaces(Nurb *nu, float *data)
basis+= KNOTSV(nu);
}
u+= ustep;
if (rowstride!=0) in = (float*) (((unsigned char*) in) + (rowstride - 3*nu->resolv*sizeof(*in)));
}
/* free */
@ -1088,7 +1050,6 @@ void make_orco_surf(Curve *cu)
/* first calculate the size of the datablock */
nu= cu->nurb.first;
while(nu) {
#ifdef STRUBI
/* this is a bad hack: as we want to avoid the seam in a cyclic nurbs
texture wrapping, reserve extra orco data space to save these extra needed
vertex based UV coordinates for the meridian vertices.
@ -1103,9 +1064,7 @@ See also blenderWorldManipulation.c: init_render_surf()
if (nu->flagu & CU_CYCLIC) sizeu++;
if (nu->flagv & CU_CYCLIC) sizev++;
if(nu->pntsv>1) tot+= sizeu * sizev;
#else
if(nu->pntsv>1) tot+= nu->resolu*nu->resolv;
#endif
nu= nu->next;
}
/* makeNurbfaces wants zeros */
@ -1116,10 +1075,9 @@ See also blenderWorldManipulation.c: init_render_surf()
if(nu->pntsv>1) {
sizeu = nu->resolu;
sizev = nu->resolv;
#ifdef STRUBI
if (nu->flagu & CU_CYCLIC) sizeu++;
if (nu->flagv & CU_CYCLIC) sizev++;
#endif
if(cu->flag & CU_UV_ORCO) {
for(b=0; b< sizeu; b++) {
@ -1138,17 +1096,17 @@ See also blenderWorldManipulation.c: init_render_surf()
}
}
else {
makeNurbfaces(nu, data);
#ifdef STRUBI
for(b=0; b< nu->resolu; b++) {
for(a=0; a< nu->resolv; a++) {
data = cu->orco + 3 * (b * nu->resolv + a);
makeNurbfaces(nu, data, sizeof(*data)*sizev*3);
for(b=0; b<nu->resolu; b++) {
for(a=0; a<nu->resolv; a++) {
data = cu->orco + 3 * (b * sizev + a);
data[0]= (data[0]-cu->loc[0])/cu->size[0];
data[1]= (data[1]-cu->loc[1])/cu->size[1];
data[2]= (data[2]-cu->loc[2])/cu->size[2];
}
}
copyintoExtendedArray(cu->orco, nu->resolv, nu->resolu, cu->orco, sizev, sizeu);
/* copy U/V-cyclic orco's */
if (nu->flagv & CU_CYCLIC) {
b = sizeu - 1;
@ -1164,17 +1122,6 @@ See also blenderWorldManipulation.c: init_render_surf()
VECCOPY(data, cu->orco + 3 * b*sizev);
}
}
#else
tot= sizeu * sizev;
while(tot--) {
data[0]= (data[0]-cu->loc[0])/cu->size[0];
data[1]= (data[1]-cu->loc[1])/cu->size[1];
data[2]= (data[2]-cu->loc[2])/cu->size[2];
data+= 3;
}
#endif
}
}
nu= nu->next;

@ -185,9 +185,6 @@ int curve_modifier(Object *ob, char mode)
freeNurblist(&cu->nurb);
cu->nurb= nurb;
}
else if(mode=='a') {
freeNurblist(&nurb);
}
return done;
}

@ -1501,25 +1501,18 @@ void makeDispListCurveTypes(Object *ob)
dl->verts= MEM_callocN(len*3*sizeof(float), "dlverts");
BLI_addtail(dispbase, dl);
if(draw==0) {
dl->parts= nu->pntsv;
dl->nr= nu->pntsu;
if(nu->flagu & 1) dl->flag|= DL_CYCL_U;
if(nu->flagv & 1) dl->flag|= DL_CYCL_V;
}
else {
dl->parts= nu->resolu; /* in reverse, because makeNurbfaces works that way */
dl->nr= nu->resolv;
if(nu->flagv & 1) dl->flag|= DL_CYCL_U; /* reverse too! */
if(nu->flagu & 1) dl->flag|= DL_CYCL_V;
}
dl->col= nu->mat_nr;
dl->rt= nu->flag;
data= dl->verts;
dl->type= DL_SURF;
if(draw==0) {
dl->parts= nu->pntsv;
dl->nr= nu->pntsu;
if(nu->flagu & CU_CYCLIC) dl->flag|= DL_CYCL_U;
if(nu->flagv & CU_CYCLIC) dl->flag|= DL_CYCL_V;
bp= nu->bp;
while(len--) {
VECCOPY(data, bp->vec);
@ -1527,7 +1520,14 @@ void makeDispListCurveTypes(Object *ob)
data+= 3;
}
}
else makeNurbfaces(nu, data);
else {
dl->parts= nu->resolu; /* in reverse, because makeNurbfaces works that way */
dl->nr= nu->resolv;
if(nu->flagv & CU_CYCLIC) dl->flag|= DL_CYCL_U; /* reverse too! */
if(nu->flagu & CU_CYCLIC) dl->flag|= DL_CYCL_V;
makeNurbfaces(nu, data, 0);
}
}
}
}

@ -1955,8 +1955,8 @@ static void displist_to_mesh(DispList *dlfirst)
if(dl->type==DL_SURF) {
a= dl->nr;
b= dl->parts;
if(dl->flag & 1) a++;
if(dl->flag & 2) b++;
if(dl->flag & DL_CYCL_U) a++;
if(dl->flag & DL_CYCL_V) b++;
totquad+= a*b;
@ -2114,7 +2114,7 @@ static void displist_to_mesh(DispList *dlfirst)
for(a=0; a<dl->parts; a++) {
DL_SURFINDEX(dl->flag & 1, dl->flag & 2, dl->nr, dl->parts);
DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
p1+= startve;
p2+= startve;
p3+= startve;

@ -900,7 +900,7 @@ void nurbs_to_mesh(Object *ob)
}
else if(dl->type==DL_SURF) {
totvert+= dl->parts*dl->nr;
totvlak+= (dl->parts-1+((dl->flag & 2)==2))*(dl->nr-1+(dl->flag & 1));
totvlak+= (dl->parts-1+((dl->flag & DL_CYCL_V)==2))*(dl->nr-1+(dl->flag & DL_CYCL_U));
}
else if(dl->type==DL_INDEX3) {
totvert+= dl->nr;
@ -1021,9 +1021,9 @@ void nurbs_to_mesh(Object *ob)
for(a=0; a<dl->parts; a++) {
if( (dl->flag & 2)==0 && a==dl->parts-1) break;
if( (dl->flag & DL_CYCL_V)==0 && a==dl->parts-1) break;
if(dl->flag & 1) { /* p2 -> p1 -> */
if(dl->flag & DL_CYCL_U) { /* p2 -> p1 -> */
p1= startvert+ dl->nr*a; /* p4 -> p3 -> */
p2= p1+ dl->nr-1; /* -----> next row */
p3= p1+ dl->nr;
@ -1037,7 +1037,7 @@ void nurbs_to_mesh(Object *ob)
p3= p1+ dl->nr;
b= 1;
}
if( (dl->flag & 2) && a==dl->parts-1) {
if( (dl->flag & DL_CYCL_V) && a==dl->parts-1) {
p3-= dl->parts*dl->nr;
p4-= dl->parts*dl->nr;
}

@ -52,7 +52,6 @@ void minmax_tface(float *min, float *max);
int face_pick(struct Mesh *me, short x, short y, unsigned int *index);
void face_select(void);
void face_borderselect(void);
float CalcNormUV(float *a, float *b, float *c);
void uv_autocalc_tface(void);
void set_faceselect(void);
void face_draw(void);

@ -118,7 +118,7 @@ static PyObject *Curve_iterNext( BPy_Curve * self );
PyObject *Curve_getNurb( BPy_Curve * self, int n );
static int Curve_length( PyInstanceObject * inst );
void update_displists( void *data );
struct chartrans *text_to_curve( Object * ob, int mode );
@ -1255,7 +1255,6 @@ static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * args )
PyObject *Curve_update( BPy_Curve * self )
{
/* update_displists( ( void * ) self->curve ); */
freedisplist( &self->curve->disp );
Py_INCREF( Py_None );
@ -1597,54 +1596,3 @@ struct Curve *Curve_FromPyObject( PyObject * py_obj )
}
/*
* NOTE: this func has been replaced by freedisplist() in the recent
* display list refactoring.
*
* walk across all objects looking for curves
* so we can update their ob's disp list
*/
void update_displists( void *data )
{
#if 0
Base *base;
Object *ob;
unsigned int layer;
/* background */
layer = G.scene->lay;
base = G.scene->base.first;
while( base ) {
if( base->lay & layer ) {
ob = base->object;
if( ELEM( ob->type, OB_CURVE, OB_SURF ) ) {
if( ob != G.obedit ) {
if( ob->data == data ) {
makeDispListCurveTypes( ob );
}
}
} else if( ob->type == OB_FONT ) {
Curve *cu = ob->data;
if( cu->textoncurve ) {
if( ( ( Curve * ) cu->textoncurve->
data )->key ) {
text_to_curve( ob, 0 );
makeDispListCurveTypes( ob );
}
}
}
}
if( base->next == 0 && G.scene->set
&& base == G.scene->base.last )
base = G.scene->set->base.first;
else
base = base->next;
}
#endif
}

@ -31,12 +31,6 @@
* Interface to transform the Blender scene into renderable data.
*/
/* check for dl->flag, 1 or 2 should be replaced be the def's below */
#define STRUBI hack
#define DL_CYCLIC_U 1
#define DL_CYCLIC_V 2
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
@ -1773,12 +1767,10 @@ static void init_render_surf(Object *ob)
Material *matar[32];
float *data, *fp, *orco, n1[3], flen, mat[4][4];
int len, a, need_orco=0, startvlak, startvert, p1, p2, p3, p4;
#ifdef STRUBI
int u, v;
int sizeu, sizev;
VlakRen *vlr1, *vlr2, *vlr3;
float vn[3]; // n2[3],
#endif
cu= ob->data;
nu= cu->nurb.first;
@ -1809,7 +1801,6 @@ static void init_render_surf(Object *ob)
nu= cu->nurb.first;
while(nu) {
if(nu->pntsv>1) {
// if (dl->flag & DL_CYCLIC_V) {
len= nu->resolu*nu->resolv;
/* makeNurbfaces wants zeros */
@ -1825,10 +1816,10 @@ static void init_render_surf(Object *ob)
data= dl->verts;
dl->type= DL_SURF;
/* if nurbs cyclic (u/v) set flags in displist accordingly */
if(nu->flagv & 1) dl->flag |= DL_CYCLIC_V;
if(nu->flagu & 1) dl->flag |= DL_CYCLIC_U;
if(nu->flagv & CU_CYCLIC) dl->flag |= DL_CYCL_V;
if(nu->flagu & CU_CYCLIC) dl->flag |= DL_CYCL_U;
makeNurbfaces(nu, data);
makeNurbfaces(nu, data, 0);
}
nu= nu->next;
}
@ -1850,26 +1841,10 @@ static void init_render_surf(Object *ob)
/* note; deform will be included in modifier() later */
curve_modifier(ob, 'e');
if(ob->partype==PARSKEL && ob->parent && ob->parent->type==OB_ARMATURE) {
/* bArmature *arm= ob->parent->data; */
init_armature_deform(ob->parent, ob);
dl= displist.first;
while(dl) {
fp= dl->verts;
len= dl->nr*dl->parts;
for(a=0; a<len; a++, fp+=3)
calc_armature_deform(ob->parent, fp, a);
dl= dl->next;
}
}
dl= displist.first;
/* walk along displaylist and create rendervertices/-faces */
while(dl) {
#ifdef STRUBI
/* watch out: u ^= y, v ^= x !! */
/* watch out: u ^= y, v ^= x !! */
if(dl->type==DL_SURF) {
startvert= R.totvert;
sizeu = dl->parts; sizev = dl->nr;
@ -1892,7 +1867,7 @@ static void init_render_surf(Object *ob)
MTC_Mat4MulVecfl(mat, ver->co);
}
/* if V-cyclic, add extra vertices at end of the row */
if (dl->flag & DL_CYCLIC_V) {
if (dl->flag & DL_CYCL_V) {
ver= RE_findOrAddVert(R.totvert++);
VECCOPY(ver->co, v1->co);
if(orco) {
@ -1902,11 +1877,11 @@ static void init_render_surf(Object *ob)
}
}
if (dl->flag & DL_CYCLIC_V) sizev++; /* adapt U dimension */
if (dl->flag & DL_CYCL_V) sizev++; /* adapt U dimension */
/* if U cyclic, add extra row at end of column */
if (dl->flag & DL_CYCLIC_U) {
if (dl->flag & DL_CYCL_U) {
for (v = 0; v < sizev; v++) {
v1= RE_findOrAddVert(startvert + v);
ver= RE_findOrAddVert(R.totvert++);
@ -1979,7 +1954,7 @@ static void init_render_surf(Object *ob)
}
/* fix normals for U resp. V cyclic faces */
sizeu--; sizev--; /* dec size for face array */
if (dl->flag & DL_CYCLIC_U) {
if (dl->flag & DL_CYCL_U) {
for (v = 0; v < sizev; v++)
{
@ -1992,7 +1967,7 @@ static void init_render_surf(Object *ob)
VecAddf(vlr->v4->n, vlr->v4->n, vlr1->n);
}
}
if (dl->flag & DL_CYCLIC_V) {
if (dl->flag & DL_CYCL_V) {
for (u = 0; u < sizeu; u++)
{
@ -2022,7 +1997,7 @@ static void init_render_surf(Object *ob)
normals of the surrounding faces to all of the duplicates of []
*/
if ((dl->flag & DL_CYCLIC_U) && (dl->flag & DL_CYCLIC_V))
if ((dl->flag & DL_CYCL_U) && (dl->flag & DL_CYCL_V))
{
vlr= RE_findOrAddVlak(UVTOINDEX(sizeu - 1, sizev - 1)); /* (m,n) */
vlr1= RE_findOrAddVlak(UVTOINDEX(0,0)); /* (0,0) */
@ -2043,77 +2018,7 @@ static void init_render_surf(Object *ob)
}
#else
if(dl->type==DL_SURF) {
startvert= R.totvert;
a= dl->nr*dl->parts;
data= dl->verts;
while(a--) {
ver= RE_findOrAddVert(R.totvert++);
VECCOPY(ver->co, data);
if(orco) {
ver->orco= orco;
orco+= 3;
}
MTC_Mat4MulVecfl(mat, ver->co);
data+= 3;
}
startvlak= R.totvlak;
for(a=0; a<dl->parts; a++) {
DL_SURFINDEX(dl->flag & DL_CYCLIC_V, dl->flag & DL_CYCLIC_U, dl->nr, dl->parts);
p1+= startvert;
p2+= startvert;
p3+= startvert;
p4+= startvert;
for(; b<dl->nr; b++) {
v1= RE_findOrAddVert(p1);
v2= RE_findOrAddVert(p2);
v3= RE_findOrAddVert(p3);
v4= RE_findOrAddVert(p4);
flen= CalcNormFloat4(v1->co, v3->co, v4->co, v2->co, n1);
if(flen!=0.0) {
vlr= RE_findOrAddVlak(R.totvlak++);
vlr->ob= vlr_set_ob(ob);
vlr->v1= v1;
vlr->v2= v3;
vlr->v3= v4;
vlr->v4= v2;
VECCOPY(vlr->n, n1);
vlr->lay= ob->lay;
vlr->mat= matar[ dl->col];
vlr->ec= ME_V1V2+ME_V2V3;
vlr->flag= dl->rt;
if( (cu->flag & CU_NOPUNOFLIP) ) {
vlr->flag |= R_NOPUNOFLIP;
}
}
VecAddf(v1->n, v1->n, n1);
VecAddf(v2->n, v2->n, n1);
VecAddf(v3->n, v3->n, n1);
VecAddf(v4->n, v4->n, n1);
p4= p3;
p3++;
p2= p1;
p1++;
}
}
for(a=startvert; a<R.totvert; a++) {
ver= RE_findOrAddVert(a);
Normalise(ver->n);
}
}
#endif
dl= dl->next;
}
freedisplist(&displist);
@ -2218,11 +2123,6 @@ static void init_render_curve(Object *ob)
init_latt_deform(ob->parent, ob);
need_orco= 1;
}
if(ob->parent && ob->parent->type==OB_ARMATURE) {
init_armature_deform(ob->parent, ob);
need_orco= 1;
}
/* do keypos? NOTE: watch it : orcos */

@ -1181,21 +1181,6 @@ void face_borderselect()
#endif
}
#define TEST_STRUBI 1
#ifdef TEST_STRUBI
float CalcNormUV(float *a, float *b, float *c)
{
float d1[3], d2[3];
d1[0] = a[0] - b[0];
d1[1] = a[1] - b[1];
d2[0] = b[0] - c[0];
d2[1] = b[1] - c[1];
return (d1[0] * d2[1] - d1[1] * d2[0]);
}
#endif
/* Pupmenu codes: */
#define UV_CUBE_MAPPING 2
#define UV_CYL_MAPPING 3