#include <v_lib.h>

void dump(char *name,tripatch_t *pat)
{
  FILE *fp;
  int i;
  if(!pat) return;
  if(name)
  {
    fp=fopen(name,"wt");
    if(!fp)
    {
      printf("can't open %s\n",name);
      return;
    }
  } else fp=stdout;
  fprintf(fp,"%d vertices, %d triangles, %s\n",pat->numvert,pat->numtri,
    pat->extinfo ? "extra info" : "no extra info");
  fprintf(fp,"base: ( %g %g %g ) ( %g %g %g ) ( %g %g %g )\nbase normal ( %g %g %g )\n",
    pat->base[0][0],pat->base[0][1],pat->base[0][2],
    pat->base[1][0],pat->base[1][1],pat->base[1][2],
    pat->base[2][0],pat->base[2][1],pat->base[2][2],
    pat->basenormal[0],pat->basenormal[1],pat->basenormal[2]
    );
  for(i=0;i<pat->numvert;i++)
    fprintf(fp,"vertex %d ( %g %g %g )\n",i,
      pat->vlist[i][0],pat->vlist[i][1],pat->vlist[i][2]);
  for(i=0;i<pat->numtri;i++)
    fprintf(fp,"triangle %d ( %d %d %d )\n",i,
      pat->tlist[i][0],pat->tlist[i][1],pat->tlist[i][2]);
  if(!pat->extinfo)
  {
    fclose(fp);
    return;
  }
  for(i=0;i<pat->numvert;i++)
    fprintf(fp,"color %d ( %2X %2X %2X %2X )\n",i,
      pat->clist[i][0],pat->clist[i][1],pat->clist[i][2],pat->clist[i][3]);
  for(i=0;i<pat->numvert;i++)
    fprintf(fp,"normal %d ( %g %g %g )\n",i,
      pat->nlist[i][0],pat->nlist[i][1],pat->nlist[i][2]);
  for(i=0;i<pat->numvert;i++)
    fprintf(fp,"texture coord %d ( %g %g )\n",i,
      pat->uvlist[i][0],pat->uvlist[i][1]);
  for(i=0;i<pat->numtri;i++)
    fprintf(fp,"face normal %d ( %g %g %g )\n",i,
      pat->fnlist[i][0],pat->fnlist[i][1],pat->fnlist[i][2]);
}

void main()
{
  /*vec3_t av[3]={
  {1,0,0},
  {0,1,0},
  {0,0,1}
  };*/
  tripatch_p pat;
  pat=patCreateRectangular(0,0,12,8,6,2,1);
  patDefaultGeometry(pat,NULL);
  dump(NULL,pat);
  patFree(pat);
}
