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