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