I am trying to have an SCNNode with plane geometry, which presents 2d text inside it. I'm doing that through setting SKLabelNode as geometry's material (took that from here)
Here's my code:
let label = SKLabelNode(text: "Test Text 1")
label.fontColor = .white
label.fontName = UIFont.systemFont(ofSize: 32).fontName
label.fontSize = 32
let backgroundRectShape = SKShapeNode(rect: CGRect(origin: .zero, size: label.frame.size))
backgroundRectShape.fillColor = .orange
backgroundRectShape.addChild(label)
label.position = CGPoint(x: backgroundRectShape.frame.width / 2, y: 0)
let skScene = SKScene(size: label.frame.size)
skScene.addChild(backgroundRectShape)
backgroundRectShape.position = .zero
let plane = SCNPlane(width: label.frame.width / 10, height: label.frame.height / 10)
plane.firstMaterial?.diffuse.contents = skScene
let node = SCNNode(geometry: plane)
scene.rootNode.addChildNode(node)
Everything seems fine, but the SKLabelNode appears upside-down:
The SCNNode is surely properly aligned and not rotated, because when I set an image as material content, everything is ok:
I just can't understand why it is happening. The easiest solution would be setting SKLabelNode
's yScale
to -1, but I don't want to do that without understanding the reason why it appears upside down by default.
plane.firstMaterial?.diffuse.contentsTransform = SCNMatrix4Translate(SCNMatrix4MakeScale(1, -1, 1), 0, 1, 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With