Add SCNText to SCNScene with ARKit

前端 未结 1 1643
無奈伤痛
無奈伤痛 2021-02-10 04:13

I just started studying for ARKitexample and Scenekit. I read a few Scenekit and found out that in order to add text, I need to use SCNText.

I try to write like this bu

相关标签:
1条回答
  • 2021-02-10 04:20

    You have at least two problems here.


    If you set a node's position to match that of the camera, you probably won't see any of that node's content. You want to position things in front of the camera for them to be seen. A camera always looks in the -z direction of its local space. There's a ton of ways to do the requisite math, but here's one that might be handy (coded on phone, so YMMV):

    textNode.simdPosition = pointOfView.simdPosition + pointOfView.simdWorldFront * 0.5
    

    This should put your object half a meter in front of the camera (or rather, where the camera is at that moment — it won't follow the camera). It works because simdWorldFront is the vector (0,0,-1), which in local space means the direction the camera node points, converted from local space to world space.


    The default font size for SCNText is something like 16. But that's in scene units, and scene units map to meters in ARKit. Also, the "text box" is anchored at its lower left. So quite likely your text isn't visible because it's sixteen meters tall and off to your right.

    An easy way to handle this is by setting a scale or pivot on the node that makes its contents much smaller.

    0 讨论(0)
提交回复
热议问题