加载.dae模型时,纹理不会显示

时间:2016-04-28 18:13:07

标签: javascript three.js

我正在尝试在three.js中加载.dae模型,但纹理没有加载(我猜)。在这里我的代码:

<script src="js/three.js"></script>

    <script src="js/Animation.js"></script>
    <script src="js/AnimationHandler.js"></script>
    <script src="js/KeyFrameAnimation.js"></script>

    <script src="js/ColladaLoader.js"></script>

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

    <script>
        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );

        var renderer = new THREE.WebGLRenderer();
        renderer.setSize( window.innerWidth, window.innerHeight );
        document.body.appendChild( renderer.domElement );

        //load collada
        var loader = new THREE.ColladaLoader();
        loader.options.convertUpAxis = true;
        loader.load('model/Wood.dae', function(collada){
            collada.scene.traverse(function (child){
            if(child instanceof THREE.SkinnedMesh)
                {
                    var animation = new THREE.Animation (child, child.geometry.animation);
                    animation.play();

                    camera.lookAt( child.position );
                }
            });

        scene.add(collada.scene);
        });

        camera.position.z = 10;

        var render = function () {
            requestAnimationFrame( render );
            renderer.setClearColor(0xffe5e5, 1);

            renderer.render(scene, camera);
        };

        render();

我希望能够更改材料,并遵循许多教程,但实际上没有任何工作。一些技巧?

1 个答案:

答案 0 :(得分:0)

我这样做了

function newTexture(texture){
            dae.traverse(function(child){
                if(child instanceof THREE.Mesh){
                    child;
                    child.material.map = texture;
                    child.material.needsUpdate = true;
                }
            });

并且为了加载你可以使用TextureLoader的纹理,它对我有效。