GLTF exported from Blender has type 'scene' rather than 'mesh' in its children

I exported two gltf models from Blender to use in my Three.js scene. What I could not understand is - in one case gltf.scene.children[0] has type ‘Mesh’ but the other gltf has type ‘Group’. I need it to be ‘Mesh’ in order to use raycasting later in the code. I cross-checked both the files but could not know why it is happening.
Find my .blend files attached. pin1.blend shows mesh. Any lead on this will be appreciated.
Thanks
hospital1.blend (860.0 KB)
pin1.blend (1.3 MB)

You can see the whole model’s scene graph if you open the JS Console on https://gltf-viewer.donmccurdy.com/

Screen Shot 2021-12-14 at 11.39.08 AM

The hospital1.blend file has three materials on different parts of the Blender mesh. For three.js this means it will be imported as three meshes in a group, not one mesh. You can still raycast against a group but will need to enable the recursive option on the raycaster so that it checks the descendants of the group.

2 Likes

You could recursively iterate over the children to add a property like ‘eventParent’ to each of the meshes after loading the GLTF. This way you can later when raycasting check whether the raycasted mesh has this eventParent, and then use that for further handling:

			let obj = gltf.scene;
			setEventParent(obj, obj);
                            .....

	function setEventParent(parent, ele) {
		for (var n = 0; n < ele.children.length; n++) {
			var ch = ele.children[n];
			setEventParent(parent, ch);
			if (ch.type == "Mesh") {
				ch.eventParent = parent;
			}
		}
	}
1 Like

This works! Thanks for the super-fast reply.

1 Like