| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | #define LIB3DS_EXPORT |
|---|
| 23 | #include "atmosphere.h" |
|---|
| 24 | #include "chunk.h" |
|---|
| 25 | #include "readwrite.h" |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | static Lib3dsBool |
|---|
| 36 | fog_read(Lib3dsFog *fog, iostream *strm) |
|---|
| 37 | { |
|---|
| 38 | Lib3dsChunk c; |
|---|
| 39 | Lib3dsWord chunk; |
|---|
| 40 | |
|---|
| 41 | if (!lib3ds_chunk_read_start(&c, LIB3DS_FOG, strm)) { |
|---|
| 42 | return(LIB3DS_FALSE); |
|---|
| 43 | } |
|---|
| 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) { |
|---|
| 51 | switch (chunk) { |
|---|
| 52 | case LIB3DS_LIN_COLOR_F: |
|---|
| 53 | { |
|---|
| 54 | int i; |
|---|
| 55 | for (i=0; i<3; ++i) { |
|---|
| 56 | fog->col[i]=lib3ds_float_read(strm); |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | break; |
|---|
| 60 | case LIB3DS_COLOR_F: |
|---|
| 61 | break; |
|---|
| 62 | case LIB3DS_FOG_BGND: |
|---|
| 63 | { |
|---|
| 64 | fog->fog_background=LIB3DS_TRUE; |
|---|
| 65 | } |
|---|
| 66 | break; |
|---|
| 67 | default: |
|---|
| 68 | lib3ds_chunk_unknown(chunk); |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | lib3ds_chunk_read_end(&c, strm); |
|---|
| 73 | return(LIB3DS_TRUE); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | static Lib3dsBool |
|---|
| 78 | layer_fog_read(Lib3dsLayerFog *fog, iostream *strm) |
|---|
| 79 | { |
|---|
| 80 | Lib3dsChunk c; |
|---|
| 81 | Lib3dsWord chunk; |
|---|
| 82 | |
|---|
| 83 | if (!lib3ds_chunk_read_start(&c, LIB3DS_LAYER_FOG, strm)) { |
|---|
| 84 | return(LIB3DS_FALSE); |
|---|
| 85 | } |
|---|
| 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) { |
|---|
| 93 | switch (chunk) { |
|---|
| 94 | case LIB3DS_LIN_COLOR_F: |
|---|
| 95 | lib3ds_rgb_read(fog->col,strm); |
|---|
| 96 | break; |
|---|
| 97 | case LIB3DS_COLOR_F: |
|---|
| 98 | lib3ds_rgb_read(fog->col,strm); |
|---|
| 99 | break; |
|---|
| 100 | default: |
|---|
| 101 | lib3ds_chunk_unknown(chunk); |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | lib3ds_chunk_read_end(&c, strm); |
|---|
| 106 | return(LIB3DS_TRUE); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | static Lib3dsBool |
|---|
| 111 | distance_cue_read(Lib3dsDistanceCue *cue, iostream *strm) |
|---|
| 112 | { |
|---|
| 113 | Lib3dsChunk c; |
|---|
| 114 | Lib3dsWord chunk; |
|---|
| 115 | |
|---|
| 116 | if (!lib3ds_chunk_read_start(&c, LIB3DS_DISTANCE_CUE, strm)) { |
|---|
| 117 | return(LIB3DS_FALSE); |
|---|
| 118 | } |
|---|
| 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) { |
|---|
| 126 | switch (chunk) { |
|---|
| 127 | case LIB3DS_DCUE_BGND: |
|---|
| 128 | { |
|---|
| 129 | cue->cue_background=LIB3DS_TRUE; |
|---|
| 130 | } |
|---|
| 131 | break; |
|---|
| 132 | default: |
|---|
| 133 | lib3ds_chunk_unknown(chunk); |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | lib3ds_chunk_read_end(&c, strm); |
|---|
| 138 | return(LIB3DS_TRUE); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | Lib3dsBool |
|---|
| 146 | lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, iostream *strm) |
|---|
| 147 | { |
|---|
| 148 | Lib3dsChunk c; |
|---|
| 149 | |
|---|
| 150 | if (!lib3ds_chunk_read(&c, strm)) { |
|---|
| 151 | return(LIB3DS_FALSE); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | switch (c.chunk) { |
|---|
| 155 | case LIB3DS_FOG: |
|---|
| 156 | { |
|---|
| 157 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 158 | if (!fog_read(&atmosphere->fog, strm)) { |
|---|
| 159 | return(LIB3DS_FALSE); |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | break; |
|---|
| 163 | case LIB3DS_LAYER_FOG: |
|---|
| 164 | { |
|---|
| 165 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 166 | if (!layer_fog_read(&atmosphere->layer_fog, strm)) { |
|---|
| 167 | return(LIB3DS_FALSE); |
|---|
| 168 | } |
|---|
| 169 | } |
|---|
| 170 | break; |
|---|
| 171 | case LIB3DS_DISTANCE_CUE: |
|---|
| 172 | { |
|---|
| 173 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 174 | if (!distance_cue_read(&atmosphere->dist_cue, strm)) { |
|---|
| 175 | return(LIB3DS_FALSE); |
|---|
| 176 | } |
|---|
| 177 | } |
|---|
| 178 | break; |
|---|
| 179 | case LIB3DS_USE_FOG: |
|---|
| 180 | { |
|---|
| 181 | atmosphere->fog.use=LIB3DS_TRUE; |
|---|
| 182 | } |
|---|
| 183 | break; |
|---|
| 184 | case LIB3DS_USE_LAYER_FOG: |
|---|
| 185 | { |
|---|
| 186 | atmosphere->fog.use=LIB3DS_TRUE; |
|---|
| 187 | } |
|---|
| 188 | break; |
|---|
| 189 | case LIB3DS_USE_DISTANCE_CUE: |
|---|
| 190 | { |
|---|
| 191 | atmosphere->dist_cue.use=LIB3DS_TRUE; |
|---|
| 192 | } |
|---|
| 193 | break; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | return(LIB3DS_TRUE); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | Lib3dsBool |
|---|
| 204 | lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, iostream *strm) |
|---|
| 205 | { |
|---|
| 206 | if (atmosphere->fog.use) { |
|---|
| 207 | Lib3dsChunk c; |
|---|
| 208 | c.chunk=LIB3DS_FOG; |
|---|
| 209 | if (!lib3ds_chunk_write_start(&c,strm)) { |
|---|
| 210 | return(LIB3DS_FALSE); |
|---|
| 211 | } |
|---|
| 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); |
|---|
| 216 | { |
|---|
| 217 | Lib3dsChunk c; |
|---|
| 218 | c.chunk=LIB3DS_COLOR_F; |
|---|
| 219 | c.size=18; |
|---|
| 220 | lib3ds_chunk_write(&c,strm); |
|---|
| 221 | lib3ds_rgb_write(atmosphere->fog.col,strm); |
|---|
| 222 | } |
|---|
| 223 | if (atmosphere->fog.fog_background) { |
|---|
| 224 | Lib3dsChunk c; |
|---|
| 225 | c.chunk=LIB3DS_FOG_BGND; |
|---|
| 226 | c.size=6; |
|---|
| 227 | lib3ds_chunk_write(&c,strm); |
|---|
| 228 | } |
|---|
| 229 | if (!lib3ds_chunk_write_end(&c,strm)) { |
|---|
| 230 | return(LIB3DS_FALSE); |
|---|
| 231 | } |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | if (atmosphere->layer_fog.use) { |
|---|
| 235 | Lib3dsChunk c; |
|---|
| 236 | c.chunk=LIB3DS_LAYER_FOG; |
|---|
| 237 | c.size=40; |
|---|
| 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); |
|---|
| 243 | { |
|---|
| 244 | Lib3dsChunk c; |
|---|
| 245 | c.chunk=LIB3DS_COLOR_F; |
|---|
| 246 | c.size=18; |
|---|
| 247 | lib3ds_chunk_write(&c,strm); |
|---|
| 248 | lib3ds_rgb_write(atmosphere->fog.col,strm); |
|---|
| 249 | } |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | if (atmosphere->dist_cue.use) { |
|---|
| 253 | Lib3dsChunk c; |
|---|
| 254 | c.chunk=LIB3DS_DISTANCE_CUE; |
|---|
| 255 | if (!lib3ds_chunk_write_start(&c,strm)) { |
|---|
| 256 | return(LIB3DS_FALSE); |
|---|
| 257 | } |
|---|
| 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); |
|---|
| 262 | if (atmosphere->dist_cue.cue_background) { |
|---|
| 263 | Lib3dsChunk c; |
|---|
| 264 | c.chunk=LIB3DS_DCUE_BGND; |
|---|
| 265 | c.size=6; |
|---|
| 266 | lib3ds_chunk_write(&c,strm); |
|---|
| 267 | } |
|---|
| 268 | if (!lib3ds_chunk_write_end(&c,strm)) { |
|---|
| 269 | return(LIB3DS_FALSE); |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | if (atmosphere->fog.use) { |
|---|
| 274 | Lib3dsChunk c; |
|---|
| 275 | c.chunk=LIB3DS_USE_FOG; |
|---|
| 276 | c.size=6; |
|---|
| 277 | lib3ds_chunk_write(&c,strm); |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | if (atmosphere->layer_fog.use) { |
|---|
| 281 | Lib3dsChunk c; |
|---|
| 282 | c.chunk=LIB3DS_USE_LAYER_FOG; |
|---|
| 283 | c.size=6; |
|---|
| 284 | lib3ds_chunk_write(&c,strm); |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | if (atmosphere->dist_cue.use) { |
|---|
| 288 | Lib3dsChunk c; |
|---|
| 289 | c.chunk=LIB3DS_USE_V_GRADIENT; |
|---|
| 290 | c.size=6; |
|---|
| 291 | lib3ds_chunk_write(&c,strm); |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | return(LIB3DS_TRUE); |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|