Skip to content

importing a .glb file fails if only local path is provided and not served through HTTP #165

Open
@f4z3k4s

Description

@f4z3k4s

Hi!

First of all, thanks for the great work for all maintainers.

I've just started using this library in my project for rendering .glb files.

When the .glb file is served from a local static server, SceneLoader.ImportMeshAsync and other similar methods used for importing assets, such as Append, AppendAsync, etc.. work perfectly. However, when the file is not requested over HTTP, but rather the local path is provided to the above stated methods, the app just crashes without any easily traceable error (I wasn't looking so hard for the error, but it didn't appear in the terminal of the packager). Maybe it's my uneducatedness but from the documentation available here, I expected the import to work with just a local path.

I was able to solve the issue by using expo-asset to load the .glb file instead and provide a local uri, and then passing that local uri to Babylon, described in the below way:

import '@babylonjs/loaders';
import { Asset } from 'expo-asset';
import { SceneLoader, ... } from '@babylonjs/core';
 
const [{ localUri }] = await Asset.loadAsync(
  require('/assets/3d/tesla-high.glb')
);

const { meshes } = await SceneLoader.ImportMeshAsync(
  '',
  localUri as string,
  '',
  scene
);

However, I'd expect the library to do something similar internally, making the user to be able to only provide a path to a local .glb file and it load it without issues. If this work is purposefully left for the user, it would be nice to have it stated in the main documentation, since I think it's quite a common use-case.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions