obj文件

时间:2017-03-28 18:36:14

标签: javascript three.js texture-mapping uv-mapping

我在单个面上为STL模型应用了简单的UV贴图,结果如下:

enter image description here

现在我从blender导出.obj.mtl个文件。 Here如果您愿意,可以下载它们。当我使用objmtl加载此OBJLoaderMTLLoader个文件时,结果如下:

enter image description here

为什么映射不一样?我虽然three.js可以从文件中读取UV映射。有没有其他方法可以将UV贴图导出到模型中,或者我做错了什么?

这是我用来加载objmtl文件的代码:

this.loadOBJ = function (baseURL, objFile, mtlFile, type) {
        return new Promise(function (resolve, reject) {
            console.log("Adding OBJ file '" + objFile + "' with MTL file '" + mtlFile + "'");
            scope.clearScene();

            // OBJ file loader
            function loadOBJ(materials) {
                var objLoader = new THREE.OBJLoader();
                if (materials) {
                    objLoader.setMaterials(materials);
                }

                objLoader.setPath(baseURL);
                objLoader.load(objFile, function (object) {

                    loadedMesh = object.children[0];

                    scene.add(loadedMesh);
                    centerCamera(loadedMesh);

                    render();
                    resolve();
                }, function (xhr) {
                    if (xhr.lengthComputable) {
                        var percentComplete = xhr.loaded / xhr.total * 100;
                        console.log("Loading OBJ file: " + Math.round(percentComplete, 2) + '% downloaded');
                    }
                }, function (xhr) {
                    console.log("Error loading OBJ: " + JSON.stringify(xhr));
                    reject();
                });
            };

            if (!mtlFile) {
                console.log("No MTL file specified, just loading OBJ");
                loadOBJ();
            }
            else {
                // Try to load the materials file first
                var mtlLoader = new THREE.MTLLoader();
                mtlLoader.setPath(baseURL);
                mtlLoader.load(mtlFile, function (materials) {

                    // File loaded, load the OBJ file now
                    materials.preload();
                    loadOBJ(materials);

                }, function (xhr) {
                    if (xhr.lengthComputable) {
                        var percentComplete = xhr.loaded / xhr.total * 100;
                        console.log("Loading MTL file: " + Math.round(percentComplete, 2) + '% downloaded');
                    }
                }, function (xhr) {
                    // We couldn't load the MTL file, load the OBJ anyway
                    console.log("Error loading MTL file: " + JSON.stringify(xhr) + ". Will load only OBJ file");
                    loadOBJ();
                });
            }
        });
    }

2 个答案:

答案 0 :(得分:1)

那只是一个Blender出口问题。我刚用这个设置导出了我的模型,它运行得很好!

enter image description here

答案 1 :(得分:0)

在你的mtl文件中更改以下行:

map_Kd uv_checker large.png

map_Kd large.png