【问题标题】:How to use GLKTextureLoader to load a cubemap from a web url如何使用 GLKTextureLoader 从 web url 加载立方体贴图
【发布时间】:2013-08-21 01:20:16
【问题描述】:

不确定如何使用从网络加载的图像作为 GLKit 天空盒中的资产(如旧的苹果/谷歌地图街景) 使用 GLKTextureLoader 加载立方体贴图有两种方法:cubeMapWithContentsOfFile 和 cubeMapWithContentsOfUrl

如果我在本地抓取图像,它可以正常工作:

NSString *path = [[NSBundle mainBundle] pathForResource:@"pano" ofType:@"jpg"];
GLKTextureInfo *skyboxCubemap =  [GLKTextureLoader cubeMapWithContentsOfFile:imgPath options:options error:&error];

那么有没有办法从从网络加载的图像中获取路径并在此处使用它?

【问题讨论】:

    标签: glkit panoramas skybox ios6.0 glktextureloader


    【解决方案1】:

    我最终像这样从网络加载图像:

    - (void) cacheImage: (NSURL *) ImageURL : (NSString *)imageName
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *dir = [paths objectAtIndex: 0];
        NSString *file = [docDir stringByAppendingPathComponent: imageName];
    
        if(![[NSFileManager defaultManager] fileExistsAtPath: file])
        {
            NSData *data = [[NSData alloc] initWithContentsOfURL: ImageURL];
            UIImage *image = [[UIImage alloc] initWithData: data];
            [UIImageJPEGRepresentation(image, 100) writeToFile: docFile atomically: YES];
        }
    }
    

    通过 :

    缓存并返回文件 url
    - (NSString *) getCachedImage : (NSString *)imageName
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains
        (NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString* cachedPath = [documentsDirectory stringByAppendingPathComponent:imageName];
        NSString *path;
        if([[NSFileManager defaultManager] fileExistsAtPath: cachedPath])
        {
            path = cachedPath;
        }
        return path;
    }
    

    并通过

    加载文件
    NSString *cached = [self getCachedImage:@"cacheKey"];
    self.skyboxCubemap =  [GLKTextureLoader cubeMapWithContentsOfFile:cached options:options error:&error];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-06
      相关资源
      最近更新 更多