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 Lib3dsBool nodes_write(Lib3dsNode *node, Lib3dsFile *file, FILE *f) { { Lib3dsNode *p; for (p=node->childs; p!=0; p=p->next) { if (!lib3ds_node_write(p, file, f)) { return(LIB3DS_FALSE); } nodes_write(p, file, f); } } return(LIB3DS_TRUE); }
static void nodes_write(Lib3dsNode *first_node, uint16_t *default_id, uint16_t parent_id, Lib3dsIo *io) { Lib3dsNode *p; for (p = first_node; p != NULL; p = p->next) { uint16_t node_id; if ((p->type == LIB3DS_NODE_AMBIENT_COLOR) || (p->node_id != 65535)) { node_id = p->node_id; } else { node_id = *default_id; } ++(*default_id); lib3ds_node_write(p, node_id, parent_id, io); nodes_write(p->childs, default_id, node_id, io); } }
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); }