static Lib3dsBool kfdata_write(Lib3dsFile *file, Lib3dsIo *io) { Lib3dsChunk c; if (!file->nodes) { return(LIB3DS_TRUE); } c.chunk=LIB3DS_KFDATA; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } { /*---- LIB3DS_KFHDR ----*/ Lib3dsChunk c; c.chunk=LIB3DS_KFHDR; c.size=6 + 2 + (Lib3dsDword)strlen(file->name)+1 +4; lib3ds_chunk_write(&c,io); lib3ds_io_write_intw(io, file->keyf_revision); lib3ds_io_write_string(io, file->name); lib3ds_io_write_intd(io, file->frames); } { /*---- LIB3DS_KFSEG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_KFSEG; c.size=14; lib3ds_chunk_write(&c,io); lib3ds_io_write_intd(io, file->segment_from); lib3ds_io_write_intd(io, file->segment_to); } { /*---- LIB3DS_KFCURTIME ----*/ Lib3dsChunk c; c.chunk=LIB3DS_KFCURTIME; c.size=10; lib3ds_chunk_write(&c,io); lib3ds_io_write_intd(io, file->current_frame); } lib3ds_viewport_write(&file->viewport_keyf, io); { Lib3dsNode *p; for (p=file->nodes; p!=0; p=p->next) { if (!lib3ds_node_write(p, file, io)) { return(LIB3DS_FALSE); } if (!nodes_write(p, file, io)) { return(LIB3DS_FALSE); } } } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } return(LIB3DS_TRUE); }
static Lib3dsBool kfdata_write(Lib3dsFile *file, FILE *f) { Lib3dsChunk c; c.chunk=LIB3DS_KFDATA; if (!lib3ds_chunk_write_start(&c,f)) { return(LIB3DS_FALSE); } { /*---- LIB3DS_KFHDR ----*/ Lib3dsChunk c; c.chunk=LIB3DS_KFHDR; c.size=6 + 2 + strlen(file->name)+1 +4; lib3ds_chunk_write(&c,f); lib3ds_intw_write(file->keyf_revision,f); lib3ds_string_write(file->name, f); lib3ds_intd_write(file->frames, f); } { /*---- LIB3DS_KFSEG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_KFSEG; c.size=14; lib3ds_chunk_write(&c,f); lib3ds_intd_write(file->segment_from,f); lib3ds_intd_write(file->segment_to,f); } { /*---- LIB3DS_KFCURTIME ----*/ Lib3dsChunk c; c.chunk=LIB3DS_KFCURTIME; c.size=10; lib3ds_chunk_write(&c,f); lib3ds_intd_write(file->current_frame,f); } lib3ds_viewport_write(&file->viewport_keyf, f); { Lib3dsNode *p; for (p=file->nodes; p!=0; p=p->next) { if (!lib3ds_node_write(p, file, f)) { return(LIB3DS_FALSE); } if (!nodes_write(p, file, f)) { return(LIB3DS_FALSE); } } } if (!lib3ds_chunk_write_end(&c,f)) { return(LIB3DS_FALSE); } return(LIB3DS_TRUE); }
static void kfdata_write(Lib3dsFile *file, Lib3dsIo *io) { Lib3dsChunk c; if (!file->nodes) { return; } c.chunk = CHK_KFDATA; lib3ds_chunk_write_start(&c, io); { /*---- LIB3DS_KFHDR ----*/ Lib3dsChunk c; c.chunk = CHK_KFHDR; c.size = 6 + 2 + (uint32_t)strlen(file->name) + 1 + 4; lib3ds_chunk_write(&c, io); lib3ds_io_write_intw(io, (int16_t)file->keyf_revision); lib3ds_io_write_string(io, file->name); lib3ds_io_write_intd(io, file->frames); } { /*---- LIB3DS_KFSEG ----*/ Lib3dsChunk c; c.chunk = CHK_KFSEG; c.size = 14; lib3ds_chunk_write(&c, io); lib3ds_io_write_intd(io, file->segment_from); lib3ds_io_write_intd(io, file->segment_to); } { /*---- LIB3DS_KFCURTIME ----*/ Lib3dsChunk c; c.chunk = CHK_KFCURTIME; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_intd(io, file->current_frame); } lib3ds_viewport_write(&file->viewport_keyf, io); { uint16_t default_id = 0; nodes_write(file->nodes, &default_id, 65535, io); } lib3ds_chunk_write_end(&c, io); }
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); }