SCNText with SCNLookAtConstraint does not look right

I want to display text next to my 3D model using SceneKit in iOS. It just has to look like it's 2D. Therefore, the text should always be facing the camera, however, I rotate the 3D model. I have an SCNNode with SCNNode geometry, and I attached SCNLookAtConstraint like this:

 let constraint = SCNLookAtConstraint(target: cameraNode) constraint.gimbalLockEnabled = true textNode.constraints = [constraint] 

They seem to be looking at the camera, but not so! I see all the text in a mirror! Also, sometimes the text rotates, I want it to be horizontally aligned at any time. So that’s all I don’t want.

Can anyone help me here? I just want to have some text that follows several nodes of my 3D object. I don't care how. This does not have to be SCNText for everyone that I need if it can be done with a simple UILabel: great with me! Just tell me how!

+5
source share
3 answers

From the documentation:

When SceneKit evaluates a view restriction, it updates the transform property with bounded node s, so that node s negative z-axis points to the target node.

You can get around this by installing node pivot or using an intermediate node. This node would be bounded and have text as a child node (which would be rotated π along the y axis)

Update

Running iOS 11.0 in the SCNLookAtConstraint class provides a localFront property that allows you to specify a different front axis. The default value is (0, 0, -1) , and you can change it to (0, 0, 1) to achieve what you want.

+4
source

According to @mnuages ​​answer, setting the node tag to the next should do the trick.

node.pivot = SCNMatrix4Rotate(node.pivot, Float.pi, 0, 1, 0)

+2
source

I ran into this problem on iOS11 beta 5, Swift4:

 //1. Rotate your `textNode`, and don't add `textNode` into `sceneView` textNode.eulerAngles = SCNVector3Make(0, .pi, 0) //2. Create new wrapper node, add `textNode` as a child node let textWrapperNode = SCNNode() textWrapperNode.addChildNode(textNode) //3. Add constraint for wrapper node let constraint = SCNLookAtConstraint(target: cameraNode) constraint.gimbalLockEnabled = true textWrapperNode.constraints = [constraint] //4. Add wrapper node into `sceneView` sceneView.scene.rootNode.addChildNode(textNode) 
0
source

Source: https://habr.com/ru/post/1214864/


All Articles