3

I have a problem reported by the console of Google Chrome. I am on Ubuntu 12.04. The problem in the console is :

    Uncaught TypeError: Cannot read property 'rotation' of undefined 
(reported five times).

And I can modify the position without problem in the function init() with these lines :

object.position.y = 0;

Also, I declare my variable object as a global variable.

I create a scene by importing an object (obj +mtl) with THREE.OBJMTLLoader(). And then for animate my object I do :

    object.rotation.y += 0.01;

The problem comes from the previous declaration. It's weird because it's working but I have this problem in the console. Do you know what could I do to fix it?

Thank you for your answers.

1 Answer 1

5

Loading is asynchronous. You are likely calling animate() before the object is fully loaded.

Put the animate() call in the loader callback.

Or alternatively, add the object to the scene in the loader callback.

See https://github.com/mrdoob/three.js/blob/master/examples/webgl_loader_obj_mtl.html.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.