Exemplo n.º 1
0
/*!
 * \ingroup background
 */
Lib3dsBool
lib3ds_background_write(Lib3dsBackground *background, Lib3dsIo *io)
{
  if (strlen(background->bitmap.name)) { /*---- LIB3DS_BIT_MAP ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_BIT_MAP;
    c.size=6+1+(Lib3dsDword)strlen(background->bitmap.name);
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_string(io, background->bitmap.name);
  }

  if (colorf_defined(background->solid.col)) { /*---- LIB3DS_SOLID_BGND ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_SOLID_BGND;
    c.size=42;
    lib3ds_chunk_write(&c,io);
    colorf_write(background->solid.col, io);
  }

  if (colorf_defined(background->gradient.top) ||
    colorf_defined(background->gradient.middle) ||
    colorf_defined(background->gradient.bottom)) { /*---- LIB3DS_V_GRADIENT ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_V_GRADIENT;
    c.size=118;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, background->gradient.percent);
    colorf_write(background->gradient.top,io);
    colorf_write(background->gradient.middle,io);
    colorf_write(background->gradient.bottom,io);
  }

  if (background->bitmap.use) { /*---- LIB3DS_USE_BIT_MAP ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_USE_BIT_MAP;
    c.size=6;
    lib3ds_chunk_write(&c,io);
  }

  if (background->solid.use) { /*---- LIB3DS_USE_SOLID_BGND ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_USE_SOLID_BGND;
    c.size=6;
    lib3ds_chunk_write(&c,io);
  }

  if (background->gradient.use) { /*---- LIB3DS_USE_V_GRADIENT ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_USE_V_GRADIENT;
    c.size=6;
    lib3ds_chunk_write(&c,io);
  }
  
  return(LIB3DS_TRUE);
}
Exemplo n.º 2
0
void
lib3ds_background_write(Lib3dsBackground *background, Lib3dsIo *io) {
    if (strlen(background->bitmap_name)) { /*---- LIB3DS_BIT_MAP ----*/
        Lib3dsChunk c;
        c.chunk = CHK_BIT_MAP;
        c.size = 6 + 1 + (uint32_t)strlen(background->bitmap_name);
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_string(io, background->bitmap_name);
    }

    if (colorf_defined(background->solid_color)) { /*---- LIB3DS_SOLID_BGND ----*/
        Lib3dsChunk c;
        c.chunk = CHK_SOLID_BGND;
        c.size = 42;
        lib3ds_chunk_write(&c, io);
        colorf_write(background->solid_color, io);
    }

    if (colorf_defined(background->gradient_top) ||
        colorf_defined(background->gradient_middle) ||
        colorf_defined(background->gradient_bottom)) { /*---- LIB3DS_V_GRADIENT ----*/
        Lib3dsChunk c;
        c.chunk = CHK_V_GRADIENT;
        c.size = 118;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, background->gradient_percent);
        colorf_write(background->gradient_top, io);
        colorf_write(background->gradient_middle, io);
        colorf_write(background->gradient_bottom, io);
    }

    if (background->use_bitmap) { /*---- LIB3DS_USE_BIT_MAP ----*/
        Lib3dsChunk c;
        c.chunk = CHK_USE_BIT_MAP;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    if (background->use_solid) { /*---- LIB3DS_USE_SOLID_BGND ----*/
        Lib3dsChunk c;
        c.chunk = CHK_USE_SOLID_BGND;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    if (background->use_gradient) { /*---- LIB3DS_USE_V_GRADIENT ----*/
        Lib3dsChunk c;
        c.chunk = CHK_USE_V_GRADIENT;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
0
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);
}