+
+
+// ------ custom file I/O for assimp -------
+
+static aiFile *io_open(aiFileIO *io, const char *fname, const char *mode)
+{
+ ass_file *fp;
+ if(!(fp = ass_fopen(fname, mode))) {
+ error_log("failed to open scene file: %s: %s\n", fname, strerror(ass_errno));
+ return 0;
+ }
+
+ aiFile *aifp = new aiFile;
+ aifp->ReadProc = io_read;
+ aifp->WriteProc = 0;
+ aifp->TellProc = io_tell;
+ aifp->FileSizeProc = io_filesize;
+ aifp->SeekProc = io_seek;
+ aifp->FlushProc = 0;
+ aifp->UserData = (aiUserData)fp;
+ return aifp;
+}
+
+static void io_close(aiFileIO *io, aiFile *aifp)
+{
+ ass_fclose(aifp->UserData);
+ delete aifp;
+}
+
+static size_t io_read(aiFile *aifp, char *buf, size_t size, size_t count)
+{
+ return ass_fread(buf, size, count, aifp->UserData);
+}
+
+static size_t io_tell(aiFile *aifp)
+{
+ return ass_ftell(aifp->UserData);
+}
+
+static size_t io_filesize(aiFile *aifp)
+{
+ ass_file *fp = aifp->UserData;
+ long cur = ass_ftell(fp);
+ ass_fseek(fp, 0, SEEK_END);
+ long off = ass_ftell(fp);
+ ass_fseek(fp, cur, SEEK_SET);
+ return off;
+}
+
+static aiReturn io_seek(aiFile *aifp, size_t offs, aiOrigin whence)
+{
+ if(ass_fseek(aifp->UserData, offs, (int)whence) == -1) {
+ return aiReturn_FAILURE;
+ }
+ return aiReturn_SUCCESS;
+}