TEST_F(utLineSplitter, tokenizetest) { DefaultIOSystem fs; IOStream* file = fs.Open(ASSIMP_TEST_MODELS_DIR"/ParsingFiles/linesplitter_tokenizetest.txt", "rb"); StreamReaderLE stream(file); LineSplitter myLineSplitter(stream); }
// ------------------------------------------------------------------------------------------------ // Default constructor ObjFileImporter::ObjFileImporter() : m_Buffer() , m_pRootObject( nullptr ) , m_strAbsPath( "" ) { DefaultIOSystem io; m_strAbsPath = io.getOsSeparator(); }
// ------------------------------------------------------------------------------------------------ // Default constructor ObjFileImporter::ObjFileImporter() : m_pRootObject(NULL) { DefaultIOSystem io; m_strAbsPath = io.getOsSeparator(); }
// ------------------------------------------------------------------------------------------------ // Default constructor MTLImporter::MTLImporter() : m_Buffer(), m_pRootObject( NULL ), m_strAbsPath( "" ) { DefaultIOSystem io; m_strAbsPath = io.getOsSeparator(); }
TEST_F( utLineSplitter, issue212Test) { DefaultIOSystem fs; IOStream* file = fs.Open(ASSIMP_TEST_MODELS_DIR"/ParsingFiles/linesplitter_emptyline_test.txt", "rb"); StreamReaderLE stream(file); LineSplitter myLineSplitter(stream); myLineSplitter++; EXPECT_THROW( myLineSplitter++, std::logic_error ); }
// ------------------------------------------------------------------------------------------------ // Extracts android asset bool AndroidJNIIOSystem::AndroidExtractAsset(std::string name) { std::string newPath = mApkWorkspacePath + getOsSeparator() + name; DefaultIOSystem io; // Do not extract if extracted already if ( io.Exists(newPath.c_str()) ) { __android_log_print(ANDROID_LOG_DEFAULT, "Assimp", "Asset already extracted"); return true; } // Open file AAsset* asset = AAssetManager_open(mApkAssetManager, name.c_str(), AASSET_MODE_UNKNOWN); std::vector<char> assetContent; if (asset != NULL) { // Find size off_t assetSize = AAsset_getLength(asset); // Prepare input buffer assetContent.resize(assetSize); // Store input buffer AAsset_read(asset, &assetContent[0], assetSize); // Close AAsset_close(asset); // Prepare output buffer std::ofstream assetExtracted(newPath.c_str(), std::ios::out | std::ios::binary); if (!assetExtracted) { __android_log_print(ANDROID_LOG_ERROR, "assimp", "Can not open output file"); } // Write output buffer into a file assetExtracted.write(&assetContent[0], assetContent.size()); assetExtracted.close(); __android_log_print(ANDROID_LOG_DEFAULT, "Assimp", "Asset extracted"); } else { __android_log_print(ANDROID_LOG_ERROR, "assimp", "Asset not found: %s", name.c_str()); return false; } return true; }
// ------------------------------------------------------------------------------------------------ // Obj-file import implementation void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) { DefaultIOSystem io; // Read file into memory const std::string mode = "rb"; boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile, mode)); if (NULL == file.get()) throw new ImportErrorException( "Failed to open file " + pFile + "."); // Get the filesize and vaslidate it, throwing an exception when failes size_t fileSize = file->FileSize(); if( fileSize < 16) throw new ImportErrorException( "OBJ-file is too small."); // Allocate buffer and read file into it m_Buffer.resize( fileSize ); const size_t readsize = file->Read(&m_Buffer.front(), sizeof(char), fileSize); assert (readsize == fileSize); // std::string strDirectory(1,io.getOsSeparator()), strModelName; std::string::size_type pos = pFile.find_last_of(io.getOsSeparator()); if (pos != std::string::npos) { strDirectory = pFile.substr(0, pos); strModelName = pFile.substr(pos+1, pFile.size() - pos - 1); } else { strModelName = pFile; } // parse the file into a temporary representation ObjFileParser parser(m_Buffer, strDirectory, strModelName, pIOHandler); // And create the proper return structures out of it CreateDataFromImport(parser.GetModel(), pScene); }