I am trying to change a current sceneNamed
with code but it seems my method has some problems. First, the new scene will be changed but I have to touch or rate the object to changing process happens.Second, it seems childNodeWithName
doesn't change at all ! Here is my code :
- (void)load3DObjectName:(NSString*)name nodeName:(NSString*)nodeName zPhone:(CGFloat)positioniPhone zPad:(CGFloat)positioniPad{
SCNScene * scene = [SCNScene sceneNamed:name];
// retrieve the ship node
SCNNode *trex = [scene.rootNode childNodeWithName:nodeName recursively:YES];
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
trex.position = SCNVector3Make(0, 0, positioniPhone);
} else {
trex.position = SCNVector3Make(0, 0, positioniPad);
}
_the3DScence.scene = scene;
_the3DScence.autoenablesDefaultLighting = YES;
_the3DScence.allowsCameraControl = YES;
_the3DScence.backgroundColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1.00];
}
// Load default object :
- (void)viewDidLoad {
[self load3DObjectName:@"cube.dae" nodeName:@"cube1" zPhone:-40 zPad:-30];
}
//Trying to change the 3D object with button:
- (IBAction)nextObject:(id)sender {
[self load3DObjectName:@"redCube.dae" nodeName:@"cube2" zPhone:-40 zPad:-30];
}
- (IBAction)changeIt:(id)sender {
[self load3DObjectName:@"dayere.dae" nodeName:@"Sphere" zPhone:-40 zPad:-40];
}
Here is a source code : https://www.dropbox.com/s/rrvbxmrb9wcrnoj/3D%20Objects%20Change.zip?dl=0
The code in the Dropbox version is not what I posted above. Here is the Dropbox version:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self load3DObjectName:@"cube.dae" nodeName:@"Cube" zPhone:-40 zPad:-40]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)load3DObjectName:(NSString*)name nodeName:(NSString*)nodeName zPhone:(CGFloat)positioniPhone zPad:(CGFloat)positioniPad{ SCNScene * scene = [SCNScene sceneNamed:name]; // retrieve the ship node SCNNode *node = [scene.rootNode childNodeWithName:nodeName recursively:YES]; if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) { node.position = SCNVector3Make(0, 0, positioniPhone); } else { node.position = SCNVector3Make(0, 0, positioniPad); } _the3DView.scene = scene; _the3DView.autoenablesDefaultLighting = YES; _the3DView.allowsCameraControl = YES; _the3DView.backgroundColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1.00]; } - (IBAction)changeIt:(id)sender { [self load3DObjectName:@"dayere.dae" nodeName:@"Sphere" zPhone:-40 zPad:-40]; }
viewDidLoad
I loaded default object which is a cube for example. innextObject
action, I am trying to change the 3D object with code that's all . - Mc.Lovercube object
inviewDidLoad
there isbutton
that should change the cube object to something new for example a red cube or any object. When I tap the button the object doesn't change properly. I have to touch and rotate the object to scene changing occurs. - Mc.Lover