Before stating what my problem is I want to clarify that there are multiple answers to my question out there, unfortunately, none of them is solving my problem. Please don't mark this as a duplicate.
Now this is the code I have to create my text node
let textNode: SCNNode = {
let text = SCNText.init(string: "250.9cm", extrusionDepth: 0.01)
text.font = UIFont(name: "System", size: 32)
text.flatness = 0.2
let node = SCNNode.init(geometry: text)
node.pivot = SCNMatrix4Scale(node.transform, 1/72, 1/72, 1/72)
node.scale = SCNVector3(0.1, 0.1, 0.1)
node.geometry?.materials.first?.diffuse.contents = UIColor.red
return node
}()
This is built up by multiple different solutions that i have found and i have tried it in many different ways. However, none is working.
Here i add 1 view as a childNode and then another 3 childNodes to that child.
self.addChildNode(mainNode)
topNode.position = SCNVector3(mainNode.getMidX(), mainNode.boundingBox.max.y, mainNode.getMidZ())
bottomNode.position = SCNVector3(mainNode.getMidX(), mainNode.boundingBox.min.y, mainNode.getMidZ())
textNode.position = SCNVector3(mainNode.getMidX()+0.005, mainNode.getMidY(), mainNode.getMidZ())
mainNode.addChildNode(topNode)
mainNode.addChildNode(bottomNode)
mainNode.addChildNode(textNode)
As you can see in the picture below, everything is displayed properly and exactly in the location i expect. Except the textNode
that is nowhere to be found. (note that it's the black line with hat and shoes that is main, top and bottom node)
According to the other position attributes set, the text should appear perfectly in the middle of the black line vertically and slightly to the right horizontally.
What i am missing is something i can't find in other answers. Please come with suggestions how i should approach this.