Rotating the volume programtically does not work in NRRD example

Hello friends,

I am trying to use this NRRD volume example three.js webgl - loaders - NRRD loader. So i created my code based on that and everything works fine. But i can not
programmatically rotate the volume in X, Y, and Z coordinates to face the camera. all my attempts at rotating the meshes using rotateX or rotateY or rotateZ dont rotate anything for this example. I also tried the camera rotation using code like this:
camera.rotation.z += Math.PI/2

But as soon as the conrtol.update() is called from trackball control it goes back to original position. In any case i want to rotate the mesh using rotateXYZ methods and not use the camera. I am sytuck here. Again this is strictly with this example that mesh rotate is not rotating anything. Any ideas or suggestions are appreciated.
Thanks

If you have controls objects controlling the camera, you can’t change the camera look target yourself. You have to set the corresponding .target position on the orbitcontrols object itself… or disable the controls.

For rotating a mesh, you can set its .rotation.x , y and z…

If you want to rotate the geometry itself… then you can use mesh.geometry.rotateX , Y, Z

Thanks @manthrax for your reply. I did try the various methods you suggested and for this particular volume renderer non of them worked. The only thing that worked for me was to switch to orbitcontrol and try this code:

              controls.enabled = false;      //disable orbitControls
              controls.reset();         //reset orbitControls
              const vect3 = new THREE.Vector3(); //define any vector (here we just point at 0,0,0)
              controls.target = vect3;      //update orbitControls target
              switch(axis) {
                case 'x':
                  camera.position.set(300,0,0);
                  break;
                case 'y':
                  // code block
                  camera.position.set(0,350,0);
                  break;
                case 'z':
                  camera.position.set(0,0,250); 
                  break;  
                default:
                  // code block
              }
              camera.lookAt(vect3);       //optional pre-rotation (in case orbit is not updated in render loop)
              controls.enabled = true;      //enable orbitControl again

Thanks to this article: Rotate camera and adapt OrbitControls - #2 by Oxyn

The rotation now works in all three axises.

1 Like

Nice! Glad you figured it out.

Thanks again @manthrax for your help.

1 Like