【问题标题】:TrackballControls with Collada kfAnimation Three JSTrackballControls with Collada kfAnimation 三 JS
【发布时间】:2017-04-23 23:48:22
【问题描述】:

大家好,我正在处理来自 Collada 模型的 kfAnimation 动画。我想包含一个轨迹球控件,但是当我超过堆栈大小时,我不知道为什么我的代码如下

        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();

            }

我尝试将控件更新放在 animate 和 start 函数中,但我认为它消耗了大量资源。我也尝试放入渲染但结果相同。

感谢您的帮助,我希望更多的实验可以帮助我。

【问题讨论】:

    标签: three.js collada trackball


    【解决方案1】:

    最后我找到了解决方案,它是一个选项 enableDampingdampingFactor

     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;
                }
    

    在此之后我只需添加 controls.update();

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

    【讨论】:

      猜你喜欢
      • 2019-01-11
      • 2016-03-26
      • 2015-08-31
      • 2013-05-24
      • 2017-08-26
      • 2014-06-05
      • 2018-04-04
      • 2015-02-06
      • 2016-12-03
      相关资源
      最近更新 更多