diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs
index c08ee784b..a5b29d16c 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs
@@ -138,66 +138,6 @@ namespace UniGLTF
#endregion
#region ToGltf & ToGlb
- static Utf8String s_extensions = Utf8String.From("extensions");
-
- static bool UsedExtension(glTF self, string key)
- {
- if (self.extensionsUsed.Contains(key))
- {
- return true;
- }
-
- return false;
- }
-
- static void Traverse(glTF self, JsonNode node, JsonFormatter f, Utf8String parentKey)
- {
- if (node.IsMap())
- {
- f.BeginMap();
- foreach (var kv in node.ObjectItems())
- {
- if (parentKey == s_extensions)
- {
- if (!UsedExtension(self, kv.Key.GetString()))
- {
- // skip extension not in used
- continue;
- }
- }
- f.Key(kv.Key.GetUtf8String());
- Traverse(self, kv.Value, f, kv.Key.GetUtf8String());
- }
- f.EndMap();
- }
- else if (node.IsArray())
- {
- f.BeginList();
- foreach (var x in node.ArrayItems())
- {
- Traverse(self, x, f, default(Utf8String));
- }
- f.EndList();
- }
- else
- {
- f.Value(node);
- }
- }
-
- ///
- /// 出力前に不要な extension を削除する
- ///
- ///
- ///
- ///
- static string RemoveUnusedExtensions(glTF self, string json)
- {
- var f = new JsonFormatter();
- Traverse(self, JsonParser.Parse(json), f, default(Utf8String));
- return f.ToString();
- }
-
///
/// GLBバイト列
///
@@ -207,9 +147,10 @@ namespace UniGLTF
var f = new JsonFormatter();
GltfSerializer.Serialize(f, GLTF);
- // remove unused extenions
var json = f.ToString().ParseAsJson().ToString(" ");
- RemoveUnusedExtensions(GLTF, json);
+
+ json = GltfJsonUtil.FindUsedExtensionsAndUpdateJson(json);
+
return Glb.Create(json, BinBytes).ToBytes();
}
@@ -234,7 +175,9 @@ namespace UniGLTF
var f = new JsonFormatter();
GltfSerializer.Serialize(f, GLTF);
var json = f.ToString().ParseAsJson().ToString(" ");
- RemoveUnusedExtensions(GLTF, json);
+
+ json = GltfJsonUtil.FindUsedExtensionsAndUpdateJson(json);
+
return (json, GLTF.buffers[0]);
}
#endregion
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfJsonUtil.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfJsonUtil.cs
new file mode 100644
index 000000000..c96e33e84
--- /dev/null
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfJsonUtil.cs
@@ -0,0 +1,212 @@
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using UniJSON;
+using UnityEngine;
+
+namespace UniGLTF
+{
+ public static class GltfJsonUtil
+ {
+ const string EXTENSION_USED_KEY = "extensionUsed";
+
+ ///
+ /// JsonPath を 再帰的に列挙する
+ /// object[] の中身は int(array index) or string(object key)
+ ///
+ ///
+ ///
+ ///
+ public static IEnumerable