GLTFLoader imports object as Object3D, not as Mesh

Hi everyone,

I would like to import a GLTF file with the GLTFLoader and assign a VideoTexture after it has been loaded. I wanted to assign the material like so:

obj.material = new MeshBasicMaterial({
      map: texture

However, my IDE is giving me errors that ‘material’ does not exist on Object3D. So I guess I want to convert the Object3D into a Mesh, which does have the material property. But it is kind of confusing to me, because when I log the loaded GLTF object (from ‘glft.scene.children[0]’), I do see it has a material property. Can I use the imported GLTF object to add a new custom material to it or do I need a different approach?

This is the code I am using to import the GLTF:

const loader = new GLTFLoader();

loader.load(gltfFilePath, (gltf: GLTF) => {
   const mesh = gltf.scene.children[0];
   mesh.scale.set(40, 40, 40);

It’s a bit risky picking children from glTFs using indices (gltf.scene.children[0];) - hierarchy of children can be pretty much anything (it’s enough to just assign more than one material in Blender to get an additional child appended somewhere in the tree without realising it.)

Try picking a submesh from gltf using Object3D.getObjectByName instead - you can assign the name in Blender and then pick the right element in code - without worrying about automatically generated Groups / Object3Ds. If you do it that way you should get a nice, valid Mesh - and won’t have to worry about converting it.

Thanks! This getObjectByName works well! I will use this from now on!
Unfortunately, it does still return a Object3D instead of a Mesh for me.
My code completion only helps me when I type:

const obj = gltf.scene.getObjectByName('Earth');
console.log(obj.isObject3D); // returns true

So it doesn’t give me back the nice Mesh object I was hoping for :frowning:
It’s so weird, because in my console it does log the whole object with a geometry and material property. But I cannot access those in my code editor, because it says those do not exist on Object3D. (Which makes sense when I check the docs)

I think I’m mixing things up somewhere, but I’m not sure where exactly and how.

Three.Mesh is an extension of Three.Object3D - maybe it’s a typings issue?

I think you’re right! It seems like I got it working. Thanks a lot for the help!