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/atmosphere.cpp

    r1563 r10076  
    3434 
    3535static Lib3dsBool 
    36 fog_read(Lib3dsFog *fog, FILE *f) 
     36fog_read(Lib3dsFog *fog, iostream *strm) 
    3737{ 
    3838  Lib3dsChunk c; 
    3939  Lib3dsWord chunk; 
    4040 
    41   if (!lib3ds_chunk_read_start(&c, LIB3DS_FOG, f)) { 
     41  if (!lib3ds_chunk_read_start(&c, LIB3DS_FOG, strm)) { 
    4242    return(LIB3DS_FALSE); 
    4343  } 
    44   fog->near_plane=lib3ds_float_read(f); 
    45   fog->near_density=lib3ds_float_read(f); 
    46   fog->far_plane=lib3ds_float_read(f); 
    47   fog->far_density=lib3ds_float_read(f); 
    48   lib3ds_chunk_read_tell(&c, f); 
    49    
    50   while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) { 
     44  fog->near_plane=lib3ds_float_read(strm); 
     45  fog->near_density=lib3ds_float_read(strm); 
     46  fog->far_plane=lib3ds_float_read(strm); 
     47  fog->far_density=lib3ds_float_read(strm); 
     48  lib3ds_chunk_read_tell(&c, strm); 
     49   
     50  while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { 
    5151    switch (chunk) { 
    5252      case LIB3DS_LIN_COLOR_F: 
     
    5454          int i; 
    5555          for (i=0; i<3; ++i) { 
    56             fog->col[i]=lib3ds_float_read(f); 
     56            fog->col[i]=lib3ds_float_read(strm); 
    5757          } 
    5858        } 
     
    7070  } 
    7171   
    72   lib3ds_chunk_read_end(&c, f); 
     72  lib3ds_chunk_read_end(&c, strm); 
    7373  return(LIB3DS_TRUE); 
    7474} 
     
    7676 
    7777static Lib3dsBool 
    78 layer_fog_read(Lib3dsLayerFog *fog, FILE *f) 
     78layer_fog_read(Lib3dsLayerFog *fog, iostream *strm) 
    7979{ 
    8080  Lib3dsChunk c; 
    8181  Lib3dsWord chunk; 
    8282 
    83   if (!lib3ds_chunk_read_start(&c, LIB3DS_LAYER_FOG, f)) { 
     83  if (!lib3ds_chunk_read_start(&c, LIB3DS_LAYER_FOG, strm)) { 
    8484    return(LIB3DS_FALSE); 
    8585  } 
    86   fog->near_y=lib3ds_float_read(f); 
    87   fog->far_y=lib3ds_float_read(f); 
    88   fog->density=lib3ds_float_read(f); 
    89   fog->flags=lib3ds_dword_read(f); 
    90   lib3ds_chunk_read_tell(&c, f); 
    91    
    92   while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) { 
     86  fog->near_y=lib3ds_float_read(strm); 
     87  fog->far_y=lib3ds_float_read(strm); 
     88  fog->density=lib3ds_float_read(strm); 
     89  fog->flags=lib3ds_dword_read(strm); 
     90  lib3ds_chunk_read_tell(&c, strm); 
     91   
     92  while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { 
    9393    switch (chunk) { 
    9494      case LIB3DS_LIN_COLOR_F: 
    95         lib3ds_rgb_read(fog->col,f); 
     95        lib3ds_rgb_read(fog->col,strm); 
    9696        break; 
    9797      case LIB3DS_COLOR_F: 
    98         lib3ds_rgb_read(fog->col,f); 
     98        lib3ds_rgb_read(fog->col,strm); 
    9999        break; 
    100100      default: 
     
    103103  } 
    104104   
    105   lib3ds_chunk_read_end(&c, f); 
     105  lib3ds_chunk_read_end(&c, strm); 
    106106  return(LIB3DS_TRUE); 
    107107} 
     
    109109 
    110110static Lib3dsBool 
    111 distance_cue_read(Lib3dsDistanceCue *cue, FILE *f) 
     111distance_cue_read(Lib3dsDistanceCue *cue, iostream *strm) 
    112112{ 
    113113  Lib3dsChunk c; 
    114114  Lib3dsWord chunk; 
    115115 
    116   if (!lib3ds_chunk_read_start(&c, LIB3DS_DISTANCE_CUE, f)) { 
     116  if (!lib3ds_chunk_read_start(&c, LIB3DS_DISTANCE_CUE, strm)) { 
    117117    return(LIB3DS_FALSE); 
    118118  } 
    119   cue->near_plane=lib3ds_float_read(f); 
    120   cue->near_dimming=lib3ds_float_read(f); 
    121   cue->far_plane=lib3ds_float_read(f); 
    122   cue->far_dimming=lib3ds_float_read(f); 
    123   lib3ds_chunk_read_tell(&c, f); 
    124    
    125   while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) { 
     119  cue->near_plane=lib3ds_float_read(strm); 
     120  cue->near_dimming=lib3ds_float_read(strm); 
     121  cue->far_plane=lib3ds_float_read(strm); 
     122  cue->far_dimming=lib3ds_float_read(strm); 
     123  lib3ds_chunk_read_tell(&c, strm); 
     124   
     125  while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { 
    126126    switch (chunk) { 
    127127      case LIB3DS_DCUE_BGND: 
     
    135135  } 
    136136   
    137   lib3ds_chunk_read_end(&c, f); 
     137  lib3ds_chunk_read_end(&c, strm); 
    138138  return(LIB3DS_TRUE); 
    139139} 
     
    144144 */ 
    145145Lib3dsBool 
    146 lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, FILE *f) 
     146lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, iostream *strm) 
    147147{ 
    148148  Lib3dsChunk c; 
    149149 
    150   if (!lib3ds_chunk_read(&c, f)) { 
     150  if (!lib3ds_chunk_read(&c, strm)) { 
    151151    return(LIB3DS_FALSE); 
    152152  } 
     
    155155      case LIB3DS_FOG: 
    156156        { 
    157           lib3ds_chunk_read_reset(&c, f); 
    158           if (!fog_read(&atmosphere->fog, f)) { 
     157          lib3ds_chunk_read_reset(&c, strm); 
     158          if (!fog_read(&atmosphere->fog, strm)) { 
    159159            return(LIB3DS_FALSE); 
    160160          } 
     
    163163      case LIB3DS_LAYER_FOG: 
    164164        { 
    165           lib3ds_chunk_read_reset(&c, f); 
    166           if (!layer_fog_read(&atmosphere->layer_fog, f)) { 
     165          lib3ds_chunk_read_reset(&c, strm); 
     166          if (!layer_fog_read(&atmosphere->layer_fog, strm)) { 
    167167            return(LIB3DS_FALSE); 
    168168          } 
     
    171171      case LIB3DS_DISTANCE_CUE: 
    172172        { 
    173           lib3ds_chunk_read_reset(&c, f); 
    174           if (!distance_cue_read(&atmosphere->dist_cue, f)) { 
     173          lib3ds_chunk_read_reset(&c, strm); 
     174          if (!distance_cue_read(&atmosphere->dist_cue, strm)) { 
    175175            return(LIB3DS_FALSE); 
    176176          } 
     
    202202 */ 
    203203Lib3dsBool 
    204 lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, FILE *f) 
     204lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, iostream *strm) 
    205205{ 
    206206  if (atmosphere->fog.use) { /*---- LIB3DS_FOG ----*/ 
    207207    Lib3dsChunk c; 
    208208    c.chunk=LIB3DS_FOG; 
    209     if (!lib3ds_chunk_write_start(&c,f)) { 
     209    if (!lib3ds_chunk_write_start(&c,strm)) { 
    210210      return(LIB3DS_FALSE); 
    211211    } 
    212     lib3ds_float_write(atmosphere->fog.near_plane,f); 
    213     lib3ds_float_write(atmosphere->fog.near_density,f); 
    214     lib3ds_float_write(atmosphere->fog.far_plane,f); 
    215     lib3ds_float_write(atmosphere->fog.far_density,f); 
     212    lib3ds_float_write(atmosphere->fog.near_plane,strm); 
     213    lib3ds_float_write(atmosphere->fog.near_density,strm); 
     214    lib3ds_float_write(atmosphere->fog.far_plane,strm); 
     215    lib3ds_float_write(atmosphere->fog.far_density,strm); 
    216216    { 
    217217      Lib3dsChunk c; 
    218218      c.chunk=LIB3DS_COLOR_F; 
    219219      c.size=18; 
    220       lib3ds_chunk_write(&c,f); 
    221       lib3ds_rgb_write(atmosphere->fog.col,f); 
     220      lib3ds_chunk_write(&c,strm); 
     221      lib3ds_rgb_write(atmosphere->fog.col,strm); 
    222222    } 
    223223    if (atmosphere->fog.fog_background) { 
     
    225225      c.chunk=LIB3DS_FOG_BGND; 
    226226      c.size=6; 
    227       lib3ds_chunk_write(&c,f); 
    228     } 
    229     if (!lib3ds_chunk_write_end(&c,f)) { 
     227      lib3ds_chunk_write(&c,strm); 
     228    } 
     229    if (!lib3ds_chunk_write_end(&c,strm)) { 
    230230      return(LIB3DS_FALSE); 
    231231    } 
     
    236236    c.chunk=LIB3DS_LAYER_FOG; 
    237237    c.size=40; 
    238     lib3ds_chunk_write(&c,f); 
    239     lib3ds_float_write(atmosphere->layer_fog.near_y,f); 
    240     lib3ds_float_write(atmosphere->layer_fog.far_y,f); 
    241     lib3ds_float_write(atmosphere->layer_fog.near_y,f); 
    242     lib3ds_dword_write(atmosphere->layer_fog.flags,f); 
     238    lib3ds_chunk_write(&c,strm); 
     239    lib3ds_float_write(atmosphere->layer_fog.near_y,strm); 
     240    lib3ds_float_write(atmosphere->layer_fog.far_y,strm); 
     241    lib3ds_float_write(atmosphere->layer_fog.near_y,strm); 
     242    lib3ds_dword_write(atmosphere->layer_fog.flags,strm); 
    243243    { 
    244244      Lib3dsChunk c; 
    245245      c.chunk=LIB3DS_COLOR_F; 
    246246      c.size=18; 
    247       lib3ds_chunk_write(&c,f); 
    248       lib3ds_rgb_write(atmosphere->fog.col,f); 
     247      lib3ds_chunk_write(&c,strm); 
     248      lib3ds_rgb_write(atmosphere->fog.col,strm); 
    249249    } 
    250250  } 
     
    253253    Lib3dsChunk c; 
    254254    c.chunk=LIB3DS_DISTANCE_CUE; 
    255     if (!lib3ds_chunk_write_start(&c,f)) { 
     255    if (!lib3ds_chunk_write_start(&c,strm)) { 
    256256      return(LIB3DS_FALSE); 
    257257    } 
    258     lib3ds_float_write(atmosphere->dist_cue.near_plane,f); 
    259     lib3ds_float_write(atmosphere->dist_cue.near_dimming,f); 
    260     lib3ds_float_write(atmosphere->dist_cue.far_plane,f); 
    261     lib3ds_float_write(atmosphere->dist_cue.far_dimming,f); 
     258    lib3ds_float_write(atmosphere->dist_cue.near_plane,strm); 
     259    lib3ds_float_write(atmosphere->dist_cue.near_dimming,strm); 
     260    lib3ds_float_write(atmosphere->dist_cue.far_plane,strm); 
     261    lib3ds_float_write(atmosphere->dist_cue.far_dimming,strm); 
    262262    if (atmosphere->dist_cue.cue_background) { 
    263263      Lib3dsChunk c; 
    264264      c.chunk=LIB3DS_DCUE_BGND; 
    265265      c.size=6; 
    266       lib3ds_chunk_write(&c,f); 
    267     } 
    268     if (!lib3ds_chunk_write_end(&c,f)) { 
     266      lib3ds_chunk_write(&c,strm); 
     267    } 
     268    if (!lib3ds_chunk_write_end(&c,strm)) { 
    269269      return(LIB3DS_FALSE); 
    270270    } 
     
    275275    c.chunk=LIB3DS_USE_FOG; 
    276276    c.size=6; 
    277     lib3ds_chunk_write(&c,f); 
     277    lib3ds_chunk_write(&c,strm); 
    278278  } 
    279279 
     
    282282    c.chunk=LIB3DS_USE_LAYER_FOG; 
    283283    c.size=6; 
    284     lib3ds_chunk_write(&c,f); 
     284    lib3ds_chunk_write(&c,strm); 
    285285  } 
    286286 
     
    289289    c.chunk=LIB3DS_USE_V_GRADIENT; 
    290290    c.size=6; 
    291     lib3ds_chunk_write(&c,f); 
     291    lib3ds_chunk_write(&c,strm); 
    292292  } 
    293293