lenyapugachev
lenyapugachev

Reputation: 81

SceneKit: text node font not applying

Can't find any issue about this, so:

SceneKit, Xcode 10.1

Applying font to SCNText:

enter image description here

Result:

enter image description here

Even when I'm:

textNode.geometry?.font = UIFont(name: "SF Mono Heavy", size: 170)

it is still in default font look.

I'm also tried a lot of other different fonts, but no luck.

What do I do wrong?

Upvotes: 0

Views: 337

Answers (2)

Fattie
Fattie

Reputation: 12296

It's very likely the SIZE IS INCREDIBLY TOO LARGE.

The typical size you use for text in SCNText is 0.1.

SCNText is not measured in points, it is measured in meters.

  1. put a 1 meter cube in your scene

  2. run the scene and be sure you can see all of the cube

  3. now add some text with size "1". sit it in front of the cube towards the camera.

Now you should see it.

Font names:

for family in UIFont.familyNames.sorted() {
 print("family: \(family) names: (UIFont.fontNames(forFamilyName: family))")
}

Put that code anywhere in the app in a viewDidLoad. You will get the exact names you must use.

Upvotes: 0

mnuages
mnuages

Reputation: 13462

The first level of debugging would be to verify that the UIFont object isn't nil. What happens if you print the object? The editor is used on macOS. Are you sure the font exists on iOS?

Upvotes: 0

Related Questions