RealityKit: How to drag a model to a different plane(like ARQuickLook)

268 Views Asked by At

When the user drags the ModelEntity, the ModelEntity can switch planes.

Look at this function

This is my code github-link, but don't know what to do next.

@objc
func handleGesture(_ gesture: UIGestureRecognizer){
    guard let boxEntity = boxEntity,
          let boxAnchorEntity = boxAnchorEntity else {
        return
    }

    if let panGesture = gesture as? EntityTranslationGestureRecognizer {
        switch panGesture.state {
        case .changed:
            let currentLocation = panGesture.location(in: arView)
            guard let rayCast = arView.raycast(from: currentLocation, allowing: .estimatedPlane, alignment: .horizontal).first,
                  let currentPlaneAnchor = rayCast.anchor as? ARPlaneAnchor,
                  let previousPlaneAnchor = previousPlaneAnchor else {
                return
            }
            if currentPlaneAnchor.identifier != previousPlaneAnchor.identifier {                    

                /// ??? what should be done
                self.previousPlaneAnchor = currentPlaneAnchor
            }
        default:
            break
        }
    }

It's so difficult , i don't know how to do next? Can anyone help me ? Thank you

0

There are 0 best solutions below