void * GetTexBody(parsehandle * ph, SceneHandle scene, int modeflag) {
  char tmp[255];
  float a,b,c,d, phong, phongexp;
  int phongtype;
  apitexture tex;
  void * voidtex; 
  errcode rc;

  rc = GetString(ph, "AMBIENT");
  fscanf(ph->ifp, "%f", &a); 
  tex.ambient=a;

  rc |= GetString(ph, "DIFFUSE");
  fscanf(ph->ifp, "%f", &b);
  tex.diffuse=b;

  rc |= GetString(ph, "SPECULAR");
  fscanf(ph->ifp, "%f", &c);
  tex.specular=c;

  rc |= GetString(ph, "OPACITY");
  fscanf(ph->ifp, "%f", &d);  
  tex.opacity=d;

  fscanf(ph->ifp, "%s", tmp);
  if (!stringcmp(tmp, "PHONG")) {
    fscanf(ph->ifp, "%s", tmp);
    if (!stringcmp(tmp, "METAL")) {
      phongtype = RT_PHONG_METAL;
    }
    else if (!stringcmp(tmp, "PLASTIC")) {
      phongtype = RT_PHONG_PLASTIC;
    }
    else {
      phongtype = RT_PHONG_PLASTIC;
    } 

    fscanf(ph->ifp, "%f", &phong);
    GetString(ph, "PHONG_SIZE");
    fscanf(ph->ifp, "%f", &phongexp);
    fscanf(ph->ifp, "%s", tmp);
  } else { 
    /* assume we found "COLOR" otherwise */
    phong = 0.0;
    phongexp = 100.0;
    phongtype = RT_PHONG_PLASTIC;
  }

  /* if we're processing normal objects, use the regular */
  /* texture definition pattern.                         */
  /* VCSTri objects skip the normal color and texture    */
  /* function definition since they are unused.          */ 
  if (modeflag == 0) { 
    if (stringcmp(tmp, "COLOR")) {
      rc |= PARSEBADSYNTAX;
    }

    fscanf(ph->ifp, "%f %f %f", &a, &b, &c);
    tex.col.r = a;
    tex.col.g = b;
    tex.col.b = c;
 
    rc |= GetString(ph, "TEXFUNC");

    /* this really ought to be a string, not a number... */
    fscanf(ph->ifp, "%d", &tex.texturefunc);

    switch (tex.texturefunc) {
      case RT_TEXTURE_CONSTANT:
      default: 
        break;

      case RT_TEXTURE_3D_CHECKER:
      case RT_TEXTURE_GRIT:
      case RT_TEXTURE_MARBLE:
      case RT_TEXTURE_WOOD:
      case RT_TEXTURE_GRADIENT:
      case RT_TEXTURE_CYLINDRICAL_CHECKER:
        rc |= GetString(ph, "CENTER");
        rc |= GetVector(ph, &tex.ctr);
        rc |= GetString(ph, "ROTATE");
        rc |= GetVector(ph, &tex.rot);
        rc |= GetString(ph, "SCALE");
        rc |= GetVector(ph, &tex.scale);
        break;

      case RT_TEXTURE_CYLINDRICAL_IMAGE:
      case RT_TEXTURE_SPHERICAL_IMAGE:
        fscanf(ph->ifp, "%s", tex.imap);
        rc |= GetString(ph, "CENTER");
        rc |= GetVector(ph, &tex.ctr);
        rc |= GetString(ph, "ROTATE");
        rc |= GetVector(ph, &tex.rot);
        rc |= GetString(ph, "SCALE");
        rc |= GetVector(ph, &tex.scale);
        break;
     
      case RT_TEXTURE_PLANAR_IMAGE:
        fscanf(ph->ifp, "%s", tex.imap);
        rc |= GetString(ph, "CENTER");
        rc |= GetVector(ph, &tex.ctr);
        rc |= GetString(ph, "ROTATE");
        rc |= GetVector(ph, &tex.rot);
        rc |= GetString(ph, "SCALE");
        rc |= GetVector(ph, &tex.scale);
        rc |= GetString(ph, "UAXIS");
        rc |= GetVector(ph, &tex.uaxs);
        rc |= GetString(ph, "VAXIS");
        rc |= GetVector(ph, &tex.vaxs);
        break;
    }
  } else {
    if (stringcmp(tmp, "VCST")) {
      rc |= PARSEBADSYNTAX;
    }

    /* if we're processing VCSTri objects, set some defaults */
    tex.col.r = 1.0;
    tex.col.g = 1.0;
    tex.col.b = 1.0;
    tex.texturefunc = 0; /* set to none by default, gets reset anyway */
  }

  voidtex = rt_texture(scene, &tex);
  rt_tex_phong(voidtex, phong, phongexp, phongtype);

  return voidtex;
}
Example #2
0
void * GetTexBody(FILE * dfile) {
  char tmp[255];
  float a,b,c,d, phong, phongexp, phongtype;
  apitexture tex;
  void * voidtex; 
  errcode rc;

  rc = GetString(dfile, "AMBIENT");
  fscanf(dfile, "%f", &a); 
  tex.ambient=a;

  rc |= GetString(dfile, "DIFFUSE");
  fscanf(dfile, "%f", &b);
  tex.diffuse=b;

  rc |= GetString(dfile, "SPECULAR");
  fscanf(dfile, "%f", &c);
  tex.specular=c;

  rc |= GetString(dfile, "OPACITY");
  fscanf(dfile, "%f", &d);  
  tex.opacity=d;

  fscanf(dfile, "%s", tmp);
  if (!stringcmp("PHONG", tmp)) {
    fscanf(dfile, "%s", tmp);
    if (!stringcmp("METAL", tmp)) {
      phongtype = RT_PHONG_METAL;
    }
    else if (!stringcmp("PLASTIC", tmp)) {
      phongtype = RT_PHONG_PLASTIC;
    }
    else {
      phongtype = RT_PHONG_PLASTIC;
    } 

    fscanf(dfile, "%f", &phong);
    GetString(dfile, "PHONG_SIZE");
    fscanf(dfile, "%f", &phongexp);
    fscanf(dfile, "%s", tmp);
  }     
  else { 
    phong = 0.0;
    phongexp = 100.0;
    phongtype = RT_PHONG_PLASTIC;
  }
  
  fscanf(dfile, "%f %f %f", &a, &b, &c);
  tex.col.r = a;
  tex.col.g = b;
  tex.col.b = c;
 
  rc |= GetString(dfile, "TEXFUNC");
  fscanf(dfile, "%d", &tex.texturefunc);
  if (tex.texturefunc >= 7) {    /* if its an image map, we need a filename */
    fscanf(dfile, "%s", tex.imap);
  }
  if (tex.texturefunc != 0) {
    rc |= GetString(dfile, "CENTER");
    rc |= GetVector(dfile, &tex.ctr);
    rc |= GetString(dfile, "ROTATE");
    rc |= GetVector(dfile, &tex.rot);
    rc |= GetString(dfile, "SCALE");
    rc |= GetVector(dfile, &tex.scale);
  }
  if (tex.texturefunc == 9) {
    rc |= GetString(dfile, "UAXIS");
    rc |= GetVector(dfile, &tex.uaxs);
    rc |= GetString(dfile, "VAXIS");
    rc |= GetVector(dfile, &tex.vaxs);
  }

  voidtex = rt_texture(&tex);
  rt_tex_phong(voidtex, phong, phongexp, (int) phongtype);

  return voidtex;
}