Code to add x axis rotation to orbitControls auto rotation

Hi All,
I have a scene that orbitControls auto-rotates around. When I drag up with the mouse the scene tips along the x axis. I need to mimic this behaviour in the code. Here’s the code to a simplified scene; commented out are failed attempts with camera.rotation.x, camera.lookAt, and Everything I’ve tried looks at the cube from different locations but doesn’t rotate the scene around the x axis. Running live here:



<!doctype html>
<html lang="en">
  <title>Test tip x axis 210613</title>
  <meta charset="utf-8">
<body style="margin: 0;">

  <script src="js/three.js"></script>
  <script src="js/OrbitControls.js"></script>


    // Set up the scene, camera, and renderer as global variables.
    var scene, camera, renderer;


    // Sets up the scene.
    function init() {

      // Create the scene and set the scene size.
      scene = new THREE.Scene();

      // Create a renderer and add it to the DOM.
            renderer = new THREE.WebGLRenderer();
            renderer.setSize( window.innerWidth, window.innerHeight );
            renderer.setClearColor( 0x72C4DA );
            document.body.appendChild( renderer.domElement );

      // Create a camera, zoom it out from the model a bit, and add it to the scene.
      camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
      camera.position.z = 1.5;
       //camera.rotation.x = THREE.Math.degToRad(45);
  //    camera.position.set( 500, 500, 0);
//camera.lookAt( 0, -100, 0 );
//camera.up.set( 0, 0, 1 );

 // Add OrbitControls so that we can pan around with the mouse.
 controls = new THREE.OrbitControls( camera, renderer.domElement);
            controls.autoRotate = true;
            controls.autoRotateSpeed = 0.5;
           // controls.rotation.x = THREE.Math.degToRad(45);
  = new THREE.Vector3(0, 0, 0); // what 

// Create an event listener that resizes the renderer with the browser window.
         window.addEventListener('resize', function () 
              var width = window.innerWidth;
              var height = window.innerHeight;
              renderer.setSize ( width, height );
              camera.aspect = width / height ;

            } );

      // Set the background color of the scene.
      renderer.setClearColor( 0xFFFFFF );

      // Create a light, set its position, and add it to the scene.
      var ambientLight = new THREE.AmbientLight(0xFFFFFF, 0.9);
           scene.add( ambientLight);

      // add geometry

      const geometry = new THREE.BoxGeometry( 1, 1, 1 );
      const wireframe = new THREE.WireframeGeometry( geometry );

      const line = new THREE.LineSegments( wireframe );
      line.material.depthTest = false;
      line.material.opacity = 1;
      line.material.transparent = false;

      scene.add( line );
     // Renders the scene and updates the render as needed.
    function animate() {

      // Read more about requestAnimationFrame at
      // Render the scene.
      renderer.render(scene, camera);




You probably figured out your issue since this post is almost a year old but I was dealing with something similar and i figured I’d mention it here for anyone who might stumble on it.

For non symmetrical objects, you can effectively change the rotation axis using setting the up vector of the camera using

camera.up.set( 0, 0, 1 );

0,0,1 being the vector defining the up axis, this essentially rotates the object but keeps the visible rotation axis the same. So for your symmetrical cube there appears to be no effect other than changing the direction of the autorotation

You can add constant x axis rotation to your model by modifying your animate function like so

This will auto rotate your object along the x-axis, but it wont pause the rotation when you move the camera with your mouse. So, not quite ideal. Wish there was an easy way to just declare your desired autorotation axis