Exemple #1
0
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);
}
Exemple #2
0
/*!
 * \ingroup tcb 
 */
Lib3dsBool
lib3ds_tcb_write(Lib3dsTcb *tcb, FILE *f)
{
  lib3ds_intd_write(tcb->frame,f);
  lib3ds_word_write(tcb->flags,f);
  if (tcb->flags&LIB3DS_USE_TENSION) {
    lib3ds_float_write(tcb->tens,f);
  }
  if (tcb->flags&LIB3DS_USE_CONTINUITY) {
    lib3ds_float_write(tcb->cont,f);
  }
  if (tcb->flags&LIB3DS_USE_BIAS) {
    lib3ds_float_write(tcb->bias,f);
  }
  if (tcb->flags&LIB3DS_USE_EASE_TO) {
    lib3ds_float_write(tcb->ease_to,f);
  }
  if (tcb->flags&LIB3DS_USE_EASE_FROM) {
    lib3ds_float_write(tcb->ease_from,f);
  }
  if (ferror(f)) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
Exemple #3
0
/*!
 * \ingroup shadow 
 */
Lib3dsBool
lib3ds_shadow_write(Lib3dsShadow *shadow, FILE *f)
{
  if (fabs(shadow->lo_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_LO_SHADOW_BIAS ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_LO_SHADOW_BIAS;
    c.size=10;
    lib3ds_chunk_write(&c,f);
    lib3ds_float_write(shadow->lo_bias,f);
  }

  if (fabs(shadow->hi_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_HI_SHADOW_BIAS ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_HI_SHADOW_BIAS;
    c.size=10;
    lib3ds_chunk_write(&c,f);
    lib3ds_float_write(shadow->hi_bias,f);
  }

  if (shadow->map_size) { /*---- LIB3DS_SHADOW_MAP_SIZE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_SHADOW_MAP_SIZE;
    c.size=8;
    lib3ds_chunk_write(&c,f);
    lib3ds_intw_write(shadow->map_size,f);
  }
  
  if (shadow->samples) { /*---- LIB3DS_SHADOW_SAMPLES ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_SHADOW_SAMPLES;
    c.size=8;
    lib3ds_chunk_write(&c,f);
    lib3ds_intw_write(shadow->samples,f);
  }

  if (shadow->range) { /*---- LIB3DS_SHADOW_RANGE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_SHADOW_RANGE;
    c.size=10;
    lib3ds_chunk_write(&c,f);
    lib3ds_intd_write(shadow->range,f);
  }

  if (fabs(shadow->filter)>LIB3DS_EPSILON) { /*---- LIB3DS_SHADOW_FILTER ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_SHADOW_FILTER;
    c.size=10;
    lib3ds_chunk_write(&c,f);
    lib3ds_float_write(shadow->filter,f);
  }
  if (fabs(shadow->ray_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_RAY_BIAS ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_RAY_BIAS;
    c.size=10;
    lib3ds_chunk_write(&c,f);
    lib3ds_float_write(shadow->ray_bias,f);
  }
  return(LIB3DS_TRUE);
}
Exemple #4
0
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);
}