简体   繁体   中英

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. The problem is that ARCore doesn't give any functions to set state. The idea then is to serialize the Session object and then deserialize it when needed.

I first tried to create a subclass of Session which implements Serializable, but that gave multiple NotSerializableException errors. Now I'm trying to solve this problem with Gson, using its ExclusionStrategy, to exclude the classes that aren't serializable. I'm not sure though how to approach this.

In 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.

I don't think you'll be able to serialize your Session and recover it later. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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