Import a mesh from an API rest endpoint

Hello, this is my first post on a forum.

my problem is that I need to import a mesh, but for importing them, I need to get it from an API REST stub made with mockoon, who just have 2 root who each of them return a 3d modele(.glb) so for import them I tried with :
BABYLON.SceneLoader.ImportMesh(“”, “http://localhost:3001/”, “lamp”, scene, function (newMeshes) {
but it return this error : importMesh of undefined from undefined version: undefined, exporter version: undefinedimportMesh has failed JSON parse
I really dont know how import meshes by this way

You should force in the import function the file extension to “.glb” to let the importer know of the correct loader to use.

ok, but how do I do that?
because my API stub returns the file directly the file .glb as the address http://localhost:3001/lamp so how where do I force the extension and do I need to specify that the address returns a file that is not local but on a server?

There is an optional argument at the end of importMesh for which extension to use. See the docs here: SceneLoader | Babylon.js Documentation

thanks, it’s work perfectly on pc, but when I launch it on my phone, connected with a cable to my pc, the phone dont access to the api, whereas the address is localhost

If you are on the same network you could access the the app by using your IP address of your PC

So something like 192.168.0.xx:3001/lamp (check out what is your IPv4 address (on windows you can open console and call “ipconfig” and read the address) or on mac you go to “system preferences/network” and read the IP address.

nevermind, I found it, it was just I don’t add the port forwarding for my API in chrome inspect devices(localhost:3001) but thanks for reply me

1 Like