Changeset 10076 for OpenSceneGraph/trunk/src/osgPlugins/3ds/material.cpp
- Timestamp:
- 04/22/09 17:46:24 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/3ds/material.cpp
r7057 r10076 68 68 69 69 static Lib3dsBool 70 color_read(Lib3dsRgba rgb, FILE *f)70 color_read(Lib3dsRgba rgb, iostream *strm) 71 71 { 72 72 Lib3dsChunk c; … … 74 74 Lib3dsBool have_lin=LIB3DS_FALSE; 75 75 76 if (!lib3ds_chunk_read_start(&c, 0, f)) {77 return(LIB3DS_FALSE); 78 } 79 80 while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {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 81 switch (chunk) { 82 82 case LIB3DS_LIN_COLOR_24: … … 84 84 int i; 85 85 for (i=0; i<3; ++i) { 86 rgb[i]=1.0f*lib3ds_byte_read( f)/255.0f;86 rgb[i]=1.0f*lib3ds_byte_read(strm)/255.0f; 87 87 } 88 88 rgb[3]=1.0f; … … 96 96 int i; 97 97 for (i=0; i<3; ++i) { 98 rgb[i]=1.0f*lib3ds_byte_read( f)/255.0f;98 rgb[i]=1.0f*lib3ds_byte_read(strm)/255.0f; 99 99 } 100 100 rgb[3]=1.0f; … … 103 103 case LIB3DS_COLOR_F: 104 104 // sth: this will fix 3ds-files exported from cinema 4d 105 lib3ds_rgb_read(rgb, f);105 lib3ds_rgb_read(rgb, strm); 106 106 break; 107 107 default: … … 110 110 } 111 111 112 lib3ds_chunk_read_end(&c, f);112 lib3ds_chunk_read_end(&c, strm); 113 113 return(LIB3DS_TRUE); 114 114 } … … 116 116 117 117 static Lib3dsBool 118 int_percentage_read(Lib3dsFloat *p, FILE *f)118 int_percentage_read(Lib3dsFloat *p, iostream *strm) 119 119 { 120 120 Lib3dsChunk c; 121 121 Lib3dsWord chunk; 122 122 123 if (!lib3ds_chunk_read_start(&c, 0, f)) {124 return(LIB3DS_FALSE); 125 } 126 127 while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {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 128 switch (chunk) { 129 129 case LIB3DS_INT_PERCENTAGE: 130 130 { 131 Lib3dsIntw i=lib3ds_intw_read( f);131 Lib3dsIntw i=lib3ds_intw_read(strm); 132 132 *p=(Lib3dsFloat)(1.0*i/100.0); 133 133 } … … 138 138 } 139 139 140 lib3ds_chunk_read_end(&c, f);140 lib3ds_chunk_read_end(&c, strm); 141 141 return(LIB3DS_TRUE); 142 142 } … … 144 144 145 145 static Lib3dsBool 146 texture_map_read(Lib3dsTextureMap *map, FILE *f)146 texture_map_read(Lib3dsTextureMap *map, iostream *strm) 147 147 { 148 148 Lib3dsChunk c; 149 149 Lib3dsWord chunk; 150 150 151 if (!lib3ds_chunk_read_start(&c, 0, f)) {152 return(LIB3DS_FALSE); 153 } 154 155 while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {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 156 switch (chunk) { 157 157 case LIB3DS_INT_PERCENTAGE: 158 158 { 159 map->percent=1.0f*lib3ds_intw_read( f)/100.0f;159 map->percent=1.0f*lib3ds_intw_read(strm)/100.0f; 160 160 } 161 161 break; 162 162 case LIB3DS_MAT_MAPNAME: 163 163 { 164 if (!lib3ds_string_read(map->name, 64, f)) {164 if (!lib3ds_string_read(map->name, 64, strm)) { 165 165 return(LIB3DS_FALSE); 166 166 } … … 170 170 case LIB3DS_MAT_MAP_TILING: 171 171 { 172 map->flags=lib3ds_word_read( f);172 map->flags=lib3ds_word_read(strm); 173 173 } 174 174 break; 175 175 case LIB3DS_MAT_MAP_TEXBLUR: 176 176 { 177 map->blur=lib3ds_float_read( f);177 map->blur=lib3ds_float_read(strm); 178 178 } 179 179 break; 180 180 case LIB3DS_MAT_MAP_USCALE: 181 181 { 182 map->scale[0]=lib3ds_float_read( f);182 map->scale[0]=lib3ds_float_read(strm); 183 183 } 184 184 break; 185 185 case LIB3DS_MAT_MAP_VSCALE: 186 186 { 187 map->scale[1]=lib3ds_float_read( f);187 map->scale[1]=lib3ds_float_read(strm); 188 188 } 189 189 break; 190 190 case LIB3DS_MAT_MAP_UOFFSET: 191 191 { 192 map->offset[0]=lib3ds_float_read( f);192 map->offset[0]=lib3ds_float_read(strm); 193 193 } 194 194 break; 195 195 case LIB3DS_MAT_MAP_VOFFSET: 196 196 { 197 map->offset[1]=lib3ds_float_read( f);197 map->offset[1]=lib3ds_float_read(strm); 198 198 } 199 199 break; 200 200 case LIB3DS_MAT_MAP_ANG: 201 201 { 202 map->rotation=lib3ds_float_read( f);202 map->rotation=lib3ds_float_read(strm); 203 203 } 204 204 break; 205 205 case LIB3DS_MAT_MAP_COL1: 206 206 { 207 map->tint_1[0]=1.0f*lib3ds_byte_read( f)/255.0f;208 map->tint_1[1]=1.0f*lib3ds_byte_read( f)/255.0f;209 map->tint_1[2]=1.0f*lib3ds_byte_read( f)/255.0f;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 210 } 211 211 break; 212 212 case LIB3DS_MAT_MAP_COL2: 213 213 { 214 map->tint_2[0]=1.0f*lib3ds_byte_read( f)/255.0f;215 map->tint_2[1]=1.0f*lib3ds_byte_read( f)/255.0f;216 map->tint_2[2]=1.0f*lib3ds_byte_read( f)/255.0f;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 217 } 218 218 break; 219 219 case LIB3DS_MAT_MAP_RCOL: 220 220 { 221 map->tint_r[0]=1.0f*lib3ds_byte_read( f)/255.0f;222 map->tint_r[1]=1.0f*lib3ds_byte_read( f)/255.0f;223 map->tint_r[2]=1.0f*lib3ds_byte_read( f)/255.0f;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 224 } 225 225 break; 226 226 case LIB3DS_MAT_MAP_GCOL: 227 227 { 228 map->tint_g[0]=1.0f*lib3ds_byte_read( f)/255.0f;229 map->tint_g[1]=1.0f*lib3ds_byte_read( f)/255.0f;230 map->tint_g[2]=1.0f*lib3ds_byte_read( f)/255.0f;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 231 } 232 232 break; 233 233 case LIB3DS_MAT_MAP_BCOL: 234 234 { 235 map->tint_b[0]=1.0f*lib3ds_byte_read( f)/255.0f;236 map->tint_b[1]=1.0f*lib3ds_byte_read( f)/255.0f;237 map->tint_b[2]=1.0f*lib3ds_byte_read( f)/255.0f;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 238 } 239 239 break; … … 243 243 } 244 244 245 lib3ds_chunk_read_end(&c, f);245 lib3ds_chunk_read_end(&c, strm); 246 246 return(LIB3DS_TRUE); 247 247 } … … 338 338 */ 339 339 Lib3dsBool 340 lib3ds_material_read(Lib3dsMaterial *material, FILE *f)340 lib3ds_material_read(Lib3dsMaterial *material, iostream *strm) 341 341 { 342 342 Lib3dsChunk c; … … 344 344 345 345 ASSERT(material); 346 if (!lib3ds_chunk_read_start(&c, LIB3DS_MAT_ENTRY, f)) {347 return(LIB3DS_FALSE); 348 } 349 350 while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {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 351 switch (chunk) { 352 352 case LIB3DS_MAT_NAME: 353 353 { 354 if (!lib3ds_string_read(material->name, 64, f)) {354 if (!lib3ds_string_read(material->name, 64, strm)) { 355 355 return(LIB3DS_FALSE); 356 356 } … … 360 360 case LIB3DS_MAT_AMBIENT: 361 361 { 362 lib3ds_chunk_read_reset(&c, f);363 if (!color_read(material->ambient, f)) {362 lib3ds_chunk_read_reset(&c, strm); 363 if (!color_read(material->ambient, strm)) { 364 364 return(LIB3DS_FALSE); 365 365 } … … 368 368 case LIB3DS_MAT_DIFFUSE: 369 369 { 370 lib3ds_chunk_read_reset(&c, f);371 if (!color_read(material->diffuse, f)) {370 lib3ds_chunk_read_reset(&c, strm); 371 if (!color_read(material->diffuse, strm)) { 372 372 return(LIB3DS_FALSE); 373 373 } … … 376 376 case LIB3DS_MAT_SPECULAR: 377 377 { 378 lib3ds_chunk_read_reset(&c, f);379 if (!color_read(material->specular, f)) {378 lib3ds_chunk_read_reset(&c, strm); 379 if (!color_read(material->specular, strm)) { 380 380 return(LIB3DS_FALSE); 381 381 } … … 384 384 case LIB3DS_MAT_SHININESS: 385 385 { 386 lib3ds_chunk_read_reset(&c, f);387 if (!int_percentage_read(&material->shininess, f)) {386 lib3ds_chunk_read_reset(&c, strm); 387 if (!int_percentage_read(&material->shininess, strm)) { 388 388 return(LIB3DS_FALSE); 389 389 } … … 392 392 case LIB3DS_MAT_SHIN2PCT: 393 393 { 394 lib3ds_chunk_read_reset(&c, f);395 if (!int_percentage_read(&material->shin_strength, f)) {394 lib3ds_chunk_read_reset(&c, strm); 395 if (!int_percentage_read(&material->shin_strength, strm)) { 396 396 return(LIB3DS_FALSE); 397 397 } … … 400 400 case LIB3DS_MAT_TRANSPARENCY: 401 401 { 402 lib3ds_chunk_read_reset(&c, f);403 if (!int_percentage_read(&material->transparency, f)) {402 lib3ds_chunk_read_reset(&c, strm); 403 if (!int_percentage_read(&material->transparency, strm)) { 404 404 return(LIB3DS_FALSE); 405 405 } … … 408 408 case LIB3DS_MAT_XPFALL: 409 409 { 410 lib3ds_chunk_read_reset(&c, f);411 if (!int_percentage_read(&material->falloff, f)) {410 lib3ds_chunk_read_reset(&c, strm); 411 if (!int_percentage_read(&material->falloff, strm)) { 412 412 return(LIB3DS_FALSE); 413 413 } … … 421 421 case LIB3DS_MAT_REFBLUR: 422 422 { 423 lib3ds_chunk_read_reset(&c, f);424 if (!int_percentage_read(&material->blur, f)) {423 lib3ds_chunk_read_reset(&c, strm); 424 if (!int_percentage_read(&material->blur, strm)) { 425 425 return(LIB3DS_FALSE); 426 426 } … … 434 434 case LIB3DS_MAT_SHADING: 435 435 { 436 material->shading=lib3ds_intw_read( f);436 material->shading=lib3ds_intw_read(strm); 437 437 } 438 438 break; … … 479 479 case LIB3DS_MAT_WIRE_SIZE: 480 480 { 481 material->wire_size=lib3ds_float_read( f);481 material->wire_size=lib3ds_float_read(strm); 482 482 } 483 483 break; 484 484 case LIB3DS_MAT_TEXMAP: 485 485 { 486 lib3ds_chunk_read_reset(&c, f);487 if (!texture_map_read(&material->texture1_map, f)) {486 lib3ds_chunk_read_reset(&c, strm); 487 if (!texture_map_read(&material->texture1_map, strm)) { 488 488 return(LIB3DS_FALSE); 489 489 } … … 492 492 case LIB3DS_MAT_TEXMASK: 493 493 { 494 lib3ds_chunk_read_reset(&c, f);495 if (!texture_map_read(&material->texture1_mask, f)) {494 lib3ds_chunk_read_reset(&c, strm); 495 if (!texture_map_read(&material->texture1_mask, strm)) { 496 496 return(LIB3DS_FALSE); 497 497 } … … 500 500 case LIB3DS_MAT_TEX2MAP: 501 501 { 502 lib3ds_chunk_read_reset(&c, f);503 if (!texture_map_read(&material->texture2_map, f)) {502 lib3ds_chunk_read_reset(&c, strm); 503 if (!texture_map_read(&material->texture2_map, strm)) { 504 504 return(LIB3DS_FALSE); 505 505 } … … 508 508 case LIB3DS_MAT_TEX2MASK: 509 509 { 510 lib3ds_chunk_read_reset(&c, f);511 if (!texture_map_read(&material->texture2_mask, f)) {510 lib3ds_chunk_read_reset(&c, strm); 511 if (!texture_map_read(&material->texture2_mask, strm)) { 512 512 return(LIB3DS_FALSE); 513 513 } … … 516 516 case LIB3DS_MAT_OPACMAP: 517 517 { 518 lib3ds_chunk_read_reset(&c, f);519 if (!texture_map_read(&material->opacity_map, f)) {518 lib3ds_chunk_read_reset(&c, strm); 519 if (!texture_map_read(&material->opacity_map, strm)) { 520 520 return(LIB3DS_FALSE); 521 521 } … … 524 524 case LIB3DS_MAT_OPACMASK: 525 525 { 526 lib3ds_chunk_read_reset(&c, f);527 if (!texture_map_read(&material->opacity_mask, f)) {526 lib3ds_chunk_read_reset(&c, strm); 527 if (!texture_map_read(&material->opacity_mask, strm)) { 528 528 return(LIB3DS_FALSE); 529 529 } … … 532 532 case LIB3DS_MAT_BUMPMAP: 533 533 { 534 lib3ds_chunk_read_reset(&c, f);535 if (!texture_map_read(&material->bump_map, f)) {534 lib3ds_chunk_read_reset(&c, strm); 535 if (!texture_map_read(&material->bump_map, strm)) { 536 536 return(LIB3DS_FALSE); 537 537 } … … 540 540 case LIB3DS_MAT_BUMPMASK: 541 541 { 542 lib3ds_chunk_read_reset(&c, f);543 if (!texture_map_read(&material->bump_mask, f)) {542 lib3ds_chunk_read_reset(&c, strm); 543 if (!texture_map_read(&material->bump_mask, strm)) { 544 544 return(LIB3DS_FALSE); 545 545 } … … 548 548 case LIB3DS_MAT_SPECMAP: 549 549 { 550 lib3ds_chunk_read_reset(&c, f);551 if (!texture_map_read(&material->specular_map, f)) {550 lib3ds_chunk_read_reset(&c, strm); 551 if (!texture_map_read(&material->specular_map, strm)) { 552 552 return(LIB3DS_FALSE); 553 553 } … … 556 556 case LIB3DS_MAT_SPECMASK: 557 557 { 558 lib3ds_chunk_read_reset(&c, f);559 if (!texture_map_read(&material->specular_mask, f)) {558 lib3ds_chunk_read_reset(&c, strm); 559 if (!texture_map_read(&material->specular_mask, strm)) { 560 560 return(LIB3DS_FALSE); 561 561 } … … 564 564 case LIB3DS_MAT_SHINMAP: 565 565 { 566 lib3ds_chunk_read_reset(&c, f);567 if (!texture_map_read(&material->shininess_map, f)) {566 lib3ds_chunk_read_reset(&c, strm); 567 if (!texture_map_read(&material->shininess_map, strm)) { 568 568 return(LIB3DS_FALSE); 569 569 } … … 572 572 case LIB3DS_MAT_SHINMASK: 573 573 { 574 lib3ds_chunk_read_reset(&c, f);575 if (!texture_map_read(&material->shininess_mask, f)) {574 lib3ds_chunk_read_reset(&c, strm); 575 if (!texture_map_read(&material->shininess_mask, strm)) { 576 576 return(LIB3DS_FALSE); 577 577 } … … 580 580 case LIB3DS_MAT_SELFIMAP: 581 581 { 582 lib3ds_chunk_read_reset(&c, f);583 if (!texture_map_read(&material->self_illum_map, f)) {582 lib3ds_chunk_read_reset(&c, strm); 583 if (!texture_map_read(&material->self_illum_map, strm)) { 584 584 return(LIB3DS_FALSE); 585 585 } … … 588 588 case LIB3DS_MAT_SELFIMASK: 589 589 { 590 lib3ds_chunk_read_reset(&c, f);591 if (!texture_map_read(&material->self_illum_mask, f)) {590 lib3ds_chunk_read_reset(&c, strm); 591 if (!texture_map_read(&material->self_illum_mask, strm)) { 592 592 return(LIB3DS_FALSE); 593 593 } … … 596 596 case LIB3DS_MAT_REFLMAP: 597 597 { 598 lib3ds_chunk_read_reset(&c, f);599 if (!texture_map_read(&material->reflection_map, f)) {598 lib3ds_chunk_read_reset(&c, strm); 599 if (!texture_map_read(&material->reflection_map, strm)) { 600 600 return(LIB3DS_FALSE); 601 601 } … … 604 604 case LIB3DS_MAT_REFLMASK: 605 605 { 606 lib3ds_chunk_read_reset(&c, f);607 if (!texture_map_read(&material->reflection_mask, f)) {606 lib3ds_chunk_read_reset(&c, strm); 607 if (!texture_map_read(&material->reflection_mask, strm)) { 608 608 return(LIB3DS_FALSE); 609 609 } … … 612 612 case LIB3DS_MAT_ACUBIC: 613 613 { 614 lib3ds_intb_read( f);615 material->autorefl_map.level=lib3ds_intb_read( f);616 material->autorefl_map.flags=lib3ds_intw_read( f);617 material->autorefl_map.size=lib3ds_intd_read( f);618 material->autorefl_map.frame_step=lib3ds_intd_read( f);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 619 } 620 620 break; … … 624 624 } 625 625 626 lib3ds_chunk_read_end(&c, f);626 lib3ds_chunk_read_end(&c, strm); 627 627 return(LIB3DS_TRUE); 628 628 } … … 630 630 631 631 static Lib3dsBool 632 color_write(Lib3dsRgba rgb, FILE *f)632 color_write(Lib3dsRgba rgb, iostream *strm) 633 633 { 634 634 Lib3dsChunk c; … … 636 636 c.chunk=LIB3DS_COLOR_24; 637 637 c.size=9; 638 lib3ds_chunk_write(&c, f);639 lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[0]+0.5), f);640 lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[1]+0.5), f);641 lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[2]+0.5), f);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 642 643 643 c.chunk=LIB3DS_LIN_COLOR_24; 644 644 c.size=9; 645 lib3ds_chunk_write(&c, f);646 lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[0]+0.5), f);647 lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[1]+0.5), f);648 lib3ds_byte_write((Lib3dsByte)floor(255.0*rgb[2]+0.5), f);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 649 650 650 return(LIB3DS_TRUE); … … 653 653 654 654 static Lib3dsBool 655 int_percentage_write(Lib3dsFloat p, FILE *f)655 int_percentage_write(Lib3dsFloat p, iostream *strm) 656 656 { 657 657 Lib3dsChunk c; … … 659 659 c.chunk=LIB3DS_INT_PERCENTAGE; 660 660 c.size=8; 661 lib3ds_chunk_write(&c, f);662 lib3ds_intw_write((Lib3dsByte)floor(100.0*p+0.5), f);661 lib3ds_chunk_write(&c,strm); 662 lib3ds_intw_write((Lib3dsByte)floor(100.0*p+0.5),strm); 663 663 664 664 return(LIB3DS_TRUE); … … 667 667 668 668 static Lib3dsBool 669 texture_map_write(Lib3dsWord chunk, Lib3dsTextureMap *map, FILE *f)669 texture_map_write(Lib3dsWord chunk, Lib3dsTextureMap *map, iostream *strm) 670 670 { 671 671 Lib3dsChunk c; … … 675 675 } 676 676 c.chunk=chunk; 677 if (!lib3ds_chunk_write_start(&c, f)) {677 if (!lib3ds_chunk_write_start(&c,strm)) { 678 678 return(LIB3DS_FALSE); 679 679 } 680 680 681 int_percentage_write(map->percent, f);681 int_percentage_write(map->percent,strm); 682 682 683 683 { /*---- LIB3DS_MAT_MAPNAME ----*/ … … 685 685 c.chunk=LIB3DS_MAT_MAPNAME; 686 686 c.size=6+strlen(map->name)+1; 687 lib3ds_chunk_write(&c, f);688 lib3ds_string_write(map->name, f);687 lib3ds_chunk_write(&c,strm); 688 lib3ds_string_write(map->name,strm); 689 689 } 690 690 … … 693 693 c.chunk=LIB3DS_MAT_MAP_TILING; 694 694 c.size=8; 695 lib3ds_chunk_write(&c, f);696 lib3ds_word_write((Lib3dsWord)map->flags, f);695 lib3ds_chunk_write(&c,strm); 696 lib3ds_word_write((Lib3dsWord)map->flags,strm); 697 697 } 698 698 … … 701 701 c.chunk=LIB3DS_MAT_MAP_TEXBLUR; 702 702 c.size=10; 703 lib3ds_chunk_write(&c, f);704 lib3ds_float_write(map->blur, f);703 lib3ds_chunk_write(&c,strm); 704 lib3ds_float_write(map->blur,strm); 705 705 } 706 706 … … 709 709 c.chunk=LIB3DS_MAT_MAP_USCALE; 710 710 c.size=10; 711 lib3ds_chunk_write(&c, f);712 lib3ds_float_write(map->scale[0], f);711 lib3ds_chunk_write(&c,strm); 712 lib3ds_float_write(map->scale[0],strm); 713 713 } 714 714 … … 717 717 c.chunk=LIB3DS_MAT_MAP_VSCALE; 718 718 c.size=10; 719 lib3ds_chunk_write(&c, f);720 lib3ds_float_write(map->scale[1], f);719 lib3ds_chunk_write(&c,strm); 720 lib3ds_float_write(map->scale[1],strm); 721 721 } 722 722 … … 725 725 c.chunk=LIB3DS_MAT_MAP_UOFFSET; 726 726 c.size=10; 727 lib3ds_chunk_write(&c, f);728 lib3ds_float_write(map->offset[0], f);727 lib3ds_chunk_write(&c,strm); 728 lib3ds_float_write(map->offset[0],strm); 729 729 } 730 730 … … 733 733 c.chunk=LIB3DS_MAT_MAP_VOFFSET; 734 734 c.size=10; 735 lib3ds_chunk_write(&c, f);736 lib3ds_float_write(map->offset[1], f);735 lib3ds_chunk_write(&c,strm); 736 lib3ds_float_write(map->offset[1],strm); 737 737 } 738 738 … … 741 741 c.chunk=LIB3DS_MAT_MAP_ANG; 742 742 c.size=10; 743 lib3ds_chunk_write(&c, f);744 lib3ds_float_write(map->rotation, f);743 lib3ds_chunk_write(&c,strm); 744 lib3ds_float_write(map->rotation,strm); 745 745 } 746 746 … … 749 749 c.chunk=LIB3DS_MAT_MAP_COL1; 750 750 c.size=9; 751 lib3ds_chunk_write(&c, f);752 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_1[0]+0.5), f);753 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_1[1]+0.5), f);754 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_1[2]+0.5), f);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 755 } 756 756 … … 759 759 c.chunk=LIB3DS_MAT_MAP_COL2; 760 760 c.size=9; 761 lib3ds_chunk_write(&c, f);762 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_2[0]+0.5), f);763 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_2[1]+0.5), f);764 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_2[2]+0.5), f);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 765 } 766 766 … … 769 769 c.chunk=LIB3DS_MAT_MAP_RCOL; 770 770 c.size=9; 771 lib3ds_chunk_write(&c, f);772 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_r[0]+0.5), f);773 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_r[1]+0.5), f);774 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_r[2]+0.5), f);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 775 } 776 776 … … 779 779 c.chunk=LIB3DS_MAT_MAP_GCOL; 780 780 c.size=9; 781 lib3ds_chunk_write(&c, f);782 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_g[0]+0.5), f);783 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_g[1]+0.5), f);784 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_g[2]+0.5), f);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 785 } 786 786 … … 789 789 c.chunk=LIB3DS_MAT_MAP_BCOL; 790 790 c.size=9; 791 lib3ds_chunk_write(&c, f);792 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_b[0]+0.5), f);793 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_b[1]+0.5), f);794 lib3ds_byte_write((Lib3dsByte)floor(255.0*map->tint_b[2]+0.5), f);795 } 796 797 if (!lib3ds_chunk_write_end(&c, f)) {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 798 return(LIB3DS_FALSE); 799 799 } … … 806 806 */ 807 807 Lib3dsBool 808 lib3ds_material_write(Lib3dsMaterial *material, FILE *f)808 lib3ds_material_write(Lib3dsMaterial *material, iostream *strm) 809 809 { 810 810 Lib3dsChunk c; 811 811 812 812 c.chunk=LIB3DS_MAT_ENTRY; 813 if (!lib3ds_chunk_write_start(&c, f)) {813 if (!lib3ds_chunk_write_start(&c,strm)) { 814 814 return(LIB3DS_FALSE); 815 815 } … … 819 819 c.chunk=LIB3DS_MAT_NAME; 820 820 c.size=6+strlen(material->name)+1; 821 lib3ds_chunk_write(&c, f);822 lib3ds_string_write(material->name, f);821 lib3ds_chunk_write(&c,strm); 822 lib3ds_string_write(material->name,strm); 823 823 } 824 824 … … 827 827 c.chunk=LIB3DS_MAT_AMBIENT; 828 828 c.size=24; 829 lib3ds_chunk_write(&c, f);830 color_write(material->ambient, f);829 lib3ds_chunk_write(&c,strm); 830 color_write(material->ambient,strm); 831 831 } 832 832 … … 835 835 c.chunk=LIB3DS_MAT_DIFFUSE; 836 836 c.size=24; 837 lib3ds_chunk_write(&c, f);838 color_write(material->diffuse, f);837 lib3ds_chunk_write(&c,strm); 838 color_write(material->diffuse,strm); 839 839 } 840 840 … … 843 843 c.chunk=LIB3DS_MAT_SPECULAR; 844 844 c.size=24; 845 lib3ds_chunk_write(&c, f);846 color_write(material->specular, f);845 lib3ds_chunk_write(&c,strm); 846 color_write(material->specular,strm); 847 847 } 848 848 … … 851 851 c.chunk=LIB3DS_MAT_SHININESS; 852 852 c.size=14; 853 lib3ds_chunk_write(&c, f);854 int_percentage_write(material->shininess, f);853 lib3ds_chunk_write(&c,strm); 854 int_percentage_write(material->shininess,strm); 855 855 } 856 856 … … 859 859 c.chunk=LIB3DS_MAT_SHIN2PCT; 860 860 c.size=14; 861 lib3ds_chunk_write(&c, f);862 int_percentage_write(material->shin_strength, f);861 lib3ds_chunk_write(&c,strm); 862 int_percentage_write(material->shin_strength,strm); 863 863 } 864 864 … … 867 867 c.chunk=LIB3DS_MAT_TRANSPARENCY; 868 868 c.size=14; 869 lib3ds_chunk_write(&c, f);870 int_percentage_write(material->transparency, f);869 lib3ds_chunk_write(&c,strm); 870 int_percentage_write(material->transparency,strm); 871 871 } 872 872 … … 875 875 c.chunk=LIB3DS_MAT_XPFALL; 876 876 c.size=14; 877 lib3ds_chunk_write(&c, f);878 int_percentage_write(material->falloff, f);877 lib3ds_chunk_write(&c,strm); 878 int_percentage_write(material->falloff,strm); 879 879 } 880 880 … … 883 883 c.chunk=LIB3DS_MAT_USE_XPFALL; 884 884 c.size=6; 885 lib3ds_chunk_write(&c, f);885 lib3ds_chunk_write(&c,strm); 886 886 } 887 887 … … 890 890 c.chunk=LIB3DS_MAT_SHADING; 891 891 c.size=8; 892 lib3ds_chunk_write(&c, f);893 lib3ds_intw_write(material->shading, f);892 lib3ds_chunk_write(&c,strm); 893 lib3ds_intw_write(material->shading,strm); 894 894 } 895 895 … … 898 898 c.chunk=LIB3DS_MAT_REFBLUR; 899 899 c.size=14; 900 lib3ds_chunk_write(&c, f);901 int_percentage_write(material->blur, f);900 lib3ds_chunk_write(&c,strm); 901 int_percentage_write(material->blur,strm); 902 902 } 903 903 … … 906 906 c.chunk=LIB3DS_MAT_USE_REFBLUR; 907 907 c.size=6; 908 lib3ds_chunk_write(&c, f);908 lib3ds_chunk_write(&c,strm); 909 909 } 910 910 … … 913 913 c.chunk=LIB3DS_MAT_SELF_ILLUM; 914 914 c.size=6; 915 lib3ds_chunk_write(&c, f);915 lib3ds_chunk_write(&c,strm); 916 916 } 917 917 … … 920 920 c.chunk=LIB3DS_MAT_TWO_SIDE; 921 921 c.size=6; 922 lib3ds_chunk_write(&c, f);922 lib3ds_chunk_write(&c,strm); 923 923 } 924 924 … … 927 927 c.chunk=LIB3DS_MAT_DECAL; 928 928 c.size=6; 929 lib3ds_chunk_write(&c, f);929 lib3ds_chunk_write(&c,strm); 930 930 } 931 931 … … 934 934 c.chunk=LIB3DS_MAT_ADDITIVE; 935 935 c.size=6; 936 lib3ds_chunk_write(&c, f);936 lib3ds_chunk_write(&c,strm); 937 937 } 938 938 … … 941 941 c.chunk=LIB3DS_MAT_WIRE; 942 942 c.size=6; 943 lib3ds_chunk_write(&c, f);943 lib3ds_chunk_write(&c,strm); 944 944 } 945 945 … … 948 948 c.chunk=LIB3DS_MAT_WIREABS; 949 949 c.size=6; 950 lib3ds_chunk_write(&c, f);950 lib3ds_chunk_write(&c,strm); 951 951 } 952 952 … … 955 955 c.chunk=LIB3DS_MAT_WIRE_SIZE; 956 956 c.size=10; 957 lib3ds_chunk_write(&c, f);958 lib3ds_float_write(material->wire_size, f);957 lib3ds_chunk_write(&c,strm); 958 lib3ds_float_write(material->wire_size,strm); 959 959 } 960 960 … … 963 963 c.chunk=LIB3DS_MAT_FACEMAP; 964 964 c.size=6; 965 lib3ds_chunk_write(&c, f);965 lib3ds_chunk_write(&c,strm); 966 966 } 967 967 … … 970 970 c.chunk=LIB3DS_MAT_PHONGSOFT; 971 971 c.size=6; 972 lib3ds_chunk_write(&c, f);973 } 974 975 if (!texture_map_write(LIB3DS_MAT_TEXMAP, &material->texture1_map, f)) {976 return(LIB3DS_FALSE); 977 } 978 if (!texture_map_write(LIB3DS_MAT_TEXMASK, &material->texture1_mask, f)) {979 return(LIB3DS_FALSE); 980 } 981 if (!texture_map_write(LIB3DS_MAT_TEX2MAP, &material->texture2_map, f)) {982 return(LIB3DS_FALSE); 983 } 984 if (!texture_map_write(LIB3DS_MAT_TEX2MASK, &material->texture2_mask, f)) {985 return(LIB3DS_FALSE); 986 } 987 if (!texture_map_write(LIB3DS_MAT_OPACMAP, &material->opacity_map, f)) {988 return(LIB3DS_FALSE); 989 } 990 if (!texture_map_write(LIB3DS_MAT_OPACMASK, &material->opacity_mask, f)) {991 return(LIB3DS_FALSE); 992 } 993 if (!texture_map_write(LIB3DS_MAT_BUMPMAP, &material->bump_map, f)) {994 return(LIB3DS_FALSE); 995 } 996 if (!texture_map_write(LIB3DS_MAT_BUMPMASK, &material->bump_mask, f)) {997 return(LIB3DS_FALSE); 998 } 999 if (!texture_map_write(LIB3DS_MAT_SPECMAP, &material->specular_map, f)) {1000 return(LIB3DS_FALSE); 1001 } 1002 if (!texture_map_write(LIB3DS_MAT_SPECMASK, &material->specular_mask, f)) {1003 return(LIB3DS_FALSE); 1004 } 1005 if (!texture_map_write(LIB3DS_MAT_SHINMAP, &material->shininess_map, f)) {1006 return(LIB3DS_FALSE); 1007 } 1008 if (!texture_map_write(LIB3DS_MAT_SHINMASK, &material->shininess_mask, f)) {1009 return(LIB3DS_FALSE); 1010 } 1011 if (!texture_map_write(LIB3DS_MAT_SELFIMAP, &material->self_illum_map, f)) {1012 return(LIB3DS_FALSE); 1013 } 1014 if (!texture_map_write(LIB3DS_MAT_SELFIMASK, &material->self_illum_mask, f)) {1015 return(LIB3DS_FALSE); 1016 } 1017 if (!texture_map_write(LIB3DS_MAT_REFLMAP, &material->reflection_map, f)) {1018 return(LIB3DS_FALSE); 1019 } 1020 if (!texture_map_write(LIB3DS_MAT_REFLMASK, &material->reflection_mask, f)) {1021 return(LIB3DS_FALSE); 1022 } 1023 1024 if (!lib3ds_chunk_write_end(&c, f)) {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 1025 return(LIB3DS_FALSE); 1026 1026 }
