I have created a simple scene in a RealityKit file using RealityKit composer:
Then I created an arView
and I added to its anchor my scene's anchor:
arView.scene.anchors.append(ARSceneViewModel().sceneAnchor)
I created an ARSceneViewModel
class which sets my scene up.
When I run my app this is what I see:
But when I dynamically change entity's text in ARSceneViewModel
:
I think there is something of wrong in these lines (maybe because of the hierarchy of the scene):
private func updateScene() {
self.sceneAnchor.text?.children[0].children[0].components.set(generateModelComponentForText(text: "Hello"))
}
This is the hierarchy of the scene:
Here the function to change the entity's text:
private func generateModelComponentForText(text: String, size: CGFloat = 0.02, extrusion: Float = 0.0003) -> ModelComponent {
let mesh: MeshResource = .generateText(text,
extrusionDepth: 0.001,
font: .systemFont(ofSize: 0.06),
containerFrame: CGRect.zero,
alignment: .center,
lineBreakMode: .byWordWrapping)
let material: [Material] = [SimpleMaterial(color: .black, isMetallic: true)]
return ModelComponent(mesh: mesh, materials: material)
}
When I run the app:
Ok, I didn't expect that. I don't understand why it is not text Entity is not centred to the scene. I have changed its text, not its position. Any suggestions?
Here you can download the project. (WeTransfer)