Can't load gltf models with relative path

Continuing this comment:
Why isn’t Babylon loading the file properly? The URL loads correctly from my local development server but not the production/public server. Here is a simple directory layout:

[Development Server]
├ Assets
├ other
├ libaries
└ game
	├ index.html
	├ shader
	├ image
	├ music
	├ sfx
	└ model
		├ corvette.gltf
		├ crusier.gltf
		└ ...

[Public Server]
├ index.php
├ account.php
├ login.php
├ ...
└ versions
	├ 2d
	├ indev
	└ infdev
		├ 1
		├ 2
		├ ...
		└ 11
			├ index.html
			├ sfx
			├ music
			├ ...
			└ model
				├ corvette.gltf
				├ crusier.gltf
				└ ...

Both game files (index.html) have the model in the ./model/<name>.gltf location. In the game code:

class Level extends Scene{
let model = 'model/corvette.gltf'; //this is set dynamically and maybe not be a relative path (e.g. with mods);

SceneLoader.LoadAssetContainerAsync('', model, this).then(...);

The third variable should be the root URL. You can also add a filename to the call as the last variable (setting whatever you don’t need to be undefined). The signature is this:

     * Load into an asset container.
     * @param scene The scene to load into
     * @param data The data to import
     * @param rootUrl The root url for scene and resources
     * @param onProgress The callback when the load progresses
     * @param fileName Defines the name of the file to load
     * @returns The loaded asset container
    loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;

Huh… Maybe the docs are out of date?
The params are ordered differently here.

Edit: This is for SceneLoader, and I’m using 5.3.0


(in SceneLoader._LoadData)

The plugin itself seems to load fine… maybe the loaders is out of date? The loaders on the CDN repo appear to be from 4.2.1.

After further continuing my research, I’ve found the error to origin with GLTFFileLoader.prototype.loadAssetContainerAsync, which uses the parameters you mentioned.
I managed to trigger the error using this code:

let loader = new GLTFFIleLoader();
let model = /*GLTF string*/;
//game.scene() returns a valid scene
loader.loadAssetContainerAsync(game.scene(),model,'model/corvette.gltf').then(e=>console.log('Loading successful')).catch(err=>console.log('Loading failed: ' + err.stack))

It throws: TypeError: Cannot read properties of undefined (reading 'asset') at e._getLoader. and from GLTFFileLoader.ts, e == loader.

Edit #2:
Continuing down the rabbit trail (or rather the stack trace):
The error comes from this function:

I don’t know why it wouldn’t load - the GLTF string passed to the loader is valid JSON than has a asset property.

Sorry, you are totally right. the docs i provided was for the plugins themselves. Still, the 2nd variable (in this case) should be the filename. the first should be the root url:

the CDN repo is no longer in use. the CDN has the latest 5.4.0

1 Like

Thanks! After downloading the loader off the preview CDN, the game appears is working fine. Thanks!

1 Like