t32-adapter-io-loader.mjs 1.2 KB

1234567891011121314151617181920212223
  1. import { readFile } from 'node:fs/promises'
  2. import { fileURLToPath } from 'node:url'
  3. // Real Cesium math/events/data types; only GPU/terrain I/O are replaced at the adapter boundary.
  4. export async function resolve(specifier, context, nextResolve) {
  5. if (specifier !== 'cesium') return nextResolve(specifier, context)
  6. const real = await nextResolve(specifier, context)
  7. const code = `
  8. export * from ${JSON.stringify(real.url)};
  9. import { Event } from ${JSON.stringify(real.url)};
  10. export const Model = { async fromGltfAsync(options) {
  11. const gltf = await fetch(options.url).then(r=>r.json());
  12. const model = { options, gltf, readyEvent:new Event(), errorEvent:new Event(), destroyed:false,
  13. destroy(){this.destroyed=true}, isDestroyed(){return this.destroyed} };
  14. globalThis.t32Models.push(model);
  15. return model;
  16. } };
  17. export async function sampleTerrainMostDetailed(_, points) {
  18. return points.map(point=>{point.height=globalThis.t32TerrainFails?undefined:100;return point});
  19. }
  20. `
  21. return { url:'data:text/javascript,'+encodeURIComponent(code), shortCircuit:true }
  22. }