我尝试使用 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/