0

こんにちは、私は 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 関数内にコントロールの更新を入れようとしましたが、多くのリソースを消費したと思います。また、レンダリング内に入れようとしましたが、同じ結果になりました。

ご協力いただきありがとうございます。さらに実験していただけると助かります。

4

1 に答える 1

0

最後に解決策を見つけました。それはオプションの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 );
于 2016-12-08T17:42:57.427 に答える