Optimize and robustify asset prefetching and material loading.
- Parallelize asset prefetching (max 4 workers) with retry logic and on-screen error banner, replacing silent failures and cryptic WASM out-of-bounds crashes with explicit missing-file errors. - Support binary Uint8Array/ArrayBuffer in C++ asset registry via typed_memory_view, preventing Embind string coercion from corrupting binary shader packages into ASCII text. - Automatically glob .mat files in CMake instead of maintaining a manual list. - Add missing reflection materials to prefetch arrays. - Disable caching for index.html in web server so template/script updates apply on normal page reload without stale cache issues, the file is small so caching had a negligible upside. - Add null resource and payload validation in ObjectManager::LoadMaterial before constructing Filament materials. PiperOrigin-RevId: 963364509 Change-Id: I7de79df6a5cede4e54683415ee193f1c5a665286
This commit is contained in:
committed by
Copybara-Service
parent
fb03be0e4f
commit
fca913b4f5
@@ -715,9 +715,30 @@ class AssetRegistry {
|
||||
};
|
||||
|
||||
// Exposed to JS (see EMSCRIPTEN_BINDINGS): the page calls this once per asset.
|
||||
void RegisterAsset(std::string filename, std::string contents) {
|
||||
AssetRegistry::Instance().RegisterAsset(std::move(filename),
|
||||
std::move(contents));
|
||||
void RegisterAsset(std::string filename, emscripten::val contents) {
|
||||
std::string data;
|
||||
if (contents.typeOf().as<std::string>() == "string") {
|
||||
data = contents.as<std::string>();
|
||||
} else if (contents.instanceof(emscripten::val::global("Uint8Array")) ||
|
||||
contents.hasOwnProperty("length")) {
|
||||
size_t len = contents["length"].as<size_t>();
|
||||
data.resize(len);
|
||||
if (len > 0) {
|
||||
emscripten::val memory_view =
|
||||
emscripten::val(emscripten::typed_memory_view(len, data.data()));
|
||||
memory_view.call<void>("set", contents);
|
||||
}
|
||||
} else if (contents.instanceof(emscripten::val::global("ArrayBuffer"))) {
|
||||
emscripten::val u8 = emscripten::val::global("Uint8Array").new_(contents);
|
||||
size_t len = u8["length"].as<size_t>();
|
||||
data.resize(len);
|
||||
if (len > 0) {
|
||||
emscripten::val memory_view =
|
||||
emscripten::val(emscripten::typed_memory_view(len, data.data()));
|
||||
memory_view.call<void>("set", u8);
|
||||
}
|
||||
}
|
||||
AssetRegistry::Instance().RegisterAsset(std::move(filename), std::move(data));
|
||||
}
|
||||
|
||||
// Registers resource providers so that "filament:" and "font:" asset requests
|
||||
|
||||
Reference in New Issue
Block a user