| [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 "material.h" |
|---|
| 24 | #include "chunk.h" |
|---|
| 25 | #include "readwrite.h" |
|---|
| [8] | 26 | #include <stdlib.h> |
|---|
| 27 | #include <math.h> |
|---|
| 28 | #include <string.h> |
|---|
| [1563] | 29 | #include "config.h" |
|---|
| [8] | 30 | #ifdef WITH_DMALLOC |
|---|
| 31 | #include <dmalloc.h> |
|---|
| 32 | #endif |
|---|
| 33 | |
|---|
| [151] | 34 | |
|---|
| [8] | 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| [151] | 41 | |
|---|
| [8] | 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | Lib3dsMaterial* |
|---|
| 46 | lib3ds_material_new() |
|---|
| 47 | { |
|---|
| [151] | 48 | Lib3dsMaterial *material; |
|---|
| [8] | 49 | |
|---|
| [151] | 50 | material=(Lib3dsMaterial*)calloc(sizeof(Lib3dsMaterial), 1); |
|---|
| 51 | if (!material) { |
|---|
| 52 | return(0); |
|---|
| 53 | } |
|---|
| 54 | return(material); |
|---|
| [8] | 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | void |
|---|
| 62 | lib3ds_material_free(Lib3dsMaterial *material) |
|---|
| 63 | { |
|---|
| [151] | 64 | memset(material, 0, sizeof(Lib3dsMaterial)); |
|---|
| 65 | free(material); |
|---|
| [8] | 66 | } |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | static Lib3dsBool |
|---|
| [10076] | 70 | color_read(Lib3dsRgba rgb, iostream *strm) |
|---|
| [8] | 71 | { |
|---|
| [151] | 72 | Lib3dsChunk c; |
|---|
| 73 | Lib3dsWord chunk; |
|---|
| 74 | Lib3dsBool have_lin=LIB3DS_FALSE; |
|---|
| [8] | 75 | |
|---|
| [10076] | 76 | if (!lib3ds_chunk_read_start(&c, 0, strm)) { |
|---|
| [151] | 77 | return(LIB3DS_FALSE); |
|---|
| 78 | } |
|---|
| [8] | 79 | |
|---|
| [10076] | 80 | while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { |
|---|
| [151] | 81 | switch (chunk) { |
|---|
| 82 | case LIB3DS_LIN_COLOR_24: |
|---|
| [8] | 83 | { |
|---|
| [151] | 84 | int i; |
|---|
| 85 | for (i=0; i<3; ++i) { |
|---|
| [10076] | 86 | rgb[i]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| [151] | 87 | } |
|---|
| 88 | rgb[3]=1.0f; |
|---|
| [8] | 89 | } |
|---|
| [151] | 90 | have_lin=LIB3DS_TRUE; |
|---|
| 91 | break; |
|---|
| 92 | case LIB3DS_COLOR_24: |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | if (!have_lin) { |
|---|
| 96 | int i; |
|---|
| 97 | for (i=0; i<3; ++i) { |
|---|
| [10076] | 98 | rgb[i]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| [151] | 99 | } |
|---|
| 100 | rgb[3]=1.0f; |
|---|
| 101 | } |
|---|
| 102 | break; |
|---|
| [7057] | 103 | case LIB3DS_COLOR_F: |
|---|
| 104 | |
|---|
| [10076] | 105 | lib3ds_rgb_read(rgb, strm); |
|---|
| [7057] | 106 | break; |
|---|
| [151] | 107 | default: |
|---|
| 108 | lib3ds_chunk_unknown(chunk); |
|---|
| [8] | 109 | } |
|---|
| [151] | 110 | } |
|---|
| 111 | |
|---|
| [10076] | 112 | lib3ds_chunk_read_end(&c, strm); |
|---|
| [151] | 113 | return(LIB3DS_TRUE); |
|---|
| [8] | 114 | } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | static Lib3dsBool |
|---|
| [10076] | 118 | int_percentage_read(Lib3dsFloat *p, iostream *strm) |
|---|
| [8] | 119 | { |
|---|
| [151] | 120 | Lib3dsChunk c; |
|---|
| 121 | Lib3dsWord chunk; |
|---|
| [8] | 122 | |
|---|
| [10076] | 123 | if (!lib3ds_chunk_read_start(&c, 0, strm)) { |
|---|
| [151] | 124 | return(LIB3DS_FALSE); |
|---|
| 125 | } |
|---|
| [8] | 126 | |
|---|
| [10076] | 127 | while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { |
|---|
| [151] | 128 | switch (chunk) { |
|---|
| 129 | case LIB3DS_INT_PERCENTAGE: |
|---|
| [8] | 130 | { |
|---|
| [10076] | 131 | Lib3dsIntw i=lib3ds_intw_read(strm); |
|---|
| [151] | 132 | *p=(Lib3dsFloat)(1.0*i/100.0); |
|---|
| [8] | 133 | } |
|---|
| [151] | 134 | break; |
|---|
| 135 | default: |
|---|
| 136 | lib3ds_chunk_unknown(chunk); |
|---|
| [8] | 137 | } |
|---|
| [151] | 138 | } |
|---|
| 139 | |
|---|
| [10076] | 140 | lib3ds_chunk_read_end(&c, strm); |
|---|
| [151] | 141 | return(LIB3DS_TRUE); |
|---|
| [8] | 142 | } |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | static Lib3dsBool |
|---|
| [10076] | 146 | texture_map_read(Lib3dsTextureMap *map, iostream *strm) |
|---|
| [8] | 147 | { |
|---|
| [151] | 148 | Lib3dsChunk c; |
|---|
| 149 | Lib3dsWord chunk; |
|---|
| [8] | 150 | |
|---|
| [10076] | 151 | if (!lib3ds_chunk_read_start(&c, 0, strm)) { |
|---|
| [151] | 152 | return(LIB3DS_FALSE); |
|---|
| 153 | } |
|---|
| [8] | 154 | |
|---|
| [10076] | 155 | while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { |
|---|
| [151] | 156 | switch (chunk) { |
|---|
| 157 | case LIB3DS_INT_PERCENTAGE: |
|---|
| [8] | 158 | { |
|---|
| [10076] | 159 | map->percent=1.0f*lib3ds_intw_read(strm)/100.0f; |
|---|
| [8] | 160 | } |
|---|
| [151] | 161 | break; |
|---|
| 162 | case LIB3DS_MAT_MAPNAME: |
|---|
| 163 | { |
|---|
| [10076] | 164 | if (!lib3ds_string_read(map->name, 64, strm)) { |
|---|
| [151] | 165 | return(LIB3DS_FALSE); |
|---|
| 166 | } |
|---|
| 167 | lib3ds_chunk_dump_info(" NAME=%s", map->name); |
|---|
| 168 | } |
|---|
| 169 | break; |
|---|
| 170 | case LIB3DS_MAT_MAP_TILING: |
|---|
| 171 | { |
|---|
| [10076] | 172 | map->flags=lib3ds_word_read(strm); |
|---|
| [151] | 173 | } |
|---|
| 174 | break; |
|---|
| 175 | case LIB3DS_MAT_MAP_TEXBLUR: |
|---|
| 176 | { |
|---|
| [10076] | 177 | map->blur=lib3ds_float_read(strm); |
|---|
| [151] | 178 | } |
|---|
| 179 | break; |
|---|
| 180 | case LIB3DS_MAT_MAP_USCALE: |
|---|
| 181 | { |
|---|
| [10076] | 182 | map->scale[0]=lib3ds_float_read(strm); |
|---|
| [151] | 183 | } |
|---|
| 184 | break; |
|---|
| 185 | case LIB3DS_MAT_MAP_VSCALE: |
|---|
| 186 | { |
|---|
| [10076] | 187 | map->scale[1]=lib3ds_float_read(strm); |
|---|
| [151] | 188 | } |
|---|
| 189 | break; |
|---|
| 190 | case LIB3DS_MAT_MAP_UOFFSET: |
|---|
| 191 | { |
|---|
| [10076] | 192 | map->offset[0]=lib3ds_float_read(strm); |
|---|
| [151] | 193 | } |
|---|
| 194 | break; |
|---|
| 195 | case LIB3DS_MAT_MAP_VOFFSET: |
|---|
| 196 | { |
|---|
| [10076] | 197 | map->offset[1]=lib3ds_float_read(strm); |
|---|
| [151] | 198 | } |
|---|
| 199 | break; |
|---|
| 200 | case LIB3DS_MAT_MAP_ANG: |
|---|
| 201 | { |
|---|
| [10076] | 202 | map->rotation=lib3ds_float_read(strm); |
|---|
| [151] | 203 | } |
|---|
| 204 | break; |
|---|
| 205 | case LIB3DS_MAT_MAP_COL1: |
|---|
| 206 | { |
|---|
| [10076] | 207 | map->tint_1[0]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| 208 | map->tint_1[1]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| 209 | map->tint_1[2]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| [151] | 210 | } |
|---|
| 211 | break; |
|---|
| 212 | case LIB3DS_MAT_MAP_COL2: |
|---|
| 213 | { |
|---|
| [10076] | 214 | map->tint_2[0]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| 215 | map->tint_2[1]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| 216 | map->tint_2[2]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| [151] | 217 | } |
|---|
| 218 | break; |
|---|
| 219 | case LIB3DS_MAT_MAP_RCOL: |
|---|
| 220 | { |
|---|
| [10076] | 221 | map->tint_r[0]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| 222 | map->tint_r[1]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| 223 | map->tint_r[2]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| [151] | 224 | } |
|---|
| 225 | break; |
|---|
| 226 | case LIB3DS_MAT_MAP_GCOL: |
|---|
| 227 | { |
|---|
| [10076] | 228 | map->tint_g[0]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| 229 | map->tint_g[1]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| 230 | map->tint_g[2]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| [151] | 231 | } |
|---|
| 232 | break; |
|---|
| 233 | case LIB3DS_MAT_MAP_BCOL: |
|---|
| 234 | { |
|---|
| [10076] | 235 | map->tint_b[0]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| 236 | map->tint_b[1]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| 237 | map->tint_b[2]=1.0f*lib3ds_byte_read(strm)/255.0f; |
|---|
| [151] | 238 | } |
|---|
| 239 | break; |
|---|
| 240 | default: |
|---|
| 241 | lib3ds_chunk_unknown(chunk); |
|---|
| [8] | 242 | } |
|---|
| [151] | 243 | } |
|---|
| 244 | |
|---|
| [10076] | 245 | lib3ds_chunk_read_end(&c, strm); |
|---|
| [151] | 246 | return(LIB3DS_TRUE); |
|---|
| 247 | } |
|---|
| [8] | 248 | |
|---|
| [151] | 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | static void |
|---|
| 254 | texture_dump(const char *maptype, Lib3dsTextureMap *texture) |
|---|
| 255 | { |
|---|
| 256 | ASSERT(texture); |
|---|
| 257 | if (strlen(texture->name)==0) { |
|---|
| 258 | return; |
|---|
| 259 | } |
|---|
| 260 | printf(" %s:\n", maptype); |
|---|
| 261 | printf(" name: %s\n", texture->name); |
|---|
| [576] | 262 | printf(" flags: %ii\n", static_cast<unsigned int>(texture->flags)); |
|---|
| [151] | 263 | printf(" percent: %f\n", texture->percent); |
|---|
| 264 | printf(" blur: %f\n", texture->blur); |
|---|
| 265 | printf(" scale: (%f, %f)\n", texture->scale[0], texture->scale[1]); |
|---|
| 266 | printf(" offset: (%f, %f)\n", texture->offset[0], texture->offset[1]); |
|---|
| 267 | printf(" rotation: %f\n", texture->rotation); |
|---|
| 268 | printf(" tint_1: (%f, %f, %f)\n", |
|---|
| 269 | texture->tint_1[0], texture->tint_1[1], texture->tint_1[2]); |
|---|
| 270 | printf(" tint_2: (%f, %f, %f)\n", |
|---|
| 271 | texture->tint_2[0], texture->tint_2[1], texture->tint_2[2]); |
|---|
| 272 | printf(" tint_r: (%f, %f, %f)\n", |
|---|
| 273 | texture->tint_r[0], texture->tint_r[1], texture->tint_r[2]); |
|---|
| 274 | printf(" tint_g: (%f, %f, %f)\n", |
|---|
| 275 | texture->tint_g[0], texture->tint_g[1], texture->tint_g[2]); |
|---|
| 276 | printf(" tint_b: (%f, %f, %f)\n", |
|---|
| 277 | texture->tint_b[0], texture->tint_b[1], texture->tint_b[2]); |
|---|
| [8] | 278 | } |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | void |
|---|
| 285 | lib3ds_material_dump(Lib3dsMaterial *material) |
|---|
| 286 | { |
|---|
| [151] | 287 | ASSERT(material); |
|---|
| 288 | printf(" name: %s\n", material->name); |
|---|
| 289 | printf(" ambient: (%f, %f, %f)\n", |
|---|
| 290 | material->ambient[0], material->ambient[1], material->ambient[2]); |
|---|
| 291 | printf(" diffuse: (%f, %f, %f)\n", |
|---|
| 292 | material->diffuse[0], material->diffuse[1], material->diffuse[2]); |
|---|
| 293 | printf(" specular: (%f, %f, %f)\n", |
|---|
| 294 | material->specular[0], material->specular[1], material->specular[2]); |
|---|
| 295 | printf(" shininess: %f\n", material->shininess); |
|---|
| 296 | printf(" shin_strength: %f\n", material->shin_strength); |
|---|
| 297 | printf(" use_blur: %s\n", material->use_blur ? "yes" : "no"); |
|---|
| 298 | printf(" blur: %f\n", material->blur); |
|---|
| 299 | printf(" falloff: %f\n", material->falloff); |
|---|
| 300 | printf(" additive: %s\n", material->additive ? "yes" : "no"); |
|---|
| 301 | printf(" use_falloff: %s\n", material->use_falloff ? "yes" : "no"); |
|---|
| 302 | printf(" self_illum: %s\n", material->self_illum ? "yes" : "no"); |
|---|
| 303 | printf(" shading: %d\n", material->shading); |
|---|
| 304 | printf(" soften: %s\n", material->soften ? "yes" : "no"); |
|---|
| 305 | printf(" face_map: %s\n", material->face_map ? "yes" : "no"); |
|---|
| 306 | printf(" two_sided: %s\n", material->two_sided ? "yes" : "no"); |
|---|
| 307 | printf(" map_decal: %s\n", material->map_decal ? "yes" : "no"); |
|---|
| 308 | printf(" use_wire: %s\n", material->use_wire ? "yes" : "no"); |
|---|
| 309 | printf(" use_wire_abs: %s\n", material->use_wire_abs ? "yes" : "no"); |
|---|
| 310 | printf(" wire_size: %f\n", material->wire_size); |
|---|
| 311 | texture_dump("texture1_map", &material->texture1_map); |
|---|
| 312 | texture_dump("texture1_mask", &material->texture1_mask); |
|---|
| 313 | texture_dump("texture2_map", &material->texture2_map); |
|---|
| 314 | texture_dump("texture2_mask", &material->texture2_mask); |
|---|
| 315 | texture_dump("opacity_map", &material->opacity_map); |
|---|
| 316 | texture_dump("opacity_mask", &material->opacity_mask); |
|---|
| 317 | texture_dump("bump_map", &material->bump_map); |
|---|
| 318 | texture_dump("bump_mask", &material->bump_mask); |
|---|
| 319 | texture_dump("specular_map", &material->specular_map); |
|---|
| 320 | texture_dump("specular_mask", &material->specular_mask); |
|---|
| 321 | texture_dump("shininess_map", &material->shininess_map); |
|---|
| 322 | texture_dump("shininess_mask", &material->shininess_mask); |
|---|
| 323 | texture_dump("self_illum_map", &material->self_illum_map); |
|---|
| 324 | texture_dump("self_illum_mask", &material->self_illum_mask); |
|---|
| 325 | texture_dump("reflection_map", &material->reflection_map); |
|---|
| 326 | texture_dump("reflection_mask", &material->reflection_mask); |
|---|
| 327 | printf(" autorefl_map:\n"); |
|---|
| [576] | 328 | printf(" flags %X\n", static_cast<int>(material->autorefl_map.flags)); |
|---|
| 329 | printf(" level %X\n", static_cast<int>(material->autorefl_map.level)); |
|---|
| 330 | printf(" size %X\n", static_cast<int>(material->autorefl_map.size)); |
|---|
| 331 | printf(" frame_step %d\n", static_cast<int>(material->autorefl_map.frame_step)); |
|---|
| [151] | 332 | printf("\n"); |
|---|
| [8] | 333 | } |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | Lib3dsBool |
|---|
| [10076] | 340 | lib3ds_material_read(Lib3dsMaterial *material, iostream *strm) |
|---|
| [8] | 341 | { |
|---|
| [151] | 342 | Lib3dsChunk c; |
|---|
| 343 | Lib3dsWord chunk; |
|---|
| [8] | 344 | |
|---|
| [151] | 345 | ASSERT(material); |
|---|
| [10076] | 346 | if (!lib3ds_chunk_read_start(&c, LIB3DS_MAT_ENTRY, strm)) { |
|---|
| [151] | 347 | return(LIB3DS_FALSE); |
|---|
| 348 | } |
|---|
| [8] | 349 | |
|---|
| [10076] | 350 | while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { |
|---|
| [151] | 351 | switch (chunk) { |
|---|
| 352 | case LIB3DS_MAT_NAME: |
|---|
| [8] | 353 | { |
|---|
| [10076] | 354 | if (!lib3ds_string_read(material->name, 64, strm)) { |
|---|
| [151] | 355 | return(LIB3DS_FALSE); |
|---|
| 356 | } |
|---|
| 357 | lib3ds_chunk_dump_info(" NAME=%s", material->name); |
|---|
| [8] | 358 | } |
|---|
| [151] | 359 | break; |
|---|
| 360 | case LIB3DS_MAT_AMBIENT: |
|---|
| 361 | { |
|---|
| [10076] | 362 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 363 | if (!color_read(material->ambient, strm)) { |
|---|
| [151] | 364 | return(LIB3DS_FALSE); |
|---|
| 365 | } |
|---|
| 366 | } |
|---|
| 367 | break; |
|---|
| 368 | case LIB3DS_MAT_DIFFUSE: |
|---|
| 369 | { |
|---|
| [10076] | 370 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 371 | if (!color_read(material->diffuse, strm)) { |
|---|
| [151] | 372 | return(LIB3DS_FALSE); |
|---|
| 373 | } |
|---|
| 374 | } |
|---|
| 375 | break; |
|---|
| 376 | case LIB3DS_MAT_SPECULAR: |
|---|
| 377 | { |
|---|
| [10076] | 378 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 379 | if (!color_read(material->specular, strm)) { |
|---|
| [151] | 380 | return(LIB3DS_FALSE); |
|---|
| 381 | } |
|---|
| 382 | } |
|---|
| 383 | break; |
|---|
| 384 | case LIB3DS_MAT_SHININESS: |
|---|
| 385 | { |
|---|
| [10076] | 386 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 387 | if (!int_percentage_read(&material->shininess, strm)) { |
|---|
| [151] | 388 | return(LIB3DS_FALSE); |
|---|
| 389 | } |
|---|
| 390 | } |
|---|
| 391 | break; |
|---|
| 392 | case LIB3DS_MAT_SHIN2PCT: |
|---|
| 393 | { |
|---|
| [10076] | 394 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 395 | if (!int_percentage_read(&material->shin_strength, strm)) { |
|---|
| [151] | 396 | return(LIB3DS_FALSE); |
|---|
| 397 | } |
|---|
| 398 | } |
|---|
| 399 | break; |
|---|
| 400 | case LIB3DS_MAT_TRANSPARENCY: |
|---|
| 401 | { |
|---|
| [10076] | 402 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 403 | if (!int_percentage_read(&material->transparency, strm)) { |
|---|
| [151] | 404 | return(LIB3DS_FALSE); |
|---|
| 405 | } |
|---|
| 406 | } |
|---|
| 407 | break; |
|---|
| 408 | case LIB3DS_MAT_XPFALL: |
|---|
| 409 | { |
|---|
| [10076] | 410 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 411 | if (!int_percentage_read(&material->falloff, strm)) { |
|---|
| [151] | 412 | return(LIB3DS_FALSE); |
|---|
| 413 | } |
|---|
| 414 | } |
|---|
| 415 | break; |
|---|
| 416 | case LIB3DS_MAT_USE_XPFALL: |
|---|
| 417 | { |
|---|
| 418 | material->use_falloff=LIB3DS_TRUE; |
|---|
| 419 | } |
|---|
| 420 | break; |
|---|
| 421 | case LIB3DS_MAT_REFBLUR: |
|---|
| 422 | { |
|---|
| [10076] | 423 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 424 | if (!int_percentage_read(&material->blur, strm)) { |
|---|
| [151] | 425 | return(LIB3DS_FALSE); |
|---|
| 426 | } |
|---|
| 427 | } |
|---|
| 428 | break; |
|---|
| 429 | case LIB3DS_MAT_USE_REFBLUR: |
|---|
| 430 | { |
|---|
| 431 | material->use_blur=LIB3DS_TRUE; |
|---|
| 432 | } |
|---|
| 433 | break; |
|---|
| 434 | case LIB3DS_MAT_SHADING: |
|---|
| 435 | { |
|---|
| [10076] | 436 | material->shading=lib3ds_intw_read(strm); |
|---|
| [151] | 437 | } |
|---|
| 438 | break; |
|---|
| 439 | case LIB3DS_MAT_SELF_ILLUM: |
|---|
| 440 | { |
|---|
| 441 | material->self_illum=LIB3DS_TRUE; |
|---|
| 442 | } |
|---|
| 443 | break; |
|---|
| 444 | case LIB3DS_MAT_TWO_SIDE: |
|---|
| 445 | { |
|---|
| 446 | material->two_sided=LIB3DS_TRUE; |
|---|
| 447 | } |
|---|
| 448 | break; |
|---|
| 449 | case LIB3DS_MAT_DECAL: |
|---|
| 450 | { |
|---|
| 451 | material->map_decal=LIB3DS_TRUE; |
|---|
| 452 | } |
|---|
| 453 | break; |
|---|
| 454 | case LIB3DS_MAT_ADDITIVE: |
|---|
| 455 | { |
|---|
| 456 | material->additive=LIB3DS_TRUE; |
|---|
| 457 | } |
|---|
| 458 | break; |
|---|
| 459 | case LIB3DS_MAT_FACEMAP: |
|---|
| 460 | { |
|---|
| 461 | material->face_map=LIB3DS_TRUE; |
|---|
| 462 | } |
|---|
| 463 | break; |
|---|
| 464 | case LIB3DS_MAT_PHONGSOFT: |
|---|
| 465 | { |
|---|
| 466 | material->soften=LIB3DS_TRUE; |
|---|
| 467 | } |
|---|
| 468 | break; |
|---|
| 469 | case LIB3DS_MAT_WIRE: |
|---|
| 470 | { |
|---|
| 471 | material->use_wire=LIB3DS_TRUE; |
|---|
| 472 | } |
|---|
| 473 | break; |
|---|
| 474 | case LIB3DS_MAT_WIREABS: |
|---|
| 475 | { |
|---|
| 476 | material->use_wire_abs=LIB3DS_TRUE; |
|---|
| 477 | } |
|---|
| 478 | break; |
|---|
| 479 | case LIB3DS_MAT_WIRE_SIZE: |
|---|
| 480 | { |
|---|
| [10076] | 481 | material->wire_size=lib3ds_float_read(strm); |
|---|
| [151] | 482 | } |
|---|
| 483 | break; |
|---|
| 484 | case LIB3DS_MAT_TEXMAP: |
|---|
| 485 | { |
|---|
| [10076] | 486 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 487 | if (!texture_map_read(&material->texture1_map, strm)) { |
|---|
| [151] | 488 | return(LIB3DS_FALSE); |
|---|
| 489 | } |
|---|
| 490 | } |
|---|
| 491 | break; |
|---|
| 492 | case LIB3DS_MAT_TEXMASK: |
|---|
| 493 | { |
|---|
| [10076] | 494 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 495 | if (!texture_map_read(&material->texture1_mask, strm)) { |
|---|
| [151] | 496 | return(LIB3DS_FALSE); |
|---|
| 497 | } |
|---|
| 498 | } |
|---|
| 499 | break; |
|---|
| 500 | case LIB3DS_MAT_TEX2MAP: |
|---|
| 501 | { |
|---|
| [10076] | 502 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 503 | if (!texture_map_read(&material->texture2_map, strm)) { |
|---|
| [151] | 504 | return(LIB3DS_FALSE); |
|---|
| 505 | } |
|---|
| 506 | } |
|---|
| 507 | break; |
|---|
| 508 | case LIB3DS_MAT_TEX2MASK: |
|---|
| 509 | { |
|---|
| [10076] | 510 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 511 | if (!texture_map_read(&material->texture2_mask, strm)) { |
|---|
| [151] | 512 | return(LIB3DS_FALSE); |
|---|
| 513 | } |
|---|
| 514 | } |
|---|
| 515 | break; |
|---|
| 516 | case LIB3DS_MAT_OPACMAP: |
|---|
| 517 | { |
|---|
| [10076] | 518 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 519 | if (!texture_map_read(&material->opacity_map, strm)) { |
|---|
| [151] | 520 | return(LIB3DS_FALSE); |
|---|
| 521 | } |
|---|
| 522 | } |
|---|
| 523 | break; |
|---|
| 524 | case LIB3DS_MAT_OPACMASK: |
|---|
| 525 | { |
|---|
| [10076] | 526 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 527 | if (!texture_map_read(&material->opacity_mask, strm)) { |
|---|
| [151] | 528 | return(LIB3DS_FALSE); |
|---|
| 529 | } |
|---|
| 530 | } |
|---|
| 531 | break; |
|---|
| 532 | case LIB3DS_MAT_BUMPMAP: |
|---|
| 533 | { |
|---|
| [10076] | 534 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 535 | if (!texture_map_read(&material->bump_map, strm)) { |
|---|
| [151] | 536 | return(LIB3DS_FALSE); |
|---|
| 537 | } |
|---|
| 538 | } |
|---|
| 539 | break; |
|---|
| 540 | case LIB3DS_MAT_BUMPMASK: |
|---|
| 541 | { |
|---|
| [10076] | 542 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 543 | if (!texture_map_read(&material->bump_mask, strm)) { |
|---|
| [151] | 544 | return(LIB3DS_FALSE); |
|---|
| 545 | } |
|---|
| 546 | } |
|---|
| 547 | break; |
|---|
| 548 | case LIB3DS_MAT_SPECMAP: |
|---|
| 549 | { |
|---|
| [10076] | 550 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 551 | if (!texture_map_read(&material->specular_map, strm)) { |
|---|
| [151] | 552 | return(LIB3DS_FALSE); |
|---|
| 553 | } |
|---|
| 554 | } |
|---|
| 555 | break; |
|---|
| 556 | case LIB3DS_MAT_SPECMASK: |
|---|
| 557 | { |
|---|
| [10076] | 558 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 559 | if (!texture_map_read(&material->specular_mask, strm)) { |
|---|
| [151] | 560 | return(LIB3DS_FALSE); |
|---|
| 561 | } |
|---|
| 562 | } |
|---|
| 563 | break; |
|---|
| 564 | case LIB3DS_MAT_SHINMAP: |
|---|
| 565 | { |
|---|
| [10076] | 566 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 567 | if (!texture_map_read(&material->shininess_map, strm)) { |
|---|
| [151] | 568 | return(LIB3DS_FALSE); |
|---|
| 569 | } |
|---|
| 570 | } |
|---|
| 571 | break; |
|---|
| 572 | case LIB3DS_MAT_SHINMASK: |
|---|
| 573 | { |
|---|
| [10076] | 574 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 575 | if (!texture_map_read(&material->shininess_mask, strm)) { |
|---|
| [151] | 576 | return(LIB3DS_FALSE); |
|---|
| 577 | } |
|---|
| 578 | } |
|---|
| 579 | break; |
|---|
| 580 | case LIB3DS_MAT_SELFIMAP: |
|---|
| 581 | { |
|---|
| [10076] | 582 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 583 | if (!texture_map_read(&material->self_illum_map, strm)) { |
|---|
| [151] | 584 | return(LIB3DS_FALSE); |
|---|
| 585 | } |
|---|
| 586 | } |
|---|
| 587 | break; |
|---|
| 588 | case LIB3DS_MAT_SELFIMASK: |
|---|
| 589 | { |
|---|
| [10076] | 590 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 591 | if (!texture_map_read(&material->self_illum_mask, strm)) { |
|---|
| [151] | 592 | return(LIB3DS_FALSE); |
|---|
| 593 | } |
|---|
| 594 | } |
|---|
| 595 | break; |
|---|
| 596 | case LIB3DS_MAT_REFLMAP: |
|---|
| 597 | { |
|---|
| [10076] | 598 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 599 | if (!texture_map_read(&material->reflection_map, strm)) { |
|---|
| [151] | 600 | return(LIB3DS_FALSE); |
|---|
| 601 | } |
|---|
| 602 | } |
|---|
| 603 | break; |
|---|
| 604 | case LIB3DS_MAT_REFLMASK: |
|---|
| 605 | { |
|---|
| [10076] | 606 | lib3ds_chunk_read_reset(&c, strm); |
|---|
| 607 | if (!texture_map_read(&material->reflection_mask, strm)) { |
|---|
| [151] | 608 | return(LIB3DS_FALSE); |
|---|
| 609 | } |
|---|
| 610 | } |
|---|
| 611 | break; |
|---|
| 612 | case LIB3DS_MAT_ACUBIC: |
|---|
| 613 | { |
|---|
| [10076] | 614 | lib3ds_intb_read(strm); |
|---|
| 615 | material->autorefl_map.level=lib3ds_intb_read(strm); |
|---|
| 616 | material->autorefl_map.flags=lib3ds_intw_read(strm); |
|---|
| 617 | material->autorefl_map.size=lib3ds_intd_read(strm); |
|---|
| 618 | material->autorefl_map.frame_step=lib3ds_intd_read(strm); |
|---|
| [151] | 619 | } |
|---|
| 620 | break; |
|---|
| 621 | default: |
|---|
| 622 | lib3ds_chunk_unknown(chunk); |
|---|
| [8] | 623 | } |
|---|
| [151] | 624 | } |
|---|
| [8] | 625 | |
|---|
| [10076] | 626 | lib3ds_chunk_read_end(&c, strm); |
|---|
| [151] | 627 | return(LIB3DS_TRUE); |
|---|
| [8] | 628 | } |
|---|
| 629 | |
|---|
| 630 | |
|---|
| 631 | static Lib3dsBool |
|---|
| [10076] | 632 | color_write(Lib3dsRgba rgb, iostream *strm) |
|---|
| [8] | 633 | { |
|---|
| [151] | 634 | Lib3dsChunk c; |
|---|
| [8] | 635 | |
|---|
| [151] | 636 | c.chunk=LIB3DS_COLOR_24; |
|---|
| 637 | c.size=9; |
|---|
| [10076] | 638 | lib3ds_chunk_write(&c,strm); |
|---|
| 639 | lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[0]+0.5),strm); |
|---|
| 640 | lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[1]+0.5),strm); |
|---|
| 641 | lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[2]+0.5),strm); |
|---|
| [8] | 642 | |
|---|
| [151] | 643 | c.chunk=LIB3DS_LIN_COLOR_24; |
|---|
| 644 | c.size=9; |
|---|
| [10076] | 645 | lib3ds_chunk_write(&c,strm); |
|---|
| 646 | lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[0]+0.5),strm); |
|---|
| 647 | lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[1]+0.5),strm); |
|---|
| 648 | lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[2]+0.5),strm); |
|---|
| [8] | 649 | |
|---|
| [151] | 650 | return(LIB3DS_TRUE); |
|---|
| [8] | 651 | } |
|---|
| 652 | |
|---|
| 653 | |
|---|
| 654 | static Lib3dsBool |
|---|
| [10076] | 655 | int_percentage_write(Lib3dsFloat p, iostream *strm) |
|---|
| [8] | 656 | { |
|---|
| [151] | 657 | Lib3dsChunk c; |
|---|
| [8] | 658 | |
|---|
| [151] | 659 | c.chunk=LIB3DS_INT_PERCENTAGE; |
|---|
| 660 | c.size=8; |
|---|
| [10076] | 661 | lib3ds_chunk_write(&c,strm); |
|---|
| 662 | lib3ds_intw_write((Lib3dsByte)floor(100.0*p+0.5),strm); |
|---|
| [8] | 663 | |
|---|
| [151] | 664 | return(LIB3DS_TRUE); |
|---|
| [8] | 665 | } |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | static Lib3dsBool |
|---|
| [10076] | 669 | texture_map_write(Lib3dsWord chunk, Lib3dsTextureMap *map, iostream *strm) |
|---|
| [8] | 670 | { |
|---|
| [151] | 671 | Lib3dsChunk c; |
|---|
| [8] | 672 | |
|---|
| [151] | 673 | if (strlen(map->name)==0) { |
|---|
| 674 | return(LIB3DS_TRUE); |
|---|
| 675 | } |
|---|
| 676 | c.chunk=chunk; |
|---|
| [10076] | 677 | if (!lib3ds_chunk_write_start(&c,strm)) { |
|---|
| [151] | 678 | return(LIB3DS_FALSE); |
|---|
| 679 | } |
|---|
| 680 | |
|---|
| [10076] | 681 | int_percentage_write(map->percent,strm); |
|---|
| [8] | 682 | |
|---|
| [151] | 683 | { |
|---|
| 684 | Lib3dsChunk c; |
|---|
| 685 | c.chunk=LIB3DS_MAT_MAPNAME; |
|---|
| 686 | c.size=6+strlen(map->name)+1; |
|---|
| [10076] | 687 | lib3ds_chunk_write(&c,strm); |
|---|
| 688 | lib3ds_string_write(map->name,strm); |
|---|
| [151] | 689 | } |
|---|
| [8] | 690 | |
|---|
| [151] | 691 | { |
|---|
| 692 | Lib3dsChunk c; |
|---|
| 693 | c.chunk=LIB3DS_MAT_MAP_TILING; |
|---|
| 694 | c.size=8; |
|---|
| [10076] | 695 | lib3ds_chunk_write(&c,strm); |
|---|
| 696 | lib3ds_word_write((Lib3dsWord)map->flags,strm); |
|---|
| [151] | 697 | } |
|---|
| 698 | |
|---|
| 699 | { |
|---|
| 700 | Lib3dsChunk c; |
|---|
| 701 | c.chunk=LIB3DS_MAT_MAP_TEXBLUR; |
|---|
| 702 | c.size=10; |
|---|
| [10076] | 703 | lib3ds_chunk_write(&c,strm); |
|---|
| 704 | lib3ds_float_write(map->blur,strm); |
|---|
| [151] | 705 | } |
|---|
| [8] | 706 | |
|---|
| [151] | 707 | { |
|---|
| 708 | Lib3dsChunk c; |
|---|
| 709 | c.chunk=LIB3DS_MAT_MAP_USCALE; |
|---|
| 710 | c.size=10; |
|---|
| [10076] | 711 | lib3ds_chunk_write(&c,strm); |
|---|
| 712 | lib3ds_float_write(map->scale[0],strm); |
|---|
| [151] | 713 | } |
|---|
| [8] | 714 | |
|---|
| [151] | 715 | { |
|---|
| 716 | Lib3dsChunk c; |
|---|
| 717 | c.chunk=LIB3DS_MAT_MAP_VSCALE; |
|---|
| 718 | c.size=10; |
|---|
| [10076] | 719 | lib3ds_chunk_write(&c,strm); |
|---|
| 720 | lib3ds_float_write(map->scale[1],strm); |
|---|
| [151] | 721 | } |
|---|
| [8] | 722 | |
|---|
| [151] | 723 | { |
|---|
| 724 | Lib3dsChunk c; |
|---|
| 725 | c.chunk=LIB3DS_MAT_MAP_UOFFSET; |
|---|
| 726 | c.size=10; |
|---|
| [10076] | 727 | lib3ds_chunk_write(&c,strm); |
|---|
| 728 | lib3ds_float_write(map->offset[0],strm); |
|---|
| [151] | 729 | } |
|---|
| [8] | 730 | |
|---|
| [151] | 731 | { |
|---|
| 732 | Lib3dsChunk c; |
|---|
| 733 | c.chunk=LIB3DS_MAT_MAP_VOFFSET; |
|---|
| 734 | c.size=10; |
|---|
| [10076] | 735 | lib3ds_chunk_write(&c,strm); |
|---|
| 736 | lib3ds_float_write(map->offset[1],strm); |
|---|
| [151] | 737 | } |
|---|
| [8] | 738 | |
|---|
| [151] | 739 | { |
|---|
| 740 | Lib3dsChunk c; |
|---|
| 741 | c.chunk=LIB3DS_MAT_MAP_ANG; |
|---|
| 742 | c.size=10; |
|---|
| [10076] | 743 | lib3ds_chunk_write(&c,strm); |
|---|
| 744 | lib3ds_float_write(map->rotation,strm); |
|---|
| [151] | 745 | } |
|---|
| [8] | 746 | |
|---|
| [151] | 747 | { |
|---|
| 748 | Lib3dsChunk c; |
|---|
| 749 | c.chunk=LIB3DS_MAT_MAP_COL1; |
|---|
| 750 | c.size=9; |
|---|
| [10076] | 751 | lib3ds_chunk_write(&c,strm); |
|---|
| 752 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_1[0]+0.5), strm); |
|---|
| 753 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_1[1]+0.5), strm); |
|---|
| 754 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_1[2]+0.5), strm); |
|---|
| [151] | 755 | } |
|---|
| [8] | 756 | |
|---|
| [151] | 757 | { |
|---|
| 758 | Lib3dsChunk c; |
|---|
| 759 | c.chunk=LIB3DS_MAT_MAP_COL2; |
|---|
| 760 | c.size=9; |
|---|
| [10076] | 761 | lib3ds_chunk_write(&c,strm); |
|---|
| 762 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_2[0]+0.5), strm); |
|---|
| 763 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_2[1]+0.5), strm); |
|---|
| 764 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_2[2]+0.5), strm); |
|---|
| [151] | 765 | } |
|---|
| 766 | |
|---|
| 767 | { |
|---|
| 768 | Lib3dsChunk c; |
|---|
| 769 | c.chunk=LIB3DS_MAT_MAP_RCOL; |
|---|
| 770 | c.size=9; |
|---|
| [10076] | 771 | lib3ds_chunk_write(&c,strm); |
|---|
| 772 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_r[0]+0.5), strm); |
|---|
| 773 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_r[1]+0.5), strm); |
|---|
| 774 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_r[2]+0.5), strm); |
|---|
| [151] | 775 | } |
|---|
| [8] | 776 | |
|---|
| [151] | 777 | { |
|---|
| 778 | Lib3dsChunk c; |
|---|
| 779 | c.chunk=LIB3DS_MAT_MAP_GCOL; |
|---|
| 780 | c.size=9; |
|---|
| [10076] | 781 | lib3ds_chunk_write(&c,strm); |
|---|
| 782 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_g[0]+0.5), strm); |
|---|
| 783 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_g[1]+0.5), strm); |
|---|
| 784 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_g[2]+0.5), strm); |
|---|
| [151] | 785 | } |
|---|
| 786 | |
|---|
| 787 | { |
|---|
| 788 | Lib3dsChunk c; |
|---|
| 789 | c.chunk=LIB3DS_MAT_MAP_BCOL; |
|---|
| 790 | c.size=9; |
|---|
| [10076] | 791 | lib3ds_chunk_write(&c,strm); |
|---|
| 792 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_b[0]+0.5), strm); |
|---|
| 793 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_b[1]+0.5), strm); |
|---|
| 794 | lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_b[2]+0.5), strm); |
|---|
| [151] | 795 | } |
|---|
| [8] | 796 | |
|---|
| [10076] | 797 | if (!lib3ds_chunk_write_end(&c,strm)) { |
|---|
| [151] | 798 | return(LIB3DS_FALSE); |
|---|
| 799 | } |
|---|
| 800 | return(LIB3DS_TRUE); |
|---|
| [8] | 801 | } |
|---|
| 802 | |
|---|
| 803 | |
|---|
| 804 | |
|---|
| 805 | |
|---|
| 806 | |
|---|
| 807 | Lib3dsBool |
|---|
| [10076] | 808 | lib3ds_material_write(Lib3dsMaterial *material, iostream *strm) |
|---|
| [8] | 809 | { |
|---|
| [151] | 810 | Lib3dsChunk c; |
|---|
| [8] | 811 | |
|---|
| [151] | 812 | c.chunk=LIB3DS_MAT_ENTRY; |
|---|
| [10076] | 813 | if (!lib3ds_chunk_write_start(&c,strm)) { |
|---|
| [151] | 814 | return(LIB3DS_FALSE); |
|---|
| 815 | } |
|---|
| [8] | 816 | |
|---|
| [151] | 817 | { |
|---|
| 818 | Lib3dsChunk c; |
|---|
| 819 | c.chunk=LIB3DS_MAT_NAME; |
|---|
| 820 | c.size=6+strlen(material->name)+1; |
|---|
| [10076] | 821 | lib3ds_chunk_write(&c,strm); |
|---|
| 822 | lib3ds_string_write(material->name,strm); |
|---|
| [151] | 823 | } |
|---|
| [8] | 824 | |
|---|
| [151] | 825 | { |
|---|
| 826 | Lib3dsChunk c; |
|---|
| 827 | c.chunk=LIB3DS_MAT_AMBIENT; |
|---|
| 828 | c.size=24; |
|---|
| [10076] | 829 | lib3ds_chunk_write(&c,strm); |
|---|
| 830 | color_write(material->ambient,strm); |
|---|
| [151] | 831 | } |
|---|
| [8] | 832 | |
|---|
| [151] | 833 | { |
|---|
| 834 | Lib3dsChunk c; |
|---|
| 835 | c.chunk=LIB3DS_MAT_DIFFUSE; |
|---|
| 836 | c.size=24; |
|---|
| [10076] | 837 | lib3ds_chunk_write(&c,strm); |
|---|
| 838 | color_write(material->diffuse,strm); |
|---|
| [151] | 839 | } |
|---|
| [8] | 840 | |
|---|
| [151] | 841 | { |
|---|
| 842 | Lib3dsChunk c; |
|---|
| 843 | c.chunk=LIB3DS_MAT_SPECULAR; |
|---|
| 844 | c.size=24; |
|---|
| [10076] | 845 | lib3ds_chunk_write(&c,strm); |
|---|
| 846 | color_write(material->specular,strm); |
|---|
| [151] | 847 | } |
|---|
| [8] | 848 | |
|---|
| [151] | 849 | { |
|---|
| 850 | Lib3dsChunk c; |
|---|
| 851 | c.chunk=LIB3DS_MAT_SHININESS; |
|---|
| 852 | c.size=14; |
|---|
| [10076] | 853 | lib3ds_chunk_write(&c,strm); |
|---|
| 854 | int_percentage_write(material->shininess,strm); |
|---|
| [151] | 855 | } |
|---|
| [8] | 856 | |
|---|
| [151] | 857 | { |
|---|
| 858 | Lib3dsChunk c; |
|---|
| 859 | c.chunk=LIB3DS_MAT_SHIN2PCT; |
|---|
| 860 | c.size=14; |
|---|
| [10076] | 861 | lib3ds_chunk_write(&c,strm); |
|---|
| 862 | int_percentage_write(material->shin_strength,strm); |
|---|
| [151] | 863 | } |
|---|
| [8] | 864 | |
|---|
| [151] | 865 | { |
|---|
| 866 | Lib3dsChunk c; |
|---|
| 867 | c.chunk=LIB3DS_MAT_TRANSPARENCY; |
|---|
| 868 | c.size=14; |
|---|
| [10076] | 869 | lib3ds_chunk_write(&c,strm); |
|---|
| 870 | int_percentage_write(material->transparency,strm); |
|---|
| [151] | 871 | } |
|---|
| [8] | 872 | |
|---|
| [151] | 873 | { |
|---|
| 874 | Lib3dsChunk c; |
|---|
| 875 | c.chunk=LIB3DS_MAT_XPFALL; |
|---|
| 876 | c.size=14; |
|---|
| [10076] | 877 | lib3ds_chunk_write(&c,strm); |
|---|
| 878 | int_percentage_write(material->falloff,strm); |
|---|
| [151] | 879 | } |
|---|
| [8] | 880 | |
|---|
| [151] | 881 | if (material->use_falloff) { |
|---|
| 882 | Lib3dsChunk c; |
|---|
| 883 | c.chunk=LIB3DS_MAT_USE_XPFALL; |
|---|
| 884 | c.size=6; |
|---|
| [10076] | 885 | lib3ds_chunk_write(&c,strm); |
|---|
| [151] | 886 | } |
|---|
| [8] | 887 | |
|---|
| [151] | 888 | { |
|---|
| 889 | Lib3dsChunk c; |
|---|
| 890 | c.chunk=LIB3DS_MAT_SHADING; |
|---|
| 891 | c.size=8; |
|---|
| [10076] | 892 | lib3ds_chunk_write(&c,strm); |
|---|
| 893 | lib3ds_intw_write(material->shading,strm); |
|---|
| [151] | 894 | } |
|---|
| [8] | 895 | |
|---|
| [151] | 896 | { |
|---|
| 897 | Lib3dsChunk c; |
|---|
| 898 | c.chunk=LIB3DS_MAT_REFBLUR; |
|---|
| 899 | c.size=14; |
|---|
| [10076] | 900 | lib3ds_chunk_write(&c,strm); |
|---|
| 901 | int_percentage_write(material->blur,strm); |
|---|
| [151] | 902 | } |
|---|
| [8] | 903 | |
|---|
| [151] | 904 | if (material->use_blur) { |
|---|
| 905 | Lib3dsChunk c; |
|---|
| 906 | c.chunk=LIB3DS_MAT_USE_REFBLUR; |
|---|
| 907 | c.size=6; |
|---|
| [10076] | 908 | lib3ds_chunk_write(&c,strm); |
|---|
| [151] | 909 | } |
|---|
| [8] | 910 | |
|---|
| [151] | 911 | if (material->self_illum) { |
|---|
| 912 | Lib3dsChunk c; |
|---|
| 913 | c.chunk=LIB3DS_MAT_SELF_ILLUM; |
|---|
| 914 | c.size=6; |
|---|
| [10076] | 915 | lib3ds_chunk_write(&c,strm); |
|---|
| [151] | 916 | } |
|---|
| [8] | 917 | |
|---|
| [151] | 918 | if (material->two_sided) { |
|---|
| 919 | Lib3dsChunk c; |
|---|
| 920 | c.chunk=LIB3DS_MAT_TWO_SIDE; |
|---|
| 921 | c.size=6; |
|---|
| [10076] | 922 | lib3ds_chunk_write(&c,strm); |
|---|
| [151] | 923 | } |
|---|
| 924 | |
|---|
| 925 | if (material->map_decal) { |
|---|
| 926 | Lib3dsChunk c; |
|---|
| 927 | c.chunk=LIB3DS_MAT_DECAL; |
|---|
| 928 | c.size=6; |
|---|
| [10076] | 929 | lib3ds_chunk_write(&c,strm); |
|---|
| [151] | 930 | } |
|---|
| [8] | 931 | |
|---|
| [151] | 932 | if (material->additive) { |
|---|
| 933 | Lib3dsChunk c; |
|---|
| 934 | c.chunk=LIB3DS_MAT_ADDITIVE; |
|---|
| 935 | c.size=6; |
|---|
| [10076] | 936 | lib3ds_chunk_write(&c,strm); |
|---|
| [151] | 937 | } |
|---|
| [8] | 938 | |
|---|
| [151] | 939 | if (material->use_wire) { |
|---|
| 940 | Lib3dsChunk c; |
|---|
| 941 | c.chunk=LIB3DS_MAT_WIRE; |
|---|
| 942 | c.size=6; |
|---|
| [10076] | 943 | lib3ds_chunk_write(&c,strm); |
|---|
| [151] | 944 | } |
|---|
| [8] | 945 | |
|---|
| [151] | 946 | if (material->use_wire_abs) { |
|---|
| 947 | Lib3dsChunk c; |
|---|
| 948 | c.chunk=LIB3DS_MAT_WIREABS; |
|---|
| 949 | c.size=6; |
|---|
| [10076] | 950 | lib3ds_chunk_write(&c,strm); |
|---|
| [151] | 951 | } |
|---|
| [8] | 952 | |
|---|
| [151] | 953 | { |
|---|
| 954 | Lib3dsChunk c; |
|---|
| 955 | c.chunk=LIB3DS_MAT_WIRE_SIZE; |
|---|
| 956 | c.size=10; |
|---|
| [10076] | 957 | lib3ds_chunk_write(&c,strm); |
|---|
| 958 | lib3ds_float_write(material->wire_size,strm); |
|---|
| [151] | 959 | } |
|---|
| [8] | 960 | |
|---|
| [151] | 961 | if (material->face_map) { |
|---|
| 962 | Lib3dsChunk c; |
|---|
| 963 | c.chunk=LIB3DS_MAT_FACEMAP; |
|---|
| 964 | c.size=6; |
|---|
| [10076] | 965 | lib3ds_chunk_write(&c,strm); |
|---|
| [151] | 966 | } |
|---|
| [8] | 967 | |
|---|
| [151] | 968 | if (material->soften) { |
|---|
| 969 | Lib3dsChunk c; |
|---|
| 970 | c.chunk=LIB3DS_MAT_PHONGSOFT; |
|---|
| 971 | c.size=6; |
|---|
| [10076] | 972 | lib3ds_chunk_write(&c,strm); |
|---|
| [151] | 973 | } |
|---|
| [8] | 974 | |
|---|
| [10076] | 975 | if (!texture_map_write(LIB3DS_MAT_TEXMAP, &material->texture1_map, strm)) { |
|---|
| [151] | 976 | return(LIB3DS_FALSE); |
|---|
| 977 | } |
|---|
| [10076] | 978 | if (!texture_map_write(LIB3DS_MAT_TEXMASK, &material->texture1_mask, strm)) { |
|---|
| [151] | 979 | return(LIB3DS_FALSE); |
|---|
| 980 | } |
|---|
| [10076] | 981 | if (!texture_map_write(LIB3DS_MAT_TEX2MAP, &material->texture2_map, strm)) { |
|---|
| [151] | 982 | return(LIB3DS_FALSE); |
|---|
| 983 | } |
|---|
| [10076] | 984 | if (!texture_map_write(LIB3DS_MAT_TEX2MASK, &material->texture2_mask, strm)) { |
|---|
| [151] | 985 | return(LIB3DS_FALSE); |
|---|
| 986 | } |
|---|
| [10076] | 987 | if (!texture_map_write(LIB3DS_MAT_OPACMAP, &material->opacity_map, strm)) { |
|---|
| [151] | 988 | return(LIB3DS_FALSE); |
|---|
| 989 | } |
|---|
| [10076] | 990 | if (!texture_map_write(LIB3DS_MAT_OPACMASK, &material->opacity_mask, strm)) { |
|---|
| [151] | 991 | return(LIB3DS_FALSE); |
|---|
| 992 | } |
|---|
| [10076] | 993 | if (!texture_map_write(LIB3DS_MAT_BUMPMAP, &material->bump_map, strm)) { |
|---|
| [151] | 994 | return(LIB3DS_FALSE); |
|---|
| 995 | } |
|---|
| [10076] | 996 | if (!texture_map_write(LIB3DS_MAT_BUMPMASK, &material->bump_mask, strm)) { |
|---|
| [151] | 997 | return(LIB3DS_FALSE); |
|---|
| 998 | } |
|---|
| [10076] | 999 | if (!texture_map_write(LIB3DS_MAT_SPECMAP, &material->specular_map, strm)) { |
|---|
| [151] | 1000 | return(LIB3DS_FALSE); |
|---|
| 1001 | } |
|---|
| [10076] | 1002 | if (!texture_map_write(LIB3DS_MAT_SPECMASK, &material->specular_mask, strm)) { |
|---|
| [151] | 1003 | return(LIB3DS_FALSE); |
|---|
| 1004 | } |
|---|
| [10076] | 1005 | if (!texture_map_write(LIB3DS_MAT_SHINMAP, &material->shininess_map, strm)) { |
|---|
| [151] | 1006 | return(LIB3DS_FALSE); |
|---|
| 1007 | } |
|---|
| [10076] | 1008 | if (!texture_map_write(LIB3DS_MAT_SHINMASK, &material->shininess_mask, strm)) { |
|---|
| [151] | 1009 | return(LIB3DS_FALSE); |
|---|
| 1010 | } |
|---|
| [10076] | 1011 | if (!texture_map_write(LIB3DS_MAT_SELFIMAP, &material->self_illum_map, strm)) { |
|---|
| [151] | 1012 | return(LIB3DS_FALSE); |
|---|
| 1013 | } |
|---|
| [10076] | 1014 | if (!texture_map_write(LIB3DS_MAT_SELFIMASK, &material->self_illum_mask, strm)) { |
|---|
| [151] | 1015 | return(LIB3DS_FALSE); |
|---|
| 1016 | } |
|---|
| [10076] | 1017 | if (!texture_map_write(LIB3DS_MAT_REFLMAP, &material->reflection_map, strm)) { |
|---|
| [151] | 1018 | return(LIB3DS_FALSE); |
|---|
| 1019 | } |
|---|
| [10076] | 1020 | if (!texture_map_write(LIB3DS_MAT_REFLMASK, &material->reflection_mask, strm)) { |
|---|
| [151] | 1021 | return(LIB3DS_FALSE); |
|---|
| 1022 | } |
|---|
| [8] | 1023 | |
|---|
| [10076] | 1024 | if (!lib3ds_chunk_write_end(&c,strm)) { |
|---|
| [151] | 1025 | return(LIB3DS_FALSE); |
|---|
| 1026 | } |
|---|
| 1027 | return(LIB3DS_TRUE); |
|---|
| [8] | 1028 | } |
|---|
| 1029 | |
|---|
| 1030 | |
|---|
| 1031 | |
|---|
| 1032 | |
|---|
| 1033 | |
|---|
| 1034 | |
|---|
| 1035 | |
|---|
| 1036 | |
|---|
| 1037 | |
|---|