【问题标题】:showing progress indicator while scenekit is loading scene在 scenekit 加载场景时显示进度指示器
【发布时间】: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


    【解决方案1】:

    我想提一下,在运行时加载您的 DAE 文件并将子节点添加到场景中并不是最优的。

    在编译 iOS 程序之前,您在 -loadScene 方法中所做的所有事情都可以在辅助程序中完成。以编程方式构建场景。使用NSCoding 将其存档。将该场景文件嵌入到您的 iOS 应用程序中。在运行时加载存档。

    为了获得更好的性能,您可以(在创建场景存档的辅助程序中)展平节点,创建一些 SCNLevelOfDetail 实例,烘焙光照。在您的实时应用中,您可以在后台调用 prepareObjects:withCompletionHandler,并希望看到不需要使用 prepareObject:shouldAbortBlock:/NSProgress 的足够加速。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 2012-10-02
      • 1970-01-01
      • 2012-04-22
      • 2011-09-29
      • 1970-01-01
      相关资源
      最近更新 更多