将js模型加载到三个js项目中

时间:2017-03-27 11:13:28

标签: json three.js 3dsmax

我在我的项目中使用了以下代码(不是我的,它来自本文http://blog.andrewray.me/how-to-export-a-rigged-animated-model-from-3ds-max-three-js/),并尝试加载我的模型。但问题是作者使用动画皮肤网格,我有一个简单的模型。我将他的完整演示页面代码复制到我的项目中,改变了js模型的路径并且它没有显示出来。我应该调整什么才能使其有效?

        var container;

        var camera, scene, renderer, objects;
        var particleLight, pointLight;
        var mesh, wiggly;

        var loader = new THREE.JSONLoader();

        loader.load( './humpback-whale-animated-threejs-max-exporter.js', function ( geometry, materials ) {

    var originalMaterial = materials[ 0 ];
    originalMaterial.skinning = true;

    mesh = new THREE.SkinnedMesh( geometry, originalMaterial );
    mesh.scale.set( 0.1, 0.1, 0.1 );

            var animation = new THREE.Animation(
                mesh,
                geometry.animation
            );
            animation.play();

            init();
            animate();

        });

        function init() {

            container = document.createElement( 'div' );
            document.body.appendChild( container );

            camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );

            scene = new THREE.Scene();

    scene.add( mesh );

            // Lights

            scene.add( new THREE.AmbientLight( 0xcccccc ) );

            var directionalLight = new THREE.DirectionalLight(/*Math.random() * 0xffffff*/0xeeeeee );
            directionalLight.position.x = Math.random() - 0.5;
            directionalLight.position.y = Math.random() - 0.5;
            directionalLight.position.z = Math.random() - 0.5;
            directionalLight.position.normalize();
            scene.add( directionalLight );

            pointLight = new THREE.PointLight( 0xffffff, 4 );
            scene.add( pointLight );

            renderer = new THREE.WebGLRenderer();
            renderer.setSize( window.innerWidth, window.innerHeight );

            container.appendChild( renderer.domElement );

            window.addEventListener( 'resize', onWindowResize, false );

        }

        function onWindowResize() {

            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();

            renderer.setSize( window.innerWidth, window.innerHeight );

        }

        var clock = new THREE.Clock();

        function animate() {
            requestAnimationFrame( animate );
            render();
        }

        function render() {

            var delta = clock.getDelta();

            var timer = Date.now() * 0.0005;
    THREE.AnimationHandler.update( delta );

            camera.position.x = Math.cos( 0.5 ) * 20;
            camera.position.y = 5;
            camera.position.z = Math.sin( 0.5 ) * 20;

            camera.lookAt( scene.position );

            renderer.render( scene, camera );

        }

我知道在three.js中有不同的加载器,我不知道哪一个用于简单的静态纹理网格。

0 个答案:

没有答案