feat(frontend): cache 3D assets and restore loading feedback
Persist versioned models and validated network metadata in IndexedDB. Show scene download progress and recoverable errors with the existing frosted material. Connect existing skeletons to pending navigation and route boundaries while preserving the map. Previously only dynamic imports showed fallbacks, and rejected model promises prevented retries. Verified: 32 focused unit tests; 4 navigation and scene browser checks; 7 cache browser checks including invalid-metadata recovery; isolated production build and type checks.
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
// Framework-independent data adapter. Does not parse or modify the project's INP.
|
||||
export const CAD_ORIGIN=Object.freeze([513800,2344450]);
|
||||
// This decoder runs before IDB writes, including when checking an existing entry.
|
||||
// A parseable HTTP 200 error response must not become a permanent model cache.
|
||||
export function parseNetworkMetadata(data,modelId){
|
||||
const model=JSON.parse(new TextDecoder().decode(data));
|
||||
const arrays=['nodes','links','pipeInstances','nodeInstances','bendInstances','cadEquipmentBindings','pumpEntityBindings','cadAttachments'];
|
||||
const objects=['layouts','connectivity','coordination','coordinatedLayouts','verticalCoordination'];
|
||||
if(!model||model.modelId!==modelId||!arrays.every(key=>Array.isArray(model[key]))||!objects.every(key=>model[key]&&typeof model[key]==='object'&&!Array.isArray(model[key]))||!model.nodes.length||!model.links.length)throw Error('管网元数据格式无效,请重新载入场景。');
|
||||
return model;
|
||||
}
|
||||
export function cadToGltf(point,displayZ=0){
|
||||
if(!Array.isArray(point)||point.length<2||!point.slice(0,2).every(Number.isFinite)||!Number.isFinite(displayZ))throw Error('Expected finite CAD XY and an explicit display height.');
|
||||
return [point[0]-CAD_ORIGIN[0],displayZ,-(point[1]-CAD_ORIGIN[1])];
|
||||
|
||||
Reference in New Issue
Block a user