0

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)

enter image description here

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.

Vollan
  • 1,887
  • 11
  • 26
  • Possible duplicate of [SCNText Not Displaying](https://stackoverflow.com/questions/44510878/scntext-not-displaying) – picciano Apr 25 '18 at 19:39
  • Try making the text way bigger, use the scale and font size both to do it. Could be that it is ending up behind the other nodes that are covering it or that the text is just too small to see. – theMikeSwan Apr 25 '18 at 19:45
  • Setting the text font to size 32 is not the same as a standard font size. 32 units in SceneKit is 32meters thus scaling it by 0.1 still means the size will be 3.2 metres thus this is probably why you can’t see the text. Trying scaling it more and see if that helps – BlackMirrorz Apr 25 '18 at 22:08
  • @picciano Read what i wrote. I clearly stated that i have looked at other similar questions but the answers they've got doesn't solve my problem – Vollan Apr 26 '18 at 04:52
  • @JoshRobbins I read that answer in another question regarding SCNText not showing up, sadly that doesn't seem to be the problem for me. I've tried multiple scaling and font sizes. – Vollan Apr 26 '18 at 04:57

1 Answers1

3

Well, most likely your text isn’t showing because of the same reason as those other questions you’re sure aren’t duplicates: it’s way too big.

But I’m answering instead of voting to close as duplicate, because there’s an extra wrinkle or two worth calling out. Right here:

node.pivot = SCNMatrix4Scale(node.transform, 1/72, 1/72, 1/72)
node.scale = SCNVector3(0.1, 0.1, 0.1)

First, setting a scale and setting pivot to a scale transform have the same effect — both scale the node’s content, so you’re effectively applying one scale factor that’s the concatenation of the two transforms. (Also, as of these calls, node.transform is identity, so the first line is equivalent to SCNMatrix4MakeScale with the same factor.)

Second, as explained in this great answer, the pivot property applies the inverse of the transform you provide to the node’s content. Your transform is a reduction in scale, so the transform applied is the inverse of that: an increase in scale.

(The documentation for pivot is rather unclear on the inverse transformation part. Maybe if you tell Apple about it they’ll fix that doc.)

Putting it together: you’re scaling a 32 “point” text node down to 1/10x, then up to 72x. That’s the same as scaling it to 7.2x, or just using a 230 “point” font to start with.

And as noted elsewhere, “point” sizes for fonts are actually meters in SceneKit+ARKit, so you probably have skyscraper-size letters floating somewhere above and to your right (if they’re not invisible because they’re beyond clip depth). Hope you brought climbing gear...

rickster
  • 124,678
  • 26
  • 272
  • 326
  • Ah i see, great explaination. it was from https://stackoverflow.com/questions/41066865/how-to-place-text-in-the-certain-position-when-using-scenekit that i used 1/72 pivot, but maybe i misunderstood what he wrote. But i figured as much as my text was either to big or to small, i just couldn't figure out which one and to what degree in size it was. But you gave a great explanation of pivot, transform and scale which i have had a bit of a problem with. and even tho i already solved the problem, yours are the correct one. – Vollan Apr 26 '18 at 08:14