我在单个面上为STL模型应用了简单的UV贴图,结果如下:
现在我从blender导出.obj
和.mtl
个文件。 Here如果您愿意,可以下载它们。当我使用obj
和mtl
加载此OBJLoader
和MTLLoader
个文件时,结果如下:
为什么映射不一样?我虽然three.js
可以从文件中读取UV映射。有没有其他方法可以将UV贴图导出到模型中,或者我做错了什么?
这是我用来加载obj
和mtl
文件的代码:
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();
});
}
});
}