2017-07-29 10 views
1

基本的には、.scnファイルをWeb上にホストし、ダウンロードしてSCNNodeという名前でレンダリングしてsceneViewに入れることができるかどうか疑問に思っていました。プログラムで.scnファイルをダウンロードして実行することはできますか?

もしそうなら、どのような&機能をフレームワークは、私がプロジェクト昨年のObjective-Cの上でこのような何かをした

答えて

2

にこれを行うために呼び出す必要があります。私は、SCNファイル&他のリソースを含むzipファイルを持っていました。 AFNetworkngを使ってzipファイル&をダウンロードした後、SSZipArchiveを使用してアプリケーションのドキュメントフォルダに圧縮解除しました。

JSONファイルでは、表示したいノードのシェイプIDを持っていました。

私はSCNファイルリソースへのパスを構築しました。私は簡潔にするためにいくつかのコードを削除しました。

SCNSceneSource *sceneSource = [SCNSceneSource sceneSourceWithURL:documentsDirectoryURL options:nil]; 

newShapeNode = [sceneSource entryWithIdentifier:shapeID withClass:[SCNNode class]]; 

[parentNode addChildNode:newShapeNode]; 

ここではダウンロード方法が編集されています。

- (void) fetchRelease:(Album *) album usingProgressIndicator:(UIProgressView *) progressView completionHandler:(void(^)(NSError *error))completionHandler { 
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; 
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:configuration]; 
    [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"XXXXXXXX" password:@"XXXXXXX"]; 

    NSURL *URL = [NSURL URLWithString:album.url]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:URL]; 

    NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) { 
     return [self.documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]]; 
    } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) { 
     if (error != nil) { 
      completionHandler(error); 
     } else { 
#ifdef DEBUG 
      NSLog(@"File downloaded to: %@", filePath); 
#endif 
      NSError *error; 
      [SSZipArchive unzipFileAtPath:filePath.path toDestination:self.documentsDirectoryURL.path overwrite:YES password:nil error:&error]; 
      if (error != nil) { 
       completionHandler(error); 
      } else { 
       [self updateAlbumRelease:album]; // update the data model 
       completionHandler(nil); 
      } 
     } 
    }]; 

    if (progressView != nil) { 
     [progressView setProgressWithDownloadProgressOfTask:downloadTask animated:YES]; 
    } 
    [downloadTask resume]; 
} 

そして、ここで編集したポッドファイルです: ``ルートの `name`のをshapeID`た` `SCNNode` [::shapeID withClass [SCNNodeクラス] sceneSource entryWithIdentifier]については

platform :ios, '9.1' 

target 'SOMEAPPNAME' do 
pod 'SVProgressHUD' 
pod 'SSZipArchive' 
pod 'AFNetworking', '~> 3.0' 
end 
+0

? – 14wml

+0

はい、SCNファイル内のノード名でした。 –

+0

この場合、SCNファイルには単一の3Dジオメトリがあります。私はこのコードを1年以上書いて以来、しばらくしてきました。それはドキュメントを見て価値があるかもしれません。 https://developer.apple.com/documentation/scenekit/scnscenesource –

関連する問題