コード例 #1
0
ファイル: file.cpp プロジェクト: nitrologic/mod
/*!
 * \ingroup file
 */
Lib3dsBool
lib3ds_file_read(Lib3dsFile *file, FILE *f)
{
    Lib3dsChunk c;
    Lib3dsWord chunk;

    if (!lib3ds_chunk_read_start(&c, 0, f)) {
        return(LIB3DS_FALSE);
    }
    switch (c.chunk) {
    case LIB3DS_MDATA:
    {
        lib3ds_chunk_read_reset(&c, f);
        if (!mdata_read(file, f)) {
            return(LIB3DS_FALSE);
        }
    }
    break;
    case LIB3DS_M3DMAGIC:
    case LIB3DS_MLIBMAGIC:
    case LIB3DS_CMAGIC:
    {
        while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
            switch (chunk) {
            case LIB3DS_M3D_VERSION:
            {
                file->mesh_version=lib3ds_dword_read(f);
            }
            break;
            case LIB3DS_MDATA:
            {
                lib3ds_chunk_read_reset(&c, f);
                if (!mdata_read(file, f)) {
                    return(LIB3DS_FALSE);
                }
            }
            break;
            case LIB3DS_KFDATA:
            {
                lib3ds_chunk_read_reset(&c, f);
                if (!kfdata_read(file, f)) {
                    return(LIB3DS_FALSE);
                }
            }
            break;
            default:
                lib3ds_chunk_unknown(chunk);
            }
        }
    }
    break;
    default:
        lib3ds_chunk_unknown(c.chunk);
        return(LIB3DS_FALSE);
    }

    lib3ds_chunk_read_end(&c, f);
    return(LIB3DS_TRUE);
}
コード例 #2
0
ファイル: lib3ds_file.c プロジェクト: 0871087123/lib3ds
/*!
 * Read 3ds file data into a Lib3dsFile object.
 *
 * \param file The Lib3dsFile object to be filled.
 * \param io A Lib3dsIo object previously set up by the caller.
 *
 * \return LIB3DS_TRUE on success, LIB3DS_FALSE on failure.
 */
int
lib3ds_file_read(Lib3dsFile *file, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;
    Lib3dsIoImpl *impl;

    lib3ds_io_setup(io);
    impl = (Lib3dsIoImpl*)io->impl;

    if (setjmp(impl->jmpbuf) != 0) {
        lib3ds_io_cleanup(io);
        return FALSE;
    }

    lib3ds_chunk_read_start(&c, 0, io);
    switch (c.chunk) {
        case CHK_MDATA: {
            lib3ds_chunk_read_reset(&c, io);
            mdata_read(file, io);
            break;
        }

        case CHK_M3DMAGIC:
        case CHK_MLIBMAGIC:
        case CHK_CMAGIC: {
            while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
                switch (chunk) {
                    case CHK_M3D_VERSION: {
                        file->mesh_version = lib3ds_io_read_dword(io);
                        break;
                    }

                    case CHK_MDATA: {
                        lib3ds_chunk_read_reset(&c, io);
                        mdata_read(file, io);
                        break;
                    }

                    case CHK_KFDATA: {
                        lib3ds_chunk_read_reset(&c, io);
                        kfdata_read(file, io);
                        break;
                    }

                    default:
                        lib3ds_chunk_unknown(chunk, io);
                }
            }
            break;
        }

        default:
            lib3ds_chunk_unknown(c.chunk, io);
            return FALSE;
    }

    lib3ds_chunk_read_end(&c, io);

    memset(impl->jmpbuf, 0, sizeof(impl->jmpbuf));
    lib3ds_io_cleanup(io);
    return TRUE;
}