How to rotate a object on axis world three.js?

后端 未结 5 1375
深忆病人
深忆病人 2020-12-03 05:35

Is it possible to do rotations taking axis of the world and not of the object?

I need to do some rotations of an object, but after the first rotation, I can\'t do ot

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 05:58

    @acarlon Your answer might just have ended a week of frustration. I've refined your function a bit. Here are my variations. I hope this saves someone else the 20+ hours I spent trying to figure this out.

    function calcRotationAroundAxis( obj3D, axis, angle ){
    
        var euler;
    
        if ( axis === "x" ){
            euler = new THREE.Euler( angle, 0, 0, 'XYZ' );      
        }
    
        if ( axis === "y" ){
            euler = new THREE.Euler( 0, angle, 0, 'XYZ' );              
        }
    
        if ( axis === "z" ){
            euler = new THREE.Euler( 0, 0, angle, 'XYZ' );      
        }
        obj3D.position.applyEuler( euler );
    }
    
    function calcRotationIn3D( obj3D, angles, order = 'XYZ' ){
    
       var euler;
    
       euler = new THREE.Euler( angles.x, angles.y, angles.z, order );
    
       obj3D.position.applyEuler( euler );
    
    }
    

    This works beautifully in r91. Hope it helps.

提交回复
热议问题