Show
Ignore:
Timestamp:
04/22/09 17:46:24 (6 years ago)
Author:
robert
Message:

From Neil Hughes, converted across to use istream for reading data from file to enable reading .3ds files over http (use OSG's libcurl plugin).

From Robert Osfield, ammendments of the above to better support reading of files from local directories.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/3ds/background.cpp

    r1563 r10076  
    3636 
    3737static Lib3dsBool 
    38 solid_bgnd_read(Lib3dsBackground *background, FILE *f) 
     38solid_bgnd_read(Lib3dsBackground *background, iostream *strm) 
    3939{ 
    4040  Lib3dsChunk c; 
    4141  Lib3dsWord chunk; 
    4242           
    43   if (!lib3ds_chunk_read_start(&c, LIB3DS_SOLID_BGND, f)) { 
     43  if (!lib3ds_chunk_read_start(&c, LIB3DS_SOLID_BGND, strm)) { 
    4444    return(LIB3DS_FALSE); 
    4545  } 
    4646 
    47   while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) { 
     47  while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { 
    4848    switch (chunk) { 
    4949      case LIB3DS_LIN_COLOR_F: 
    50         lib3ds_rgb_read(background->solid.col, f); 
     50        lib3ds_rgb_read(background->solid.col, strm); 
    5151        break; 
    5252      case LIB3DS_COLOR_F: 
    53         lib3ds_rgb_read(background->solid.col, f); 
     53        lib3ds_rgb_read(background->solid.col, strm); 
    5454        break; 
    5555      default: 
     
    5858  } 
    5959   
    60   lib3ds_chunk_read_end(&c, f); 
    61   return(LIB3DS_TRUE); 
    62 } 
    63  
    64  
    65 static Lib3dsBool 
    66 v_gradient_read(Lib3dsBackground *background, FILE *f) 
     60  lib3ds_chunk_read_end(&c, strm); 
     61  return(LIB3DS_TRUE); 
     62} 
     63 
     64 
     65static Lib3dsBool 
     66v_gradient_read(Lib3dsBackground *background, iostream *strm) 
    6767{ 
    6868  Lib3dsChunk c; 
     
    7373   
    7474 
    75   if (!lib3ds_chunk_read_start(&c, LIB3DS_V_GRADIENT, f)) { 
     75  if (!lib3ds_chunk_read_start(&c, LIB3DS_V_GRADIENT, strm)) { 
    7676    return(LIB3DS_FALSE); 
    7777  } 
    78   background->gradient.percent=lib3ds_float_read(f); 
    79   lib3ds_chunk_read_tell(&c, f); 
     78  background->gradient.percent=lib3ds_float_read(strm); 
     79  lib3ds_chunk_read_tell(&c, strm); 
    8080 
    8181  index[0]=index[1]=0; 
    82   while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) { 
     82  while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { 
    8383    switch (chunk) { 
    8484      case LIB3DS_COLOR_F: 
    85         lib3ds_rgb_read(col[0][index[0]],f); 
     85        lib3ds_rgb_read(col[0][index[0]],strm); 
    8686        index[0]++; 
    8787        break; 
    8888      case LIB3DS_LIN_COLOR_F: 
    89         lib3ds_rgb_read(col[1][index[1]],f); 
     89        lib3ds_rgb_read(col[1][index[1]],strm); 
    9090        index[1]++; 
    9191        have_lin=1; 
     
    103103    } 
    104104  } 
    105   lib3ds_chunk_read_end(&c, f); 
     105  lib3ds_chunk_read_end(&c, strm); 
    106106  return(LIB3DS_TRUE); 
    107107} 
     
    112112 */ 
    113113Lib3dsBool 
    114 lib3ds_background_read(Lib3dsBackground *background, FILE *f) 
    115 { 
    116   Lib3dsChunk c; 
    117  
    118   if (!lib3ds_chunk_read(&c, f)) { 
     114lib3ds_background_read(Lib3dsBackground *background, iostream *strm) 
     115{ 
     116  Lib3dsChunk c; 
     117 
     118  if (!lib3ds_chunk_read(&c, strm)) { 
    119119    return(LIB3DS_FALSE); 
    120120  } 
     
    123123    case LIB3DS_BIT_MAP: 
    124124      { 
    125         if (!lib3ds_string_read(background->bitmap.name, 64, f)) { 
     125        if (!lib3ds_string_read(background->bitmap.name, 64, strm)) { 
    126126            return(LIB3DS_FALSE); 
    127127        } 
     
    130130      case LIB3DS_SOLID_BGND: 
    131131        { 
    132           lib3ds_chunk_read_reset(&c, f); 
    133           if (!solid_bgnd_read(background, f)) { 
     132          lib3ds_chunk_read_reset(&c, strm); 
     133          if (!solid_bgnd_read(background, strm)) { 
    134134            return(LIB3DS_FALSE); 
    135135          } 
     
    138138      case LIB3DS_V_GRADIENT: 
    139139        { 
    140           lib3ds_chunk_read_reset(&c, f); 
    141           if (!v_gradient_read(background, f)) { 
     140          lib3ds_chunk_read_reset(&c, strm); 
     141          if (!v_gradient_read(background, strm)) { 
    142142            return(LIB3DS_FALSE); 
    143143          } 
     
    166166 
    167167static Lib3dsBool 
    168 colorf_write(Lib3dsRgba rgb, FILE *f) 
     168colorf_write(Lib3dsRgba rgb, iostream *strm) 
    169169{ 
    170170  Lib3dsChunk c; 
     
    172172  c.chunk=LIB3DS_COLOR_F; 
    173173  c.size=18; 
    174   lib3ds_chunk_write(&c,f); 
    175   lib3ds_rgb_write(rgb,f); 
     174  lib3ds_chunk_write(&c,strm); 
     175  lib3ds_rgb_write(rgb,strm); 
    176176 
    177177  c.chunk=LIB3DS_LIN_COLOR_F; 
    178178  c.size=18; 
    179   lib3ds_chunk_write(&c,f); 
    180   lib3ds_rgb_write(rgb,f); 
     179  lib3ds_chunk_write(&c,strm); 
     180  lib3ds_rgb_write(rgb,strm); 
    181181  return(LIB3DS_TRUE); 
    182182} 
     
    200200 */ 
    201201Lib3dsBool 
    202 lib3ds_background_write(Lib3dsBackground *background, FILE *f) 
     202lib3ds_background_write(Lib3dsBackground *background, iostream *strm) 
    203203{ 
    204204  if (strlen(background->bitmap.name)) { /*---- LIB3DS_BIT_MAP ----*/ 
     
    206206    c.chunk=LIB3DS_BIT_MAP; 
    207207    c.size=6+1+strlen(background->bitmap.name); 
    208     lib3ds_chunk_write(&c,f); 
    209     lib3ds_string_write(background->bitmap.name, f); 
     208    lib3ds_chunk_write(&c,strm); 
     209    lib3ds_string_write(background->bitmap.name, strm); 
    210210  } 
    211211 
     
    214214    c.chunk=LIB3DS_SOLID_BGND; 
    215215    c.size=42; 
    216     lib3ds_chunk_write(&c,f); 
    217     colorf_write(background->solid.col,f); 
     216    lib3ds_chunk_write(&c,strm); 
     217    colorf_write(background->solid.col,strm); 
    218218  } 
    219219 
     
    224224    c.chunk=LIB3DS_V_GRADIENT; 
    225225    c.size=118; 
    226     lib3ds_chunk_write(&c,f); 
    227     lib3ds_float_write(background->gradient.percent,f); 
    228     colorf_write(background->gradient.top,f); 
    229     colorf_write(background->gradient.middle,f); 
    230     colorf_write(background->gradient.bottom,f); 
     226    lib3ds_chunk_write(&c,strm); 
     227    lib3ds_float_write(background->gradient.percent,strm); 
     228    colorf_write(background->gradient.top,strm); 
     229    colorf_write(background->gradient.middle,strm); 
     230    colorf_write(background->gradient.bottom,strm); 
    231231  } 
    232232 
     
    235235    c.chunk=LIB3DS_USE_BIT_MAP; 
    236236    c.size=6; 
    237     lib3ds_chunk_write(&c,f); 
     237    lib3ds_chunk_write(&c,strm); 
    238238  } 
    239239 
     
    242242    c.chunk=LIB3DS_USE_SOLID_BGND; 
    243243    c.size=6; 
    244     lib3ds_chunk_write(&c,f); 
     244    lib3ds_chunk_write(&c,strm); 
    245245  } 
    246246 
     
    249249    c.chunk=LIB3DS_USE_V_GRADIENT; 
    250250    c.size=6; 
    251     lib3ds_chunk_write(&c,f); 
     251    lib3ds_chunk_write(&c,strm); 
    252252  } 
    253253