在我的应用程序中,我使用 SceneKit Framework 在 SCNView 中显示 3D 对象,并导出修改后的文件,并进行一些小的更改,如颜色、温度等。但在将其导出到文档文件夹后,我得到了原始文件。
在这里我可以显示 3D 对象并对其进行一些修改,看起来不错,我可以在模拟器中看到 SCNView 的变化。
sceneView = [[SCNView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 100)];
[sceneView setBackgroundColor:[UIColor orangeColor]];
[self.view addSubview:sceneView];
sceneView.allowsCameraControl = true ;
// Load 3D object
NSString *path = [[NSBundle mainBundle] pathForResource:@“test” ofType:@"obj"];
NSURL * url = [NSURL fileURLWithPath:path];
scene = [SCNScene sceneWithURL:url options:nil error:nil];
sceneView.scene = scene ;
// Processing---
SCNLight *light =[[SCNLight alloc] init];
light.type = SCNLightTypeAmbient;
SCNNode *lightNode = [[SCNNode alloc] init];
lightNode.light = light ;
// Camera node
SCNCamera *camera = [[SCNCamera alloc] init];
SCNNode * Cameranode = [[SCNNode alloc]init];
camera.saturation = 0.5 ;
[scene.rootNode addChildNode:Cameranode];
Cameranode.position = SCNVector3Make(0.0, 0.0, 30.0);
sceneToExport = sceneView.scene ;
// Rotation -
SCNNode *cubeNode = [[SCNNode alloc] init];
cubeNode.rotation = SCNVector4Make(1000.0, 0.0, 30.0 , 40.0);
[scene.rootNode addChildNode:cubeNode];
现在我正在尝试导出我修改过的 3D(.obj) 文件。
- (IBAction)saveAction:(id)sender {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
NSString *exportPath = [documentsPath stringByAppendingPathComponent:@"sceneAssets.obj"];
//NSLog(@"Saved %d",[sceneView.scene writeToURL:[NSURL URLWithString:exportPath] options:nil delegate:nil progressHandler:nil]);
NSLog(@"%d",[assetsToExport exportAssetToURL:[NSURL URLWithString:exportPath]]);
}
在这里,我尝试了两种方法(MDLAssets 和 SCNKit),通过使用此 .obj 文件通过两种方法保存在文档目录中,但我得到的是原始文件而不是修改后的对象。
我也尝试过创建MDLAsset
使用 SCNScene 对象但得到相同的结果。