Skip to content

Entity Query returning nil  #7

Description

@ayush-narwal

I am using the following code to initialize my ViewController.

    var arView: ARView { view as! ARView }
    var handAnchor: HandAnchor!
    var handTracker3D: HandTracker3D!

    override func viewDidLoad() {
        super.viewDidLoad()
        setupARView()
        
        // Initialize HandAnchor
        handAnchor = HandAnchor(arView: arView)
        arView.scene.addAnchor(handAnchor)

        // Register the Hand2DSystem
        handAnchor.handTracker2D.setConfidenceThreshold(0.4)
        HandTracking2DSystem.participatingTrackers.append(handAnchor.handTracker2D)
        handTracker3D = HandTracker3D()
        handAnchor.attach(handTracker: handTracker3D)
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        handAnchor.destroy()
        handTracker3D.destroy()
    }
    
    func setupARView() {
        let configuration = ARWorldTrackingConfiguration()
        configuration.planeDetection = [.horizontal, .vertical]
        if ARWorldTrackingConfiguration.supportsFrameSemantics(.smoothedSceneDepth) {
            configuration.frameSemantics.insert(.smoothedSceneDepth)
        }
        arView.session.run(configuration)
        arView.session.delegate = self
        HandTracking2DSystem.registerSystem(with: arView)
    }

The for each block is never getting called. Hence the jointTransforms are not getting updated. the EntityQuery is returning nil probably.

    private static var handAnchorQuery = EntityQuery(where: .has(HandAnchorComponent.self))
    
    func update(context: SceneUpdateContext) {
        context.scene.performQuery(Self.handAnchorQuery).compactMap { $0 as? HandAnchor }.forEach { handAnchor in
            
            let hand2D = handAnchor.handTracker2D.hand2D
            let anchorComponent = handAnchor.handAnchorComponent
            
            guard hand2D.handWasInitiallyIdentified.value,
                  let currentFrame = Self.arView?.session.currentFrame,
                  let sceneDepth = getSceneDepth(currentFrame: currentFrame, anchorComponent: anchorComponent) else { return }
            
            updateEnabled(handAnchor: handAnchor,
                          anchorComponent: anchorComponent,
                          hand2D: hand2D)
            updateTransforms(on: handAnchor, sceneDepth: sceneDepth)
            updateTrackedEntities(on: handAnchor)
        }
    }

when i try to use the 2d system, the coordinates and everything is working perfectly.

What do i do? Can anyone please help in this?

@Reality-Dev

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions