Changeset 10076 for OpenSceneGraph/trunk/src/osgPlugins/3ds/mesh.cpp
- Timestamp:
- 04/22/09 17:46:24 (4 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgPlugins/3ds/mesh.cpp (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/3ds/mesh.cpp
r5453 r10076 43 43 44 44 static Lib3dsBool 45 face_array_read(Lib3dsMesh *mesh, FILE *f)45 face_array_read(Lib3dsMesh *mesh, iostream *strm) 46 46 { 47 47 Lib3dsChunk c; … … 50 50 int faces; 51 51 52 if (!lib3ds_chunk_read_start(&c, LIB3DS_FACE_ARRAY, f)) {52 if (!lib3ds_chunk_read_start(&c, LIB3DS_FACE_ARRAY, strm)) { 53 53 return(LIB3DS_FALSE); 54 54 } 55 55 lib3ds_mesh_free_face_list(mesh); 56 56 57 faces=lib3ds_word_read( f);57 faces=lib3ds_word_read(strm); 58 58 if (faces) { 59 59 if (!lib3ds_mesh_new_face_list(mesh, faces)) { … … 63 63 for (i=0; i<faces; ++i) { 64 64 strcpy(mesh->faceL[i].material, ""); 65 mesh->faceL[i].points[0]=lib3ds_word_read( f);66 mesh->faceL[i].points[1]=lib3ds_word_read( f);67 mesh->faceL[i].points[2]=lib3ds_word_read( f);68 mesh->faceL[i].flags=lib3ds_word_read( f);69 } 70 lib3ds_chunk_read_tell(&c, f);71 72 while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {65 mesh->faceL[i].points[0]=lib3ds_word_read(strm); 66 mesh->faceL[i].points[1]=lib3ds_word_read(strm); 67 mesh->faceL[i].points[2]=lib3ds_word_read(strm); 68 mesh->faceL[i].flags=lib3ds_word_read(strm); 69 } 70 lib3ds_chunk_read_tell(&c, strm); 71 72 while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { 73 73 switch (chunk) { 74 74 case LIB3DS_SMOOTH_GROUP: … … 77 77 78 78 for (i=0; i<mesh->faces; ++i) { 79 mesh->faceL[i].smoothing=lib3ds_dword_read( f);79 mesh->faceL[i].smoothing=lib3ds_dword_read(strm); 80 80 } 81 81 } … … 88 88 unsigned index; 89 89 90 if (!lib3ds_string_read(name, 64, f)) {90 if (!lib3ds_string_read(name, 64, strm)) { 91 91 return(LIB3DS_FALSE); 92 92 } 93 faces=lib3ds_word_read( f);93 faces=lib3ds_word_read(strm); 94 94 for (i=0; i<faces; ++i) { 95 index=lib3ds_word_read( f);95 index=lib3ds_word_read(strm); 96 96 ASSERT(index<mesh->faces); 97 97 strcpy(mesh->faceL[index].material, name); … … 103 103 char name[64]; 104 104 105 if (!lib3ds_string_read(name, 64, f)) {105 if (!lib3ds_string_read(name, 64, strm)) { 106 106 return(LIB3DS_FALSE); 107 107 } 108 108 strcpy(mesh->box_map.front, name); 109 if (!lib3ds_string_read(name, 64, f)) {109 if (!lib3ds_string_read(name, 64, strm)) { 110 110 return(LIB3DS_FALSE); 111 111 } 112 112 strcpy(mesh->box_map.back, name); 113 if (!lib3ds_string_read(name, 64, f)) {113 if (!lib3ds_string_read(name, 64, strm)) { 114 114 return(LIB3DS_FALSE); 115 115 } 116 116 strcpy(mesh->box_map.left, name); 117 if (!lib3ds_string_read(name, 64, f)) {117 if (!lib3ds_string_read(name, 64, strm)) { 118 118 return(LIB3DS_FALSE); 119 119 } 120 120 strcpy(mesh->box_map.right, name); 121 if (!lib3ds_string_read(name, 64, f)) {121 if (!lib3ds_string_read(name, 64, strm)) { 122 122 return(LIB3DS_FALSE); 123 123 } 124 124 strcpy(mesh->box_map.top, name); 125 if (!lib3ds_string_read(name, 64, f)) {125 if (!lib3ds_string_read(name, 64, strm)) { 126 126 return(LIB3DS_FALSE); 127 127 } … … 135 135 136 136 } 137 lib3ds_chunk_read_end(&c, f);137 lib3ds_chunk_read_end(&c, strm); 138 138 return(LIB3DS_TRUE); 139 139 } … … 524 524 */ 525 525 Lib3dsBool 526 lib3ds_mesh_read(Lib3dsMesh *mesh, FILE *f)526 lib3ds_mesh_read(Lib3dsMesh *mesh, iostream *strm) 527 527 { 528 528 Lib3dsChunk c; 529 529 Lib3dsWord chunk; 530 530 531 if (!lib3ds_chunk_read_start(&c, LIB3DS_N_TRI_OBJECT, f)) {532 return(LIB3DS_FALSE); 533 } 534 535 while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {531 if (!lib3ds_chunk_read_start(&c, LIB3DS_N_TRI_OBJECT, strm)) { 532 return(LIB3DS_FALSE); 533 } 534 535 while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { 536 536 switch (chunk) { 537 537 case LIB3DS_MESH_MATRIX: … … 542 542 for (i=0; i<4; i++) { 543 543 for (j=0; j<3; j++) { 544 mesh->matrix[i][j]=lib3ds_float_read( f);544 mesh->matrix[i][j]=lib3ds_float_read(strm); 545 545 } 546 546 } … … 549 549 case LIB3DS_MESH_COLOR: 550 550 { 551 mesh->color=lib3ds_byte_read( f);551 mesh->color=lib3ds_byte_read(strm); 552 552 } 553 553 break; … … 558 558 559 559 lib3ds_mesh_free_point_list(mesh); 560 points=lib3ds_word_read( f);560 points=lib3ds_word_read(strm); 561 561 if (points) { 562 562 if (!lib3ds_mesh_new_point_list(mesh, points)) { … … 566 566 for (i=0; i<mesh->points; ++i) { 567 567 for (j=0; j<3; ++j) { 568 mesh->pointL[i].pos[j]=lib3ds_float_read( f);568 mesh->pointL[i].pos[j]=lib3ds_float_read(strm); 569 569 } 570 570 } … … 580 580 581 581 lib3ds_mesh_free_flag_list(mesh); 582 flags=lib3ds_word_read( f);582 flags=lib3ds_word_read(strm); 583 583 if (flags) { 584 584 if (!lib3ds_mesh_new_flag_list(mesh, flags)) { … … 587 587 } 588 588 for (i=0; i<mesh->flags; ++i) { 589 mesh->flagL[i]=lib3ds_word_read( f);589 mesh->flagL[i]=lib3ds_word_read(strm); 590 590 } 591 591 ASSERT((!mesh->points) || (mesh->flags==mesh->points)); … … 596 596 case LIB3DS_FACE_ARRAY: 597 597 { 598 lib3ds_chunk_read_reset(&c, f);599 if (!face_array_read(mesh, f)) {598 lib3ds_chunk_read_reset(&c, strm); 599 if (!face_array_read(mesh, strm)) { 600 600 return(LIB3DS_FALSE); 601 601 } … … 607 607 608 608 for (i=0; i<2; ++i) { 609 mesh->map_data.tile[i]=lib3ds_float_read( f);609 mesh->map_data.tile[i]=lib3ds_float_read(strm); 610 610 } 611 611 for (i=0; i<3; ++i) { 612 mesh->map_data.pos[i]=lib3ds_float_read( f);613 } 614 mesh->map_data.scale=lib3ds_float_read( f);612 mesh->map_data.pos[i]=lib3ds_float_read(strm); 613 } 614 mesh->map_data.scale=lib3ds_float_read(strm); 615 615 616 616 lib3ds_matrix_identity(mesh->map_data.matrix); 617 617 for (i=0; i<4; i++) { 618 618 for (j=0; j<3; j++) { 619 mesh->map_data.matrix[i][j]=lib3ds_float_read( f);619 mesh->map_data.matrix[i][j]=lib3ds_float_read(strm); 620 620 } 621 621 } 622 622 for (i=0; i<2; ++i) { 623 mesh->map_data.planar_size[i]=lib3ds_float_read( f);624 } 625 mesh->map_data.cylinder_height=lib3ds_float_read( f);623 mesh->map_data.planar_size[i]=lib3ds_float_read(strm); 624 } 625 mesh->map_data.cylinder_height=lib3ds_float_read(strm); 626 626 } 627 627 break; … … 632 632 633 633 lib3ds_mesh_free_texel_list(mesh); 634 texels=lib3ds_word_read( f);634 texels=lib3ds_word_read(strm); 635 635 if (texels) { 636 636 if (!lib3ds_mesh_new_texel_list(mesh, texels)) { … … 639 639 } 640 640 for (i=0; i<mesh->texels; ++i) { 641 mesh->texelL[i][0]=lib3ds_float_read( f);642 mesh->texelL[i][1]=lib3ds_float_read( f);641 mesh->texelL[i][0]=lib3ds_float_read(strm); 642 mesh->texelL[i][1]=lib3ds_float_read(strm); 643 643 } 644 644 ASSERT((!mesh->points) || (mesh->texels==mesh->points)); … … 667 667 } 668 668 669 lib3ds_chunk_read_end(&c, f);669 lib3ds_chunk_read_end(&c, strm); 670 670 return(LIB3DS_TRUE); 671 671 } … … 673 673 674 674 static Lib3dsBool 675 point_array_write(Lib3dsMesh *mesh, FILE *f)675 point_array_write(Lib3dsMesh *mesh, iostream *strm) 676 676 { 677 677 Lib3dsChunk c; … … 684 684 c.chunk=LIB3DS_POINT_ARRAY; 685 685 c.size=8+12*mesh->points; 686 lib3ds_chunk_write(&c, f);687 688 lib3ds_word_write((Lib3dsWord)mesh->points, f);686 lib3ds_chunk_write(&c, strm); 687 688 lib3ds_word_write((Lib3dsWord)mesh->points, strm); 689 689 for (i=0; i<mesh->points; ++i) { 690 lib3ds_vector_write(mesh->pointL[i].pos, f);690 lib3ds_vector_write(mesh->pointL[i].pos, strm); 691 691 } 692 692 return(LIB3DS_TRUE); … … 695 695 696 696 static Lib3dsBool 697 flag_array_write(Lib3dsMesh *mesh, FILE *f)697 flag_array_write(Lib3dsMesh *mesh, iostream *strm) 698 698 { 699 699 Lib3dsChunk c; … … 706 706 c.chunk=LIB3DS_POINT_FLAG_ARRAY; 707 707 c.size=8+2*mesh->flags; 708 lib3ds_chunk_write(&c, f);709 710 lib3ds_word_write((Lib3dsWord)mesh->flags, f);708 lib3ds_chunk_write(&c, strm); 709 710 lib3ds_word_write((Lib3dsWord)mesh->flags, strm); 711 711 for (i=0; i<mesh->flags; ++i) { 712 lib3ds_word_write(mesh->flagL[i], f);712 lib3ds_word_write(mesh->flagL[i], strm); 713 713 } 714 714 return(LIB3DS_TRUE); … … 717 717 718 718 static Lib3dsBool 719 face_array_write(Lib3dsMesh *mesh, FILE *f)719 face_array_write(Lib3dsMesh *mesh, iostream *strm) 720 720 { 721 721 Lib3dsChunk c; … … 726 726 ASSERT(mesh->faces<0x10000); 727 727 c.chunk=LIB3DS_FACE_ARRAY; 728 if (!lib3ds_chunk_write_start(&c, f)) {728 if (!lib3ds_chunk_write_start(&c, strm)) { 729 729 return(LIB3DS_FALSE); 730 730 } … … 732 732 unsigned i; 733 733 734 lib3ds_word_write((Lib3dsWord)mesh->faces, f);734 lib3ds_word_write((Lib3dsWord)mesh->faces, strm); 735 735 for (i=0; i<mesh->faces; ++i) { 736 lib3ds_word_write(mesh->faceL[i].points[0], f);737 lib3ds_word_write(mesh->faceL[i].points[1], f);738 lib3ds_word_write(mesh->faceL[i].points[2], f);739 lib3ds_word_write(mesh->faceL[i].flags, f);736 lib3ds_word_write(mesh->faceL[i].points[0], strm); 737 lib3ds_word_write(mesh->faceL[i].points[1], strm); 738 lib3ds_word_write(mesh->faceL[i].points[2], strm); 739 lib3ds_word_write(mesh->faceL[i].flags, strm); 740 740 } 741 741 } … … 761 761 c.chunk=LIB3DS_MSH_MAT_GROUP; 762 762 c.size=6+ strlen(mesh->faceL[i].material)+1 +2+2*num; 763 lib3ds_chunk_write(&c, f);764 lib3ds_string_write(mesh->faceL[i].material, f);765 lib3ds_word_write(num, f);766 lib3ds_word_write((Lib3dsWord)i, f);763 lib3ds_chunk_write(&c, strm); 764 lib3ds_string_write(mesh->faceL[i].material, strm); 765 lib3ds_word_write(num, strm); 766 lib3ds_word_write((Lib3dsWord)i, strm); 767 767 768 768 for (j=i+1; j<mesh->faces; ++j) { 769 769 if (strcmp(mesh->faceL[i].material, mesh->faceL[j].material)==0) { 770 lib3ds_word_write((Lib3dsWord)j, f);770 lib3ds_word_write((Lib3dsWord)j, strm); 771 771 matf[j]=1; 772 772 } … … 783 783 c.chunk=LIB3DS_SMOOTH_GROUP; 784 784 c.size=6+4*mesh->faces; 785 lib3ds_chunk_write(&c, f);785 lib3ds_chunk_write(&c, strm); 786 786 787 787 for (i=0; i<mesh->faces; ++i) { 788 lib3ds_dword_write(mesh->faceL[i].smoothing, f);788 lib3ds_dword_write(mesh->faceL[i].smoothing, strm); 789 789 } 790 790 } … … 801 801 802 802 c.chunk=LIB3DS_MSH_BOXMAP; 803 if (!lib3ds_chunk_write_start(&c, f)) {803 if (!lib3ds_chunk_write_start(&c, strm)) { 804 804 return(LIB3DS_FALSE); 805 805 } 806 806 807 lib3ds_string_write(mesh->box_map.front, f);808 lib3ds_string_write(mesh->box_map.back, f);809 lib3ds_string_write(mesh->box_map.left, f);810 lib3ds_string_write(mesh->box_map.right, f);811 lib3ds_string_write(mesh->box_map.top, f);812 lib3ds_string_write(mesh->box_map.bottom, f);807 lib3ds_string_write(mesh->box_map.front, strm); 808 lib3ds_string_write(mesh->box_map.back, strm); 809 lib3ds_string_write(mesh->box_map.left, strm); 810 lib3ds_string_write(mesh->box_map.right, strm); 811 lib3ds_string_write(mesh->box_map.top, strm); 812 lib3ds_string_write(mesh->box_map.bottom, strm); 813 813 814 if (!lib3ds_chunk_write_end(&c, f)) {814 if (!lib3ds_chunk_write_end(&c, strm)) { 815 815 return(LIB3DS_FALSE); 816 816 } … … 818 818 } 819 819 820 if (!lib3ds_chunk_write_end(&c, f)) {820 if (!lib3ds_chunk_write_end(&c, strm)) { 821 821 return(LIB3DS_FALSE); 822 822 } … … 826 826 827 827 static Lib3dsBool 828 texel_array_write(Lib3dsMesh *mesh, FILE *f)828 texel_array_write(Lib3dsMesh *mesh, iostream *strm) 829 829 { 830 830 Lib3dsChunk c; … … 837 837 c.chunk=LIB3DS_TEX_VERTS; 838 838 c.size=8+8*mesh->texels; 839 lib3ds_chunk_write(&c, f);840 841 lib3ds_word_write((Lib3dsWord)mesh->texels, f);839 lib3ds_chunk_write(&c, strm); 840 841 lib3ds_word_write((Lib3dsWord)mesh->texels, strm); 842 842 for (i=0; i<mesh->texels; ++i) { 843 lib3ds_float_write(mesh->texelL[i][0], f);844 lib3ds_float_write(mesh->texelL[i][1], f);843 lib3ds_float_write(mesh->texelL[i][0], strm); 844 lib3ds_float_write(mesh->texelL[i][1], strm); 845 845 } 846 846 return(LIB3DS_TRUE); … … 852 852 */ 853 853 Lib3dsBool 854 lib3ds_mesh_write(Lib3dsMesh *mesh, FILE *f)854 lib3ds_mesh_write(Lib3dsMesh *mesh, iostream *strm) 855 855 { 856 856 Lib3dsChunk c; 857 857 858 858 c.chunk=LIB3DS_N_TRI_OBJECT; 859 if (!lib3ds_chunk_write_start(&c, f)) {860 return(LIB3DS_FALSE); 861 } 862 if (!point_array_write(mesh, f)) {863 return(LIB3DS_FALSE); 864 } 865 if (!texel_array_write(mesh, f)) {859 if (!lib3ds_chunk_write_start(&c,strm)) { 860 return(LIB3DS_FALSE); 861 } 862 if (!point_array_write(mesh, strm)) { 863 return(LIB3DS_FALSE); 864 } 865 if (!texel_array_write(mesh, strm)) { 866 866 return(LIB3DS_FALSE); 867 867 } … … 873 873 c.chunk=LIB3DS_MESH_TEXTURE_INFO; 874 874 c.size=92; 875 if (!lib3ds_chunk_write(&c, f)) {875 if (!lib3ds_chunk_write(&c,strm)) { 876 876 return(LIB3DS_FALSE); 877 877 } 878 878 879 lib3ds_word_write(mesh->map_data.maptype, f);879 lib3ds_word_write(mesh->map_data.maptype, strm); 880 880 881 881 for (i=0; i<2; ++i) { 882 lib3ds_float_write(mesh->map_data.tile[i], f);882 lib3ds_float_write(mesh->map_data.tile[i], strm); 883 883 } 884 884 for (i=0; i<3; ++i) { 885 lib3ds_float_write(mesh->map_data.pos[i], f);886 } 887 lib3ds_float_write(mesh->map_data.scale, f);885 lib3ds_float_write(mesh->map_data.pos[i], strm); 886 } 887 lib3ds_float_write(mesh->map_data.scale, strm); 888 888 889 889 for (i=0; i<4; i++) { 890 890 for (j=0; j<3; j++) { 891 lib3ds_float_write(mesh->map_data.matrix[i][j], f);891 lib3ds_float_write(mesh->map_data.matrix[i][j], strm); 892 892 } 893 893 } 894 894 for (i=0; i<2; ++i) { 895 lib3ds_float_write(mesh->map_data.planar_size[i], f);896 } 897 lib3ds_float_write(mesh->map_data.cylinder_height, f);898 } 899 900 if (!flag_array_write(mesh, f)) {895 lib3ds_float_write(mesh->map_data.planar_size[i], strm); 896 } 897 lib3ds_float_write(mesh->map_data.cylinder_height, strm); 898 } 899 900 if (!flag_array_write(mesh, strm)) { 901 901 return(LIB3DS_FALSE); 902 902 } … … 907 907 c.chunk=LIB3DS_MESH_MATRIX; 908 908 c.size=54; 909 if (!lib3ds_chunk_write(&c, f)) {909 if (!lib3ds_chunk_write(&c,strm)) { 910 910 return(LIB3DS_FALSE); 911 911 } 912 912 for (i=0; i<4; i++) { 913 913 for (j=0; j<3; j++) { 914 lib3ds_float_write(mesh->matrix[i][j], f);914 lib3ds_float_write(mesh->matrix[i][j], strm); 915 915 } 916 916 } … … 922 922 c.chunk=LIB3DS_MESH_COLOR; 923 923 c.size=7; 924 if (!lib3ds_chunk_write(&c, f)) {924 if (!lib3ds_chunk_write(&c,strm)) { 925 925 return(LIB3DS_FALSE); 926 926 } 927 lib3ds_byte_write(mesh->color, f);928 } 929 if (!face_array_write(mesh, f)) {930 return(LIB3DS_FALSE); 931 } 932 933 if (!lib3ds_chunk_write_end(&c, f)) {927 lib3ds_byte_write(mesh->color, strm); 928 } 929 if (!face_array_write(mesh, strm)) { 930 return(LIB3DS_FALSE); 931 } 932 933 if (!lib3ds_chunk_write_end(&c,strm)) { 934 934 return(LIB3DS_FALSE); 935 935 }
