diff --git a/Samples/GLTFViewer/src/GLTFViewer.cpp b/Samples/GLTFViewer/src/GLTFViewer.cpp index 539317ab..308293ca 100644 --- a/Samples/GLTFViewer/src/GLTFViewer.cpp +++ b/Samples/GLTFViewer/src/GLTFViewer.cpp @@ -246,7 +246,7 @@ void GLTFViewer::UpdateScene() } -void GLTFViewer::UpdateModelsList(const std::string& Dir) +void GLTFViewer::UpdateModelsList(const std::string& Dir, const std::string& Ext) { m_Models.clear(); for (size_t i = 0; i < _countof(DefaultGLTFModels); ++i) @@ -257,8 +257,17 @@ void GLTFViewer::UpdateModelsList(const std::string& Dir) #if PLATFORM_WIN32 || PLATFORM_LINUX || PLATFORM_MACOS if (!Dir.empty()) { - FileSystem::SearchFilesResult SearchRes = FileSystem::SearchRecursive(Dir.c_str(), "*.gltf"); - for (const auto& File : SearchRes) + FileSystem::SearchFilesResult SearchRes{}; + std::vector patterns = Ext.empty() ? std::vector{"*.gltf"} : SplitString(Ext.begin(), Ext.end(), ";"); + for (const std::string& pattern : patterns) + { + FileSystem::SearchFilesResult CurrentSearchRes = FileSystem::SearchRecursive(Dir.c_str(), pattern.c_str()); + std::move(CurrentSearchRes.begin(), CurrentSearchRes.end(), std::back_inserter(SearchRes)); + } + std::sort(SearchRes.begin(), SearchRes.end(), [](const FindFileData& lhs, const FindFileData& rhs) -> bool { + return lhs.Name < rhs.Name; + }); + for (const FindFileData& File : SearchRes) { m_Models.push_back(ModelInfo{File.Name, Dir + FileSystem::SlashSymbol + File.Name}); } @@ -281,8 +290,10 @@ GLTFViewer::CommandLineStatus GLTFViewer::ProcessCommandLine(int argc, const cha m_TextureArrayMode); std::string ExtraModelsDir; + std::string ExtraModelsExt; ArgsParser.Parse("dir", 'd', ExtraModelsDir); - UpdateModelsList(ExtraModelsDir.c_str()); + ArgsParser.Parse("ext", 'e', ExtraModelsExt); + UpdateModelsList(ExtraModelsDir.c_str(), ExtraModelsExt.c_str()); return CommandLineStatus::OK; } @@ -706,7 +717,7 @@ void GLTFViewer::Initialize(const SampleInitInfo& InitInfo) if (m_Models.empty()) { // ProcessCommandLine is not called on all platforms, so we need to initialize the models list. - UpdateModelsList(""); + UpdateModelsList("", ""); } LoadModel(!m_ModelPath.empty() ? m_ModelPath.c_str() : m_Models[m_SelectedModel].Path.c_str()); } diff --git a/Samples/GLTFViewer/src/GLTFViewer.hpp b/Samples/GLTFViewer/src/GLTFViewer.hpp index 496b7e25..b7565758 100644 --- a/Samples/GLTFViewer/src/GLTFViewer.hpp +++ b/Samples/GLTFViewer/src/GLTFViewer.hpp @@ -73,7 +73,7 @@ class GLTFViewer final : public SampleBase void LoadEnvironmentMap(const char* Path); void UpdateScene(); void CreateGLTFResourceCache(); - void UpdateModelsList(const std::string& Dir); + void UpdateModelsList(const std::string& Dir, const std::string& Ext); bool SetEnvironmentMap(ITextureView* pEnvMap); void CreateGLTFRenderer(); void CrateEnvMapRenderer();