The mesh of GLTF model cannot be recongnized as type Mesh or Object3D

Hi everyone,

I need to load external GLTF models and unpack them to use their Mesh object in my scene. I use following code to unpack child:

      this.gltfLoader.load(url, (gltf) => {
        const model = gltf.scene.children[0];
        Object.defineProperty(res, 'entity', { value: model });
      });

But when I was about to remove them from scene and dispose their resources such as material or texture, I found its type is strange:

      gltf instanceof Object3D; // false
      gltf instanceof Mesh; // false
      gltf.isMesh; // true

I guess the gltf model should be an instance of Mesh, but it isn’t. Is this a bug?

PS: My model is created by Blender. gltf-viewer.donmccurdy.com gives me following detail:

Validation report

  • Format: glTF 2.0
  • Generator: Khronos glTF Blender I/O v0.9.36
  • Stats:
    • 0 animations
    • 1 materials
    • 1 meshes
    • 1 nodes
    • 1 primitives
    • 1 textures
  • Extensions: None

Report generated by KhronosGroup/glTF-Validator 2.0.0-dev.2.7.

Are you using GLTFLoader from the three npm package or from a different one?

Currently it’s best practice to use .isMesh and similar properties to see what an object is. I don’t recall why that is, as opposed to using instanceof. There may be a few cases where the class hierarchy is non-obvious.

Butt as @Mugen87’s question suggests, it sounds like maybe there are two copies of three.js on your page? In that case comparing an instance from one copy to a constructor from the other will always fail. Always using the official three npm package and loaders/controls/subpackages from its examples/* folder should avoid that.

Aside: I wonder if we could ask the three-gltf-loader maintainer, and maintainers of similar packages, to mark them as deprecated (npm has a feature for this) now that threejs provides modules and typings?

I’ve actually had the same idea^^. Filed this issue some days ago. However, the package is still not deprecated :frowning_face:

Would be great if you could add a comment, too. Right now, three-gltf-loader has still approx. 4000 (!) downloads per week.

Thanks! Since the owner commented quite recently let’s give them a bit longer to respond…

1 Like

The package is now deprecated :tada:

2 Likes

Butt… lol.

1 Like

I’ll show myself out… :sweat_smile:

2 Likes