SCNNode not at the center

Hi! I have the following problem:

I create a SCNNode, which works perfectly fine, and add it to a SCNView as a childNode, that also works.

However, when interacting with the scene, the node is placed somewhere on the screen/scene and not at the center, which causes weird behaviour when the user rotates the scene, since that rotation happens relative to the center of the view, but the node is - for example (not always) - on the left side, meaning the interaction is very hard to handle.
The main use would be for the user to view the node (which represents a custom object) from different perspectives by rotating/zooming/etc.

Here is my code:

Code Block
let scene = SCNScene()
     
prepareData()
let geometry = createFromData()
let objectNode = SCNNode()
     
objectNode.geometry = geometry
scene.rootNode.addChildNode(objectNode)
     
self.sceneView = self.view as! SCNView
self.sceneView.scene = scene
     
self.sceneView.backgroundColor = UIColor.black
self.sceneView.allowsCameraControl = true


I spent a lot of time debugging and trying to find what causes the problem, but I did not find the cause. I think the geometry should be fine, there are no outliers.

Also, I tested with different objects (which I basically create from an array of points with x, y, z coordinates and rgb values) and sometimes it works as intended (even though there is no difference between the objects aside from the different coordinates of the points, obviously). At least it feels like that, the node still might not be exactly in the middle, but might just be off by a very small margin.

Is there anything obvious that I am missing here?

Any tips would be very much appreciated!
Where do you set position of node in view ?

Could you show the code, otherwise it is pretty hard to guess…
I do not set the position explicitly. I tried
objectNode.position = SCNVector3(self.sceneView.center.x, self.sceneView.center.y, 0),
but that did not make any difference. Is there another way to set the position?

There is not much more code apart from that in the question, the geometry is created from an array of points with x, y, z coordinates and rgb values. What code do you mean?
Could you print the values of self.sceneView.center.x, self.sceneView.center.y ?
Sure!

self.sceneView.center.x = 195.0
self.sceneView.center.y = 422.0

I did some experiments with the point cloud and my guess is that there could be one or more (but very few) outliers, which are not clearly visible when looking at illustration. Could that be? Also, is there some way to easily remove them?

self.sceneView.center.x = 195.0
self.sceneView.center.y = 422.0

Are they the expected values ?
What type of outlier do you think of ?

Did you try to debug the view hierarchy ?
I don't know, I would have expected them to be both 0, right?

Well, I think if there exist some outliers which are very far away from the other points, then the bounding box of the node would become much bigger, meaning the node might actually be placed in the center of the view, only most of the points seem not to be aligned because of the outliers. Does that make sense? Is there some way to show/illustrate the bounding box? I couldn't find anything expect printing the values of the bounding box.

No, I did not. What exactly do you mean by that?

Also, thanks a lot for your help!! It is very much appreciated.

I don't know, I would have expected them to be both 0, right?

No, screen center should be close to the values you get.

No, I did not. What exactly do you mean by that?

that, you mean Did you try to debug the view hierarchy ?

When you run code in simulator, if you breakpoint, then you will see on the line at top of console panel a series of icons.
The seventh from the left is the debug hierarchy (icon is like this 🀓)

When you click, you will see the realtime view displayed and you can rotate the view to see all objects.
Try to see if some are off bounds.

Maybe this could help you (even though it is more ARKit, but that may help you understand what's occurring):
https://stackoverflow.com/questions/55906182/how-to-position-scenenode-always-at-the-center-of-the-sceneview-while-using-arfa
SCNNode not at the center
 
 
Q