简体   繁体   English

如何在ARCore中序列化会话对象?

[英]How to serialize session object in ARCore?

I use ARCore in a project and need to save the state from ARCore to use it at a later stage. 我在项目中使用了ARCore,并且需要保存ARCore的状态以在以后使用。 The problem is that ARCore doesn't give any functions to set state. 问题在于ARCore没有提供任何设置状态的功能。 The idea then is to serialize the Session object and then deserialize it when needed. 然后的想法是序列化Session对象,然后在需要时反序列化它。

I first tried to create a subclass of Session which implements Serializable, but that gave multiple NotSerializableException errors. 我首先尝试创建Session的子类,该子类实现Serializable,但是却产生了多个NotSerializableException错误。 Now I'm trying to solve this problem with Gson, using its ExclusionStrategy, to exclude the classes that aren't serializable. 现在,我正在尝试使用Gson的ExclusionStrategy解决此问题,以排除无法序列化的类。 I'm not sure though how to approach this. 我不确定该如何处理。

In MainActivity: 在MainActivity中:

Gson gson = new GsonBuilder()
                .addSerializationExclusionStrategy(new Strategy())
                .create();
String jsonString = gson.toJson(session);

Strategy: 战略:

@Override
    public boolean shouldSkipField(FieldAttributes field) {
        return field.getDeclaredType().equals(** WHAT TO PUT HERE **.class);
    }
@Override
public boolean shouldSkipClass(Class<?> clazz) {
    return false;
}

I want the Session object serialized into a JSON object to be able to store it. 我希望将Session对象序列化为JSON对象,以便能够存储它。

I don't think you'll be able to serialize your Session and recover it later. 我认为您将无法序列化Session并在以后恢复它。 What you can do is store anchors informations to use it later. 您可以做的是存储锚点信息,以便以后使用。 Services like AR Core Cloud Anchors and Azure Spatial Anchors can help you doing that. 诸如AR Core Cloud Anchors和Azure Spatial Anchors之类的服务可以帮助您做到这一点。

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

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