Three.js和帧动画跳过

时间:2013-02-20 18:33:20

标签: animation three.js frame

我目前正在使用three.js进行动画项目。我正在使用morphtargets,并想问为什么我的帧经常被跳过?我的动画有7个形态目标,它围绕着它们。它从0到6开始(输出:console.log('frame:'+ lastKeyframe)),但有时我的帧从0跳到3或从1跳到4 ..这里真的发生了什么?顺便说一句,动画代码运作良好

[if ( Mesh && playBack ) // exists / is loaded 
{   
    time = new Date().getTime() % duration; //arba Date.now()
    keyframe = Math.floor( time / interpolation ) + animOffset;
    if ( keyframe != currentKeyframe ) 
    {
        Mesh.morphTargetInfluences[ lastKeyframe ] = 0;
        Mesh.morphTargetInfluences[ currentKeyframe ] = 1;
        Mesh.morphTargetInfluences[ keyframe ] = 0;
        //console.log(Mesh.morphTargetInfluences[ 0 ]);
        lastKeyframe = currentKeyframe;
        currentKeyframe = keyframe;

    }
    //The two lines after the if statement interpolate between frames. 
    //The value at currentKeyFrame starts decreasing from 1, and the value at keyFrame starts increasing.
    Mesh.morphTargetInfluences[ keyframe ] = ( time % interpolation ) / interpolation;
    Mesh.morphTargetInfluences[ lastKeyframe ] = 1 - Mesh.morphTargetInfluences[ keyframe ];
    //console.log('current: ' + Mesh.morphTargetInfluences[ keyframe ]);
    console.log('frame: ' + lastKeyframe);

}]

1 个答案:

答案 0 :(得分:0)

我认为这是因为你正在根据阅读挂钟来选择新的框架..所以如果你的帧速率下降那么你可能会失去一个框架