【问题标题】:How to make use of cube texture type in XCassets如何在 XCassets 中使用立方体纹理类型
【发布时间】:2018-12-12 18:31:57
【问题描述】:

我正在尝试学习 SceneKit 开发并尝试在后台添加天空盒。 为了存储立方体贴图纹理,我发现 XCAssets 有一个 Cube Texture Set 类型,这似乎完全符合要求。

但是。我还没有找到任何方法来访问代码中的纹理(例如,作为您调用 UIImage(named: "asset_name") 的图像集)。我尝试从资产创建SKTextureMDLTexture og MTKTexture,但没有成功。有谁知道我如何使用立方体纹理集?

【问题讨论】:

    标签: ios xcode scenekit


    【解决方案1】:

    您可以使用 MetalKit 从资产目录轻松加载立方体纹理。

    import MetalKit
    

    在文件的顶部。这两条线做生意:

      let textureLoader = MTKTextureLoader(device: scnView.device!)
      scene.background.contents = try! textureLoader.newTexture(name: textureName, 
                                           scaleFactor: 1.0, 
                                           bundle: .main, options: nil)
    

    我在从默认的 SceneKit 游戏模板创建的项目中尝试了这个,并在设置视图的背景颜色后将这两行放在 GameViewController.swift 中

    (我希望您也可以使用其他技术来做到这一点,但这是您可以使用 Metal 加载立方体纹理的方式)

    【讨论】:

      猜你喜欢
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-08
      • 2017-01-18
      • 2018-07-29
      相关资源
      最近更新 更多