Error with glTF loader module in recent 5.0.1+ releases

Project itself :slight_smile:

I am sorry, but looking at cut out sources will not be helpful for me. It is very much possible it is happening because of the module resolution, or because of the bundler configuration, or because different reasons. What I can tell you is this - usually there is no need to use this package directly. If you do want, it should work, as it works in any other project importing it (including our loaders). Something in your project setup tries to actively import something from this package, and this is wrong.

these are const enums. typescript embeds them in your code and removes the import. Try playing around with the tsconfig or your bundler configuration to check why typescript doesn’t do that

Okay, the project itself is confidential and not available to the public. I’ll take a closer look at what you said to check on the project

1 Like

As I see in this screenshot, you mix 2 different Babylon npm packages - with @ (ES6) and without @.
I’ve heard from friends that it is much better to use only one npm package :slight_smile:

1 Like

But is there an ES6 version for babylonjs-gltf2interface?

I dont think so since there is no need in it.
Probably you just don’t need to use its types and just GLTFFileLoader will be enough?
I agree with this:

1 Like

Agreed with others, that there is generally no reason to use these types directly. So it’s unclear what you are trying to do. However, if you have some legit reason for trying to use these types, perhaps something like this helps you:

import type { IGLTFAnimationChannelTarget } from '@babylonjs/loaders/glTF/1.0'
1 Like

Generally speaking, GLTFFileLoader is sufficient, but now we have unique requirements and need to make some modifications based on gltf. Therefore, we plan to make modifications on glTFLoader.ts. My current approach is to copy a copy of
@babylonjs/loaders/glTF/2.0/glTFLoader.ts
for modification. In glTFLoader. ts, there is a type for importing babylonjs-gltf2interface. The Vite scaffold I used encountered an error when I introduced const enum.

import type { IProperty } from "babylonjs-gltf2interface";
import {
    AnimationChannelTargetPath,
    AnimationSamplerInterpolation,
    AccessorType,
    CameraType,
    AccessorComponentType,
    MaterialAlphaMode,
    TextureMinFilter,
    TextureWrapMode,
    TextureMagFilter,
    MeshPrimitiveMode,
} from "babylonjs-gltf2interface";

This is what I want to do now

Now we have more context :slight_smile:
Did you try to copy Babylon.js/packages/tools/devHost/src/babylon.glTF2Interface.ts at bf3ce60729dae5eb78d97201737689c07c7c172c · BabylonJS/Babylon.js · GitHub and import needed types locally?

Yes, I have tried it. But it will prompt that there is an error in the type, and comparing it like this seems unintentional, because the types “BABYLON.GLTF2. AccessorElementType” and babylon.glTF2Interface AccessorWidgetType "does not overlap

contrast:

hi, I think I have already solved it. My project uses Vite, and I need to configure a real . ts file for babylonjs-gltf2interface. Then I will copy the packages/tools/devHost/src/babylon.glTF2Interface. ts
from the internet to my local device for use.

I saw that babylonjs also does this, so as a reference

@labris @kaliatech @RaananW

3 Likes