Using GLTF Loader on the Server with Node

In my node.js application running on a server, I have

import * as BABYLON from 'babylonjs';
import loaders from 'babylonjs-loaders';

but then I still cannot load .glb files and both dotglb and glb are false. Is there something else I need to do to activate the .gltf & .glb loaders int the node app?

Thanks,
Michael

const dotglb = BABYLON.SceneLoader.IsPluginForExtensionAvailable(".glb"); // always false
    
const glb = BABYLON.SceneLoader.IsPluginForExtensionAvailable("glb"); //always false
 
const modelContent = `data:;base64,${base64}`;
await BABYLON.SceneLoader.AppendAsync("", modelContent, scene); //fails

Hi Michael,

Usually loaders are available via the main SceneLoader module. However it looks like your code cannot access those modules for some reason :thinking:

One solution that might work:

import { IspluginForExtensionAvailable, /*etc*/ } from "@babylonjs/loaders/glTF";

IsPluginForExtensionAvailable(".glb") //hopefully true?

Or

import {IspluginForExtensionAvailable} from  "babylonj-s-loaders/glTF"

I think the problem is that you need to get the loaders from the object’s specific subdirectory, like obj or glTF.

The import you use may also depend on whether you need an ES6 ready package?

I hope this is a suitable fix :crossed_fingers:

Could you try import 'babylonjs-loaders'; instead as the sideEffects should be sufficient.

cc @RaananW in case he has more ideas ?

This is how I’ve been trying [link to discussion], but I still couldn’t figure out yet :frowning:

I’m not sure if it was the case, but there’s typo in the code

change below

const modelContent = `data:;base64,${base64}`;

to

const modelContent = `data:base64,${base64}`;

I will share if I get the node server to render a model perfectly! Please share if there’s any progress in yours! :slight_smile:

Happy coding! :computer: