ios - makeRenderPipelineState 失败 [ushort 类型的输出与 MTLPixelFormatR16Float 颜色附件不兼容。]

标签 ios swift arkit metal realitykit

我尝试使用 Realitykit 呈现一些文本,代码编译,场景启动,但场景中没有显示任何文本。

我使用的是运行 iOS 13.1.2 的 iPhone 7,我尝试了相同的代码,但使用了盒子网格资源,效果很好。

我的 Controller 看起来像这样

    func makeUIView(context: Context) -> ARView {

        let arView = ARView(frame: .zero)

        let anchor = AnchorEntity(plane: .horizontal)

        let mesh = MeshResource.generateText("text")
        let color = UIColor.systemBlue
        let material = UnlitMaterial(color: color)
        let entity = ModelEntity(mesh: mesh, materials: [material])

        anchor.addChild(entity)

        // Add the box anchor to the scene
        arView.scene.anchors.append(anchor)

        return arView

    }

正如我之前所说,当我进入运行时时,控制台显示这些错误:

2019-10-02 09:07:33.707275+0200 tesss[646:78901] Compiler failed to build request
2019-10-02 09:07:33.707476+0200 tesss[646:78901] [Graphics] makeRenderPipelineState failed [output of type ushort is not compatible with a MTLPixelFormatR16Float color attachement.].
2019-10-02 09:07:33.707507+0200 tesss[646:78901] [Graphics] makeRenderPipelineState failed.

最佳答案

默认情况下,MeshResource.generateText 方法使用系统字体,默认情况下该字体非常大,因此您需要调整其大小。有两种方法可以做到这一点:

1) 调整实体大小:

entity.scale = SIMD3<Float>(0.01, 0.01, 0.1)

2)更改字体大小:

let mesh = MeshResource.generateText(
            "text", 
            extrusionDepth: 0.1,
            font: .systemFont(ofSize: 0.1),
            containerFrame: CGRect.zero,
            alignment: .left,
            lineBreakMode: .byTruncatingTail)

关于ios - makeRenderPipelineState 失败 [ushort 类型的输出与 MTLPixelFormatR16Float 颜色附件不兼容。],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58196819/

相关文章:

ios - 使 iOS 应用程序中的缓存数据失效的理想时间

ios - 使用 UIViewPropertyAnimator 多次重复和反转动画

objective-c - 使用 NSInterger 值对 NSMuatbleArray 进行排序

ios - Cookies.ttf 字体不能在 iOS 应用程序中使用?

ios - 如何从 GameScene 刷新 GameViewController?

ios - ARKIT - 它可以跟踪多少个跟踪图像?

ios - ARKIT:使用 PanGesture 移动对象(正确方式)

swift - 缩放 SCNNode 时更新 SCNPhysicsBody

ios - Iphone 6 plus 模拟器工作正常,除了设备

swift - 使用通用约束