Load 3Dmodels in real world using reality kit without any tilt or rotation

48 Views Asked by At

When i'm trying to load a 3dmodel in to the real world using realitykit it is loaded correctly but the problem i'm facing right now is this model appears to be tilted from right or can say as slightly rotated on its y axis

I'm currently using "VNDetectRectanglesRequest" to detect any rectangle and place an 3dModel on it like shown in image

private func searchForRect(from currentCapturedPixelBuffer: CVPixelBuffer) {
        
        /// Create a request handler
        let handler = VNImageRequestHandler(cvPixelBuffer: currentCapturedPixelBuffer, orientation: .up)
        currentCameraImage = currentCapturedPixelBuffer
        /// Create a rewuest
        let request = VNDetectRectanglesRequest { [weak self] request, error in
            if error == nil {
                guard let self else { return }
                self.handleRequest(request: request)
            } else {
                print("Error: \(error)")
            }
        }

        request.minimumConfidence = 0.8
        request.minimumSize = 0.25
        request.minimumAspectRatio = 4/3
        request.maximumObservations = 1
        request.quadratureTolerance = 20

        request.usesCPUOnly = false

        do {
            try handler.perform([request])
        } catch {
            print("Error: Rectangle detection failed - vision request failed.")
        }
    }

Once rectangle is detected i'm trying to place a 3Dmodel on the detected rectangle which is also a success (have tried to place it at the midpoint of detected rectangle using raycasting) like this image

Also i have a timer which keep searching for rectangles every 2 seconds and every time it finds a rectangle it appears to be slightly tilted

I'm expecting it to always be parallel to the edges like shown in following image i have tried many different models but with all rectangular models i try to load it always appears to be somewhat tilted, Is there someway to fix this or is there any other way to get the angle of how much it's tilted so we can difference out that angle from the loaded entity's rotation?

0

There are 0 best solutions below