To work with the textured OBJ scene in Xcode you need a bundle of three files: .obj
, .mtl
and .jpg
. To load an .obj
scene with its corresponding textures, all three bundle-files must be located in the same Documents directory. Here's how your code might look when using Objective-C app:
#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
As you know, a .mtl
file is an ASCII-based definitions of materials for .obj
file.
Here's how it looks like:
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
