OK… GLTF2 and GLTFLoader in my ES6 builds. First of all i am trying to mirror functionality from my main UMD build. For my GLTF parser i was using alot of classes in my PARSER functions:
BABYLON.GLTF2.GLTFLoader
BABYLON.GLTF2.IGLTFLoaderExtension
BABYLON.GLTF2.Loader.IScene
BABYLON.GLTF2.Loader.INode
BABYLON.GLTF2.IMaterial
BABYLON.GLTF2.Loader.IAnimation
BABYLON.GLTF2.ArrayItem
BABYLON.GLTF2.INode
BABYLON.GLTF2.IMesh
BABYLON.GLTF2.IMeshPrimitive
Once I moved over to the ES6 @babylonjs versions, and to keep my same codebase for my gltf parser, I removed the BABYLON from all the references above… Leaving GLTF2.GLTFLoader and etc…
I use a centralized import to gather all the classes above that come from different sources into once export called GLTF2 to mimic what the UMD version signatures look. So I can use the same exact GLTF PARSING code for both UMD and ESM Builds. So its is actually using imports and not globals:
this is a file i call babylon-gltf where i centralize all my GLTFLoader type imports to a fake namespace called GLTF2
// Import from the ES6 version of BabylonJS
import { GLTFLoader } from '@babylonjs/loaders/glTF/2.0/glTFLoader';
import { IGLTFLoaderExtension } from '@babylonjs/loaders/glTF/2.0/glTFLoaderExtension';
import { IScene, INode, IMaterial, IAnimation, IMesh, IMeshPrimitive } from '@babylonjs/loaders/glTF/2.0/glTFLoaderInterfaces';
import { ArrayItem } from '@babylonjs/loaders/glTF/2.0/glTFLoader';
import { GLTFFileLoader } from '@babylonjs/loaders/glTF';
export { GLTFLoader, GLTFFileLoader, IGLTFLoaderExtension, IScene, INode, IMaterial, IAnimation, IMesh, IMeshPrimitive, ArrayItem }
Then i make imports in code to reference them like so:
import * as GLTF2 from './babylon-gltf';
In the UMD it would still be the global BABYLON.GLTF2.GLTFLoader.RegisterExtension and on ESM it would be GLTF2.GLTFLoader.RegisterExtension.
So in ESM, GLTF2.GLTFLoader is really being directly imported from @babylonjs/loaders/glTF/2.0/glTFLoader
So that makes me ask if the endpoints for my GLTF2 imports are correct. These paths ChatGPT help me find the equivalent UMD to ESM for each of BABYLON.GLTF2 classes
listed above
Should the import for GLTFLoader be:
import { GLTFLoader } from '@babylonjs/loaders/glTF/2.0/glTFLoader';
and
import { IGLTFLoaderExtension } from '@babylonjs/loaders/glTF/2.0/glTFLoaderExtension';
and
import { IScene, INode, IMaterial, IAnimation, IMesh, IMeshPrimitive } from '@babylonjs/loaders/glTF/2.0/glTFLoaderInterfaces';
Cause i was getting error if i tried something:
import { GLTFLoader } from '@babylonjs/loaders';
and
import { IGLTFLoaderExtension } from '@babylonjs/loaders';
and
import { IScene, INode, IMaterial, IAnimation, IMesh, IMeshPrimitive } from '@babylonjs/loaders';