How to access text element from a .dae file in SceneKit?

I have a .dae file which is in shape of a Medal. Now this .dae file has a label element. I want to load this .dae file and want to update text on that label at runtime so user name will come there.

let originalNode = scene?.rootNode.childNode(withName: "label", recursively: true) 
if let _text = originalNode?.geometry as? SCNText { 
      _text.string = "Mohsin Khan" 
}  
// another way i tried 
let originalNode = scene?.rootNode.childNode(withName: "label", recursively: true) 
(originalNode?.geometry as! SCNText).string = "Mohsin Khan"

I have tried various ways but nothing is working. For

originalNode?.geometry as! SCNText // returning nil

Below if the structure of my model:

Replies

where did you make your dae file? when you open the file in scenekit does it show up as scntext or as a scnnode?


i don't think you can bring text geometry from other apps as SCNText, it would be just a mesh. SCNText can only be created in scenekit.


I'm making a lot of assumptions here because i don't know where your dae came from. but the thing to do would be to replace the "label element" with scntext and then access that in your code. just a headsup scnekit text is a little hard to work with as its scale is ridiculous - 1pt = 1 meter and you can't set text at something like 0.1pts because it will be deformed. so you'll have to make your text really gigantic and scale it down. also in the editor, there are no justification options, like center-align, so if you need this text to maintaing it's relationship to your medal, it's gonna take some in-code adjustments and you'll have to account for its crazy scale.