Reality Composer Pro: How to add text to a scene (and manipulate it with code)

I would like to add text to a Reality Composer Pro scene and set the actual text via code. How can I achieve this? I haven't seen any "Text" element in the editor.

Answered by Vision Pro Engineer in 783225022

You can use attachments with RealityView to programmatically add views (including text) to the scene. The Diorama sample code features floating placards with the name of the location for the three different points of interest. In this case, the string values are specified in Reality Composer Pro using the Point Of Interest Component and shown using the SwiftUI LearnMoreView view. You could modify this example by changing Text(description) in LearnMoreView.swift to show whatever text or view you'd like within Xcode.

If you'd like to have an extruded text effect in the 3D space, you can use MeshResource.generateText to create a 3D text entity and add that to your RealityView:

let mesh = MeshResource.generateText("Hello World", extrusionDepth: 0.005, font: .boldSystemFont(ofSize: 0.05))
let model = ModelEntity(mesh: mesh)
model.model?.materials = [UnlitMaterial(color: .white)]
model.position.x = -mesh.bounds.center.x
model.position.y = -mesh.bounds.center.y
content.add(model)

Outside of these options, there is no text feature inside of Reality Composer Pro. If this is a feature you'd like please file an enhancement request via Feedback Assistant.

You can use attachments with RealityView to programmatically add views (including text) to the scene. The Diorama sample code features floating placards with the name of the location for the three different points of interest. In this case, the string values are specified in Reality Composer Pro using the Point Of Interest Component and shown using the SwiftUI LearnMoreView view. You could modify this example by changing Text(description) in LearnMoreView.swift to show whatever text or view you'd like within Xcode.

If you'd like to have an extruded text effect in the 3D space, you can use MeshResource.generateText to create a 3D text entity and add that to your RealityView:

let mesh = MeshResource.generateText("Hello World", extrusionDepth: 0.005, font: .boldSystemFont(ofSize: 0.05))
let model = ModelEntity(mesh: mesh)
model.model?.materials = [UnlitMaterial(color: .white)]
model.position.x = -mesh.bounds.center.x
model.position.y = -mesh.bounds.center.y
content.add(model)

Outside of these options, there is no text feature inside of Reality Composer Pro. If this is a feature you'd like please file an enhancement request via Feedback Assistant.

Reality Composer Pro: How to add text to a scene (and manipulate it with code)
 
 
Q