gpt4 book ai didi

ios - ARKIT 2.0 - ARImageTrackingConfiguration

转载 作者:行者123 更新时间:2023-11-28 14:11:54 29 4
gpt4 key购买 nike

我有一个应用程序可以检测一些图像并做一些效果(主要是在图像中播放视频)只要在检测到图像时触发 func 渲染器,是否有在未检测到图像时触发的函数?

当没有检测到图像时,我想停止播放视频。谢谢!

最佳答案

如果您查看文档,您会发现 ARImageAnchor 符合 ARTrackable 协议(protocol),其中:

is adopted by ARKit classes, such as the ARFaceAnchor class, that represent moving objects in a scene.

ARSCNView and ARSKView automatically hide the nodes for anchors whose isTracked property is false.

ARKit automatically manages representations of such objects in an active AR session, ensuring that changes in the real-world object's position and orientation (the transform property for anchors) are reflected in corresponding ARKit objects. The isTracked property indicates whether the current transform is valid with respect to movement of the real-world object.

因此,您可以检测您的 ARImageAnchor 当前是否正在使用像这样的东西作为启动器进行跟踪:

//--------------------------
//MARK: - ARSessionDelegate
//--------------------------

extension ViewController: ARSessionDelegate{

func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {

//1. Enumerate Our Anchors To See If We Have Found Our Target Anchor
for anchor in anchors{

if let imageAnchor = anchor as? ARImageAnchor, imageAnchor == videoAnchor{

//2. If The ImageAnchor Is No Longer Tracked Then Handle The Event
if !imageAnchor.isTracked{

}else{


}
}
}
}
}

其中 videoAnchor 只是一个 ARImageAnchor 我已将引用存储为 全局变量

或者,如果您想在特定的 SCNNode 位于相机的 Frostrum 之外时取消操作,您可以这样做:

/// Stops All VideoPlayers Outside Of Frostrum
///
/// - Parameter currentVideoNode: SCNNode
func stopAllVideoPlayersOutsideOfPointOfView(){

//a. Get The Current Point Of You & Our SCNScene
guard let currentPointOfView = self.augmentedRealityView?.pointOfView,
let scnView = self.augmentedRealityView else { return }

//b. Loop Through All The Hierachy
if let childNodes = self.augmentedRealityView?.scene.rootNode.childNodes{

childNodes.forEach { (node) in

//c. If Our Node Isn't In View Of The Camera Then Stop The Video
if !scnView.isNode(node, insideFrustumOf: currentPointOfView){


}
}

}
}

希望对你有帮助

关于ios - ARKIT 2.0 - ARImageTrackingConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52442108/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com