I made a simple example and it seemed to be working fine. So I have worked my way back through rewritten everything and it's working again. I'm not sure why the planes were not being added after the initial flush, but it seems to work fine now. Thank you for your help. Much appreciated.
Post
Replies
Boosts
Views
Activity
Well that's encouraging. I do have a reference to the ARKitSession. I am also running the world tracking provider at the same time so I can track the head. I wonder if that's changing things? I'm also running the 2.0 beta.
This is how I originate the session
try? await session.run([worldInfo, planeData])
but everything I get back in
.task {
for await update in planeData.anchorUpdates {
}
}
seems to be filtered within 5 meters of the origin.
Any luck figuring this out? It seems very odd that there's no simple way to get a notification.
Did you ever get to the bottom of this? I'd really like to know the position of the device when in a volumetric window. It seems like this is not possible.
I am too. Did you get anywhere with it?
I wonder if this had anything to do with the Instagram camera grinding on these devices.
I just downloaded the new 16.1 beta and it appears to be fixed there. They don't seem to ever give you both fovs for the cropped and full frame format, but at least now the default is the wide angle.
This has now been fixed in beta 4.
I have temporarily fixed this by saving a world map before I stop the roomScan session and then starting a new ARSession and immediately loading that world up again.
It's clumsy but it works. I get a new arSession which fairly quickly snaps to the old origin. It would be nice to be able to just turn the room scanning off and keep the same arsession. Users will not understand why there's a jump and there's a chance they will lose it.
I would also like to be able to keep the arsession alive but turn off the processor-intensive roomcapture session. Maybe this could be done with a configuration? That way we can do some basic editing of the room when roomcapture is complete.
I figured it out by trial and error. My problem was that I had a navigationcontroller that was in the way. I had to make sure that navigationControllerSupportedInterfaceOrientations was updated too.
CapturedRoom.Surface has a transform simd_float4x4 and a dimensions simd_float3. The wall length is the dimensions.x and the position can be extracted from the transform with
extension matrix_float4x4 {
var position:SCNVector3 {
return SCNVector3(columns.3.x, columns.3.y, columns.3.z)
}
}
The Euler angles for the wall can be extracted using
extension float4x4 {
var eulerAngles: simd_float3 {
simd_float3(
x: asin(-self[2][1]),
y: atan2(self[2][0], self[2][2]),
z: atan2(self[0][1], self[1][1])
)
}
}
this works for me
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait))
But what I cannot get it to do is to honour that rotation change afterwards.
I've tried .setNeedsUpdateOfSupportedInterfaceOrientations()
but supportedInterfaceOrientations is ignored.
I may have a solution for finding the the local coordinates of the window in the wall. What I did was to rotate the centerpoint of window or door around by the angle of the wall (which should be the same as the window angle) to make them essentially parallel to the x axis. Then I check that the distance between their position.z is very small (so in the same plane) then it's relatively simple to find the relative center point of the windows by subtracting it from the wall center point. Then to top left and bottom right points are that center point plus the width and height of the window.
Roomkit occasionally puts windows and doors through the edge of the wall so I constrain it to just inside.
This function runs on the window surface
func surfaceIsWithinSurface(wall:CodableWall)->Bool{
var angle:Float = transform.eulerAngles.y
let wallPosition = CGPoint.init(wall.transform.position)
let myPosition = CGPoint.init(self.transform.position)
let newPosition = myPosition.pointRotated(aroundOrigin: wallPosition, byRadians: CGFloat(angle))
let offset = wallPosition - newPosition
let floorOffset = wall.position.y - wall.halfHeight
let heightOffset = self.position.y - floorOffset
let centerPoint:SCNVector3 = SCNVector3.init(x: Float(offset.x), y: heightOffset , z: Float(offset.y))
guard abs(centerPoint.z) < 0.1 else {return false}
var right = centerPoint.x + halfWidth + wall.halfWidth
var left = centerPoint.x - halfWidth + wall.halfWidth
var top = centerPoint.y + halfHeight
var bottom = centerPoint.y - halfHeight
let smidge:Float = 0.01
top = min (top, wall.dimensions.y - smidge)
right = min (right, wall.dimensions.x - smidge)
left = max (left, smidge)
bottom = max (bottom, smidge)
topLeft = CGPoint(x: left - wall.halfWidth, y: top)
bottomRight = CGPoint(x: right - wall.halfWidth, y: bottom)
return true
}
extension CGPoint
init (_ vector:SCNVector3){
self.init(x: vector.x, y: vector.z)
}
func pointRotated(aroundOrigin origin: CGPoint, byRadians: CGFloat) -> CGPoint {
let dx = self.x - origin.x
let dy = self.y - origin.y
let radius = sqrt(dx * dx + dy * dy)
let azimuth = atan2(dy, dx) // in radians
let newAzimuth = azimuth + byRadians // convert it to radians
let x = origin.x + radius * cos(newAzimuth)
let y = origin.y + radius * sin(newAzimuth)
return CGPoint(x: x, y: y)
}
setNeedsUpdateOfSupportedInterfaceOrientations is a method of UIViewController it seems not UIWindow.