From 139181bb53b86b362f6393a215d5dfdb0702fa57 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 2 Sep 2023 20:36:55 +0800 Subject: [PATCH] Particle3D: add wasm support for load materials --- .../Particle3D/PU/PUMaterialManager.cpp | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/extensions/Particle3D/PU/PUMaterialManager.cpp b/extensions/Particle3D/PU/PUMaterialManager.cpp index 6a5412f277..57e6b5c57c 100644 --- a/extensions/Particle3D/PU/PUMaterialManager.cpp +++ b/extensions/Particle3D/PU/PUMaterialManager.cpp @@ -42,7 +42,12 @@ # include # include # include +#else +# include "base/filesystem.h" #endif + +#include "yasio/string_view.hpp" + NS_AX_BEGIN PUMaterial::PUMaterial() @@ -132,13 +137,12 @@ bool PUMaterialCache::loadMaterialsFromSearchPaths(std::string_view fileFolder) { bool state = false; #if defined(_WIN32) - std::string seg("/"); + std::string_view seg("/"); std::string fullPath{fileFolder}; fullPath += seg; - fullPath += std::string("*.material"); + fullPath += "*.material"sv; WIN32_FIND_DATAA data; - HANDLE handle = - FindFirstFileExA(fullPath.c_str(), FindExInfoStandard, &data, FindExSearchNameMatch, NULL, 0); + HANDLE handle = FindFirstFileExA(fullPath.c_str(), FindExInfoStandard, &data, FindExSearchNameMatch, NULL, 0); if (handle != INVALID_HANDLE_VALUE) { state = true; @@ -148,7 +152,7 @@ bool PUMaterialCache::loadMaterialsFromSearchPaths(std::string_view fileFolder) fullPath += seg; fullPath += data.cFileName; loadMaterials(fullPath); - + } while (FindNextFileA(handle, &data)); FindClose(handle); } @@ -204,7 +208,20 @@ bool PUMaterialCache::loadMaterialsFromSearchPaths(std::string_view fileFolder) } closedir(d); #else - AXASSERT(0, "no implement for this platform"); + // use c++17 filesystem + for (const auto& entry : stdfs::recursive_directory_iterator(fileFolder)) + { +# if !defined(_WIN32) + if (entry.is_regular_file() && cxx20::ends_with(entry.path().native(), ".material"sv)) +# else + if (entry.is_regular_file() && cxx20::ends_with(entry.path().native(), L".material"sv)) +# endif + { + auto pathU8Str = entry.path().generic_u8string(); + auto& pathStr = *reinterpret_cast(&pathU8Str); + loadMaterials(pathStr); + } + } #endif return state;