MODEL LOADING BABY WORKS
This commit is contained in:
@@ -12,7 +12,17 @@ void AssetFS::Init(std::filesystem::path exeDir) {
|
||||
|
||||
void AssetFS::Mount(std::string scheme, std::filesystem::path root) {
|
||||
spdlog::debug("Mounting assetfs scheme '{}' to root '{}'", scheme, root.string());
|
||||
mounts.push_back({std::move(scheme), std::move(root)});
|
||||
|
||||
FSMount m;
|
||||
m.scheme = std::move(scheme);
|
||||
m.root = std::move(root);
|
||||
|
||||
const auto manifestPath = m.root / "manifest.json";
|
||||
if (std::filesystem::exists(manifestPath)) {
|
||||
m.manifest = FS::LoadAssetManifest(manifestPath);
|
||||
}
|
||||
|
||||
mounts.push_back(std::move(m));
|
||||
}
|
||||
|
||||
std::vector<uint8_t> AssetFS::ReadBytes(std::string_view vpath) {
|
||||
@@ -51,6 +61,37 @@ std::filesystem::path AssetFS::GetFullPath(std::string_view vpath) const {
|
||||
throw std::runtime_error("mount not found");
|
||||
}
|
||||
|
||||
std::filesystem::path AssetFS::GetCookedPathForFile(std::string_view vpath) const {
|
||||
assert(initialized && "AssetFS not initialized");
|
||||
|
||||
const auto pos = vpath.find("://");
|
||||
if (pos == std::string_view::npos)
|
||||
throw std::runtime_error("bad vpath");
|
||||
|
||||
const std::string scheme(vpath.substr(0, pos));
|
||||
const std::filesystem::path rel(std::string(vpath.substr(pos + 3)));
|
||||
const std::string relStr = rel.generic_string();
|
||||
|
||||
for (const auto& m : mounts) {
|
||||
if (m.scheme != scheme) continue;
|
||||
|
||||
// If we have a manifest, consult it
|
||||
if (m.manifest) {
|
||||
if (const ManifestAsset* asset = m.manifest->FindBySrc(relStr)) {
|
||||
if (asset->out) {
|
||||
return m.root / *asset->out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to raw file
|
||||
return m.root / rel;
|
||||
}
|
||||
|
||||
throw std::runtime_error("mount not found");
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> AssetFS::ReadFile(const std::filesystem::path& fullPath) {
|
||||
std::ifstream file(fullPath, std::ios::binary);
|
||||
if (!file) {
|
||||
|
||||
Reference in New Issue
Block a user