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); }
/*! * 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, * lib3ds_file_new, * lib3ds_file_free */ Lib3dsFile* lib3ds_file_open(const char *filename) { FILE *f; Lib3dsFile *file; Lib3dsIo io; f = fopen(filename, "rb"); if (!f) { return NULL; } file = lib3ds_file_new(); if (!file) { fclose(f); return NULL; } memset(&io, 0, sizeof(io)); io.self = f; io.seek_func = fileio_seek_func; io.tell_func = fileio_tell_func; io.read_func = fileio_read_func; io.write_func = fileio_write_func; io.log_func = NULL; if (!lib3ds_file_read(file, &io)) { fclose(f); free(file); return NULL; } fclose(f); return file; }
void CL_Lib3dsFile::load(CL_IODevice device) { CL_Lib3dsIo io(device); int result = lib3ds_file_read(file, io); if (!result) throw CL_Exception("Unable to load 3ds file"); }
//*********************************************************************************** int charge_scene3ds(char * fichier3ds, Lib3dsFile** out_scene3ds) { FILE * file; Lib3dsIo io; *out_scene3ds = lib3ds_file_new(); printf("LOAD 3DS SCENE FILE : %s\n", fichier3ds); if(!fichier3ds) { printf("[ERROR] File name NULL.\n"); return -1; } if(!(file = fopen(fichier3ds, "rb"))) { printf("[ERROR] File not found : %s\n", fichier3ds); return -1; } io.self = file; io.seek_func = fileio_seek_func; io.tell_func = fileio_tell_func; io.read_func = fileio_read_func; io.write_func = fileio_write_func; io.log_func = fileio_log_func; lib3ds_file_read(*out_scene3ds, &io); printf("LOAD 3DS SCENE FILE - END\n"); return 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); }
/*! * 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 pointer 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; f=osgDB::fopen(filename, "rb"); if (!f) { return(0); } file=lib3ds_file_new(); if (!file) { fclose(f); return(0); } if (!lib3ds_file_read(file, f)) { free(file); fclose(f); return(0); } fclose(f); return(file); }
int main(int argc, char **argv) { FILE *file; Lib3dsFile *f = 0; Lib3dsIo io; int result; int i; parse_args(argc, argv); file = fopen(filename, "rb"); if (!file) { fprintf(stderr, "***ERROR***\nFile not found: %s\n", filename); exit(1); } f = lib3ds_file_new(); memset(&io, 0, sizeof(io)); io.self = file; io.seek_func = fileio_seek_func; io.tell_func = fileio_tell_func; io.read_func = fileio_read_func; io.write_func = fileio_write_func; io.log_func = fileio_log_func; result = lib3ds_file_read(f, &io); fclose(file); if (!result) { fprintf(stderr, "***ERROR***\nLoading file failed: %s\n", filename); exit(1); } if (flags & LIB3DSDUMP_MATERIALS) { printf("Dumping materials:\n"); for (i = 0; i < f->nmaterials; ++i) material_dump(f->materials[i]); printf("\n"); } if (flags & LIB3DSDUMP_TRIMESHES) { printf("Dumping meshes:\n"); for (i = 0; i < f->nmeshes; ++i) mesh_dump(f->meshes[i]); printf("\n"); } if (flags & LIB3DSDUMP_INSTANCES) { Lib3dsNode *p; printf("Dumping instances:\n"); for (p = f->nodes; p != 0; p = p->next) { dump_instances(p, ""); } printf("\n"); } if (flags & LIB3DSDUMP_CAMERAS) { printf("Dumping cameras:\n"); for (i = 0; i < f->ncameras; ++i) camera_dump(f->cameras[i]); printf("\n"); } if (flags & LIB3DSDUMP_LIGHTS) { printf("Dumping lights:\n"); for (i = 0; i < f->nlights; ++i) light_dump(f->lights[i]); printf("\n"); } if (flags & LIB3DSDUMP_NODES) { Lib3dsNode *p; printf("Dumping node hierarchy:\n"); for (p = f->nodes; p != 0; p = p->next) { node_dump(p, 1); } printf("\n"); } if (output) { if (!lib3ds_file_save(f, output)) { printf("***ERROR**** Writing %s\n", output); } } lib3ds_file_free(f); return 0; }