iOS Development

ios – ARKit: Anchor Dimension Bigger Than Seen Space in Digital camera in swift

Spread the love


I am encountering a problem in ARKit the place the anchor measurement, created when capturing a picture and including a crimson field, seems to be a lot bigger than the seen space within the digicam. I am utilizing the next code to create the field:

 func createBox(hit:ARHitTestResult, isLandscape:Bool) -> SCNNode {
        let dimensions = calculateVisibleSize(hitTestResult: hit)

      var field : SCNBox = SCNBox(width: (dimensions.width/2) , top: dimensions.top, size: 0.05, chamferRadius:0)
        
        if isLandscape {
            field = SCNBox(width: dimensions.top, top: (dimensions.width/2) , size: 0.05, chamferRadius:0)
        }
        
        let boxNode = SCNNode(geometry: field)
        boxNode.physicsBody = SCNPhysicsBody(sort: .static, form: SCNPhysicsShape(geometry: field, choices: nil))
        boxNode.geometry?.firstMaterial?.diffuse.contents = UIColor.crimson.withAlphaComponent(0.7)
    
        }

     func calculateVisibleSize(hitTestResult: ARHitTestResult) -> CGSize {
        guard let currentFrame = arView.session.currentFrame else { return CGSize(width: 0, top: 0) }
        
        let rayFrom = simd_float3(currentFrame.digicam.rework.columns.3.x,
                                  currentFrame.digicam.rework.columns.3.y,
                                  currentFrame.digicam.rework.columns.3.z)
        
        let rayTo = simd_float3(rayFrom.x, rayFrom.y, rayFrom.z - 0.1) // Barely under the digicam
        
        let screenPosition = arView.projectPoint(SCNVector3(rayTo.x, rayTo.y, rayTo.z))
        let screenPoint = CGPoint(x: CGFloat(screenPosition.x), y: CGFloat(screenPosition.y))
        
        let planeDimensions = calculateDistance(from: rayFrom, to: hitTestResult.worldTransform, digicam: currentFrame.digicam)
        
        return planeDimensions
    }

The calculateVisibleSize perform is meant to find out the scale of the field based mostly on the digicam’s perspective. Nonetheless, evidently the anchor measurement does not match the seen space as anticipated. If i exploit a distance of 140 to 160 cm, it really works high-quality.

Any insights on why the anchor measurement is perhaps off or ideas for changes to make sure the anchor aligns with the seen space within the digicam can be drastically appreciated.

Thanks prematurely!

8 thoughts on “ios – ARKit: Anchor Dimension Bigger Than Seen Space in Digital camera in swift

  1. Ive read several just right stuff here Certainly price bookmarking for revisiting I wonder how a lot effort you place to create this kind of great informative website

  2. Hello Neat post Theres an issue together with your site in internet explorer would check this IE still is the marketplace chief and a large element of other folks will leave out your magnificent writing due to this problem

  3. Thank you for the good writeup It in fact was a amusement account it Look advanced to far added agreeable from you However how could we communicate

  4. I have been surfing online more than 3 hours today yet I never found any interesting article like yours It is pretty worth enough for me In my opinion if all web owners and bloggers made good content as you did the web will be much more useful than ever before

Leave a Reply

Your email address will not be published. Required fields are marked *