我正在使用RealityKit,并且在设置可读并能够放置在盒子上的文本时遇到了困难。无论如何设置盒子,文本都应该始终跟随盒子的位置。
let textMesh = MeshResource.generateText("ABC", extrusionDepth: 0.001, font: fonts)
let textEntity = ModelEntity(mesh: textMesh, materials: [UnlitMaterial(color: .black)])
let boxMeshForText = MeshResource.generateBox(width: 0.25,
height: 0.1,
depth: 0,
cornerRadius: 0.001)
let boxEntityForText = ModelEntity(mesh: boxMeshForText,
materials: [UnlitMaterial(color: UIColor.white)])
textEntity.setPosition([-0.09, -0.03, 0.001], relativeTo: boxEntityForText)
boxEntityForText.addChild(textEntity)
let textAnchor = ARAnchorEntity()
textAnchor.addChild(boxEntityForText, preservingWorldTransform: true)
textAnchor.setPosition([0.05, 0.05, 0.02], relativeTo: anchor)
textAnchor.transform.rotation = simd_quatf(angle: -90 * .pi/180, axis: [1,0,0])
anchor.addChild(textAnchor)
上述代码给出的结果是错误的。我想要的结果可以在附加的图片中看到。
![enter image description here](https://istack.dev59.com/bvj0B.webp)