Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKScene in SCNMaterial's contents appears upside down

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: Screenshot 1

The SCNNode is surely properly aligned and not rotated, because when I set an image as material content, everything is ok: Screenshot 2

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.

like image 384
khabiroff Avatar asked Feb 20 '18 16:02

khabiroff


1 Answers

plane.firstMaterial?.diffuse.contentsTransform = SCNMatrix4Translate(SCNMatrix4MakeScale(1, -1, 1), 0, 1, 0)
like image 93
Bobby Avatar answered Sep 21 '22 06:09

Bobby