I am working on a AR based application. I am using https://docs-assets.developer.apple.com/published/c5ad3d23f4/Handling3DInteractionandUIControlsinAugmentedReality.zip as example. I am trying to implement a overlay over each child node of a 3D object with text description of the same.
For that i tried to get the position of each child node. For example, if we take chair object in the apple's sample, when i look into Xcode scene editor all the child nodes are placed in same position. How to get the center position of a child node in this case? For example if i have to get the approx. position of the chair's legs, how to do that?
The position of a node is always relative to another node, at the very least the scene’s rootNode. To get a childnode’s position relative to the rootnode (i.e. the position in world space) you can use convertPosition to: rootNode. To get the position of a childnode relative to the parent you can convert the position to the parent node’s space.
https://developer.apple.com/documentation/scenekit/scnnode/1407990-convertposition
After you get the world space coordinates you can use projectPoint to convert the 3D position to 2D screen coordinates: https://developer.apple.com/documentation/scenekit/scnscenerenderer/1524089-projectpoint
If the pivot of a chair leg is not located at the center of the legs, the position will not be at its center either. In that case, to get the center, use the average of the min and max value of the nodes bounding box (see SCNBoundingVolume), or simply use an offset in the 2D position for the overlay.