我試圖用代碼更改當前的sceneNamed
,但似乎我的方法存在一些問題。首先,新的場景會改變,但我必須觸摸或評價對象,以改變過程發生。第二,看起來childNodeWithName
根本不會改變!這裏是我的代碼:以編程方式更改SCNScene的sceneNamed
- (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];
}
這裏是一個源代碼: https://www.dropbox.com/s/rrvbxmrb9wcrnoj/3D%20Objects%20Change.zip?dl=0
在Dropbox的版本的代碼是不是我張貼以上。這裏是Dropbox版本:
- (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]; }
您已發佈3個方法定義,但沒有任何調用它們。你在打什麼?你看到了什麼? –
@HalMueller我認爲這是完全清楚!第一種方法是嘗試使用其節點設置3D場景,在'viewDidLoad'中,我加載了默認對象,例如是一個立方體。在'nextObject'動作中,我試圖用代碼來改變3D對象。 –
然後發佈該代碼。張貼足夠我可以自己嘗試。也許包含屏幕截圖。你看到了什麼?你期望看到什麼? –