简体   繁体   English

如何重置或重启 ARCore session?

[英]How to reset or restart the ARCore session?

I need to reset / restart the ARCore session. In ARKit, I just have to create a new configuration and execute the RunWithConfigAndOptions method, but I can't find any information on how to do this in ARCore.我需要reset / restart ARCore session。在 ARKit 中,我只需要创建一个新配置并执行RunWithConfigAndOptions方法,但我找不到有关如何在 ARCore 中执行此操作的任何信息。 The following is the code I use in Unity for ARKit:以下是我在 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);

I'm working in Unity, but I guess any information will be useful.我在 Unity 工作,但我想任何信息都会有用。

Thanks谢谢

Try DestroyImmediate(session) or Destroy(session) .尝试DestroyImmediate(session)Destroy(session) One of them may work.其中之一可能会起作用。

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;

Hope this helps.希望这可以帮助。

For disabling the ARCore session,要禁用 ARCore 会话,

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

For resetting the ARCore session,要重置 ARCore 会话,

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

In my case, I inherited a Unity3D ARCore project a bit weirdly setup.就我而言,我继承了一个 Unity3D ARCore 项目,设置有点奇怪。

The easiest solution in my case, in order to correctly reset the session (otherwise it would not restart tracking on scene load) was to first find the ARCore Device gameobject and uncheck the script enabled in the Unity3D editor.在我的例子中,为了正确重置 session(否则它不会在场景加载时重新开始跟踪),最简单的解决方案是首先找到 ARCore Device 游戏对象并取消选中 Unity3D 编辑器中启用的脚本。

Once that was done, I just needed to find the ARCoreSession in the Awake() function (but you may need it to do that in Start(), depending on how your project is setup if you have other pre-conditions) and then simply enable the script完成后,我只需要在 Awake() function 中找到 ARCoreSession(但您可能需要它在 Start() 中执行此操作,具体取决于您的项目是如何设置的,如果您有其他先决条件)然后简单地启用脚本

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM