【发布时间】:2017-01-11 01:46:16
【问题描述】:
我正在努力创建一个进度指示器,以显示 SCNScene 正在加载多少。 我尝试使用 SCNSceneScource 类来获取苹果文档中描述的状态处理程序。但是,这只能让我告诉我场景何时加载。然而这不是我想要的信息 - 我想显示总进度,包括加载时间和显示 SCNNode 所需的时间(我假设这是将加载的文件推送到图形适配器内存所需的时间)。
我的方法只显示了两次中的第一次。我做了以下事情:我添加了一个 SCNView 插座 (self.skView) 一个触发加载场景的按钮和一个 UIProgressBar 到我的视图。进度条反映 SCNSceneSource 的 totalProgress 属性。
- (void)viewDidLoad {
[super viewDidLoad];
// set up the SCNView
if (_skView.scene==nil) _skView.scene = [SCNScene new];
}
-(void) loadScene {
SCNSceneSource *s = [SCNSceneSource sceneSourceWithURL:[[NSBundle mainBundle] URLForResource:@"Muscles_V04" withExtension:@"dae"] options:nil];
SCNScene *scene = [s sceneWithOptions:nil statusHandler:^(float totalProgress, SCNSceneSourceStatus status, NSError * _Nullable error, BOOL * _Nonnull stop) {
self.proressBar.progress = totalProgress;
NSLog(@"Total progress %.3f",totalProgress);
// once finished remove the status indicator
if (totalProgress>=0.9999) {
[self.proressBar removeFromSuperview];
}
}];
// add the nodes of the loaded scene to the existing scene
for (SCNNode *n in scene.rootNode.childNodes) {
NSLog(@"node: %@", n.name);
[self.skView.scene.rootNode addChildNode:n];
}
}
【问题讨论】:
标签: ios objective-c progress-bar scenekit