| 60 | } |
| 61 | |
| 62 | std::shared_ptr<Poseidon::Model::Model> ModelCache::loadFromFile(const std::string& filePath) |
| 63 | { |
| 64 | std::ifstream file(filePath, std::ios::binary); |
| 65 | if (!file) |
| 66 | { |
| 67 | // Fallback to PBO archives |
| 68 | if (GFileServer) |
| 69 | { |
| 70 | return loadFromFileServer(filePath); |
| 71 | } |
| 72 | return nullptr; |
| 73 | } |
| 74 | |
| 75 | FormatInfo info = P3DFormatDetector::DetectFormat(file); |
| 76 | if (!info.isSupported) |
| 77 | { |
| 78 | return nullptr; |
| 79 | } |
| 80 | |
| 81 | auto model = std::make_shared<Poseidon::Model::Model>(); |
| 82 | |
| 83 | try |
| 84 | { |
| 85 | if (info.signature == "ODOL") |
| 86 | { |
| 87 | *model = Poseidon::Asset::Formats::ODOLLoader::load(filePath); |
| 88 | } |
| 89 | else if (info.signature == "MLOD") |
| 90 | { |
| 91 | *model = Poseidon::Asset::Formats::MLODLoader::load(filePath); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | return nullptr; |
| 96 | } |
| 97 | } |
| 98 | catch (...) |
| 99 | { |
| 100 | return nullptr; |
| 101 | } |
| 102 | |
| 103 | if (!model->compile() || !model->isCompiled()) |
| 104 | { |
| 105 | return nullptr; |
| 106 | } |
| 107 | |
| 108 | return model; |
| 109 | } |
| 110 | |
| 111 | std::shared_ptr<Poseidon::Model::Model> ModelCache::loadFromFileServer(const std::string& filePath) |
| 112 | { |
nothing calls this directly
no test coverage detected