obj文件中的threejs UV贴图

threejs UV mapping in obj file

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

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

为什么映射不一样?我虽然 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();
                });
            }
        });
    }

在您的 mtl 文件中更改此行:

map_Kd uv_checker large.png

map_Kd large.png

嗯,这只是一个 Blender 导出问题。我刚刚用这个设置导出了我的模型,它工作得很好!