问题
In my Application, I am displaying 3D object in SCNView using SceneKit Framework and export the modified file with some small changes like color, Temperature etc. But I am getting the original file after exporting it to the document folder.
Here I can display and do some modification in 3D objects, That looks good and I can see the changes in SCNView in Simulator.
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];
Now I am Trying to export the 3D(.obj) file that I have modified.
- (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]]);
}
Here I have tried both ways (MDLAssets and SCNKit) by using this .obj file is saving in Document directory by both methods but I am getting original file instead of the modified object.
I have also tried with creating MDLAsset
object using SCNScene but get the same result.
来源:https://stackoverflow.com/questions/41373803/scenekit-modification-in-3d-object-and-exporting-file