如何将obj和mtl文件导入three.js

时间:2014-11-18 14:50:06

标签: three.js .obj

我很难导入这些obj和mtl文件来加载三个js的模型。我试试这段代码:

var loader = new THREE.OBJMTLLoader();

loader.load(" test.obj"," test.mtl"); loader.addEventListener(" load",function(object){scene.add(object);},false);

我应该做些什么吗?我发现了一些关于将js / OBJMTLLoader.js等脚本导入html.if的内容,我应该从某个地方下载它们吗?

1 个答案:

答案 0 :(得分:0)

            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 ) {};
            THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() );

        if (name == "House"){
            var loader = new THREE.OBJMTLLoader();
            loader.load( 'models/House/house_obj/house_obj.obj', 'models/House/house_obj/house_obj.mtl', function ( object ) {
                object.traverse( function ( child ) {

                    if ( child instanceof THREE.Mesh ) {

                        child.material.side = THREE.DoubleSide;

                    }

                } );


                object.rotation.x = Math.PI/2;
                 var scale = 0.15/ (MapWidth*0.5/3);//upsos tabani
                object.scale.set(scale,scale,scale);
                House = object;


            }, onProgress, onError );
            }

这是我使用的代码..在这个例子中,我检查用户是否选择插入房屋模型。 onProgress和onError函数声明了加载器的完整性。我使用OBJMTLLoader.js和DDSLoader.js