/*! * \ingroup file */ Lib3dsBool lib3ds_file_write(Lib3dsFile *file, FILE *f) { Lib3dsChunk c; c.chunk=LIB3DS_M3DMAGIC; if (!lib3ds_chunk_write_start(&c,f)) { LIB3DS_ERROR_LOG; return(LIB3DS_FALSE); } { /*---- LIB3DS_M3D_VERSION ----*/ Lib3dsChunk c; c.chunk=LIB3DS_M3D_VERSION; c.size=10; lib3ds_chunk_write(&c,f); lib3ds_dword_write(file->mesh_version, f); } if (!mdata_write(file, f)) { return(LIB3DS_FALSE); } if (!kfdata_write(file, f)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,f)) { return(LIB3DS_FALSE); } return(LIB3DS_TRUE); }
/*! * Write a camera definition to a file. * * This function is called by lib3ds_file_write(), and you probably * don't want to call it directly. * * \param camera A Lib3dsCamera to be written. * \param io A Lib3dsIo object previously set up by the caller. * * \see lib3ds_file_write */ void lib3ds_camera_write(Lib3dsCamera *camera, Lib3dsIo *io) { Lib3dsChunk c; c.chunk = CHK_N_CAMERA; lib3ds_chunk_write_start(&c, io); lib3ds_io_write_vector(io, camera->position); lib3ds_io_write_vector(io, camera->target); lib3ds_io_write_float(io, camera->roll); if (fabs(camera->fov) < LIB3DS_EPSILON) { lib3ds_io_write_float(io, 2400.0f / 45.0f); } else { lib3ds_io_write_float(io, 2400.0f / camera->fov); } if (camera->see_cone) { Lib3dsChunk c; c.chunk = CHK_CAM_SEE_CONE; c.size = 6; lib3ds_chunk_write(&c, io); } { Lib3dsChunk c; c.chunk = CHK_CAM_RANGES; c.size = 14; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, camera->near_range); lib3ds_io_write_float(io, camera->far_range); } lib3ds_chunk_write_end(&c, io); }
/*! * Write 3ds file data from a Lib3dsFile object to a file. * * \param file The Lib3dsFile object to be written. * \param io A Lib3dsIo object previously set up by the caller. * * \return LIB3DS_TRUE on success, LIB3DS_FALSE on failure. */ int lib3ds_file_write(Lib3dsFile *file, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsIoImpl *impl; lib3ds_io_setup(io); impl = (Lib3dsIoImpl*)io->impl; if (setjmp(impl->jmpbuf) != 0) { lib3ds_io_cleanup(io); return FALSE; } c.chunk = CHK_M3DMAGIC; lib3ds_chunk_write_start(&c, io); { /*---- LIB3DS_M3D_VERSION ----*/ Lib3dsChunk c; c.chunk = CHK_M3D_VERSION; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_dword(io, file->mesh_version); } mdata_write(file, io); kfdata_write(file, io); lib3ds_chunk_write_end(&c, io); memset(impl->jmpbuf, 0, sizeof(impl->jmpbuf)); lib3ds_io_cleanup(io); return TRUE; }
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); }
/*! * \ingroup node */ Lib3dsBool lib3ds_node_write(Lib3dsNode *node, Lib3dsFile *file, Lib3dsIo *io) { Lib3dsChunk c; switch (node->type) { case LIB3DS_AMBIENT_NODE: c.chunk=LIB3DS_AMBIENT_NODE_TAG; break; case LIB3DS_OBJECT_NODE: c.chunk=LIB3DS_OBJECT_NODE_TAG; break; case LIB3DS_CAMERA_NODE: c.chunk=LIB3DS_CAMERA_NODE_TAG; break; case LIB3DS_TARGET_NODE: c.chunk=LIB3DS_TARGET_NODE_TAG; break; case LIB3DS_LIGHT_NODE: if (lib3ds_file_node_by_name(file, node->name, LIB3DS_SPOT_NODE)) { c.chunk=LIB3DS_SPOTLIGHT_NODE_TAG; } else { c.chunk=LIB3DS_LIGHT_NODE_TAG; } break; case LIB3DS_SPOT_NODE: c.chunk=LIB3DS_L_TARGET_NODE_TAG; break; default: return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } { /*---- LIB3DS_NODE_ID ----*/ Lib3dsChunk c; c.chunk=LIB3DS_NODE_ID; c.size=8; lib3ds_chunk_write(&c,io); lib3ds_io_write_intw(io, node->node_id); } { /*---- LIB3DS_NODE_HDR ----*/ Lib3dsChunk c; c.chunk=LIB3DS_NODE_HDR; c.size=6+ 1+(Lib3dsDword)strlen(node->name) +2+2+2; lib3ds_chunk_write(&c,io); lib3ds_io_write_string(io, node->name); lib3ds_io_write_word(io, node->flags1); lib3ds_io_write_word(io, node->flags2); lib3ds_io_write_word(io, node->parent_id); } switch (c.chunk) { case LIB3DS_AMBIENT_NODE_TAG: { /*---- LIB3DS_COL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_COL_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin3_track_write(&node->data.ambient.col_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_OBJECT_NODE_TAG: { /*---- LIB3DS_PIVOT ----*/ Lib3dsChunk c; c.chunk=LIB3DS_PIVOT; c.size=18; lib3ds_chunk_write(&c,io); lib3ds_io_write_vector(io, node->data.object.pivot); } { /*---- LIB3DS_INSTANCE_NAME ----*/ Lib3dsChunk c; const char *name; if (strlen(node->data.object.instance)) { name=node->data.object.instance; c.chunk=LIB3DS_INSTANCE_NAME; c.size=6+1+(Lib3dsDword)strlen(name); lib3ds_chunk_write(&c,io); lib3ds_io_write_string(io, name); } } { int i; for (i=0; i<3; ++i) { if ((fabs(node->data.object.bbox_min[i])>LIB3DS_EPSILON) || (fabs(node->data.object.bbox_max[i])>LIB3DS_EPSILON)) { break; } } if (i<3) { /*---- LIB3DS_BOUNDBOX ----*/ Lib3dsChunk c; c.chunk=LIB3DS_BOUNDBOX; c.size=30; lib3ds_chunk_write(&c,io); lib3ds_io_write_vector(io, node->data.object.bbox_min); lib3ds_io_write_vector(io, node->data.object.bbox_max); } } { /*---- LIB3DS_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_POS_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin3_track_write(&node->data.object.pos_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } { /*---- LIB3DS_ROT_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_ROT_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_quat_track_write(&node->data.object.rot_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } { /*---- LIB3DS_SCL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_SCL_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin3_track_write(&node->data.object.scl_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } if (node->data.object.hide_track.keyL) { /*---- LIB3DS_HIDE_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_HIDE_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_bool_track_write(&node->data.object.hide_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } if (fabs(node->data.object.morph_smooth)>LIB3DS_EPSILON){ /*---- LIB3DS_MORPH_SMOOTH ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MORPH_SMOOTH; c.size=10; lib3ds_chunk_write(&c,io); lib3ds_io_write_float(io, node->data.object.morph_smooth); } break; case LIB3DS_CAMERA_NODE_TAG: { /*---- LIB3DS_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_POS_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin3_track_write(&node->data.camera.pos_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } { /*---- LIB3DS_FOV_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_FOV_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin1_track_write(&node->data.camera.fov_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } { /*---- LIB3DS_ROLL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_ROLL_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin1_track_write(&node->data.camera.roll_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_TARGET_NODE_TAG: { /*---- LIB3DS_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_POS_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin3_track_write(&node->data.target.pos_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_LIGHT_NODE_TAG: { /*---- LIB3DS_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_POS_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin3_track_write(&node->data.light.pos_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } { /*---- LIB3DS_COL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_COL_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin3_track_write(&node->data.light.col_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_SPOTLIGHT_NODE_TAG: { /*---- LIB3DS_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_POS_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin3_track_write(&node->data.light.pos_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } { /*---- LIB3DS_COL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_COL_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin3_track_write(&node->data.light.col_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } { /*---- LIB3DS_HOT_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_HOT_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin1_track_write(&node->data.light.hotspot_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } { /*---- LIB3DS_FALL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_FALL_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin1_track_write(&node->data.light.falloff_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } { /*---- LIB3DS_ROLL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_ROLL_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin1_track_write(&node->data.light.roll_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_L_TARGET_NODE_TAG: { /*---- LIB3DS_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_POS_TRACK_TAG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } if (!lib3ds_lin3_track_write(&node->data.spot.pos_track,io)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } break; default: return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } return(LIB3DS_TRUE); }
void lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io) { if (atmosphere->use_fog) /*---- LIB3DS_FOG ----*/ { Lib3dsChunk c; c.chunk = CHK_FOG; lib3ds_chunk_write_start(&c, io); lib3ds_io_write_float(io, atmosphere->fog_near_plane); lib3ds_io_write_float(io, atmosphere->fog_near_density); lib3ds_io_write_float(io, atmosphere->fog_far_plane); lib3ds_io_write_float(io, atmosphere->fog_far_density); { Lib3dsChunk c; c.chunk = CHK_COLOR_F; c.size = 18; lib3ds_chunk_write(&c, io); lib3ds_io_write_rgb(io, atmosphere->fog_color); } if (atmosphere->fog_background) { Lib3dsChunk c; c.chunk = CHK_FOG_BGND; c.size = 6; lib3ds_chunk_write(&c, io); } lib3ds_chunk_write_end(&c, io); } if (atmosphere->use_layer_fog) /*---- LIB3DS_LAYER_FOG ----*/ { Lib3dsChunk c; c.chunk = CHK_LAYER_FOG; c.size = 40; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, atmosphere->layer_fog_near_y); lib3ds_io_write_float(io, atmosphere->layer_fog_far_y); lib3ds_io_write_float(io, atmosphere->layer_fog_near_y); lib3ds_io_write_dword(io, atmosphere->layer_fog_flags); { Lib3dsChunk c; c.chunk = CHK_COLOR_F; c.size = 18; lib3ds_chunk_write(&c, io); lib3ds_io_write_rgb(io, atmosphere->fog_color); } } if (atmosphere->use_dist_cue) /*---- LIB3DS_DISTANCE_CUE ----*/ { Lib3dsChunk c; c.chunk = CHK_DISTANCE_CUE; lib3ds_chunk_write_start(&c, io); lib3ds_io_write_float(io, atmosphere->dist_cue_near_plane); lib3ds_io_write_float(io, atmosphere->dist_cue_near_dimming); lib3ds_io_write_float(io, atmosphere->dist_cue_far_plane); lib3ds_io_write_float(io, atmosphere->dist_cue_far_dimming); if (atmosphere->dist_cue_background) { Lib3dsChunk c; c.chunk = CHK_DCUE_BGND; c.size = 6; lib3ds_chunk_write(&c, io); } lib3ds_chunk_write_end(&c, io); } if (atmosphere->use_fog) /*---- LIB3DS_USE_FOG ----*/ { Lib3dsChunk c; c.chunk = CHK_USE_FOG; c.size = 6; lib3ds_chunk_write(&c, io); } if (atmosphere->use_layer_fog) /*---- LIB3DS_USE_LAYER_FOG ----*/ { Lib3dsChunk c; c.chunk = CHK_USE_LAYER_FOG; c.size = 6; lib3ds_chunk_write(&c, io); } if (atmosphere->use_dist_cue) /*---- LIB3DS_USE_DISTANCE_CUE ----*/ { Lib3dsChunk c; c.chunk = CHK_USE_V_GRADIENT; c.size = 6; lib3ds_chunk_write(&c, io); } }
static void face_array_write(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io) { Lib3dsChunk c; if (mesh->nfaces == 0) { return; } c.chunk = CHK_FACE_ARRAY; lib3ds_chunk_write_start(&c, io); { int i; lib3ds_io_write_word(io, (uint16_t) mesh->nfaces); for (i = 0; i < mesh->nfaces; ++i) { lib3ds_io_write_word(io, mesh->faces[i].index[0]); lib3ds_io_write_word(io, mesh->faces[i].index[1]); lib3ds_io_write_word(io, mesh->faces[i].index[2]); lib3ds_io_write_word(io, mesh->faces[i].flags); } } { /*---- MSH_CHK_MAT_GROUP ----*/ Lib3dsChunk c; int i, j; uint16_t num; char *matf = (char*)calloc(sizeof(char), mesh->nfaces); ((Lib3dsIoImpl*)io->impl)->tmp_mem = matf; assert(matf); for (i = 0; i < mesh->nfaces; ++i) { if (!matf[i] && (mesh->faces[i].material >= 0) && (mesh->faces[i].material < file->nmaterials)) { matf[i] = 1; num = 1; for (j = i + 1; j < mesh->nfaces; ++j) { if (mesh->faces[i].material == mesh->faces[j].material) ++num; } c.chunk = CHK_MSH_MAT_GROUP; c.size = 6 + (uint32_t)strlen(file->materials[mesh->faces[i].material]->name) + 1 + 2 + 2 * num; lib3ds_chunk_write(&c, io); lib3ds_io_write_string(io, file->materials[mesh->faces[i].material]->name); lib3ds_io_write_word(io, num); lib3ds_io_write_word(io, (uint16_t) i); for (j = i + 1; j < mesh->nfaces; ++j) { if (mesh->faces[i].material == mesh->faces[j].material) { lib3ds_io_write_word(io, (uint16_t) j); matf[j] = 1; } } } } ((Lib3dsIoImpl*)io->impl)->tmp_mem = NULL; free(matf); } { /*---- SMOOTH_GROUP ----*/ Lib3dsChunk c; int i; c.chunk = CHK_SMOOTH_GROUP; c.size = 6 + 4 * mesh->nfaces; lib3ds_chunk_write(&c, io); for (i = 0; i < mesh->nfaces; ++i) { lib3ds_io_write_dword(io, mesh->faces[i].smoothing_group); } } { /*---- MSH_BOXMAP ----*/ Lib3dsChunk c; if (strlen(mesh->box_front) || strlen(mesh->box_back) || strlen(mesh->box_left) || strlen(mesh->box_right) || strlen(mesh->box_top) || strlen(mesh->box_bottom)) { c.chunk = CHK_MSH_BOXMAP; lib3ds_chunk_write_start(&c, io); lib3ds_io_write_string(io, mesh->box_front); lib3ds_io_write_string(io, mesh->box_back); lib3ds_io_write_string(io, mesh->box_left); lib3ds_io_write_string(io, mesh->box_right); lib3ds_io_write_string(io, mesh->box_top); lib3ds_io_write_string(io, mesh->box_bottom); lib3ds_chunk_write_end(&c, io); } } lib3ds_chunk_write_end(&c, io); }
static Lib3dsBool face_array_write(Lib3dsMesh *mesh, Lib3dsIo *io) { Lib3dsChunk c; if (!mesh->faces || !mesh->faceL) { return(LIB3DS_TRUE); } ASSERT(mesh->faces<0x10000); c.chunk=LIB3DS_FACE_ARRAY; if (!lib3ds_chunk_write_start(&c, io)) { return(LIB3DS_FALSE); } { unsigned i; lib3ds_io_write_word(io, (Lib3dsWord)mesh->faces); for (i=0; i<mesh->faces; ++i) { lib3ds_io_write_word(io, mesh->faceL[i].points[0]); lib3ds_io_write_word(io, mesh->faceL[i].points[1]); lib3ds_io_write_word(io, mesh->faceL[i].points[2]); lib3ds_io_write_word(io, mesh->faceL[i].flags); } } { /*---- MSH_MAT_GROUP ----*/ Lib3dsChunk c; unsigned i,j; Lib3dsWord num; char *matf=calloc(sizeof(char), mesh->faces); if (!matf) { return(LIB3DS_FALSE); } for (i=0; i<mesh->faces; ++i) { if (!matf[i] && strlen(mesh->faceL[i].material)) { matf[i]=1; num=1; for (j=i+1; j<mesh->faces; ++j) { if (strcmp(mesh->faceL[i].material, mesh->faceL[j].material)==0) ++num; } c.chunk=LIB3DS_MSH_MAT_GROUP; c.size=6+ (Lib3dsDword)strlen(mesh->faceL[i].material)+1 +2+2*num; lib3ds_chunk_write(&c, io); lib3ds_io_write_string(io, mesh->faceL[i].material); lib3ds_io_write_word(io, num); lib3ds_io_write_word(io, (Lib3dsWord)i); for (j=i+1; j<mesh->faces; ++j) { if (strcmp(mesh->faceL[i].material, mesh->faceL[j].material)==0) { lib3ds_io_write_word(io, (Lib3dsWord)j); matf[j]=1; } } } } free(matf); } { /*---- SMOOTH_GROUP ----*/ Lib3dsChunk c; unsigned i; c.chunk=LIB3DS_SMOOTH_GROUP; c.size=6+4*mesh->faces; lib3ds_chunk_write(&c, io); for (i=0; i<mesh->faces; ++i) { lib3ds_io_write_dword(io, mesh->faceL[i].smoothing); } } { /*---- MSH_BOXMAP ----*/ Lib3dsChunk c; if (strlen(mesh->box_map.front) || strlen(mesh->box_map.back) || strlen(mesh->box_map.left) || strlen(mesh->box_map.right) || strlen(mesh->box_map.top) || strlen(mesh->box_map.bottom)) { c.chunk=LIB3DS_MSH_BOXMAP; if (!lib3ds_chunk_write_start(&c, io)) { return(LIB3DS_FALSE); } lib3ds_io_write_string(io, mesh->box_map.front); lib3ds_io_write_string(io, mesh->box_map.back); lib3ds_io_write_string(io, mesh->box_map.left); lib3ds_io_write_string(io, mesh->box_map.right); lib3ds_io_write_string(io, mesh->box_map.top); lib3ds_io_write_string(io, mesh->box_map.bottom); if (!lib3ds_chunk_write_end(&c, io)) { return(LIB3DS_FALSE); } } } if (!lib3ds_chunk_write_end(&c, io)) { 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); }
/*! * \ingroup light */ Lib3dsBool lib3ds_light_write(Lib3dsLight *light, Lib3dsIo *io) { Lib3dsChunk c; c.chunk=LIB3DS_N_DIRECT_LIGHT; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } lib3ds_io_write_vector(io, light->position); { /*---- LIB3DS_COLOR_F ----*/ Lib3dsChunk c; c.chunk=LIB3DS_COLOR_F; c.size=18; lib3ds_chunk_write(&c, io); lib3ds_io_write_rgb(io, light->color); } if (light->off) { /*---- LIB3DS_DL_OFF ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_OFF; c.size=6; lib3ds_chunk_write(&c, io); } { /*---- LIB3DS_DL_OUTER_RANGE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_OUTER_RANGE; c.size=10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, light->outer_range); } { /*---- LIB3DS_DL_INNER_RANGE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_INNER_RANGE; c.size=10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, light->inner_range); } { /*---- LIB3DS_DL_MULTIPLIER ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_MULTIPLIER; c.size=10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, light->multiplier); } if (light->attenuation) { /*---- LIB3DS_DL_ATTENUATE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_ATTENUATE; c.size=6; lib3ds_chunk_write(&c, io); } if (light->spot_light) { Lib3dsChunk c; c.chunk=LIB3DS_DL_SPOTLIGHT; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } lib3ds_io_write_vector(io, light->spot); lib3ds_io_write_float(io, light->hot_spot); lib3ds_io_write_float(io, light->fall_off); { /*---- LIB3DS_DL_SPOT_ROLL ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_SPOT_ROLL; c.size=10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, light->roll); } if (light->shadowed) { /*---- LIB3DS_DL_SHADOWED ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_SHADOWED; c.size=6; lib3ds_chunk_write(&c, io); } if ((fabs(light->shadow_bias)>LIB3DS_EPSILON) || (fabs(light->shadow_filter)>LIB3DS_EPSILON) || (light->shadow_size!=0)) { /*---- LIB3DS_DL_LOCAL_SHADOW2 ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_LOCAL_SHADOW2; c.size=16; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, light->shadow_bias); lib3ds_io_write_float(io, light->shadow_filter); lib3ds_io_write_intw(io, light->shadow_size); } if (light->see_cone) { /*---- LIB3DS_DL_SEE_CONE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_SEE_CONE; c.size=6; lib3ds_chunk_write(&c, io); } if (light->rectangular_spot) { /*---- LIB3DS_DL_SPOT_RECTANGULAR ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_SPOT_RECTANGULAR; c.size=6; lib3ds_chunk_write(&c, io); } if (fabs(light->spot_aspect)>LIB3DS_EPSILON) { /*---- LIB3DS_DL_SPOT_ASPECT ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_SPOT_ASPECT; c.size=10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, light->spot_aspect); } if (light->use_projector) { /*---- LIB3DS_DL_SPOT_PROJECTOR ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_SPOT_PROJECTOR; c.size=10; lib3ds_chunk_write(&c, io); lib3ds_io_write_string(io, light->projector); } if (light->spot_overshoot) { /*---- LIB3DS_DL_SPOT_OVERSHOOT ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_SPOT_OVERSHOOT; c.size=6; lib3ds_chunk_write(&c, io); } if (fabs(light->ray_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_DL_RAY_BIAS ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_RAY_BIAS; c.size=10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, light->ray_bias); } if (light->ray_shadows) { /*---- LIB3DS_DL_RAYSHAD ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DL_RAYSHAD; c.size=6; lib3ds_chunk_write(&c, io); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } return(LIB3DS_TRUE); }
static Lib3dsBool texture_map_write(Lib3dsWord chunk, Lib3dsTextureMap *map, Lib3dsIo *io) { Lib3dsChunk c; if (strlen(map->name)==0) { return(LIB3DS_TRUE); } c.chunk=chunk; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } int_percentage_write(map->percent,io); { /*---- LIB3DS_MAT_MAPNAME ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAPNAME; c.size=6+(Lib3dsDword)strlen(map->name)+1; lib3ds_chunk_write(&c,io); lib3ds_io_write_string(io, map->name); } { /*---- LIB3DS_MAT_MAP_TILING ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_TILING; c.size=8; lib3ds_chunk_write(&c,io); lib3ds_io_write_word(io, (Lib3dsWord)map->flags); } { /*---- LIB3DS_MAT_MAP_TEXBLUR ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_TEXBLUR; c.size=10; lib3ds_chunk_write(&c,io); lib3ds_io_write_float(io, map->blur); } { /*---- LIB3DS_MAT_MAP_USCALE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_USCALE; c.size=10; lib3ds_chunk_write(&c,io); lib3ds_io_write_float(io, map->scale[0]); } { /*---- LIB3DS_MAT_MAP_VSCALE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_VSCALE; c.size=10; lib3ds_chunk_write(&c,io); lib3ds_io_write_float(io, map->scale[1]); } { /*---- LIB3DS_MAT_MAP_UOFFSET ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_UOFFSET; c.size=10; lib3ds_chunk_write(&c,io); lib3ds_io_write_float(io, map->offset[0]); } { /*---- LIB3DS_MAT_MAP_VOFFSET ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_VOFFSET; c.size=10; lib3ds_chunk_write(&c,io); lib3ds_io_write_float(io, map->offset[1]); } { /*---- LIB3DS_MAT_MAP_ANG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_ANG; c.size=10; lib3ds_chunk_write(&c,io); lib3ds_io_write_float(io, map->rotation); } { /*---- LIB3DS_MAT_MAP_COL1 ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_COL1; c.size=9; lib3ds_chunk_write(&c,io); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_1[0]+0.5)); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_1[1]+0.5)); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_1[2]+0.5)); } { /*---- LIB3DS_MAT_MAP_COL2 ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_COL2; c.size=9; lib3ds_chunk_write(&c,io); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_2[0]+0.5)); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_2[1]+0.5)); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_2[2]+0.5)); } { /*---- LIB3DS_MAT_MAP_RCOL ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_RCOL; c.size=9; lib3ds_chunk_write(&c,io); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_r[0]+0.5)); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_r[1]+0.5)); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_r[2]+0.5)); } { /*---- LIB3DS_MAT_MAP_GCOL ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_GCOL; c.size=9; lib3ds_chunk_write(&c,io); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_g[0]+0.5)); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_g[1]+0.5)); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_g[2]+0.5)); } { /*---- LIB3DS_MAT_MAP_BCOL ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_MAP_BCOL; c.size=9; lib3ds_chunk_write(&c,io); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_b[0]+0.5)); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_b[1]+0.5)); lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_b[2]+0.5)); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } return(LIB3DS_TRUE); }
/*! * \ingroup viewport */ Lib3dsBool lib3ds_viewport_write(Lib3dsViewport *viewport, Lib3dsIo *io) { if (viewport->layout.views) { Lib3dsChunk c; unsigned i; c.chunk=LIB3DS_VIEWPORT_LAYOUT; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } lib3ds_io_write_word(io, viewport->layout.style); lib3ds_io_write_intw(io, viewport->layout.active); lib3ds_io_write_intw(io, 0); lib3ds_io_write_intw(io, viewport->layout.swap); lib3ds_io_write_intw(io, 0); lib3ds_io_write_intw(io, viewport->layout.swap_prior); lib3ds_io_write_intw(io, viewport->layout.swap_view); { Lib3dsChunk c; c.chunk=LIB3DS_VIEWPORT_SIZE; c.size=14; lib3ds_chunk_write(&c,io); lib3ds_io_write_intw(io, viewport->layout.position[0]); lib3ds_io_write_intw(io, viewport->layout.position[1]); lib3ds_io_write_intw(io, viewport->layout.size[0]); lib3ds_io_write_intw(io, viewport->layout.size[1]); } for (i=0; i<viewport->layout.views; ++i) { Lib3dsChunk c; c.chunk=LIB3DS_VIEWPORT_DATA_3; c.size=55; lib3ds_chunk_write(&c,io); lib3ds_io_write_intw(io, 0); lib3ds_io_write_word(io, viewport->layout.viewL[i].axis_lock); lib3ds_io_write_intw(io, viewport->layout.viewL[i].position[0]); lib3ds_io_write_intw(io, viewport->layout.viewL[i].position[1]); lib3ds_io_write_intw(io, viewport->layout.viewL[i].size[0]); lib3ds_io_write_intw(io, viewport->layout.viewL[i].size[1]); lib3ds_io_write_word(io, viewport->layout.viewL[i].type); lib3ds_io_write_float(io, viewport->layout.viewL[i].zoom); lib3ds_io_write_vector(io, viewport->layout.viewL[i].center); lib3ds_io_write_float(io, viewport->layout.viewL[i].horiz_angle); lib3ds_io_write_float(io, viewport->layout.viewL[i].vert_angle); lib3ds_io_write(io, viewport->layout.viewL[i].camera,11); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } if (viewport->default_view.type) { Lib3dsChunk c; c.chunk=LIB3DS_DEFAULT_VIEW; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } switch (viewport->default_view.type) { case LIB3DS_VIEW_TYPE_TOP: { Lib3dsChunk c; c.chunk=LIB3DS_VIEW_TOP; c.size=22; lib3ds_chunk_write(&c,io); lib3ds_io_write_vector(io, viewport->default_view.position); lib3ds_io_write_float(io, viewport->default_view.width); } break; case LIB3DS_VIEW_TYPE_BOTTOM: { Lib3dsChunk c; c.chunk=LIB3DS_VIEW_BOTTOM; c.size=22; lib3ds_chunk_write(&c,io); lib3ds_io_write_vector(io, viewport->default_view.position); lib3ds_io_write_float(io, viewport->default_view.width); } break; case LIB3DS_VIEW_TYPE_LEFT: { Lib3dsChunk c; c.chunk=LIB3DS_VIEW_LEFT; c.size=22; lib3ds_chunk_write(&c,io); lib3ds_io_write_vector(io, viewport->default_view.position); lib3ds_io_write_float(io, viewport->default_view.width); } break; case LIB3DS_VIEW_TYPE_RIGHT: { Lib3dsChunk c; c.chunk=LIB3DS_VIEW_RIGHT; c.size=22; lib3ds_chunk_write(&c,io); lib3ds_io_write_vector(io, viewport->default_view.position); lib3ds_io_write_float(io, viewport->default_view.width); } break; case LIB3DS_VIEW_TYPE_FRONT: { Lib3dsChunk c; c.chunk=LIB3DS_VIEW_FRONT; c.size=22; lib3ds_chunk_write(&c,io); lib3ds_io_write_vector(io, viewport->default_view.position); lib3ds_io_write_float(io, viewport->default_view.width); } break; case LIB3DS_VIEW_TYPE_BACK: { Lib3dsChunk c; c.chunk=LIB3DS_VIEW_BACK; c.size=22; lib3ds_chunk_write(&c,io); lib3ds_io_write_vector(io, viewport->default_view.position); lib3ds_io_write_float(io, viewport->default_view.width); } break; case LIB3DS_VIEW_TYPE_USER: { Lib3dsChunk c; c.chunk=LIB3DS_VIEW_USER; c.size=34; lib3ds_chunk_write(&c,io); lib3ds_io_write_vector(io, viewport->default_view.position); lib3ds_io_write_float(io, viewport->default_view.width); lib3ds_io_write_float(io, viewport->default_view.horiz_angle); lib3ds_io_write_float(io, viewport->default_view.vert_angle); lib3ds_io_write_float(io, viewport->default_view.roll_angle); } break; case LIB3DS_VIEW_TYPE_CAMERA: { Lib3dsChunk c; c.chunk=LIB3DS_VIEW_CAMERA; c.size=17; lib3ds_chunk_write(&c, io); lib3ds_io_write(io, viewport->default_view.camera, 11); } break; } if (!lib3ds_chunk_write_end(&c, io)) { return(LIB3DS_FALSE); } } return(LIB3DS_TRUE); }
static void texture_map_write(uint16_t chunk, Lib3dsTextureMap *map, Lib3dsIo *io) { Lib3dsChunk c; if (strlen(map->name) == 0) { return; } c.chunk = chunk; lib3ds_chunk_write_start(&c, io); int_percentage_write(map->percent, io); { /*---- CHK_MAT_MAPNAME ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAPNAME; c.size = 6 + (uint32_t)strlen(map->name) + 1; lib3ds_chunk_write(&c, io); lib3ds_io_write_string(io, map->name); } { /*---- CHK_MAT_MAP_TILING ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_TILING; c.size = 8; lib3ds_chunk_write(&c, io); lib3ds_io_write_word(io, (uint16_t)map->flags); } { /*---- CHK_MAT_MAP_TEXBLUR ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_TEXBLUR; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, map->blur); } { /*---- CHK_MAT_MAP_USCALE ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_USCALE; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, map->scale[0]); } { /*---- CHK_MAT_MAP_VSCALE ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_VSCALE; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, map->scale[1]); } { /*---- CHK_MAT_MAP_UOFFSET ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_UOFFSET; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, map->offset[0]); } { /*---- CHK_MAT_MAP_VOFFSET ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_VOFFSET; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, map->offset[1]); } { /*---- CHK_MAT_MAP_ANG ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_ANG; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, map->rotation); } { /*---- CHK_MAT_MAP_COL1 ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_COL1; c.size = 9; lib3ds_chunk_write(&c, io); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_1[0] + 0.5)); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_1[1] + 0.5)); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_1[2] + 0.5)); } { /*---- CHK_MAT_MAP_COL2 ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_COL2; c.size = 9; lib3ds_chunk_write(&c, io); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_2[0] + 0.5)); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_2[1] + 0.5)); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_2[2] + 0.5)); } { /*---- CHK_MAT_MAP_RCOL ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_RCOL; c.size = 9; lib3ds_chunk_write(&c, io); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_r[0] + 0.5)); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_r[1] + 0.5)); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_r[2] + 0.5)); } { /*---- CHK_MAT_MAP_GCOL ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_GCOL; c.size = 9; lib3ds_chunk_write(&c, io); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_g[0] + 0.5)); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_g[1] + 0.5)); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_g[2] + 0.5)); } { /*---- CHK_MAT_MAP_BCOL ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_MAP_BCOL; c.size = 9; lib3ds_chunk_write(&c, io); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_b[0] + 0.5)); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_b[1] + 0.5)); lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_b[2] + 0.5)); } lib3ds_chunk_write_end(&c, io); }
void lib3ds_material_write(Lib3dsMaterial *material, Lib3dsIo *io) { Lib3dsChunk c; c.chunk = CHK_MAT_ENTRY; lib3ds_chunk_write_start(&c, io); { /*---- CHK_MAT_NAME ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_NAME; c.size = 6 + (uint32_t)strlen(material->name) + 1; lib3ds_chunk_write(&c, io); lib3ds_io_write_string(io, material->name); } { /*---- CHK_MAT_AMBIENT ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_AMBIENT; c.size = 24; lib3ds_chunk_write(&c, io); color_write(material->ambient, io); } { /*---- CHK_MAT_DIFFUSE ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_DIFFUSE; c.size = 24; lib3ds_chunk_write(&c, io); color_write(material->diffuse, io); } { /*---- CHK_MAT_SPECULAR ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_SPECULAR; c.size = 24; lib3ds_chunk_write(&c, io); color_write(material->specular, io); } { /*---- CHK_MAT_SHININESS ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_SHININESS; c.size = 14; lib3ds_chunk_write(&c, io); int_percentage_write(material->shininess, io); } { /*---- CHK_MAT_SHIN2PCT ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_SHIN2PCT; c.size = 14; lib3ds_chunk_write(&c, io); int_percentage_write(material->shin_strength, io); } { /*---- CHK_MAT_TRANSPARENCY ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_TRANSPARENCY; c.size = 14; lib3ds_chunk_write(&c, io); int_percentage_write(material->transparency, io); } { /*---- CHK_MAT_XPFALL ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_XPFALL; c.size = 14; lib3ds_chunk_write(&c, io); int_percentage_write(material->falloff, io); } if (material->use_falloff) { /*---- CHK_MAT_USE_XPFALL ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_USE_XPFALL; c.size = 6; lib3ds_chunk_write(&c, io); } { /*---- CHK_MAT_SHADING ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_SHADING; c.size = 8; lib3ds_chunk_write(&c, io); lib3ds_io_write_intw(io, material->shading); } { /*---- CHK_MAT_REFBLUR ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_REFBLUR; c.size = 14; lib3ds_chunk_write(&c, io); int_percentage_write(material->blur, io); } if (material->use_blur) { /*---- CHK_MAT_USE_REFBLUR ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_USE_REFBLUR; c.size = 6; lib3ds_chunk_write(&c, io); } if (material->self_illum_flag) { /*---- CHK_MAT_SELF_ILLUM ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_SELF_ILLUM; c.size = 6; lib3ds_chunk_write(&c, io); } if (material->two_sided) { /*---- CHK_MAT_TWO_SIDE ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_TWO_SIDE; c.size = 6; lib3ds_chunk_write(&c, io); } if (material->map_decal) { /*---- CHK_MAT_DECAL ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_DECAL; c.size = 6; lib3ds_chunk_write(&c, io); } if (material->is_additive) { /*---- CHK_MAT_ADDITIVE ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_ADDITIVE; c.size = 6; lib3ds_chunk_write(&c, io); } if (material->use_wire) { /*---- CHK_MAT_WIRE ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_WIRE; c.size = 6; lib3ds_chunk_write(&c, io); } if (material->use_wire_abs) { /*---- CHK_MAT_WIREABS ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_WIREABS; c.size = 6; lib3ds_chunk_write(&c, io); } { /*---- CHK_MAT_WIRE_SIZE ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_WIRE_SIZE; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, material->wire_size); } if (material->face_map) { /*---- CHK_MAT_FACEMAP ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_FACEMAP; c.size = 6; lib3ds_chunk_write(&c, io); } if (material->soften) { /*---- CHK_MAT_PHONGSOFT ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_PHONGSOFT; c.size = 6; lib3ds_chunk_write(&c, io); } texture_map_write(CHK_MAT_TEXMAP, &material->texture1_map, io); texture_map_write(CHK_MAT_TEXMASK, &material->texture1_mask, io); texture_map_write(CHK_MAT_TEX2MAP, &material->texture2_map, io); texture_map_write(CHK_MAT_TEX2MASK, &material->texture2_mask, io); texture_map_write(CHK_MAT_OPACMAP, &material->opacity_map, io); texture_map_write(CHK_MAT_OPACMASK, &material->opacity_mask, io); texture_map_write(CHK_MAT_BUMPMAP, &material->bump_map, io); texture_map_write(CHK_MAT_BUMPMASK, &material->bump_mask, io); texture_map_write(CHK_MAT_SPECMAP, &material->specular_map, io); texture_map_write(CHK_MAT_SPECMASK, &material->specular_mask, io); texture_map_write(CHK_MAT_SHINMAP, &material->shininess_map, io); texture_map_write(CHK_MAT_SHINMASK, &material->shininess_mask, io); texture_map_write(CHK_MAT_SELFIMAP, &material->self_illum_map, io); texture_map_write(CHK_MAT_SELFIMASK, &material->self_illum_mask, io); texture_map_write(CHK_MAT_REFLMAP, &material->reflection_map, io); texture_map_write(CHK_MAT_REFLMASK, &material->reflection_mask, io); { /*---- CHK_MAT_ACUBIC ----*/ Lib3dsChunk c; c.chunk = CHK_MAT_ACUBIC; c.size = 18; lib3ds_chunk_write(&c, io); lib3ds_io_write_intb(io, 0); lib3ds_io_write_intb(io, material->autorefl_map_anti_alias); lib3ds_io_write_intw(io, material->autorefl_map_flags); lib3ds_io_write_intd(io, material->autorefl_map_size); lib3ds_io_write_intd(io, material->autorefl_map_frame_step); } lib3ds_chunk_write_end(&c, io); }
void lib3ds_node_write(Lib3dsNode *node, uint16_t node_id, uint16_t parent_id, Lib3dsIo *io) { Lib3dsChunk c; switch (node->type) { case LIB3DS_NODE_AMBIENT_COLOR: c.chunk = CHK_AMBIENT_NODE_TAG; break; case LIB3DS_NODE_MESH_INSTANCE: c.chunk = CHK_OBJECT_NODE_TAG; break; case LIB3DS_NODE_CAMERA: c.chunk = CHK_CAMERA_NODE_TAG; break; case LIB3DS_NODE_CAMERA_TARGET: c.chunk = CHK_TARGET_NODE_TAG; break; case LIB3DS_NODE_OMNILIGHT: c.chunk = CHK_LIGHT_NODE_TAG; break; case LIB3DS_NODE_SPOTLIGHT: c.chunk = CHK_SPOTLIGHT_NODE_TAG; break; case LIB3DS_NODE_SPOTLIGHT_TARGET: c.chunk = CHK_L_TARGET_NODE_TAG; break; default: assert(0); return; } lib3ds_chunk_write_start(&c, io); { /*---- CHK_NODE_ID ----*/ Lib3dsChunk c; c.chunk = CHK_NODE_ID; c.size = 8; lib3ds_chunk_write(&c, io); lib3ds_io_write_intw(io, node_id); } { /*---- CHK_NODE_HDR ----*/ Lib3dsChunk c; c.chunk = CHK_NODE_HDR; c.size = 6 + 1 + (uint32_t)strlen(node->name) + 2 + 2 + 2; lib3ds_chunk_write(&c, io); lib3ds_io_write_string(io, node->name); lib3ds_io_write_word(io, node->flags & 0xffff); lib3ds_io_write_word(io, (node->flags >> 16) & 0xffff); lib3ds_io_write_word(io, parent_id); } switch (c.chunk) { case CHK_AMBIENT_NODE_TAG: { Lib3dsAmbientColorNode *n = (Lib3dsAmbientColorNode*)node; if (n->color_track.nkeys) { /*---- CHK_COL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_COL_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->color_track, io); lib3ds_chunk_write_end(&c, io); } break; } case CHK_OBJECT_NODE_TAG: { Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node; { /*---- CHK_PIVOT ----*/ Lib3dsChunk c; c.chunk = CHK_PIVOT; c.size = 18; lib3ds_chunk_write(&c, io); lib3ds_io_write_vector(io, n->pivot); } { /*---- CHK_INSTANCE_NAME ----*/ Lib3dsChunk c; const char *name; if (strlen(n->instance_name)) { name = n->instance_name; c.chunk = CHK_INSTANCE_NAME; c.size = 6 + 1 + (uint32_t)strlen(name); lib3ds_chunk_write(&c, io); lib3ds_io_write_string(io, name); } } { int i; for (i = 0; i < 3; ++i) { if ((fabs(n->bbox_min[i]) > LIB3DS_EPSILON) || (fabs(n->bbox_max[i]) > LIB3DS_EPSILON)) { break; } } if (i < 3) { /*---- CHK_BOUNDBOX ----*/ Lib3dsChunk c; c.chunk = CHK_BOUNDBOX; c.size = 30; lib3ds_chunk_write(&c, io); lib3ds_io_write_vector(io, n->bbox_min); lib3ds_io_write_vector(io, n->bbox_max); } } if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_POS_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->pos_track, io); lib3ds_chunk_write_end(&c, io); } if (n->rot_track.nkeys) { /*---- CHK_ROT_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_ROT_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->rot_track, io); lib3ds_chunk_write_end(&c, io); } if (n->scl_track.nkeys) { /*---- LIB3DS_SCL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_SCL_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->scl_track, io); lib3ds_chunk_write_end(&c, io); } if (n->hide_track.nkeys) { /*---- CHK_HIDE_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_HIDE_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->hide_track, io); lib3ds_chunk_write_end(&c, io); } if (fabs(n->morph_smooth) > LIB3DS_EPSILON) { /*---- CHK_MORPH_SMOOTH ----*/ Lib3dsChunk c; c.chunk = CHK_MORPH_SMOOTH; c.size = 10; lib3ds_chunk_write(&c, io); lib3ds_io_write_float(io, n->morph_smooth); } break; } case CHK_CAMERA_NODE_TAG: { Lib3dsCameraNode *n = (Lib3dsCameraNode*)node; if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_POS_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->pos_track, io); lib3ds_chunk_write_end(&c, io); } if (n->fov_track.nkeys) { /*---- CHK_FOV_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_FOV_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->fov_track, io); lib3ds_chunk_write_end(&c, io); } if (n->roll_track.nkeys) { /*---- CHK_ROLL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_ROLL_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->roll_track, io); lib3ds_chunk_write_end(&c, io); } break; } case CHK_TARGET_NODE_TAG: { Lib3dsTargetNode *n = (Lib3dsTargetNode*)node; if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_POS_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->pos_track, io); lib3ds_chunk_write_end(&c, io); } break; } case CHK_LIGHT_NODE_TAG: { Lib3dsOmnilightNode *n = (Lib3dsOmnilightNode*)node; if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_POS_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->pos_track, io); lib3ds_chunk_write_end(&c, io); } if (n->color_track.nkeys) { /*---- CHK_COL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_COL_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->color_track, io); lib3ds_chunk_write_end(&c, io); } break; } case CHK_SPOTLIGHT_NODE_TAG: { Lib3dsSpotlightNode *n = (Lib3dsSpotlightNode*)node; if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_POS_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->pos_track, io); lib3ds_chunk_write_end(&c, io); } if (n->color_track.nkeys) { /*---- CHK_COL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_COL_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->color_track, io); lib3ds_chunk_write_end(&c, io); } if (n->hotspot_track.nkeys) { /*---- CHK_HOT_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_HOT_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->hotspot_track, io); lib3ds_chunk_write_end(&c, io); } if (n->falloff_track.nkeys) { /*---- CHK_FALL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_FALL_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->falloff_track, io); lib3ds_chunk_write_end(&c, io); } if (n->roll_track.nkeys) { /*---- CHK_ROLL_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_ROLL_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->roll_track, io); lib3ds_chunk_write_end(&c, io); } break; } case CHK_L_TARGET_NODE_TAG: { Lib3dsTargetNode *n = (Lib3dsTargetNode*)node; if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/ Lib3dsChunk c; c.chunk = CHK_POS_TRACK_TAG; lib3ds_chunk_write_start(&c, io); lib3ds_track_write(&n->pos_track, io); lib3ds_chunk_write_end(&c, io); } break; } default: break; } 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); }
/*! * \ingroup atmosphere */ Lib3dsBool lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io) { if (atmosphere->fog.use) { /*---- LIB3DS_FOG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_FOG; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } lib3ds_io_write_float(io, atmosphere->fog.near_plane); lib3ds_io_write_float(io, atmosphere->fog.near_density); lib3ds_io_write_float(io, atmosphere->fog.far_plane); lib3ds_io_write_float(io, atmosphere->fog.far_density); { Lib3dsChunk c; c.chunk=LIB3DS_COLOR_F; c.size=18; lib3ds_chunk_write(&c,io); lib3ds_io_write_rgb(io, atmosphere->fog.col); } if (atmosphere->fog.fog_background) { Lib3dsChunk c; c.chunk=LIB3DS_FOG_BGND; c.size=6; lib3ds_chunk_write(&c,io); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } if (atmosphere->layer_fog.use) { /*---- LIB3DS_LAYER_FOG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_LAYER_FOG; c.size=40; lib3ds_chunk_write(&c,io); lib3ds_io_write_float(io, atmosphere->layer_fog.near_y); lib3ds_io_write_float(io, atmosphere->layer_fog.far_y); lib3ds_io_write_float(io, atmosphere->layer_fog.near_y); lib3ds_io_write_dword(io, atmosphere->layer_fog.flags); { Lib3dsChunk c; c.chunk=LIB3DS_COLOR_F; c.size=18; lib3ds_chunk_write(&c,io); lib3ds_io_write_rgb(io, atmosphere->fog.col); } } if (atmosphere->dist_cue.use) { /*---- LIB3DS_DISTANCE_CUE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_DISTANCE_CUE; if (!lib3ds_chunk_write_start(&c,io)) { return(LIB3DS_FALSE); } lib3ds_io_write_float(io, atmosphere->dist_cue.near_plane); lib3ds_io_write_float(io, atmosphere->dist_cue.near_dimming); lib3ds_io_write_float(io, atmosphere->dist_cue.far_plane); lib3ds_io_write_float(io, atmosphere->dist_cue.far_dimming); if (atmosphere->dist_cue.cue_background) { Lib3dsChunk c; c.chunk=LIB3DS_DCUE_BGND; c.size=6; lib3ds_chunk_write(&c,io); } if (!lib3ds_chunk_write_end(&c,io)) { return(LIB3DS_FALSE); } } if (atmosphere->fog.use) { /*---- LIB3DS_USE_FOG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_USE_FOG; c.size=6; lib3ds_chunk_write(&c,io); } if (atmosphere->layer_fog.use) { /*---- LIB3DS_USE_LAYER_FOG ----*/ Lib3dsChunk c; c.chunk=LIB3DS_USE_LAYER_FOG; c.size=6; lib3ds_chunk_write(&c,io); } if (atmosphere->dist_cue.use) { /*---- LIB3DS_USE_DISTANCE_CUE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_USE_V_GRADIENT; c.size=6; lib3ds_chunk_write(&c,io); } return(LIB3DS_TRUE); }
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 material */ Lib3dsBool lib3ds_material_write(Lib3dsMaterial *material, FILE *f) { Lib3dsChunk c; c.chunk=LIB3DS_MAT_ENTRY; if (!lib3ds_chunk_write_start(&c,f)) { return(LIB3DS_FALSE); } { /*---- LIB3DS_MAT_NAME ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_NAME; c.size=6+strlen(material->name)+1; lib3ds_chunk_write(&c,f); lib3ds_string_write(material->name,f); } { /*---- LIB3DS_MAT_AMBIENT ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_AMBIENT; c.size=24; lib3ds_chunk_write(&c,f); color_write(material->ambient,f); } { /*---- LIB3DS_MAT_DIFFUSE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_DIFFUSE; c.size=24; lib3ds_chunk_write(&c,f); color_write(material->diffuse,f); } { /*---- LIB3DS_MAT_SPECULAR ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_SPECULAR; c.size=24; lib3ds_chunk_write(&c,f); color_write(material->specular,f); } { /*---- LIB3DS_MAT_SHININESS ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_SHININESS; c.size=14; lib3ds_chunk_write(&c,f); int_percentage_write(material->shininess,f); } { /*---- LIB3DS_MAT_SHIN2PCT ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_SHIN2PCT; c.size=14; lib3ds_chunk_write(&c,f); int_percentage_write(material->shin_strength,f); } { /*---- LIB3DS_MAT_TRANSPARENCY ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_TRANSPARENCY; c.size=14; lib3ds_chunk_write(&c,f); int_percentage_write(material->transparency,f); } { /*---- LIB3DS_MAT_XPFALL ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_XPFALL; c.size=14; lib3ds_chunk_write(&c,f); int_percentage_write(material->falloff,f); } if (material->use_falloff) { /*---- LIB3DS_MAT_USE_XPFALL ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_USE_XPFALL; c.size=6; lib3ds_chunk_write(&c,f); } { /*---- LIB3DS_MAT_SHADING ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_SHADING; c.size=8; lib3ds_chunk_write(&c,f); lib3ds_intw_write(material->shading,f); } { /*---- LIB3DS_MAT_REFBLUR ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_REFBLUR; c.size=14; lib3ds_chunk_write(&c,f); int_percentage_write(material->blur,f); } if (material->use_blur) { /*---- LIB3DS_MAT_USE_REFBLUR ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_USE_REFBLUR; c.size=6; lib3ds_chunk_write(&c,f); } if (material->self_illum) { /*---- LIB3DS_MAT_SELF_ILLUM ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_SELF_ILLUM; c.size=6; lib3ds_chunk_write(&c,f); } if (material->two_sided) { /*---- LIB3DS_MAT_TWO_SIDE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_TWO_SIDE; c.size=6; lib3ds_chunk_write(&c,f); } if (material->map_decal) { /*---- LIB3DS_MAT_DECAL ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_DECAL; c.size=6; lib3ds_chunk_write(&c,f); } if (material->additive) { /*---- LIB3DS_MAT_ADDITIVE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_ADDITIVE; c.size=6; lib3ds_chunk_write(&c,f); } if (material->use_wire) { /*---- LIB3DS_MAT_WIRE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_WIRE; c.size=6; lib3ds_chunk_write(&c,f); } if (material->use_wire_abs) { /*---- LIB3DS_MAT_WIREABS ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_WIREABS; c.size=6; lib3ds_chunk_write(&c,f); } { /*---- LIB3DS_MAT_WIRE_SIZE ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_WIRE_SIZE; c.size=10; lib3ds_chunk_write(&c,f); lib3ds_float_write(material->wire_size,f); } if (material->face_map) { /*---- LIB3DS_MAT_FACEMAP ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_FACEMAP; c.size=6; lib3ds_chunk_write(&c,f); } if (material->soften) { /*---- LIB3DS_MAT_PHONGSOFT ----*/ Lib3dsChunk c; c.chunk=LIB3DS_MAT_PHONGSOFT; c.size=6; lib3ds_chunk_write(&c,f); } if (!texture_map_write(LIB3DS_MAT_TEXMAP, &material->texture1_map, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_TEXMASK, &material->texture1_mask, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_TEX2MAP, &material->texture2_map, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_TEX2MASK, &material->texture2_mask, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_OPACMAP, &material->opacity_map, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_OPACMASK, &material->opacity_mask, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_BUMPMAP, &material->bump_map, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_BUMPMASK, &material->bump_mask, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_SPECMAP, &material->specular_map, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_SPECMASK, &material->specular_mask, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_SHINMAP, &material->shininess_map, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_SHINMASK, &material->shininess_mask, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_SELFIMAP, &material->self_illum_map, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_SELFIMASK, &material->self_illum_mask, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_REFLMAP, &material->reflection_map, f)) { return(LIB3DS_FALSE); } if (!texture_map_write(LIB3DS_MAT_REFLMASK, &material->reflection_mask, f)) { return(LIB3DS_FALSE); } if (!lib3ds_chunk_write_end(&c,f)) { return(LIB3DS_FALSE); } return(LIB3DS_TRUE); }