Md Johirul Islam
Md Johirul Islam

Reputation: 5162

How to access loaded model with objectLoader

I am trying to load an external model using ObjectLoader. I am using the following code

loader.load( 'teapot.obj', function ( object ) {

        globalobject=object;
        object.traverse( function ( child ) {

            if ( child instanceof THREE.Mesh ) {

                child.material.map = texture;
                console.log(child);
                child.position.x = 3;
                child.position.y = -6;
                child.position.z = -17;
                child.scale.x=.04;
                child.scale.y=.04;
                child.scale.z=.04;
                child.name='tea';
                scene.add( child );

            }

        });

But when I try to access this object in my render method using the following code it shows error

scene.getObjectByName('tea').rotation.z+=.01;

I saw using console that scene.getObjectByName('tea') is undefined I can use all other standard Mesh objects using the above command but what is the problem with my object loaded using loader? Can anyone help me to get the way?

Upvotes: 0

Views: 779

Answers (1)

Siraj ul Haq
Siraj ul Haq

Reputation: 885

If you have multiple childs in one obj file then append some number to differentiate between multiple mesh. Then this should work:

scene.getObjectByName( "objectName" ); 

This answer may help

Upvotes: 1

Related Questions