我试图在我的代码中更改在 Reality Composer 中创建的文本实体的模型组件,但这是!将 gui 创建的实体转换为对具有模型组件的实体的引用失败。
self.entityReference = scene.realityComposerEntity as! HasModel
textEntity.model!.mesh = MeshResource.generateText("New Text")
RealityKit 中的文本实体应该有一个模型属性,因为它在 ARView 中具有视觉外观,但我不知道如何访问它。有人知道怎么做吗?
是否有任何其他简单的方法可以使用 RealityKit
/Reality Composer
在同一位置动态显示不同的文本?
最佳答案
要在 RealityKit 中访问 Reality Composer 的 ModelComponent
,请尝试以下方法:
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
arView.environment.background = .color(.darkGray)
let textAnchor = try! SomeText.loadTextScene() // SomeText is enum
let textEntity: Entity = textAnchor.realityComp!.children[0]
textEntity.scale = [5,5,5]
var textModelComp: ModelComponent = textEntity.children[0].components[ModelComponent]!
var material = SimpleMaterial()
material.baseColor = .color(.systemTeal)
textModelComp.materials[0] = material
textAnchor.realityComp!.children[0].children[0].components.set(textModelComp)
arView.scene.anchors.append(textAnchor)
}
}
关于swift - 如何在 RealityKit 中访问 Reality Composer 的模型组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59796488/