What is the type of object of the imported models?

I’ve imported an .obj model in my scene, but I can’t get any other attributes such as mesh, materials, etc from it. I want to do some collision detection and ray casting, but they all seem to work with meshes (I’ve tested with a box mesh), and nothing happened when I tried to apply them to the model. So my questions are: what is the type of object of the imported models? And if it’s some kind of general object, can we turn it to object3D or some other three.js objects type without distording it in the scene? Thanks a lot

Here is the loading code:

var mtlLoader = new THREE.MTLLoader();
mtlLoader.load('/3dbaotang.mtl', (materials) => {

    var objLoader = new THREE.OBJLoader();
    console.log(typeof objLoader);
    objLoader.load('3dbaotang.obj', (object) => {
        object.castShadow = true;
        object.receiveShadow = true;
        object.position.y = 70;

        scene.add(object); // <-- what type is this object?

It’s an instance of THREE.Group. It acts like some sort of container for lines, meshes or points. It’s not possible to “convert” the group object into something else. But it’s possible to select specific objects from it. There are different way to do this. One possibility is a traversal through all objects:

object.traverse( function ( child ) {

    // do something with child

} );

If you know the name of your object, you can also use Object3D.getObjectByName().

BTW: THREE.Group is derived from THREE.Object3D.


Moreover, you can call console.log(object) to investigate the case :slight_smile:

@prisoner849 It just printed out object, almost to every object type, even with the ones that were clearly defined. That’s why I came here

@Mugen87 Thanks for the answer. It really shed some light :+1:

Okay. What about this: console.log(object.type);

1 Like

@prisoner849 Haaa now that’s the one. Thanks a lot!

You’re welcome :slight_smile:

1 Like