예제 #1
0
bool CMeshList::Load_meshes_in_list(char *file_name)
{
  bool   ret;

  ret = load_meshes((char*)DATAPATH, file_name, &m_mesh_list);
  return ret;
}
예제 #2
0
std::pair<model, std::list<animation>>
load (const boost::filesystem::path& file)
{
    auto file_size (boost::filesystem::file_size(file));
    if (file_size < sizeof(header))
        throw std::runtime_error("iqm::read: file too small");

    if (file_size > 16000000)
        throw std::runtime_error("iqm::read: file too large");

    std::ifstream str (file.string(), std::ios::binary);
    if (!str)
        throw std::runtime_error("iqm::read: cannot open file");

    std::vector<char> buf;
    buf.resize(file_size + 1);
    str.read(&buf[0], sizeof(header));

    const header& hdr (*(header*)&buf[0]);
    if (!std::equal(std::begin(hdr.magic), std::end(hdr.magic), "INTERQUAKEMODEL"))
        throw std::runtime_error("iqm::read: not an IQM file");

    if (hdr.filesize > file_size)
        throw std::runtime_error("iqm::read: file is incomplete");

    if (hdr.ofs_vertexarrays + hdr.num_vertexarrays * sizeof(vertexarray) > hdr.filesize)
        throw std::runtime_error("iqm::read: vertex array out of bounds");

    if (hdr.ofs_meshes + hdr.num_meshes * sizeof(mesh) > hdr.filesize)
        throw std::runtime_error("iqm::read: mesh array out of bounds");

    if (hdr.ofs_triangles + hdr.num_triangles * sizeof(triangle) > hdr.filesize)
        throw std::runtime_error("iqm::read: triangle array out of bounds");

    auto remaining (hdr.filesize - sizeof(hdr));
    str.read(&buf[sizeof(header)], remaining);
    buf[hdr.filesize] = 0;

    return std::make_pair(load_meshes(buf), load_anims(buf));
}