FCT
载入中...
搜索中...
未找到
ModelLoader.cpp
浏览该文件的文档.
1#include "./ModelLoader.h"
2namespace FCT {
3 std::set<std::string> ModelLoader::resolveModePaths(const std::string& modelPath)
4 {
5 std::set<std::string> allPaths;
6
7 std::string absoluteModelPath;
8 try {
9 if (std::filesystem::exists(modelPath)) {
10 absoluteModelPath = std::filesystem::canonical(modelPath).string();
11 } else {
12 absoluteModelPath = std::filesystem::absolute(modelPath).string();
13 }
14 allPaths.insert(absoluteModelPath);
15 } catch (const std::filesystem::filesystem_error&) {
16 allPaths.insert(modelPath);
17 absoluteModelPath = modelPath;
18 }
19
20 std::filesystem::path modelFilePath(absoluteModelPath);
21 std::string extension = modelFilePath.extension().string();
22
23 std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
24
25 std::set<std::string> texturePaths = resolveTexturePaths(absoluteModelPath);
26 allPaths.insert(texturePaths.begin(), texturePaths.end());
27
28 std::set<std::string> specificDependencies = getModelSpecificDependencies(absoluteModelPath);
29
30 std::filesystem::path modelDir = std::filesystem::path(absoluteModelPath).parent_path();
31 for (const auto& relativePath : specificDependencies) {
32 try {
33 std::string absolutePath = std::filesystem::canonical(modelDir / relativePath).string();
34 allPaths.insert(absolutePath);
35 } catch (const std::filesystem::filesystem_error&) {
36 std::string absolutePath = std::filesystem::absolute(modelDir / relativePath).string();
37 allPaths.insert(absolutePath);
38 }
39 }
40
41 return allPaths;
42 }
43
44 std::set<std::string> ModelLoader::getModelSpecificDependencies(const std::string& modelPath) const
45 {
46 std::set<std::string> dependencies;
47
48 std::filesystem::path modelFilePath(modelPath);
49 std::string extension = modelFilePath.extension().string();
50 std::string baseName = modelFilePath.stem().string();
51
52 std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
53 if (extension == ".obj") {
54 dependencies.insert(baseName + ".mtl");
55 }
56 else if (extension == ".gltf")
57 {
58 dependencies.insert(baseName + ".bin");
59 }
60 else if (extension == ".fbx")
61 {
62
63 } else if (extension == ".glb")
64 {
65
66 } else if (extension == ".usdz")
67 {
68
69 }
70 return dependencies;
71 }
72
73 std::set<std::string> ModelLoader::getSupportedExtensions() const
74 {
75 auto platform = getPlatformSupportedExtensions();
76 std::set<std::string> supportedExtensions = {
77 ".obj",
78 ".gltf",
79 ".fbx",
80 ".glb",
81 ".usdz"
82 };
83 return supportedExtensions;
84 }
85}
virtual std::set< std::string > resolveTexturePaths(const std::string &modelPath) const =0
解析模型依赖的纹理位置
std::set< std::string > getModelSpecificDependencies(const std::string &modelPath) const
std::set< std::string > getSupportedExtensions() const
virtual std::set< std::string > getPlatformSupportedExtensions() const =0
std::set< std::string > resolveModePaths(const std::string &modelPath)
解析模型路径,获取模型文件的所有依赖路径