Exemplo n.º 1
0
static int GetPoint(LWOBInfo *object, LWPoint *pnt)
{
   float x,y,z;




   fsetpos(object->fp,&object->pntPosCur);


   if (object->pntSizeCur<object->pntSize)
   {
      fread(&x,4,1,object->fp);
      fread(&y,4,1,object->fp);
      fread(&z,4,1,object->fp);


      BSWAP_L(x);
      BSWAP_L(y);
      BSWAP_L(z);

      pnt->x=x;
      pnt->y=y;
      pnt->z=z;


      fgetpos(object->fp,&object->pntPosCur);
      object->pntSizeCur = object->pntSizeCur + 12;
   }
   else
      return(0);


   return(1);
}
Exemplo n.º 2
0
static int GetSDatSize(LWOBInfo *object, char *name, fpos_t *datpos)
{
   char temp[MAX_SURFNAME];
   int readsize=0,objsize,tempsize,len;
   if(!object->nSdat)
      return 0;
   if( !(len=strlen(name)) )
      return 0;
   len++;
   if(len&1)
      len++;
   fseek(object->fp, 8, SEEK_SET);
   fread(&temp,4,1,object->fp);
   if (strncmp(temp,"LWOB",4)==0)
   {
      //Get the object size
      fseek(object->fp,4,SEEK_SET);
      fread(&objsize,4,1,object->fp);
      BSWAP_L(objsize);
      fseek(object->fp,4,SEEK_CUR); //Skip the LWOB deal


      readsize=4;
      while(readsize<objsize)
      {
         fread(temp,4,1,object->fp);
         fread(&tempsize,4,1,object->fp);
         BSWAP_L(tempsize);
         if(strncmp(temp,"SURF",4)==0)
         {
            fgetpos(object->fp,datpos);
            fread(temp,1,len,object->fp);
            if(!strcmp(name,temp))
            {
               fgetpos(object->fp,datpos);
               return tempsize-len;
            }
            else
               fsetpos(object->fp,datpos);
         }
         fseek(object->fp,tempsize,SEEK_CUR);
         readsize+=tempsize+8;
      }
   }
   return 0;
}
Exemplo n.º 3
0
int dxExporter::ffp_dwords( DX_DWORD *vals, int num )
{
    DX_DWORD    data[1];
    int         i;

    for (i = 0; i < num; i++)
    {
        data[0] = vals[i];
        BSWAP_L(data[0]);
        if (fwrite( data, sizeof(DX_DWORD), 1, _fp ) != 1) {
            return 0;
        }
    }

    return num;
}
Exemplo n.º 4
0
static int ReadSURF(LWSurface *lwsur, surfAttr *surf)
{
   unsigned char *p,r,g,b,*databuf;
   short *size,*t,s;
   int len,max;
   char     *st;

   max = lwsur->size;
   databuf = lwsur->data;
   surf->su_tx.xTextureCenter = 0.0f;
   surf->su_tx.yTextureCenter = 0.0f;
   surf->su_tx.zTextureCenter = 0.0f;
   surf->su_tx.xTextureSize = 1.0f;
   surf->su_tx.yTextureSize = 1.0f;
   surf->su_tx.zTextureSize = 1.0f;
   surf->su_tx.textureAxis = TA_Z;
   surf->su_tx.textureType = TT_CUBIC;
   surf->su_tx.textureFlags = 0;
   surf->su_tx.wTiles = 1.0f;
   surf->su_tx.hTiles = 1.0f;
   surf->su_red = 0.8f;
   surf->su_green = 0.8f;
   surf->su_blue = 0.8f;
   surf->su_lumi = 0;
   surf->su_diff = 256; // 256 = 100%
   surf->su_spec = 0;
   surf->su_refl = 0;
   surf->su_tran = 0;
   surf->su_image = NULL;


   for(len=0; len<max; databuf +=(6 + s), len+=(6 + s) )
   {
      size=(short *)&(databuf[4]);
      s=*size;
      BSWAP_W(s);
      if( STR_IS_ID(databuf,'C','O','L','R') ) //if(!strncmp(data,"COLR",4))
      {
         p=&databuf[6]; // Skip COLR, 2-byte size
         r=*p++;
         surf->su_red=r;
         surf->su_red /= 255;
         g=*p++;
         surf->su_green=g;
         surf->su_green /= 255;
         b=*p++;
         surf->su_blue=b;
         surf->su_blue /= 255;
      }
      else if( STR_IS_ID(databuf,'F','L','A','G') ) //  if(!strncmp(data,"FLAG",4))
      {
         t=(short *)&(databuf[6]);
         surf->su_flags = (short)*t;
         BSWAP_W(surf->su_flags);
      }
      else if( STR_IS_ID(databuf,'S','M','A','N') ) //  if(!strncmp(data,"SMAN",4))
      {
         float f;
         /*at = (float *)(data+6);
         f = at[0];*/
         f = STR_TO_FLOAT( (&(databuf[6])) );
         BSWAP_L(f);
         surf->su_tx.smAngle = f;
      }
      else if( STR_IS_ID(databuf,'T','R','A','N') ) // if(!strncmp(data,"TRAN",4))
      {
         t=(short *)(databuf+6);
         surf->su_tran = *t;
         BSWAP_W(surf->su_tran);
      }
      else if( STR_IS_ID(databuf,'L','U','M','I') ) // if(!strncmp(data,"LUMI",4))
      {
         t=(short *)(databuf+6);
         surf->su_lumi = *t;
         BSWAP_W(surf->su_lumi);
      }
      else if( STR_IS_ID(databuf,'S','P','E','C') ) // if(!strncmp(data,"SPEC",4))
      {
         t=(short *)(databuf+6);
         surf->su_spec = *t;
         BSWAP_W(surf->su_spec);
      }
      else if( STR_IS_ID(databuf,'D','I','F','F') ) // if(!strncmp(data,"DIFF",4))
      {
         t=(short *)(databuf+6);
         surf->su_diff = *t;
         BSWAP_W(surf->su_diff);
      }
      else if( STR_IS_ID(databuf,'C','T','E','X') ) // if(!strncmp(data,"CTEX",4))
      {
         st=(char *)databuf+6;
         surf->su_tx.textureType = TT_PLANAR;

         if( STR_IS_ID(st,'P','l','a','n') )  // if(!strncmp(st,"Plan",4))
         {
            surf->su_tx.textureType = TT_PLANAR;
         }
         else if( STR_IS_ID(st,'C','y','l','i') )  // if(!strncmp(st,"Cyli",4))
         {
            surf->su_tx.textureType = TT_CYLINDRICAL;
         }
         else if( STR_IS_ID(st,'S','p','h','e') )  // if(!strncmp(st,"Sphe",4))
         {
            surf->su_tx.textureType = TT_SPHERICAL;
         }
         else if( STR_IS_ID(st,'C','u','b','i') )  // if(!strncmp(st,"Cubi",4))
         {
            surf->su_tx.textureType = TT_CUBIC;
         }
      }
      else if( STR_IS_ID(databuf,'T','I','M','G') ) // if(chnk=='TIMG') //if(!strncmp(databuf,"TIMG",4))
      {
         surf->su_image = (char *)(databuf+6);
      }
      else if( STR_IS_ID(databuf,'T','F','P','0') ) // if(chnk=='TFP0') //if(!strncmp(databuf,"TFP0",4))  // width tiling.. for spher,cyl
      {
         float f;
         //at = (float *)(databuf+6);
         //f = at[0];
         f = STR_TO_FLOAT( (&(databuf[6])) );
         BSWAP_L(f);
         surf->su_tx.wTiles = f;
      }
      else if( STR_IS_ID(databuf,'T','F','P','1') ) // if(chnk=='TFP1') //if(!strncmp(databuf,"TFP1",4))   // height tiling.. for spher
      {
         float f;
         //at = (float *)(databuf+6);
         //f = at[0];
         f = STR_TO_FLOAT( (&(databuf[6])) );
         BSWAP_L(f);
         surf->su_tx.hTiles = f;
      }
      else if( STR_IS_ID(databuf,'T','W','R','P') ) // if(!strncmp(data,"TWRP",4))
      {
         unsigned short *f;
         f=(unsigned short *)(databuf+6);
         if(*f!=0)
            surf->su_tx.textureFlags |= TXF_UDECAL;
         f++;
         if(*f!=0)
            surf->su_tx.textureFlags |= TXF_VDECAL;
      }


      else if( STR_IS_ID(databuf,'T','C','T','R') ) // if(!strncmp(data,"TCTR",4))
      {
         float *at,f;


         at = (float *)(databuf+6);


         f = STR_TO_FLOAT( (&(databuf[6])) );
         //f = at[0];
         BSWAP_L(f);
         surf->su_tx.xTextureCenter = f;
         f = STR_TO_FLOAT( (&(databuf[10])) );
         //f = at[1];
         BSWAP_L(f);
         surf->su_tx.yTextureCenter = f;
         f = STR_TO_FLOAT( (&(databuf[14])) );
         //f = at[2];
         BSWAP_L(f);
         surf->su_tx.zTextureCenter = f;
      }
      else if( STR_IS_ID(databuf,'T','S','I','Z') ) // if(chnk=='TSIZ') //if(!strncmp(databuf,"TSIZ",4))
      {
         float *at,f;
         at = (float *)(databuf+6);
         f = STR_TO_FLOAT( (&(databuf[6])) );
         //f = at[0];
         BSWAP_L(f);
         surf->su_tx.xTextureSize = f;
         f = STR_TO_FLOAT( (&(databuf[10])) );
         //f = at[1];
         BSWAP_L(f);
         surf->su_tx.yTextureSize = f;
         f = STR_TO_FLOAT( (&(databuf[14])) );
         //f = at[2];
         BSWAP_L(f);
         surf->su_tx.zTextureSize = f;
      }
      else if( STR_IS_ID(databuf,'T','F','L','G') ) // if(chnk=='TFLG') //if(!strncmp(databuf,"TFLG",4))
      {
         unsigned short f;
         t=(short *)(databuf+6);
         f= *t;
         BSWAP_W(f);
         surf->su_tx.textureFlags |= f;
         if(f&TXF_AXIS_X)
            surf->su_tx.textureAxis = TA_X;
         else if(f&TXF_AXIS_Y)
            surf->su_tx.textureAxis = TA_Y;
         else // if(*t&TXF_AXIS_Z)
            surf->su_tx.textureAxis = TA_Z;
   //    BSWAP_W(surf->su_tx.textureFlags);
      }
   }
   return(len);
}
Exemplo n.º 5
0
static int OpenLWObject(char *name, LWOBInfo *object)
{
   char temp[10];
   int readsize=0;
   int objsize;
   int polsize, pntsize;
   int tempsize;


   object->fp=NULL;
   object->pntPos=0;
   object->polPos=0;
   object->polSize=0;
   object->pntSize=0;
   object->nSdat = 0;    /* [EW 7 Jun 00] */

   object->fp=fopen(name,"rb");
   if (object->fp==NULL)
      return(0);


   fseek(object->fp, 8, SEEK_SET);
   fread(&temp,4,1,object->fp);
   if (strncmp(temp,"LWOB",4)==0)
   {
      //Get the object size
      fseek(object->fp,4,SEEK_SET);
      fread(&objsize,4,1,object->fp);
      BSWAP_L(objsize);
      fseek(object->fp,4,SEEK_CUR); //Skip the LWOB deal


      readsize=4;
      while(readsize<objsize){


         fread(temp,4,1,object->fp);
         if(strncmp(temp,"POLS",4)==0){
            fread(&polsize,4,1,object->fp);
            BSWAP_L(polsize);


            fgetpos(object->fp,&object->polPos);
            fseek(object->fp,polsize,SEEK_CUR);
            object->polSize=polsize;
            readsize+=polsize+8;
            }
         else if(strncmp(temp,"PNTS",4)==0){
            fread(&pntsize,4,1,object->fp);
            BSWAP_L(pntsize);


            fgetpos(object->fp,&object->pntPos);
            fseek(object->fp,pntsize,SEEK_CUR);
            object->pntSize=pntsize;
            readsize+=pntsize+8;
            }
         else if(strncmp(temp,"SRFS",4)==0){
            fread(&pntsize,4,1,object->fp);
            BSWAP_L(pntsize);


            fgetpos(object->fp,&object->srfPos);
            fseek(object->fp,pntsize,SEEK_CUR);
            object->srfSize=pntsize;
            readsize+=pntsize+8;
            }
         else{
            if(strncmp(temp,"SURF",4)==0)
               object->nSdat++;
            fread(&tempsize,4,1,object->fp);
            BSWAP_L(tempsize);
            fseek(object->fp,tempsize,SEEK_CUR);
            readsize+=tempsize+8;
            }


         }


      ResetPosition(object);


   }
   else  return(0);


      //printf("Not a LightWave Object!\n");

   return(1);
}