【问题标题】:RealityKit – Dragged Object Switches PlanesRealityKit - 拖动对象切换平面
【发布时间】:2022-01-12 06:51:17
【问题描述】:

如何开发这个功能?

当用户拖动ModelEntity时,ModelEntity可以切换平面。

看看这个demo video

【问题讨论】:

    标签: swift augmented-reality arkit realitykit


    【解决方案1】:

    我认为您应该使用 ray-casting 实例方法来获得所需的行为:

    @IBOutlet weak var arView: ARView!
    
    guard let raycastQuery = arView.makeRaycastQuery(from: arView.center,   // CGPoint
                                                 allowing: .estimatedPlane, // Target
                                                alignment: .horizontal)     // TargetAlignment
    else { 
        return 
    }
    
    // This method checks once for intersections between a ray and real-world surfaces
    
    guard let raycastResult = arView.session.raycast(raycastQuery).first
    
    else { 
        return 
    }
    
    let worldTransform = Transform(matrix: raycastResult.worldTransform)    // simd_float4x4
    // yourModel.transform = worldTransform
    
    let anchor = AnchorEntity(raycastResult: raycastResult)
    anchor.addChild(yourModel)
    arView.scene.anchors.append(anchor)
    

    【讨论】:

      猜你喜欢
      • 2018-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      • 2018-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多