Пример #1
0
 MeshVersion getMeshVersion(const std::string& filename)
 {
     CompressedFile file;
     file.open(filename, ios::in | ios::binary);
     if (file.is_open())
     {
         MeshVersion version;
         file.read(reinterpret_cast<char*>(&version), sizeof(MeshVersion));
         file.close();
         return version;
     }
     return MeshVersion{};
 }
Пример #2
0
CompressionTest::CompressionTest(const std::string& testFile, CompressionTypes type)
{
    ifstream in;
    in.open(testFile, ios::binary);
    std::vector<char> inBuf;
    in.seekg(0, ios::end);
    size_t inSize = static_cast<size_t>(in.tellg());
    inBuf.resize(inSize);
    in.seekg(0, ios::beg);
    in.read(&inBuf[0], static_cast<streamsize>(inSize));
    in.close();

    CompressedFile outCompress;
    outCompress.open(testFile + ".compressed", ios::out | ios::binary, type);
    outCompress.write(&inBuf[0], static_cast<streamsize>(inSize));
    outCompress.close();

    CompressedFile inCompress;
    inCompress.open(testFile + ".compressed", ios::in | ios::binary);
    std::vector<char> resInBuf;
    inCompress.seekg(0, ios::end);
    size_t inCompressSize = inCompress.tellg();
    inCompress.seekg(0, ios::beg);
    resInBuf.resize(inCompressSize);
    inCompress.read(&resInBuf[0], static_cast<streamsize>(inCompressSize));
    inCompress.close();

    ofstream out;
    out.open(testFile + ".result", ios::binary);
    out.write(&resInBuf[0], static_cast<streamsize>(inCompressSize));
    out.close();

    // is the original file the same size as the resulting file
    ASSERT(inSize == inCompressSize);

    // is the content identical
    for (size_t i = 0; i < inSize; ++i)
    {
        ASSERT(inBuf[i] == resInBuf[i]);
    }
}
Пример #3
0
    void Mesh::load(ModelResources& modelResources)
    {
        CompressedFile file;
        file.open(m_filename, ios::in | ios::binary);
        if (file.is_open())
        {
            MeshVersion version;
            file.read(reinterpret_cast<char*>(&version), sizeof(MeshVersion));

            while (!file.eof())
            {
                m_subMeshes.emplace_back(SubMesh());
                if (!m_subMeshes.back().load(modelResources, file))
                {
                    m_subMeshes.pop_back();
                }
            }

            file.close();
        }
    }