Loading GLTF models in Nodejs

Hi everyone,

Wow, this took me a while to get working :dizzy_face: Sharing the following node setup. Hope is saves you some time :slight_smile:

Use case? Needed this setup for unit testing.

//package.json
  "devDependencies": {
    "xhr2": "^0.2.1"
  },
  "dependencies": {
    "@babylonjs/core": "^6.5.0",
    "@babylonjs/loaders": "^6.5.0"
  }

//or
//npm install @babylonjs/core
//npm install @babylonjs/loaders
//npm install @xhr2
//file.js
import * as BABYLON from "@babylonjs/core";
import "@babylonjs/loaders";
import XMLHttpRequest from 'xhr2';

//test setup
global.XMLHttpRequest = XMLHttpRequest;

//test
var gltf = `data:{ ... }`;
await BABYLON.SceneLoader.AppendAsync("", gltf, scene);
console.log( scene.getMeshByName("UnitTestCubeWDirs") )

Best wishes
Joe

3 Likes

Thanks, I bet it can help !!!

Thanks for sharing with the community!