ARKit nodes disappear after sceneView.session.setWorldOrigin conversion

I have some code that consists of a delegate method to get the header and transform. I take the title and turn it into radians and use the angle to rotate around the y axis:

โ”Œ โ” Y = | cos(ry) 0 sin(ry) 0 | | 0 1 0 0 | | -sin(ry) 0 cos(ry) 0 | | 0 0 0 1 | โ”” โ”˜ 

What are the first two columns in SCNMatrix4

code:

 func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { print("received heading: \(String(describing: newHeading))") self.currentHeading = newHeading print("\(Float(currentHeading.trueHeading)) or for magneticHeading: \(currentHeading.magneticHeading)") let headingInRadians = degreesToRadians(deg: Float(currentHeading.trueHeading)) print("\(headingInRadians) -------- headingInRadians") var m = matrix_float4x4() m.columns.3 = [0.0, 0.0, 0.0, 1.0] m.columns.2 = [sin(headingInRadians), 0.0, cos(headingInRadians), 0.0] m.columns.1 = [0.0, 1.0, 0.0, 0.0] m.columns.0 = [cos(headingInRadians), 0.0, -sin(headingInRadians), 0.0] sceneView.session.setWorldOrigin(relativeTransform: m) } 

It removes all nodes when I call setWorldOrigin . I tried to pause the session by running the function and then starting the session again and I get this weird winning low fps, low light situation. I know that this is a call to the setWorldOrigin function, because when I delete it, I see the nodes and they are saved.

UPDATE

I am working on this ... I am debugging, just trying to zoom by 2 ... all I have to see is that the nodes that I placed in the grid should propagate ... however, I still get that same result. After attempting setWorldOrigin , the nodes are deleted. Does this function use reset something? Is there any special place I should use? (some delegate function)?

UPDATE

print("\(sceneView.scene.rootNode) --- rootNode in renderer") produces:

 <SCNNode: 0x1c01f8100 | 111 children> --- rootNode in renderer 

So it seems that rootNode and its children are still somewhere ... but where do they go with such a simple and small conversion?

UPDATE

print("\(sceneView.scene.rootNode.position) --- rootNode in renderer") produces:

 SCNVector3(x: 0.0, y: 0.0, z: 0.0) --- rootNode in renderer 

However ... I don't see any of the children ... so the rootNode seems to be somewhere else.

UPDATE

I can confirm that the conversion does not occur ... the positioning of the child nodes (which I do not see) still matches its initial state (a node every 2 grid blocks (meters), i.e.:

 SCNVector3(x: 6.0, y: 0.0, z: -4.0) --- rootNode child node SCNVector3(x: 6.0, y: 0.0, z: -2.0) --- rootNode child node 

UPDATE

The narrowest view of this problem that I am facing right now is that even a simple rotation removes the nodes from the view ... since there is no change in position ... this means that something is happening with the rendering process that I consider .

 func viewDidLoad() { ... sceneView.scene = scene view.addSubview(sceneView) let angle = coordinateConverter.getUprightMKMapCameraHeading() print("\(angle) --- angle") mRotate = matrix_float4x4() mRotate.columns.3 = [0.0, 0.0, 0.0, 1.0] mRotate.columns.2 = [Float(sin(angle)), 0.0, Float(cos(angle)), 0.0] mRotate.columns.1 = [0.0, 0.0, 0.0, 0.0] mRotate.columns.0 = [Float(cos(angle)), 0.0, Float(-sin(angle)), 0.0] sceneView.session.setWorldOrigin(relativeTransform: mRotate) 

console output:

 281.689248803283 --- angle 

However, virtual objects remain invisible, but are placed at the origin ... which should still be the same.

I should also note that the standard 1,1,1,1 DOES conversion works ... but obviously it doesnโ€™t do anything ... but I think just using the function doesnโ€™t make them disappear ... they only disappear, if your conversion is really doing something ...

 ... var identity = matrix_float4x4() identity.columns.3 = [0.0, 0.0, 0.0, 1.0] identity.columns.2 = [0.0, 0.0, 1.0, 0.0] identity.columns.1 = [0.0, 1.0, 0.0, 0.0] identity.columns.0 = [1.0, 0.0, 0.0, 0.0] sceneView.session.setWorldOrigin(relativeTransform: identity) ... 

The above does not transform anything ... and the nodes remain in sight.

If I change the matrix to this (translate to 10.10):

 var identity = matrix_float4x4() identity.columns.3 = [10.0, 0.0, 10.0, 1.0] identity.columns.2 = [0.0, 0.0, 1.0, 0.0] identity.columns.1 = [0.0, 1.0, 0.0, 0.0] identity.columns.0 = [1.0, 0.0, 0.0, 0.0] 

He works...

I just think ... I have to scale my world down (real coordinates / MKMapKit block of the real world), possibly because the hardware cannot handle a world that scales. Also, from the above test ... I think I realized that the origin moves when you use this function, but the nodes do not, so if I want the nodes to remain in my place after the transformation ... and I need to convert them back. However, the result is the same:

 print("\(transformerFromPDFToMk.tx) -- tx") print("\(transformerFromPDFToMk.ty) -- ty") m = matrix_float4x4() m.columns.3 = [Float(transformerFromPDFToMk.tx), 0.0, Float(transformerFromPDFToMk.ty), 1.0] m.columns.2 = [0.0, 0.0, 1.0, 0.0] m.columns.1 = [0.0, 1.0, 0.0, 0.0] m.columns.0 = [1.0, 0.0, 0.0, 0.0] sceneView.session.setWorldOrigin(relativeTransform: m) for node in scene.rootNode.childNodes { node.position = SCNVector3Make(-Float(transformerFromPDFToMk.tx) + node.position.x, node.position.y, Float(transformerFromPDFToMk.ty) + node.position.z) } 

console output:

 81145547.3824476 -- tx 99399579.5362287 -- ty 

UPDATE

I SEE MY OBJECTS (view)! I thought I tried this before ... but now it works a little better - the code package I used determined the scale ( coordinateConverter.unitSizeInMeters ) ... and I didnโ€™t convert it correctly. But ... they flicker quickly and quickly ...

 m = matrix_float4x4() m.columns.3 = [Float(transformerFromPDFToMk.tx) / Float(coordinateConverter.unitSizeInMeters), 0.0, Float(transformerFromPDFToMk.ty) / Float(coordinateConverter.unitSizeInMeters), 1.0] m.columns.2 = [0.0, 0.0, 1.0, 0.0] m.columns.1 = [0.0, 1.0, 0.0, 0.0] m.columns.0 = [1.0, 0.0, 0.0, 0.0] sceneView.session.setWorldOrigin(relativeTransform: m) sceneView.session.setWorldOrigin(relativeTransform: m) for node in scene.rootNode.childNodes { node.position = SCNVector3Make(-Float(transformerFromPDFToMk.tx) / Float(coordinateConverter.unitSizeInMeters) + node.position.x / Float(coordinateConverter.unitSizeInMeters), node.position.y / Float(coordinateConverter.unitSizeInMeters), - Float(transformerFromPDFToMk.ty) / Float(coordinateConverter.unitSizeInMeters) + node.position.z / Float(coordinateConverter.unitSizeInMeters)) } 

UPDATE

Is the flickering "z-fight"? https://en.wikipedia.org/wiki/Z-fighting

+5
source share
1 answer

After solving the scaling problems, I reduced the size of the world (scale) and placed the objects a little further apart (to fix the flicker / "z-fight"). The wikipedia page was very useful, Iโ€™m sure that all I had to do was reduce the size of the world.

+3
source

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


All Articles