// Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.
using OVRSimpleJSON;
using System.Collections.Generic;
namespace Meta.XR.Movement.FaceTracking.Samples
{
///
/// Provides useful JSON deserialization function that parse face tracking-related
/// configuration files, or parts of those files.
///
public static class JSONRigParser
{
///
/// Returns a dictionary-of-dictionary collection from provided json.
/// Assumes that the JSON blob provided comforms to an expected output.
///
///
/// Dictionary-of-dictionaries.
public static Dictionary> DeserializeV1Mapping(string json)
{
var v1Mapping = new Dictionary>();
JSONNode rootNode = JSONNode.Parse(json);
foreach (var jsonNode in rootNode)
{
var blendshapeToValue = new Dictionary();
foreach (var keyValuePair in jsonNode.Value)
{
blendshapeToValue.Add(keyValuePair.Key.ToString(), keyValuePair.Value.AsFloat);
}
v1Mapping.Add(jsonNode.Key.ToString(), blendshapeToValue);
}
return v1Mapping;
}
///
/// Returns a list-of-dictionary collection from provided json.
/// Assumes that the JSON blob provided comforms to an expected output.
///
/// JSON input.
/// List of dictionaries.
public static List>> DeserializeV2Mapping(string json)
{
var v2Mapping = new List>>();
JSONNode rootNode = JSONNode.Parse(json);
// The top level is an array of nodes. Below that are collections.
foreach (var jsonNode in rootNode)
{
var stringToCollection = new Dictionary>();
foreach (var listItem in jsonNode.Value)
{
string stringKey = listItem.Key.ToString();
var blendshapeToValue = new Dictionary();
foreach (var keyValuePair in listItem.Value)
{
blendshapeToValue.Add(keyValuePair.Key.ToString(), keyValuePair.Value.AsFloat);
}
stringToCollection.Add(stringKey, blendshapeToValue);
}
v2Mapping.Add(stringToCollection);
}
return v2Mapping;
}
}
}