| [10853] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | #include "lib3ds_impl.h" |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | static void |
|---|
| 22 | fog_read(Lib3dsAtmosphere *at, Lib3dsIo *io) { |
|---|
| 23 | Lib3dsChunk c; |
|---|
| 24 | uint16_t chunk; |
|---|
| 25 | |
|---|
| 26 | lib3ds_chunk_read_start(&c, CHK_FOG, io); |
|---|
| 27 | |
|---|
| 28 | at->fog_near_plane = lib3ds_io_read_float(io); |
|---|
| 29 | at->fog_near_density = lib3ds_io_read_float(io); |
|---|
| 30 | at->fog_far_plane = lib3ds_io_read_float(io); |
|---|
| 31 | at->fog_far_density = lib3ds_io_read_float(io); |
|---|
| 32 | lib3ds_chunk_read_tell(&c, io); |
|---|
| 33 | |
|---|
| 34 | while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) { |
|---|
| 35 | switch (chunk) { |
|---|
| 36 | case CHK_LIN_COLOR_F: { |
|---|
| 37 | int i; |
|---|
| 38 | for (i = 0; i < 3; ++i) { |
|---|
| 39 | at->fog_color[i] = lib3ds_io_read_float(io); |
|---|
| 40 | } |
|---|
| 41 | } |
|---|
| 42 | break; |
|---|
| 43 | |
|---|
| 44 | case CHK_COLOR_F: |
|---|
| 45 | break; |
|---|
| 46 | |
|---|
| 47 | case CHK_FOG_BGND: { |
|---|
| 48 | at->fog_background = TRUE; |
|---|
| 49 | } |
|---|
| 50 | break; |
|---|
| 51 | |
|---|
| 52 | default: |
|---|
| 53 | lib3ds_chunk_unknown(chunk, io); |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | lib3ds_chunk_read_end(&c, io); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | static void |
|---|
| 62 | layer_fog_read(Lib3dsAtmosphere *at, Lib3dsIo *io) { |
|---|
| 63 | Lib3dsChunk c; |
|---|
| 64 | uint16_t chunk; |
|---|
| 65 | int have_lin = FALSE; |
|---|
| 66 | |
|---|
| 67 | lib3ds_chunk_read_start(&c, CHK_LAYER_FOG, io); |
|---|
| 68 | |
|---|
| 69 | at->layer_fog_near_y = lib3ds_io_read_float(io); |
|---|
| 70 | at->layer_fog_far_y = lib3ds_io_read_float(io); |
|---|
| 71 | at->layer_fog_density = lib3ds_io_read_float(io); |
|---|
| 72 | at->layer_fog_flags = lib3ds_io_read_dword(io); |
|---|
| 73 | lib3ds_chunk_read_tell(&c, io); |
|---|
| 74 | |
|---|
| 75 | while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) { |
|---|
| 76 | switch (chunk) { |
|---|
| 77 | case CHK_LIN_COLOR_F: |
|---|
| 78 | lib3ds_io_read_rgb(io, at->layer_fog_color); |
|---|
| 79 | have_lin = TRUE; |
|---|
| 80 | break; |
|---|
| 81 | |
|---|
| 82 | case CHK_COLOR_F: |
|---|
| 83 | lib3ds_io_read_rgb(io, at->layer_fog_color); |
|---|
| 84 | break; |
|---|
| 85 | |
|---|
| 86 | default: |
|---|
| 87 | lib3ds_chunk_unknown(chunk, io); |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | lib3ds_chunk_read_end(&c, io); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | static void |
|---|
| 96 | distance_cue_read(Lib3dsAtmosphere *at, Lib3dsIo *io) { |
|---|
| 97 | Lib3dsChunk c; |
|---|
| 98 | uint16_t chunk; |
|---|
| 99 | |
|---|
| 100 | lib3ds_chunk_read_start(&c, CHK_DISTANCE_CUE, io); |
|---|
| 101 | |
|---|
| 102 | at->dist_cue_near_plane = lib3ds_io_read_float(io); |
|---|
| 103 | at->dist_cue_near_dimming = lib3ds_io_read_float(io); |
|---|
| 104 | at->dist_cue_far_plane = lib3ds_io_read_float(io); |
|---|
| 105 | at->dist_cue_far_dimming = lib3ds_io_read_float(io); |
|---|
| 106 | lib3ds_chunk_read_tell(&c, io); |
|---|
| 107 | |
|---|
| 108 | while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) { |
|---|
| 109 | switch (chunk) { |
|---|
| 110 | case CHK_DCUE_BGND: { |
|---|
| 111 | at->dist_cue_background = TRUE; |
|---|
| 112 | } |
|---|
| 113 | break; |
|---|
| 114 | |
|---|
| 115 | default: |
|---|
| 116 | lib3ds_chunk_unknown(chunk, io); |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | lib3ds_chunk_read_end(&c, io); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | void |
|---|
| 125 | lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io) { |
|---|
| 126 | Lib3dsChunk c; |
|---|
| 127 | |
|---|
| 128 | lib3ds_chunk_read(&c, io); |
|---|
| 129 | switch (c.chunk) { |
|---|
| 130 | case CHK_FOG: { |
|---|
| 131 | lib3ds_chunk_read_reset(&c, io); |
|---|
| 132 | fog_read(atmosphere, io); |
|---|
| 133 | break; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | case CHK_LAYER_FOG: { |
|---|
| 137 | lib3ds_chunk_read_reset(&c, io); |
|---|
| 138 | layer_fog_read(atmosphere, io); |
|---|
| 139 | break; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | case CHK_DISTANCE_CUE: { |
|---|
| 143 | lib3ds_chunk_read_reset(&c, io); |
|---|
| 144 | distance_cue_read(atmosphere, io); |
|---|
| 145 | break; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | case CHK_USE_FOG: { |
|---|
| 149 | atmosphere->use_fog = TRUE; |
|---|
| 150 | break; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | case CHK_USE_LAYER_FOG: { |
|---|
| 154 | atmosphere->use_layer_fog = TRUE; |
|---|
| 155 | break; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | case CHK_USE_DISTANCE_CUE: { |
|---|
| 159 | atmosphere->use_dist_cue = TRUE; |
|---|
| 160 | break; |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | void |
|---|
| 167 | lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io) { |
|---|
| 168 | if (atmosphere->use_fog) { |
|---|
| 169 | Lib3dsChunk c; |
|---|
| 170 | c.chunk = CHK_FOG; |
|---|
| 171 | lib3ds_chunk_write_start(&c, io); |
|---|
| 172 | |
|---|
| 173 | lib3ds_io_write_float(io, atmosphere->fog_near_plane); |
|---|
| 174 | lib3ds_io_write_float(io, atmosphere->fog_near_density); |
|---|
| 175 | lib3ds_io_write_float(io, atmosphere->fog_far_plane); |
|---|
| 176 | lib3ds_io_write_float(io, atmosphere->fog_far_density); |
|---|
| 177 | { |
|---|
| 178 | Lib3dsChunk c; |
|---|
| 179 | c.chunk = CHK_COLOR_F; |
|---|
| 180 | c.size = 18; |
|---|
| 181 | lib3ds_chunk_write(&c, io); |
|---|
| 182 | lib3ds_io_write_rgb(io, atmosphere->fog_color); |
|---|
| 183 | } |
|---|
| 184 | if (atmosphere->fog_background) { |
|---|
| 185 | Lib3dsChunk c; |
|---|
| 186 | c.chunk = CHK_FOG_BGND; |
|---|
| 187 | c.size = 6; |
|---|
| 188 | lib3ds_chunk_write(&c, io); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | lib3ds_chunk_write_end(&c, io); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | if (atmosphere->use_layer_fog) { |
|---|
| 195 | Lib3dsChunk c; |
|---|
| 196 | c.chunk = CHK_LAYER_FOG; |
|---|
| 197 | c.size = 40; |
|---|
| 198 | lib3ds_chunk_write(&c, io); |
|---|
| 199 | lib3ds_io_write_float(io, atmosphere->layer_fog_near_y); |
|---|
| 200 | lib3ds_io_write_float(io, atmosphere->layer_fog_far_y); |
|---|
| 201 | lib3ds_io_write_float(io, atmosphere->layer_fog_near_y); |
|---|
| 202 | lib3ds_io_write_dword(io, atmosphere->layer_fog_flags); |
|---|
| 203 | { |
|---|
| 204 | Lib3dsChunk c; |
|---|
| 205 | c.chunk = CHK_COLOR_F; |
|---|
| 206 | c.size = 18; |
|---|
| 207 | lib3ds_chunk_write(&c, io); |
|---|
| 208 | lib3ds_io_write_rgb(io, atmosphere->fog_color); |
|---|
| 209 | } |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | if (atmosphere->use_dist_cue) { |
|---|
| 213 | Lib3dsChunk c; |
|---|
| 214 | c.chunk = CHK_DISTANCE_CUE; |
|---|
| 215 | lib3ds_chunk_write_start(&c, io); |
|---|
| 216 | |
|---|
| 217 | lib3ds_io_write_float(io, atmosphere->dist_cue_near_plane); |
|---|
| 218 | lib3ds_io_write_float(io, atmosphere->dist_cue_near_dimming); |
|---|
| 219 | lib3ds_io_write_float(io, atmosphere->dist_cue_far_plane); |
|---|
| 220 | lib3ds_io_write_float(io, atmosphere->dist_cue_far_dimming); |
|---|
| 221 | if (atmosphere->dist_cue_background) { |
|---|
| 222 | Lib3dsChunk c; |
|---|
| 223 | c.chunk = CHK_DCUE_BGND; |
|---|
| 224 | c.size = 6; |
|---|
| 225 | lib3ds_chunk_write(&c, io); |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | lib3ds_chunk_write_end(&c, io); |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | if (atmosphere->use_fog) { |
|---|
| 232 | Lib3dsChunk c; |
|---|
| 233 | c.chunk = CHK_USE_FOG; |
|---|
| 234 | c.size = 6; |
|---|
| 235 | lib3ds_chunk_write(&c, io); |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | if (atmosphere->use_layer_fog) { |
|---|
| 239 | Lib3dsChunk c; |
|---|
| 240 | c.chunk = CHK_USE_LAYER_FOG; |
|---|
| 241 | c.size = 6; |
|---|
| 242 | lib3ds_chunk_write(&c, io); |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | if (atmosphere->use_dist_cue) { |
|---|
| 246 | Lib3dsChunk c; |
|---|
| 247 | c.chunk = CHK_USE_V_GRADIENT; |
|---|
| 248 | c.size = 6; |
|---|
| 249 | lib3ds_chunk_write(&c, io); |
|---|
| 250 | } |
|---|
| 251 | } |
|---|
| 252 | |
|---|