RealityKit – Set text programmatically of an Entity of Reality Composer

后端 未结 1 1290
悲&欢浪女
悲&欢浪女 2021-02-06 13:27

In my iOS app I want to introduce a part of AR using the new Reality Composer.

In my project I load a scene with this code:

let arView = ARView.init(fram         


        
相关标签:
1条回答
  • 2021-02-06 13:59

    In RealityKit framework, use the following type method for generating 3D text:

    static func generateText(_ string: String, 
                       extrusionDepth: Float, 
                                 font: MeshResource.Font, 
                       containerFrame: CGRect, 
                            alignment: CTTextAlignment, 
                        lineBreakMode: CTLineBreakMode) -> MeshResource
    

    Let's see how a real code looks like:

    let textAnchor = try! SomeText.loadTextScene()
    
    let textEntity: Entity = textAnchor.vacation!.children[0].children[0]
    
    var textModelComponent: ModelComponent = (textEntity.components[ModelComponent])!
    
    textModelComponent.mesh = .generateText("Hello, World!",
                             extrusionDepth: 0.5,
                                       font: .systemFont(ofSize: 0.25),
                             containerFrame: CGRect.zero,
                                  alignment: .center,
                              lineBreakMode: .byCharWrapping)
    
    textAnchor.vacation!.children[0].children[0].components.set(textModelComponent)
    arView.scene.anchors.append(textAnchor)
    
    0 讨论(0)
提交回复
热议问题