Adding gltf loader and inline meshes to the scene results in error

Hello, Three.js community,

I’m a total newbie and finding my way into Three.js. So far it has been a very pleasant journey and adventure. Now I’m a bit stuck. Here is my problem.

I’m loading a gltf model with the GLTFLoader. Within the onLoad method, I’m using scene.add(gltf.scene) to add the models (three super basic cubes) to the scene. Right after that, I’m defining a simple plane that I want to use as a floor below the cubes.

When I try to add the plane to the scene with scene.add(gltf.floor) I’m getting an error message. I see two of the three meshes of the gltf rendered though.

Uncaught TypeError: Cannot read property 'type' of undefined at WebGLIndexedBufferRenderer.setIndex at WebGLRenderer.renderBufferDirect

I figured when I add the gltf meshes into a group (group.add(gltf.scene)), then I can add them to the scene together with the floor.

What crucial concept am I missing or what am I doing wrong on import and adding? Thank you for and information and wisdom.

Best regards
Mike

Can you share your code? gltf.floor is not a property that GLTFLoader would be creating, so we’d need to see where you are constructing that.

Good morning and thank you very much for your help.

I made a gist with the code. Here is the link:

https://gist.github.com/mikewink/24c574e5f0c095a68f51586f09a60b86

As you can see. I’m not using gltf.floor that is just me being unclear. By the way, I’m running three r108.

Another addition. The moment I uncomment the camera helper and add it to the scene, I get the same error. :thinking:

Thank you.

Are you sure it’s the line scene.add(floor); throwing the error? I don’t see anything wrong with that section, but I also can’t run this code fully without the models.

You may want to try making a live demo – on JSFiddle or Codeden — and commenting out the parts with the models. Here’s a start: https://jsfiddle.net/roywzu02/1/. That seems to work, the only error I saw along the way was that onWindowResize is sometimes called before the renderer has been created, which will throw an error.

Hello @donmccurdy,

You are right, it’s not just the scene.add(floor), it’s also happening when I add a camera helper.
Ohh the model is just the default cube from blender exported directly with the gltf exporter and no export adjustments.

I will definitely strip my script and try to figure out where the problem comes from. Using jsFiddle as a second runtime env. will definitely be helpful.

Thank you!

I suspect this is happening because you have two copies of three.js being loaded.

See: