如何重置或重启 ARCore 会话?

How to reset or restart the ARCore session?

我需要 reset/restart ARCore 会话。在 ARKit 中,我只需要创建一个新配置并执行 RunWithConfigAndOptions 方法,但我找不到任何关于如何在 ARCore 中执行此操作的信息。以下是我在 Unity 中用于 ARKit 的代码:

ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();
config.planeDetection = UnityARPlaneDetection.Horizontal;
config.alignment = UnityARAlignment.UnityARAlignmentGravity;
config.enableLightEstimation = true;  

UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfigAndOptions(config, 
                                                                                    UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | 
                                                                                    UnityARSessionRunOption.ARSessionRunOptionResetTracking);

我在 Unity 工作,但我想任何信息都会有用。

谢谢

试试 DestroyImmediate(session)Destroy(session)。其中之一可能有效。

ARCoreSession session = goARCoreDevice.GetComponent<ARCoreSession>();
ARCoreSessionConfig myConfig = session.SessionConfig;

DestroyImmediate(session);
// Destroy(session);

yield return null;

session = goARCoreDevice.AddComponent<ARCoreSession>();
session.SessionConfig = myConfig;
session.enabled = true;

希望对您有所帮助。

要禁用 ARCore 会话,

GameObject.Find ("ARCore Device").GetComponent<ARCoreSession> ().enabled = false;

要重置 ARCore 会话,

//Resetting ARCoreSession
ARCoreSession session = GameObject.Find ("ARCore Device").GetComponent<ARCoreSession> ();
ARCoreSessionConfig myConfig = session.SessionConfig;
DestroyImmediate (session);

就我而言,我继承了一个设置有点奇怪的 Unity3D ARCore 项目。

在我的案例中,为了正确重置会话(否则它不会在场景加载时重新开始跟踪),最简单的解决方案是首先找到 ARCore Device 游戏对象并取消选中 Unity3D 编辑器中启用的脚本。

完成后,我只需要在 Awake() 函数中找到 ARCoreSession(但您可能需要它在 Start() 中执行此操作,具体取决于项目的设置方式,如果您有其他 pre-conditions) 然后简单地启用脚本

GoogleARCore.ARCoreSession g = GameObject.Find("ARCore Device").GetComponent<GoogleARCore.ARCoreSession>();
g.enabled = true;