void lib3ds_mesh_write(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io) { Lib3dsChunk c; c.chunk = CHK_N_TRI_OBJECT; lib3ds_chunk_write_start(&c, io); point_array_write(mesh, io); texco_array_write(mesh, io); if (mesh->map_type != LIB3DS_MAP_NONE) { /*---- LIB3DS_MESH_TEXTURE_INFO ----*/ Lib3dsChunk c; int i, j; c.chunk = CHK_MESH_TEXTURE_INFO; c.size = 92; lib3ds_chunk_write(&c, io); lib3ds_io_write_word(io, (uint16_t)mesh->map_type); for (i = 0; i < 2; ++i) { lib3ds_io_write_float(io, mesh->map_tile[i]); } lib3ds_io_write_vector(io, mesh->map_pos); lib3ds_io_write_float(io, mesh->map_scale); for (i = 0; i < 4; i++) { for (j = 0; j < 3; j++) { lib3ds_io_write_float(io, mesh->map_matrix[i][j]); } } for (i = 0; i < 2; ++i) { lib3ds_io_write_float(io, mesh->map_planar_size[i]); } lib3ds_io_write_float(io, mesh->map_cylinder_height); } flag_array_write(mesh, io); { /*---- LIB3DS_MESH_MATRIX ----*/ Lib3dsChunk c; int i, j; c.chunk = CHK_MESH_MATRIX; c.size = 54; lib3ds_chunk_write(&c, io); for (i = 0; i < 4; i++) { for (j = 0; j < 3; j++) { lib3ds_io_write_float(io, mesh->matrix[i][j]); } } } if (mesh->color) { /*---- LIB3DS_MESH_COLOR ----*/ Lib3dsChunk c; c.chunk = CHK_MESH_COLOR; c.size = 7; lib3ds_chunk_write(&c, io); lib3ds_io_write_byte(io, (uint8_t)mesh->color); } face_array_write(file, mesh, io); lib3ds_chunk_write_end(&c, io); }
/*! * \ingroup mesh */ Lib3dsBool lib3ds_mesh_write(Lib3dsMesh *mesh, Lib3dsIo *io) { Lib3dsChunk c; c.chunk=LIB3DS_N_TRI_OBJECT; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!point_array_write(mesh, io)) { return(LIB3DS_FALSE); } if (!texel_array_write(mesh, io)) { return(LIB3DS_FALSE); } if (mesh->map_data.maptype!=LIB3DS_MAP_NONE) { /*---- LIB3DS_MESH_TEXTURE_INFO ----*/ Lib3dsChunk c; int i,j; c.chunk=LIB3DS_MESH_TEXTURE_INFO; c.size=92; if (!lib3ds_chunk_write(&c,io)) { return(LIB3DS_FALSE); } lib3ds_io_write_word(io, mesh->map_data.maptype); for (i=0; i<2; ++i) { lib3ds_io_write_float(io, mesh->map_data.tile[i]); } for (i=0; i<3; ++i) { lib3ds_io_write_float(io, mesh->map_data.pos[i]); } lib3ds_io_write_float(io, mesh->map_data.scale); for (i=0; i<4; i++) { for (j=0; j<3; j++) { lib3ds_io_write_float(io, mesh->map_data.matrix[i][j]); } } for (i=0; i<2; ++i) { lib3ds_io_write_float(io, mesh->map_data.planar_size[i]); } lib3ds_io_write_float(io, mesh->map_data.cylinder_height); } if (!flag_array_write(mesh, io)) { return(LIB3DS_FALSE); } { /*---- LIB3DS_MESH_MATRIX ----*/ Lib3dsChunk c; int i,j; c.chunk=LIB3DS_MESH_MATRIX; c.size=54; if (!lib3ds_chunk_write(&c,io)) { return(LIB3DS_FALSE); } for (i=0; i<4; i++) { for (j=0; j<3; j++) { lib3ds_io_write_float(io, mesh->matrix[i][j]); } } } if (mesh->color) { /*---- LIB3DS_MESH_COLOR ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MESH_COLOR; c.size=7; if (!lib3ds_chunk_write(&c,io)) { return(LIB3DS_FALSE); } lib3ds_io_write_byte(io, mesh->color); } if (!face_array_write(mesh, io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } return(LIB3DS_TRUE); }