美文网首页WebGLThree.js
18three.js加载obj模型和材质

18three.js加载obj模型和材质

作者: 狂暴机甲 | 来源:发表于2018-04-21 17:59 被阅读14次

    18three.js加载obj模型和材质


    图片.png

    obj和mtl加载器更新变化很大。
    下面的代码是92版本的代码,参考官方的案例。

            var onProgress = function ( xhr ) {
                if ( xhr.lengthComputable ) {
                    var percentComplete = xhr.loaded / xhr.total * 100;
                    console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
                }
            };
            var onError = function(xhr) {};
            var mtlLoader = new THREE.MTLLoader();
            mtlLoader.setPath('models/');
            mtlLoader.load('Rhino_3.mtl', function(materials) {
                materials.preload();
                var objLoader = new THREE.OBJLoader();
                objLoader.setMaterials(materials);
                objLoader.setPath('models/');
                objLoader.load('Rhino_3.OBJ', function(object) {
                    object.position.y = 3.5;
                    object.scale.set(8, 8, 8);
                    scene.add(object);
                    console.log(object);
                }, onProgress, onError);
            });
    
            var mtlLoader1 = new THREE.MTLLoader();
            mtlLoader1.setPath('models/');
            mtlLoader1.load('Rhino_1.mtl', function(materials) {
                materials.preload();
                var objLoader = new THREE.OBJLoader();
                objLoader.setMaterials(materials);
                objLoader.setPath('models/');
                objLoader.load('Rhino_1.OBJ', function(object) {
                    object.position.y = 3.5;
                    object.position.z = 5.5;
                    object.scale.set(8, 8, 8);
                    scene.add(object);
                    console.log(object);
                }, onProgress, onError);
            });
    

    相关文章

      网友评论

        本文标题:18three.js加载obj模型和材质

        本文链接:https://www.haomeiwen.com/subject/yafflftx.html