static Lib3dsBool mdata_write(Lib3dsFile *file, FILE *f) { Lib3dsChunk c; c.chunk=LIB3DS_MDATA; if (!lib3ds_chunk_write_start(&c,f)) { return(LIB3DS_FALSE); } { /*---- LIB3DS_MESH_VERSION ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MESH_VERSION; c.size=10; lib3ds_chunk_write(&c,f); lib3ds_intd_write(file->mesh_version,f); } { /*---- LIB3DS_MASTER_SCALE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MASTER_SCALE; c.size=10; lib3ds_chunk_write(&c,f); lib3ds_float_write(file->master_scale,f); } { /*---- LIB3DS_O_CONSTS ----*/ int i; for (i=0; i<3; ++i) { if (fabs(file->construction_plane[i])>LIB3DS_EPSILON) { break; } } if (i<3) { Lib3dsChunk c; c.chunk=LIB3DS_O_CONSTS; c.size=18; lib3ds_chunk_write(&c,f); lib3ds_vector_write(file->construction_plane,f); } } { /*---- LIB3DS_AMBIENT_LIGHT ----*/ int i; for (i=0; i<3; ++i) { if (fabs(file->ambient[i])>LIB3DS_EPSILON) { break; } } if (i<3) { Lib3dsChunk c; c.chunk=LIB3DS_AMBIENT_LIGHT; c.size=42; lib3ds_chunk_write(&c,f); colorf_write(file->ambient,f); } } lib3ds_background_write(&file->background, f); lib3ds_atmosphere_write(&file->atmosphere, f); lib3ds_shadow_write(&file->shadow, f); lib3ds_viewport_write(&file->viewport, f); { Lib3dsMaterial *p; for (p=file->materials; p!=0; p=p->next) { if (!lib3ds_material_write(p,f)) { return(LIB3DS_FALSE); } } } { Lib3dsCamera *p; Lib3dsChunk c; for (p=file->cameras; p!=0; p=p->next) { c.chunk=LIB3DS_NAMED_OBJECT; if (!lib3ds_chunk_write_start(&c,f)) { return(LIB3DS_FALSE); } lib3ds_string_write(p->name,f); lib3ds_camera_write(p,f); if (!lib3ds_chunk_write_end(&c,f)) { return(LIB3DS_FALSE); } } } { Lib3dsLight *p; Lib3dsChunk c; for (p=file->lights; p!=0; p=p->next) { c.chunk=LIB3DS_NAMED_OBJECT; if (!lib3ds_chunk_write_start(&c,f)) { return(LIB3DS_FALSE); } lib3ds_string_write(p->name,f); lib3ds_light_write(p,f); if (!lib3ds_chunk_write_end(&c,f)) { return(LIB3DS_FALSE); } } } { Lib3dsMesh *p; Lib3dsChunk c; for (p=file->meshes; p!=0; p=p->next) { c.chunk=LIB3DS_NAMED_OBJECT; if (!lib3ds_chunk_write_start(&c,f)) { return(LIB3DS_FALSE); } lib3ds_string_write(p->name,f); lib3ds_mesh_write(p,f); if (!lib3ds_chunk_write_end(&c,f)) { return(LIB3DS_FALSE); } } } if (!lib3ds_chunk_write_end(&c,f)) { return(LIB3DS_FALSE); } return(LIB3DS_TRUE); }
static void mdata_write(Lib3dsFile *file, Lib3dsIo *io) { Lib3dsChunk c; c.chunk = CHK_MDATA; lib3ds_chunk_write_start(&c, io); { /*---- LIB3DS_MESH_VERSION ----*/ Lib3dsChunk c; c.chunk = CHK_MESH_VERSION; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_intd(io, file->mesh_version); } { /*---- LIB3DS_MASTER_SCALE ----*/ Lib3dsChunk c; c.chunk = CHK_MASTER_SCALE; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, file->master_scale); } { /*---- LIB3DS_O_CONSTS ----*/ int i; for (i = 0; i < 3; ++i) { if (fabs(file->construction_plane[i]) > LIB3DS_EPSILON) { break; } } if (i < 3) { Lib3dsChunk c; c.chunk = CHK_O_CONSTS; c.size = 18; lib3ds_chunk_write(&c, io); lib3ds_io_write_vector(io, file->construction_plane); } } { /*---- LIB3DS_AMBIENT_LIGHT ----*/ int i; for (i = 0; i < 3; ++i) { if (fabs(file->ambient[i]) > LIB3DS_EPSILON) { break; } } if (i < 3) { Lib3dsChunk c; c.chunk = CHK_AMBIENT_LIGHT; c.size = 42; lib3ds_chunk_write(&c, io); colorf_write(file->ambient, io); } } lib3ds_background_write(&file->background, io); lib3ds_atmosphere_write(&file->atmosphere, io); lib3ds_shadow_write(&file->shadow, io); lib3ds_viewport_write(&file->viewport, io); { int i; for (i = 0; i < file->nmaterials; ++i) { lib3ds_material_write(file->materials[i], io); } } { Lib3dsChunk c; int i; for (i = 0; i < file->ncameras; ++i) { c.chunk = CHK_NAMED_OBJECT; lib3ds_chunk_write_start(&c, io); lib3ds_io_write_string(io, file->cameras[i]->name); lib3ds_camera_write(file->cameras[i], io); object_flags_write(file->cameras[i]->object_flags, io); lib3ds_chunk_write_end(&c, io); } } { Lib3dsChunk c; int i; for (i = 0; i < file->nlights; ++i) { c.chunk = CHK_NAMED_OBJECT; lib3ds_chunk_write_start(&c, io); lib3ds_io_write_string(io, file->lights[i]->name); lib3ds_light_write(file->lights[i], io); object_flags_write(file->lights[i]->object_flags, io); lib3ds_chunk_write_end(&c, io); } } { Lib3dsChunk c; int i; for (i = 0; i < file->nmeshes; ++i) { c.chunk = CHK_NAMED_OBJECT; lib3ds_chunk_write_start(&c, io); lib3ds_io_write_string(io, file->meshes[i]->name); lib3ds_mesh_write(file, file->meshes[i], io); object_flags_write(file->meshes[i]->object_flags, io); lib3ds_chunk_write_end(&c, io); } } lib3ds_chunk_write_end(&c, io); }