galacean / engine

A typescript interactive engine, support 2D, 3D, animation, physics, built on WebGL and glTF.
https://galacean.antgroup.com/engine
MIT License
4.2k stars 299 forks source link

Allow path for resource manager base url #2153

Open Oskang09 opened 3 months ago

Oskang09 commented 3 months ago

Describe the bug

When set to baseUrl it's throw error when loading i believe because of non-valid URL, and we're unable to specify the loading path so manual work is needed after exported.

const engine = await WebGLEngine.create(config);
engine.resourceManager.baseUrl = '../../../assets/games/playfulpsyduck/';
await engine.resourceManager
  .load({
    url: `${projectInfo.url}`,
    type: AssetType.Project,
  })
  // @ts-ignore
  .catch((e) => {
    throw e;
  });

engine.run();

return engine;
Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid base URL
    at Function.resolveAbsoluteUrl (chunk-4GQON2LM.js?v=58ed5193:4564:26)
    at ResourceManager2._loadSingleItem (chunk-4GQON2LM.js?v=58ed5193:20395:64)
    at ResourceManager2.load (chunk-4GQON2LM.js?v=58ed5193:20255:19)
    at init (index.ts:45:6)
    at async index.tsx:29:7

Expected behavior Allow us to set relative path when initialise the engine's resource manager.

Alternative way We're able to manually append the path in the exported files, project.json and loading project asset when initialise engine. As per screenshot shared it's was able to load fine when append the path ourselves. You can refer to Sample Game to ensure it's work fine after append path.

Screenshots

image

Desktop:

gz65555 commented 3 months ago

You can try:

import { Utils } from "@galacean/engine";

engine.resourceManager.baseUrl = Utils.resolveAbsoluteUrl(window.location.href, ".../../../assets/games/playfulpsyduck");
gz65555 commented 3 months ago

As for editor, we will add the feature which will support baseUrl soon.