【问题标题】:SceneKit – How to apply MTL texture to OBJ file?SceneKit – 如何将 MTL 纹理应用于 OBJ 文件?
【发布时间】:2021-07-20 07:34:34
【问题描述】:

作为后续行动:

ios - How to apply mtl texture file to OBJ

在将我的模型导入 SceneKit

时,我想添加 .MTL 纹理 以及我的 .OBJ 文件

使用这样的代码:

let scene = SCNScene(named: "rose.obj")

BUT我拥有的纹理文件存储在DOCUMENTS目录(iOS)中。

如何在Objective-C中调用这个函数?

【问题讨论】:

    标签: objective-c scenekit mtl-file


    【解决方案1】:

    要在 Xcode 中使用带纹理的 OBJ 场景,您需要包含三个文件:.obj.mtl.jpg。要加载具有相应纹理的.obj 场景,所有三个捆绑文件必须位于相同的Documents 目录中。以下是使用 Objective-C 应用程序时代码的外观:

    #import "ViewController.h"
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        SCNView *sceneView = (SCNView *)self.view;
        
        NSArray<NSURL *> *urls = [NSFileManager.defaultManager 
                                  URLsForDirectory:NSDocumentDirectory 
                                  inDomains:NSUserDomainMask];
    
        NSURL *sceneInDocumentsDirectory = [urls[0] 
                                          URLByAppendingPathComponent:@"file.obj"];
    
        SCNScene *scene = [SCNScene sceneWithURL:sceneInDocumentsDirectory 
                                    options:Nil 
                                    error:Nil];
    
        sceneView.scene = scene;
        sceneView.allowsCameraControl = YES;
        sceneView.autoenablesDefaultLighting = YES;
        sceneView.backgroundColor = [UIColor blackColor];
    
        NSLog(@"%@", sceneInDocumentsDirectory);
    }
    
    @end
    

    如您所知,.mtl 文件是.obj 文件的基于 ASCII 的材料定义。

    它是这样的:

    newmtl phong1SG
    illum 4
    Kd 0.00 0.00 0.00
    Ka 0.00 0.00 0.00
    Tf 1.00 1.00 1.00
    map_Kd texture.jpeg
    Ni 1.00
    Ks 0.50 0.50 0.50
    Ns 18.00
    

    【讨论】:

      猜你喜欢
      • 2018-10-18
      • 2018-03-11
      • 1970-01-01
      • 2013-07-16
      • 2017-01-24
      • 1970-01-01
      • 2017-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多