示例#1
0
/*!
 * Saves a .3DS file from memory to disk.
 *
 * \param file      A pointer to a Lib3dsFile structure containing the
 *                  the data that should be stored.
 * \param filename  The filename of the .3DS file to store the data in.
 *
 * \return          TRUE on success, FALSE otherwise.
 *
 * \see lib3ds_file_load
 *
 * \ingroup file
 */
Lib3dsBool
lib3ds_file_save(Lib3dsFile *file, const char *filename)
{
  FILE *f;
  Lib3dsIo *io;
  Lib3dsBool result;

  f = fopen(filename, "wb");
  if (!f) {
    return(LIB3DS_FALSE);
  }
  io = lib3ds_io_new(
    f, 
    fileio_error_func,
    fileio_seek_func,
    fileio_tell_func,
    fileio_read_func,
    fileio_write_func
  );
  if (!io) {
    fclose(f);
    return LIB3DS_FALSE;
  }
  
  result = lib3ds_file_write(file, io);

  fclose(f);

  lib3ds_io_free(io);
  return(result);
}
示例#2
0
static Lib3dsFile *qgl3ds_lib3ds_file_load(QIODevice *iod)
{
    Lib3dsFile *file;
    Lib3dsIo *io;
    Q_ASSERT(iod->isOpen() && iod->isReadable());
    file = lib3ds_file_new();
    if (!file) {
        iod->close();
        return(0);
    }
    IODevice3ds io3d;
    io3d.dev = iod;
    io3d.errorState = false;
    io = lib3ds_io_new(
            &io3d,
            qgl3ds_fileio_error_func,
            qgl3ds_fileio_seek_func,
            qgl3ds_fileio_tell_func,
            qgl3ds_fileio_read_func,
            qgl3ds_fileio_write_func
            );
    if (!io) {
        lib3ds_file_free(file);
        iod->close();
        return(0);
    }
    if (!lib3ds_file_read(file, io)) {
        lib3ds_file_free(file);
        iod->close();
        return(0);
    }
    lib3ds_io_free(io);
    iod->close();
    return(file);
}
示例#3
0
/*!
 * Loads a .3DS file from disk into memory.
 *
 * \param filename  The filename of the .3DS file
 *
 * \return   A pointer to the Lib3dsFile structure containing the
 *           data of the .3DS file. 
 *           If the .3DS file can not be loaded NULL is returned.
 *
 * \note     To free the returned structure use lib3ds_free.
 *
 * \see lib3ds_file_save
 * \see lib3ds_file_new
 * \see lib3ds_file_free
 *
 * \ingroup file
 */
Lib3dsFile*
lib3ds_file_load(const char *filename)
{
  FILE *f;
  Lib3dsFile *file;
  Lib3dsIo *io;

  f = fopen(filename, "rb");
  if (!f) {
    return(0);
  }
  file = lib3ds_file_new();
  if (!file) {
    fclose(f);
    return(0);
  }
  
  io = lib3ds_io_new(
    f, 
    fileio_error_func,
    fileio_seek_func,
    fileio_tell_func,
    fileio_read_func,
    fileio_write_func
  );
  if (!io) {
    lib3ds_file_free(file);
    fclose(f);
    return(0);
  }

  if (!lib3ds_file_read(file, io)) {
    free(file);
    lib3ds_io_free(io);
    fclose(f);
    return(0);
  }

  lib3ds_io_free(io);
  fclose(f);
  return(file);
}