2016-12-08 11 views
0

Hallo Leute, ich arbeite mit kfAnimation Animation von einem Collada-Modell. Ich möchte ein Trackball steuert enthalten, aber wenn ich ich die Größe Stapel überschreiten ich weiß nicht, warum mein Code derTrackballControls mit Collada kfAnimation Drei JS

finden
 function init() { 

        initRender(); 
        // Camera 
        initCamera(); 
        // Scene 
        initScene(); 
        //controlls 
        initControls(); 

        initGrid(); 

        loadObjectAnimatedFrames(); 


        window.addEventListener('resize', onWindowResize, false); 
       } 
    function loadObjectAnimatedFrames(){ 
        loader = loader.load('sources/crack-animated.dae', function (collada) { 
        model = collada.scene; 
        animations = collada.animations; 
        kfAnimationsLength = animations.length; 
        //model.scale.x = model.scale.y = model.scale.z = 0.125; // 1/8 scale, modeled in cm 

        for (var i = 0; i < kfAnimationsLength; ++i) { 
         var animation = animations[ i ]; 
         var kfAnimation = new THREE.KeyFrameAnimation(animation); 
         kfAnimation.timeScale = 1; 
         kfAnimations.push(kfAnimation); 
        } 
        start(); 
        animate(lastTimestamp); 
        scene.add(model); 
        }); 
       } 
    function initControls(){ 

        controls = new THREE.TrackballControls(camera); 
        controls.minDistance = 100; 
        controls.maxDistance = 1800; 
        controls.addEventListener('change',render); 

        } 
function animate(timestamp) { 
       var frameTime = (timestamp - lastTimestamp) * 0.001; 
       if (progress >= 0 && progress < 48) { 
        for (var i = 0; i < kfAnimationsLength; ++i) { 
         kfAnimations[ i ].update(frameTime); 
        } 
       } else if (progress >= 48) { 
        for (var i = 0; i < kfAnimationsLength; ++i) { 
         kfAnimations[ i ].stop(); 
        } 
        progress = 0; 
        start(); 
       } 
       //pointLight.position.copy(camera.position); 
       progress += frameTime; 
       lastTimestamp = timestamp; 

       render(); 

      } 

Ich versuchte Kontrollen Update innerhalb belebter zu setzen und Funktion starten, aber ich denke, es ist eine Menge verbraucht von Ressourcen. Ich habe auch versucht, das Rendering in die gleiche Richtung zu bringen.

Vielen Dank für Ihre Hilfe Ich hoffe, einige mehr experimentiert kann mir helfen.

Antwort

0

Schließlich fand ich die Lösung, und es war eine Option enableDamping und Dämpfungsfaktor

function initControls(){ 
       controls = new THREE.TrackballControls(camera, renderer.domElement); 
       //controls.addEventListener('change', render); // add this only if there is no animation loop (requestAnimationFrame) 
       controls.enableDamping = true; 
       controls.dampingFactor = 0.25; 
       controls.enableZoom = false; 
      } 

danach ich nur hinzufügen, controls.update();

renderer.render(scene, camera); 
      requestAnimationFrame(animate);