为什么我的文本网格不不断旋转?

Why my text mesh does not rotate constantly?

我需要我的文本网格不断旋转,而不管 TrackballControls(用鼠标移动)。使用以下代码,我的网格仅在移动鼠标时旋转。谁能告诉我哪里出了问题?

代码:

//Basic Three components 
var scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.z = 500;

//Set camera controls
var controls = new THREE.TrackballControls( camera );
controls.rotateSpeed = 1.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.8;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
controls.keys = [ 65, 83, 68 ];
controls.addEventListener( 'change', render );

//Set the renderer
var renderer = new THREE.WebGLRenderer( { antialias: false } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

window.addEventListener( 'resize', onWindowResize, false );

//Let's add a text
var materialT1 = new THREE.MeshNormalMaterial();
var textGeom = new THREE.TextGeometry( 'Sitescope', {
    font: 'optimer',
    weight: 'normal',
    size: 20                
});

var textMesh = new THREE.Mesh( textGeom, materialT1 );
textMesh.position.set(-40,60,50)
scene.add( textMesh );

function onWindowResize() {

    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize( window.innerWidth, window.innerHeight );
    controls.handleResize();
    render();

}

function animate() {
    requestAnimationFrame( animate );
    controls.update();

}

function render() {
    textMesh.rotation.x += 0.05;
    renderer.render( scene, camera );
} 

animate();
render();

操作顺序导致了您的问题。试试这个:

function animate() {
    requestAnimationFrame( animate );
    render();
}

function render() {
    cube.rotation.x += 0.01;
    cube.rotation.y += 0.01;
    textMesh.rotation.x += 0.05;
    controls.update();
    renderer.render( scene, camera );
}

animate();

同时删除此调用:

controls.addEventListener( 'change', render );

你可以在这里看到一个fiddle