Three.js Mesh没有使用AnimationHandler进行动画处理

时间:2013-03-01 14:29:53

标签: javascript animation three.js webgl blender

我无法将我的blender导出网格设置为动画。甚至不包括我在该示例中可以清楚地看到动画的水牛。 (我一直试图重现无济于事。 这是代码,我怀疑它是一个非常简单的缺失的东西,但我不知道。我怀疑它是一个混合器问题,因为我甚至无法为包含的网格设置动画。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>three.js webgl - blender</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <style>
        body {
            font-family: Monospace;
            background-color: #000000;
            margin: 0px;
            overflow: hidden;
        }

        #info {
            color: #fff;
            position: absolute;
            top: 10px;
            width: 100%;
            text-align: center;
            z-index: 100;
            display:block;

        }

        a { color: red }

        #stats { position: absolute; top:0; left: 0 }
        #stats #fps { background: transparent !important }
        #stats #fps #fpsText { color: #aaa !important }
        #stats #fps #fpsGraph { display: none }
    </style>
</head>

<body>
    <div id="info">
        <a href="http://crenet-games.com">025 Valgany</a>
    </div>

    <script src="/js/three.min.js"></script>
    <script src="/js/Detector.js"></script>
    <script src="/js/libs/stats.min.js"></script>

    <script>
        if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
        var modelBB={"min":new THREE.Vector3(),"max":new THREE.Vector3() };
        var crewon, animation;
        var container, stats;
        var camera, scene, renderer, objects;
        var particleLight, pointLight;
        var skin;
        var clock = new THREE.Clock();
        init();
        function init() {
            container = document.createElement( 'div' );
            document.body.appendChild( container );
            camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 10000 );
            camera.position.set( 2, 4, 5 );
            scene = new THREE.Scene();
            scene.fog = new THREE.FogExp2( 0x00FF00, 0.035 );
            var loader = new THREE.JSONLoader(true);
            loader.load("buffalo.js", function(geometry, materials) {
                geometry.computeBoundingBox();
                var faceMaterial = new THREE.MeshFaceMaterial( materials );
                faceMaterial.skinning = true;
                THREE.AnimationHandler.add( geometry.animation );
                crewon = new THREE.SkinnedMesh(geometry,faceMaterial, false);
                modelBB=geometry.boundingBox;
                crewon.position.set(0,0,0);
                scene.add(crewon);
                renderer.render(scene, camera);
                animation = new THREE.Animation( crewon, geometry.animation.name );
                animation.play( true, 0.5 );
            });
            // Lights
            scene.add( new THREE.AmbientLight( 0xcccccc ) );
            pointLight = new THREE.PointLight( 0xffffff, 1, 30 );
            pointLight.position.set( 5, 0, 0 );
            scene.add( pointLight );
            // Renderer
            renderer = new THREE.WebGLRenderer();
            renderer.setSize( window.innerWidth, window.innerHeight );
            container.appendChild( renderer.domElement );
            // Stats
            stats = new Stats();
            container.appendChild( stats.domElement );
            // Events
            window.addEventListener( 'resize', onWindowResize, false );
            animate();
        }
        function onWindowResize( event ) {
            renderer.setSize( window.innerWidth, window.innerHeight );
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
        }
        function animate() {
            requestAnimationFrame( animate, renderer.domElement );
            var delta = clock.getDelta();
            THREE.AnimationHandler.update( delta );
            render();
            stats.update();
        }

        function render() {
            if ( crewon ){
                crewon.rotation.y+=0.01;
            }
            if( typeof animation != 'undefined' && animation!=null){
                animation.update(0.1);
            }
            if( typeof modelBB != 'undefined' && modelBB!=null){
                camera.position.x = 0;
                camera.position.y = (modelBB.max.y-modelBB.min.y)/2;
                camera.position.z = (modelBB.max.z-modelBB.min.z)*2;
                camera.lookAt( new THREE.Vector3(
                    0,
                    (modelBB.max.y-modelBB.min.y)/2, 
                    0) );
            }
            renderer.render( scene, camera );
        }
    </script>
</body>
</html>

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:2)

问题可能在这里:

var faceMaterial = new THREE.MeshFaceMaterial( materials );
faceMaterial.skinning = true;

meshFaceMaterial就像是其他材料的容器 - 它本身并不是真正的材料。尝试迭代其材料集合:

var materials = faceMaterial.materials;
for (var i = 0,length = materials.length; i < length; i++) {
    var material = materials[i];
    material.skinning = true;
}