void BinaryMeshFileReader::read(IMeshBuilder& builder)
{
    BufferedFile file(
        m_filename.c_str(),
        BufferedFile::BinaryType,
        BufferedFile::ReadMode);

    if (!file.is_open())
        throw ExceptionIOError();

    read_and_check_signature(file);

    uint16 version;
    checked_read(file, version);

    auto_ptr<ReaderAdapter> reader;

    switch (version)
    {
      // Uncompressed.
      case 1:
        reader.reset(new PassthroughReaderAdapter(file));
        break;

      // LZO-compressed.
      case 2:
        throw ExceptionIOError(
            "binarymesh format version 2 is no longer supported; "
            "please use the convertmeshfile tool that ships with appleseed 1.1.0 alpha-21 or earlier");

      // LZ4-compressed.
      case 3:
        reader.reset(new LZ4CompressedReaderAdapter(file));
        break;

      // Unknown format.
      default:
        throw ExceptionIOError("unknown binarymesh format version");
    }

    read_meshes(*reader.get(), builder);
}
예제 #2
0
void BinaryMeshFileReader::read(IMeshBuilder& builder)
{
    BufferedFile file(
        m_filename.c_str(),
        BufferedFile::BinaryType,
        BufferedFile::ReadMode);

    if (!file.is_open())
        throw ExceptionIOError();

    read_and_check_signature(file);

    uint16 version;
    checked_read(file, version);

    auto_ptr<ReaderAdapter> reader;

    switch (version)
    {
      case 1:                       // uncompressed
        reader.reset(new PassthroughReaderAdapter(file));
        break;

      case 2:                       // LZO-compressed (deprecated)
        reader.reset(new LZOCompressedReaderAdapter(file));
        break;

      case 3:                       // LZ4-compressed
        reader.reset(new LZ4CompressedReaderAdapter(file));
        break;

      default:                      // unknown format
        throw ExceptionIOError();   // todo: throw better-qualified exception
    }

    read_meshes(*reader.get(), builder);
}