Allow path for resource manager base url
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
Desktop:
- OS: Windows
- Browser: Chrome
- Version: 125.0.6422.176 (Official Build) (64-bit)
- Galacean Version: 1.2.0-beta.4
You can try:
import { Utils } from "@galacean/engine";
engine.resourceManager.baseUrl = Utils.resolveAbsoluteUrl(window.location.href, ".../../../assets/games/playfulpsyduck");
As for editor, we will add the feature which will support baseUrl soon.