簡體   English   中英

如何在 RealityKit 中訪問 Reality Composer 的模型組件?

[英]How do I access the model component of Reality Composer in RealityKit?

我正在嘗試在我的代碼中更改在 Reality Composer 中創建的文本實體的模型組件,但這就像! 將 gui 創建的實體轉換為對具有模型組件的實體的引用失敗。

self.entityReference = scene.realityComposerEntity as! HasModel
textEntity.model!.mesh =  MeshResource.generateText("New Text")

RealityKit 中的文本實體應該有一個模型屬性,因為它在 ARView 中具有視覺外觀,但我不知道如何訪問它。 有誰知道如何?

是否有其他簡單的方法可以使用RealityKit / Reality Composer在同一位置動態顯示不同的文本?

為了獲得現實作曲家ModelComponent在RealityKit試試下面的辦法:

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)
    }
}

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM