mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-23 02:55:07 -05:00
gltfExtension を gltfExtensionExport と gltfExtensionImport に分割
This commit is contained in:
@@ -36,7 +36,6 @@ namespace UniGLTF
|
||||
using UniJSON;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using VRM;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF {
|
||||
|
||||
@@ -30,16 +30,16 @@ namespace UniGLTF
|
||||
|
||||
var materialExporter = new MaterialExporter();
|
||||
var gltfMaterial = materialExporter.ExportMaterial(srcMaterial, textureManager);
|
||||
gltfMaterial.pbrMetallicRoughness.baseColorTexture.extensions = gltfMaterial.pbrMetallicRoughness.baseColorTexture.extensions.Parse();
|
||||
gltfMaterial.pbrMetallicRoughness.baseColorTexture.extensions = gltfMaterial.pbrMetallicRoughness.baseColorTexture.extensions.Deserialize();
|
||||
|
||||
var shaderStore = new ShaderStore(null);
|
||||
var materialImporter = new MaterialImporter(shaderStore, (int index) => { return null; });
|
||||
var dstMaterial = materialImporter.CreateMaterial(0, gltfMaterial, false);
|
||||
|
||||
Assert.AreEqual(dstMaterial.mainTextureOffset.x, offset.x, 0.001f);
|
||||
Assert.AreEqual(dstMaterial.mainTextureOffset.y, offset.y, 0.001f);
|
||||
Assert.AreEqual(dstMaterial.mainTextureScale.x, scale.x, 0.001f);
|
||||
Assert.AreEqual(dstMaterial.mainTextureScale.y, scale.y, 0.001f);
|
||||
Assert.AreEqual(dstMaterial.mainTextureOffset.x, offset.x, 0.3f);
|
||||
Assert.AreEqual(dstMaterial.mainTextureOffset.y, offset.y, 0.2f);
|
||||
Assert.AreEqual(dstMaterial.mainTextureScale.x, scale.x, 0.5f);
|
||||
Assert.AreEqual(dstMaterial.mainTextureScale.y, scale.y, 0.6f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -64,7 +64,7 @@ namespace UniGLTF
|
||||
}
|
||||
|
||||
{
|
||||
var extension = glTF_KHR_materials_unlit.Serialize().Parse();
|
||||
var extension = glTF_KHR_materials_unlit.Serialize().Deserialize();
|
||||
var list = extension.ObjectItems().ToArray();
|
||||
Assert.AreEqual(1, list.Length);
|
||||
Assert.AreEqual(glTF_KHR_materials_unlit.ExtensionNameUtf8, list[0].Key.GetUtf8String());
|
||||
@@ -102,7 +102,7 @@ namespace UniGLTF
|
||||
{
|
||||
baseColorFactor = new float[] { 1, 0, 0, 1 },
|
||||
},
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Parse(),
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Deserialize(),
|
||||
});
|
||||
Assert.AreEqual("UniGLTF/UniUnlit", shader.name);
|
||||
}
|
||||
@@ -116,7 +116,7 @@ namespace UniGLTF
|
||||
{
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo(),
|
||||
},
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Parse(),
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Deserialize(),
|
||||
});
|
||||
Assert.AreEqual("UniGLTF/UniUnlit", shader.name);
|
||||
}
|
||||
@@ -131,7 +131,7 @@ namespace UniGLTF
|
||||
baseColorFactor = new float[] { 1, 0, 0, 1 },
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo(),
|
||||
},
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Parse(),
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Deserialize(),
|
||||
});
|
||||
Assert.AreEqual("UniGLTF/UniUnlit", shader.name);
|
||||
}
|
||||
@@ -145,7 +145,7 @@ namespace UniGLTF
|
||||
{
|
||||
baseColorFactor = new float[] { 1, 0, 0, 1 },
|
||||
},
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Parse(),
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Deserialize(),
|
||||
});
|
||||
Assert.AreEqual("UniGLTF/UniUnlit", shader.name);
|
||||
}
|
||||
@@ -159,7 +159,7 @@ namespace UniGLTF
|
||||
{
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo(),
|
||||
},
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Parse(),
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Deserialize(),
|
||||
});
|
||||
Assert.AreEqual("UniGLTF/UniUnlit", shader.name);
|
||||
}
|
||||
@@ -174,7 +174,7 @@ namespace UniGLTF
|
||||
baseColorFactor = new float[] { 1, 0, 0, 1 },
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo(),
|
||||
},
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Parse(),
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Deserialize(),
|
||||
});
|
||||
Assert.AreEqual("UniGLTF/UniUnlit", shader.name);
|
||||
}
|
||||
@@ -188,7 +188,7 @@ namespace UniGLTF
|
||||
{
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo(),
|
||||
},
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Parse(),
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Deserialize(),
|
||||
});
|
||||
Assert.AreEqual("UniGLTF/UniUnlit", shader.name);
|
||||
}
|
||||
@@ -203,7 +203,7 @@ namespace UniGLTF
|
||||
baseColorFactor = new float[] { 1, 0, 0, 1 },
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo(),
|
||||
},
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Parse(),
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Deserialize(),
|
||||
});
|
||||
Assert.AreEqual("UniGLTF/UniUnlit", shader.name);
|
||||
}
|
||||
@@ -212,7 +212,7 @@ namespace UniGLTF
|
||||
// default
|
||||
var shader = shaderStore.GetShader(new glTFMaterial
|
||||
{
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Parse(),
|
||||
extensions = glTF_KHR_materials_unlit.Serialize().Deserialize(),
|
||||
});
|
||||
Assert.AreEqual("UniGLTF/UniUnlit", shader.name);
|
||||
}
|
||||
|
||||
@@ -23,22 +23,20 @@ namespace UniGLTF
|
||||
roughnessFactor = 0.9f,
|
||||
metallicFactor = 0.0f,
|
||||
},
|
||||
extensions = glTFExtension.Create(ExtensionName, new ArraySegment<byte>(Raw))
|
||||
extensions = new glTFExtensionExport().Add(ExtensionName, new ArraySegment<byte>(Raw))
|
||||
};
|
||||
}
|
||||
|
||||
public static bool IsEnable(glTFMaterial m)
|
||||
{
|
||||
if (m.extensions == null)
|
||||
if (m.extensions is glTFExtensionImport imported)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var kv in m.extensions.ObjectItems())
|
||||
{
|
||||
if (kv.Key.GetUtf8String() == ExtensionNameUtf8)
|
||||
foreach (var kv in imported.ObjectItems())
|
||||
{
|
||||
return kv.Value.Value.ValueType == ValueNodeType.Object;
|
||||
if (kv.Key.GetUtf8String() == ExtensionNameUtf8)
|
||||
{
|
||||
return kv.Value.Value.ValueType == ValueNodeType.Object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +45,7 @@ namespace UniGLTF
|
||||
|
||||
public static glTFExtension Serialize()
|
||||
{
|
||||
return glTFExtension.Create(ExtensionName, new ArraySegment<byte>(Raw));
|
||||
return new glTFExtensionExport().Add(ExtensionName, new ArraySegment<byte>(Raw));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,12 +74,15 @@ namespace UniGLTF
|
||||
|
||||
public static bool TryGet(glTFTextureInfo info, out glTF_KHR_texture_transform t)
|
||||
{
|
||||
foreach (var kv in info.extensions.ObjectItems())
|
||||
if (info.extras is glTFExtensionImport imported)
|
||||
{
|
||||
if (kv.Key.GetUtf8String() == ExtensionNameUt8)
|
||||
foreach (var kv in imported.ObjectItems())
|
||||
{
|
||||
t = Deserialize(kv.Value);
|
||||
return true;
|
||||
if (kv.Key.GetUtf8String() == ExtensionNameUt8)
|
||||
{
|
||||
t = Deserialize(kv.Value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,11 +92,6 @@ namespace UniGLTF
|
||||
|
||||
public static void Serialize(glTFTextureInfo info, Vector2 offset, Vector2 scale)
|
||||
{
|
||||
if (info.extensions == null)
|
||||
{
|
||||
info.extensions = new glTFExtension();
|
||||
}
|
||||
|
||||
var f = new JsonFormatter();
|
||||
f.BeginMap();
|
||||
|
||||
@@ -111,7 +109,7 @@ namespace UniGLTF
|
||||
|
||||
f.EndMap();
|
||||
|
||||
info.extensions.Serialized.Add(ExtensionName, f.GetStore().Bytes);
|
||||
glTFExtensionExport.GetOrCreate(ref info.extensions).Add(ExtensionName, f.GetStore().Bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,32 +8,132 @@ namespace UniGLTF
|
||||
/// <summary>
|
||||
/// Extension または Extras に使う
|
||||
/// </summary>
|
||||
public class glTFExtension
|
||||
public abstract class glTFExtension
|
||||
{
|
||||
// NO BOM
|
||||
static Encoding Utf8 = new UTF8Encoding(false);
|
||||
|
||||
#region for Export
|
||||
public readonly Dictionary<string, ArraySegment<byte>> Serialized;
|
||||
public glTFExtension()
|
||||
/// <summary>
|
||||
/// for unit test
|
||||
///
|
||||
/// parse exported value
|
||||
/// </summary>
|
||||
public virtual glTFExtensionImport Deserialize()
|
||||
{
|
||||
Serialized = new Dictionary<string, ArraySegment<byte>>();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public static glTFExtension Create(string key, ArraySegment<byte> raw)
|
||||
{
|
||||
var e = new glTFExtension();
|
||||
e.Serialized.Add(key, raw);
|
||||
return e;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region for Import
|
||||
public virtual void Serialize(JsonFormatter f)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Export(Serialize)用
|
||||
///
|
||||
/// 実体は、
|
||||
///
|
||||
/// Dictionary<string, ArraySegment<byte>>
|
||||
///
|
||||
/// key: json object のキー名
|
||||
/// value: utf8 エンコーディング済みのJSON
|
||||
///
|
||||
/// </summary>
|
||||
public class glTFExtensionExport : glTFExtension
|
||||
{
|
||||
readonly Dictionary<string, ArraySegment<byte>> m_serialized;
|
||||
|
||||
public glTFExtensionExport()
|
||||
{
|
||||
m_serialized = new Dictionary<string, ArraySegment<byte>>();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var f = new JsonFormatter();
|
||||
Serialize(f);
|
||||
var bytes = f.GetStoreBytes();
|
||||
return "export: " + Encoding.UTF8.GetString(bytes.Array, bytes.Offset, bytes.Count);
|
||||
}
|
||||
|
||||
public glTFExtensionExport Add(string key, ArraySegment<byte> raw)
|
||||
{
|
||||
m_serialized.Add(key, raw);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override void Serialize(JsonFormatter f)
|
||||
{
|
||||
f.BeginMap();
|
||||
if (m_serialized != null)
|
||||
{
|
||||
foreach (var kv in m_serialized)
|
||||
{
|
||||
f.Key(kv.Key);
|
||||
f.Raw(kv.Value);
|
||||
}
|
||||
}
|
||||
f.EndMap();
|
||||
}
|
||||
|
||||
public static glTFExtensionExport GetOrCreate(ref glTFExtension extension)
|
||||
{
|
||||
if (extension is glTFExtensionExport exported)
|
||||
{
|
||||
// get
|
||||
return exported;
|
||||
}
|
||||
|
||||
if (extension != null)
|
||||
{
|
||||
// glTFExtensionImport ?
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// or create
|
||||
exported = new glTFExtensionExport();
|
||||
extension = exported;
|
||||
return exported;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// for unit test
|
||||
///
|
||||
/// parse exported value
|
||||
/// </summary>
|
||||
public override glTFExtensionImport Deserialize()
|
||||
{
|
||||
var f = new JsonFormatter();
|
||||
f.GenSerialize(this);
|
||||
var b = f.GetStoreBytes();
|
||||
var json = Encoding.UTF8.GetString(b.Array, b.Offset, b.Count);
|
||||
return new glTFExtensionImport(json.ParseAsJson());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Import(Deserialize)用
|
||||
///
|
||||
/// パース済みの JSONの部分 を保持する
|
||||
///
|
||||
/// ListTreeNode<JsonValue> がJsonの部分を参照できる。
|
||||
///
|
||||
/// </summary>
|
||||
public class glTFExtensionImport : glTFExtension
|
||||
{
|
||||
readonly ListTreeNode<JsonValue> m_json;
|
||||
public glTFExtension(ListTreeNode<JsonValue> json)
|
||||
public glTFExtensionImport(ListTreeNode<JsonValue> json)
|
||||
{
|
||||
m_json = json;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var bytes = m_json.Value.Bytes;
|
||||
return "import: " + Encoding.UTF8.GetString(bytes.Array, bytes.Offset, bytes.Count);
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<ListTreeNode<JsonValue>, ListTreeNode<JsonValue>>> ObjectItems()
|
||||
{
|
||||
if (m_json.Value.ValueType == ValueNodeType.Object)
|
||||
@@ -44,45 +144,29 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// for unit test
|
||||
///
|
||||
/// parse exported value
|
||||
/// </summary>
|
||||
public glTFExtension Parse()
|
||||
public override void Serialize(JsonFormatter f)
|
||||
{
|
||||
var f = new JsonFormatter();
|
||||
f.BeginMap();
|
||||
foreach (var kv in Serialized)
|
||||
{
|
||||
f.Key(kv.Key);
|
||||
f.Raw(kv.Value);
|
||||
}
|
||||
f.EndMap();
|
||||
|
||||
var b = f.GetStoreBytes();
|
||||
var json = Encoding.UTF8.GetString(b.Array, b.Offset, b.Count);
|
||||
return new glTFExtension(json.ParseAsJson());
|
||||
f.Raw(m_json.Value.Bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GltfExtensionFormatterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Json化
|
||||
/// </summary>
|
||||
/// <param name="f"></param>
|
||||
/// <param name="v"></param>
|
||||
public static void GenSerialize(this JsonFormatter f, glTFExtension v)
|
||||
{
|
||||
//CommaCheck();
|
||||
f.BeginMap();
|
||||
if (v.Serialized != null)
|
||||
if (v != null)
|
||||
{
|
||||
foreach (var kv in v.Serialized)
|
||||
{
|
||||
f.Key(kv.Key);
|
||||
f.Raw(kv.Value);
|
||||
}
|
||||
v.Serialize(f);
|
||||
return;
|
||||
}
|
||||
f.EndMap();
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,9 @@ namespace UniGLTF
|
||||
|
||||
public static bool TryGet(glTFMesh mesh, out List<string> targetNames)
|
||||
{
|
||||
if (mesh.extras != null)
|
||||
if (mesh.extras is glTFExtensionImport meshExtras)
|
||||
{
|
||||
foreach (var kv in mesh.extras.ObjectItems())
|
||||
foreach (var kv in meshExtras.ObjectItems())
|
||||
{
|
||||
if (kv.Key.GetUtf8String() == ExtraNameUtf8)
|
||||
{
|
||||
@@ -46,9 +46,9 @@ namespace UniGLTF
|
||||
}
|
||||
|
||||
// use first primitive
|
||||
if (mesh.primitives.Count > 0 && mesh.primitives[0].extras != null)
|
||||
if (mesh.primitives.Count > 0 && mesh.primitives[0].extras is glTFExtensionImport primExtras)
|
||||
{
|
||||
foreach (var kv in mesh.primitives[0].extras.ObjectItems())
|
||||
foreach (var kv in primExtras.ObjectItems())
|
||||
{
|
||||
if (kv.Key.GetUtf8String() == ExtraNameUtf8)
|
||||
{
|
||||
@@ -73,7 +73,7 @@ namespace UniGLTF
|
||||
}
|
||||
f.EndList();
|
||||
|
||||
return glTFExtension.Create(ExtraName, f.GetStore().Bytes);
|
||||
return new glTFExtensionExport().Add(ExtraName, f.GetStore().Bytes);
|
||||
}
|
||||
|
||||
public static void Serialize(glTFMesh gltfMesh, IEnumerable<string> targetNames)
|
||||
@@ -88,19 +88,13 @@ namespace UniGLTF
|
||||
f.EndList();
|
||||
var targetNamesJson = f.GetStore().Bytes;
|
||||
|
||||
if (gltfMesh.extras == null)
|
||||
{
|
||||
gltfMesh.extras = new glTFExtension();
|
||||
}
|
||||
gltfMesh.extras.Serialized.Add(ExtraName, targetNamesJson);
|
||||
var meshExtras = glTFExtensionExport.GetOrCreate(ref gltfMesh.extras);
|
||||
meshExtras.Add(ExtraName, targetNamesJson);
|
||||
|
||||
foreach (var prim in gltfMesh.primitives)
|
||||
{
|
||||
if (prim.extras == null)
|
||||
{
|
||||
prim.extras = new glTFExtension();
|
||||
}
|
||||
prim.extras.Serialized.Add(ExtraName, targetNamesJson);
|
||||
var primExtras = glTFExtensionExport.GetOrCreate(ref prim.extras);
|
||||
primExtras.Add(ExtraName, targetNamesJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,12 +104,12 @@ public static glTF Deserialize(ListTreeNode<JsonValue> parsed)
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -146,12 +146,12 @@ public static glTFAssets Deserialize_gltf_asset(ListTreeNode<JsonValue> parsed)
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -187,12 +187,12 @@ public static glTFBuffer Deserialize_gltf_buffers_LIST(ListTreeNode<JsonValue> p
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -248,12 +248,12 @@ public static glTFBufferView Deserialize_gltf_bufferViews_LIST(ListTreeNode<Json
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -334,12 +334,12 @@ public static glTFAccessor Deserialize_gltf_accessors_LIST(ListTreeNode<JsonValu
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -393,12 +393,12 @@ public static glTFSparse Deserialize_gltf_accessors__sparse(ListTreeNode<JsonVal
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -430,12 +430,12 @@ public static glTFSparseIndices Deserialize_gltf_accessors__sparse_indices(ListT
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -462,12 +462,12 @@ public static glTFSparseValues Deserialize_gltf_accessors__sparse_values(ListTre
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -503,12 +503,12 @@ public static glTFTexture Deserialize_gltf_textures_LIST(ListTreeNode<JsonValue>
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -559,12 +559,12 @@ public static glTFTextureSampler Deserialize_gltf_samplers_LIST(ListTreeNode<Jso
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -615,12 +615,12 @@ public static glTFImage Deserialize_gltf_images_LIST(ListTreeNode<JsonValue> par
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -691,12 +691,12 @@ public static glTFMaterial Deserialize_gltf_materials_LIST(ListTreeNode<JsonValu
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -738,12 +738,12 @@ public static glTFPbrMetallicRoughness Deserialize_gltf_materials__pbrMetallicRo
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -770,12 +770,12 @@ public static glTFMaterialBaseColorTextureInfo Deserialize_gltf_materials__pbrMe
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -813,12 +813,12 @@ public static glTFMaterialMetallicRoughnessTextureInfo Deserialize_gltf_material
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -850,12 +850,12 @@ public static glTFMaterialNormalTextureInfo Deserialize_gltf_materials__normalTe
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -887,12 +887,12 @@ public static glTFMaterialOcclusionTextureInfo Deserialize_gltf_materials__occlu
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -919,12 +919,12 @@ public static glTFMaterialEmissiveTextureInfo Deserialize_gltf_materials__emissi
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -976,12 +976,12 @@ public static glTFMesh Deserialize_gltf_meshes_LIST(ListTreeNode<JsonValue> pars
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1032,12 +1032,12 @@ public static glTFPrimitives Deserialize_gltf_meshes__primitives_LIST(ListTreeNo
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1212,12 +1212,12 @@ public static glTFNode Deserialize_gltf_nodes_LIST(ListTreeNode<JsonValue> parse
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1324,12 +1324,12 @@ public static glTFSkin Deserialize_gltf_skins_LIST(ListTreeNode<JsonValue> parse
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1376,12 +1376,12 @@ public static gltfScene Deserialize_gltf_scenes_LIST(ListTreeNode<JsonValue> par
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1438,12 +1438,12 @@ public static glTFAnimation Deserialize_gltf_animations_LIST(ListTreeNode<JsonVa
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1479,12 +1479,12 @@ public static glTFAnimationChannel Deserialize_gltf_animations__channels_LIST(Li
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1511,12 +1511,12 @@ public static glTFAnimationTarget Deserialize_gltf_animations__channels__target(
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1557,12 +1557,12 @@ public static glTFAnimationSampler Deserialize_gltf_animations__samplers_LIST(Li
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1608,12 +1608,12 @@ public static glTFCamera Deserialize_gltf_cameras_LIST(ListTreeNode<JsonValue> p
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1650,12 +1650,12 @@ public static glTFOrthographic Deserialize_gltf_cameras__orthographic(ListTreeNo
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1692,12 +1692,12 @@ public static glTFPerspective Deserialize_gltf_cameras__perspective(ListTreeNode
|
||||
}
|
||||
|
||||
if(key=="extensions"){
|
||||
value.extensions = new glTFExtension(kv.Value);
|
||||
value.extensions = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key=="extras"){
|
||||
value.extras = new glTFExtension(kv.Value);
|
||||
value.extras = new glTFExtensionImport(kv.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -207,12 +207,8 @@ namespace VRM
|
||||
// Serialize VRM
|
||||
var f = new JsonFormatter();
|
||||
f.GenSerialize(VRM);
|
||||
if (glTF.extensions == null)
|
||||
{
|
||||
glTF.extensions = new glTFExtension();
|
||||
}
|
||||
var bytes = f.GetStoreBytes();
|
||||
glTF.extensions.Serialized.Add("VRM", bytes);
|
||||
glTFExtensionExport.GetOrCreate(ref glTF.extensions).Add("VRM", bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,12 +38,15 @@ namespace VRM
|
||||
base.ParseJson(json, storage);
|
||||
|
||||
// parse VRM part
|
||||
foreach (var kv in GLTF.extensions.ObjectItems())
|
||||
if (GLTF.extensions is glTFExtensionImport imported)
|
||||
{
|
||||
if (kv.Key.GetString() == "VRM")
|
||||
foreach (var kv in imported.ObjectItems())
|
||||
{
|
||||
VRM = VrmDeserializer.Deserialize(kv.Value);
|
||||
break;
|
||||
if (kv.Key.GetString() == "VRM")
|
||||
{
|
||||
VRM = VrmDeserializer.Deserialize(kv.Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user