MCPcopy Create free account
hub / github.com/assimp/assimp / ReadFile

Method ReadFile

code/Common/Importer.cpp:587–785  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------ Reads the given file and returns its contents if successful.

Source from the content-addressed store, hash-verified

585// ------------------------------------------------------------------------------------------------
586// Reads the given file and returns its contents if successful.
587const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) {
588 ai_assert(nullptr != pimpl);
589
590 ASSIMP_BEGIN_EXCEPTION_REGION();
591 const std::string pFile(_pFile);
592
593 // ----------------------------------------------------------------------
594 // Put a large try block around everything to catch all std::exception's
595 // that might be thrown by STL containers or by new().
596 // ImportErrorException's are throw by ourselves and caught elsewhere.
597 //-----------------------------------------------------------------------
598
599 WriteLogOpening(pFile);
600
601#ifdef ASSIMP_CATCH_GLOBAL_EXCEPTIONS
602 try
603#endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS
604 {
605 // Check whether this Importer instance has already loaded
606 // a scene. In this case we need to delete the old one
607 if (pimpl->mScene) {
608
609 ASSIMP_LOG_DEBUG("(Deleting previous scene)");
610 FreeScene();
611 }
612
613 // First check if the file is accessible at all
614 if( !pimpl->mIOHandler->Exists( pFile)) {
615
616 pimpl->mErrorString = "Unable to open file \"" + pFile + "\".";
617 ASSIMP_LOG_ERROR(pimpl->mErrorString);
618 return nullptr;
619 }
620
621 std::unique_ptr<Profiler> profiler(GetPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME, 0) ? new Profiler() : nullptr);
622 if (profiler) {
623 profiler->BeginRegion("total");
624 }
625
626 // Find an worker class which can handle the file extension.
627 // Multiple importers may be able to handle the same extension (.xml!); gather them all.
628 SetPropertyInteger("importerIndex", -1);
629 struct ImporterAndIndex {
630 BaseImporter * importer;
631 unsigned int index;
632 };
633 std::vector<ImporterAndIndex> possibleImporters;
634 for (unsigned int a = 0; a < pimpl->mImporter.size(); a++) {
635
636 // Every importer has a list of supported extensions.
637 std::set<std::string> extensions;
638 pimpl->mImporter[a]->GetExtensionList(extensions);
639
640 if (BaseImporter::HasExtension(pFile, extensions)) {
641 ImporterAndIndex candidate = { pimpl->mImporter[a], a };
642 possibleImporters.push_back(candidate);
643 }
644 }

Callers 15

ImportModelFunction · 0.45
Assimp_TestBatchLoadFunction · 0.45
LoadMethod · 0.45
Import3DFromFileFunction · 0.45
importerTestMethod · 0.45
TEST_FFunction · 0.45
importerMatTestMethod · 0.45
binaryImporterTestMethod · 0.45
exporterTestMethod · 0.45
TEST_FFunction · 0.45

Calls 15

BeginRegionMethod · 0.80
EndRegionMethod · 0.80
HasKeyMethod · 0.80
ExecuteOnSceneMethod · 0.80
ProcessSceneMethod · 0.80
CleanMethod · 0.80
aiStringClass · 0.50
ExistsMethod · 0.45
sizeMethod · 0.45
GetExtensionListMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected