0
votes

I found the reference code from github and other questions about object rotation on stackoverflow.

var vector = new THREE.Vector3( 1, 0, 0 );
        var axis = new THREE.Vector3( 1, 0, 0 ).normalize();
        var angle = Math.PI / 2;                

        function rotateAroundWorldAxis(object, axis, angle) {                                               
            var matrix = new THREE.Matrix4().makeRotationAxis( axis, angle );
            matrix.multiplyVector3( vector );
            object.matrix = matrix;
            object.rotation.setEulerFromRotationMatrix(object.matrix);
        }

        function render() {                     
            rotateAroundWorldAxis(tubeMesh, axis, angle);
            renderer.render( scene, camera );
        }

I can't figure out what could be the reason of the error "Uncaught TypeError: Cannot read property 'x' of undefined." In google chrome it shows as

  • Uncaught TypeError: Cannot read property 'x' of undefined at three.min.js:56
  • THREE.Matrix4.makeRotationAxis at three.min.js:56
  • rotateAroundWorldAxis at my_model.htm:290
  • render at my_model.htm:297
  • animate

The error is in three.min.js at line no. 56. I am using r51 of three.js library.

1
Hi. Not sure if you've worked it out by now, but you might want to try using the uncompressed version of ThreeJS ( ie three.js rather than three.min.js ). Then you could see exactly where the error was occurring, and what it was trying to do. I've had this same error myself recently, but I think it was related to having vertex groups in a model exported from Blender that were assigned to a bone that no longer existed. I deleted and recreated my vertex groups, and it fixed the problem. - null

1 Answers

0
votes

In case we had the same problem (three.js trying to read into the uv-mapping array) you can solve it by:

adding UV-mapping (in blender) to your model.
it basically entails:

  1. marking a seam on the object.
  2. unwrapping the model.
  3. exporting the model with UVs enabled.

for steps 1 and 2 you can follow this nice walk-through.
(NB: in addition to the steps in the article, in my version (2.59), I had to create a material and texture first.)