简体   繁体   English

在 SceneKit 中导入带有纹理的 .obj 文件

[英]Importing .obj files with textures in SceneKit

I'm trying to render a 3D model .obj file downloaded from the web but I'm having issues with applying the textures to the model.我正在尝试渲染从网络下载的 3D 模型 .obj 文件,但在将纹理应用于模型时遇到问题。 .mlt, .obj and texture .jpg files are all in the same folder (eg car.obj, car.mtl, car.jpg, carDark.jpg). .mlt、.obj 和纹理 .jpg 文件都在同一个文件夹中(例如 car.obj、car.mtl、car.jpg、carDark.jpg)。

Are the textures supposed to be applied automatically by Model I/O?纹理是否应该由模型 I/O 自动应用? How am I supposed to use Model I/O to import textures?我应该如何使用模型 I/O 导入纹理?

Did you check the file path to the .mtl file in the .obj file?您是否检查了.obj文件中.mtl文件的文件路径? If this path is incorrect then the materials will not load.如果此路径不正确,则材料将不会加载。 OBJ and MTL files are text files so you can use a text editor to open them. OBJ 和 MTL 文件是文本文件,因此您可以使用文本编辑器打开它们。 The path to the .mtl file should be at the top of the .obj file: .mtl文件的路径应位于.obj文件的顶部:

mtllib mymtlfile.mtl

If they are in the same folder you can just strip the path.如果它们在同一个文件夹中,您可以删除路径。

If this path is okay then you should check the paths to the textures in the .mtl file.如果此路径没问题,那么您应该检查.mtl文件中纹理的路径。 Look for lines starting with map_ .查找以map_开头的map_ For instance:例如:

map_Kd mydiffusetexture.png
map_Ka /path/to/myambienttexture.tga
map_bump mybumptexture.jpg

If you strip all the paths then the file import should work.如果删除所有路径,则文件导入应该可以工作。

Add your textures images files in art.scnassets在 art.scnassets 中添加您的纹理图像文件

在此处输入图片说明

Select your scene and select your textures in Material properties选择您的场景并在材质属性中选择您的纹理

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM