本文介绍了如何从three.js中的OBJ+MTL文件加载纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个导出到 OBJ 和 MTL 的 Maya 文件.我可以成功看到 OBJ 纹理,但我如何实际获取纹理?我在搅拌机中查看了three.js"格式,它似乎只有形状,没有纹理.

I have a Maya file exported to OBJ and MTL. I can see the OBJ texture successfully, but how do I actually get the texture in? I looked at the "three.js" format in blender, which appears to be shape only, no texture.

这个 three.js 示例 似乎在 obj 中加载了很好的形状,但是纹理似乎来自 jpg 图像而不是 mtl:

This three.js example appears to load in the obj fine for the shape, but the texture appears to come from a jpg image and not an mtl:

loader.load('textures/ash_uvgrid01.jpg', function(image) {
    texture.image = image;
    texture.needsUpdate = true;
});

我的问题是,如何为我的模型获取这个uvgrid01.jpg"图像?有什么方法可以将 MTL 转换为这种 .jpg 格式的纹理吗?或者我应该通过其他方式导出纹理以便能够加载它吗?

My question is, how do I get this "uvgrid01.jpg" image for my model? Is there some way to convert MTL to this .jpg format for the texture only? Or is there some other way I should be exporting the texture to be able to load it in?

推荐答案

你可以使用 OBJLoader 和 MTLLoader,见 这个例子(至少三个.js r77):

You can use OBJLoader and MTLLoader, as seen in this example (at least three.js r77):

var mtlLoader = new THREE.MTLLoader();
mtlLoader.setPath('obj/male02/');
mtlLoader.load('male02_dds.mtl', function(materials) {
  materials.preload();
  var objLoader = new THREE.OBJLoader();
  objLoader.setMaterials(materials);
  objLoader.setPath('obj/male02/');
  objLoader.load('male02.obj', function(object) {
    object.position.y = -95;
    scene.add(object);
  }, onProgress, onError);
});

这篇关于如何从three.js中的OBJ+MTL文件加载纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 21:23