VRMDeserializerGenerator

This commit is contained in:
ousttrue 2020-11-20 14:55:34 +09:00
parent 913dd97554
commit 8a959fc88a
8 changed files with 1400 additions and 1651 deletions

View File

@ -22,7 +22,7 @@ namespace UniGLTF
/// <summary>
/// AOT向けにデシリアライザを生成する
/// </summary>
[MenuItem(VRM.VRMVersion.MENU + "/Generate Deserializer")]
[MenuItem(VRM.VRMVersion.MENU + "/GLTF: Generate Deserializer")]
static void GenerateSerializer()
{
var info = new ObjectSerialization(typeof(glTF), "gltf");

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,8 @@
"UniHumanoid",
"MeshUtility",
"MeshUtility.Editor",
"UniUnlit"
"UniUnlit",
"UniGLTF.Editor"
],
"optionalUnityReferences": [],
"includePlatforms": [

View File

@ -0,0 +1,61 @@
using System.IO;
using System.Reflection;
using System.Text;
using UnityEditor;
using UnityEngine;
namespace VRM
{
public static class DeserializerGenerator
{
public const BindingFlags FIELD_FLAGS = BindingFlags.Instance | BindingFlags.Public;
static string OutPath
{
get
{
return Path.Combine(UnityEngine.Application.dataPath,
"VRM/UniVRM/Scripts/Format/VRMDeserializer.g.cs");
}
}
/// <summary>
/// AOT向けにデシリアライザを生成する
/// </summary>
[MenuItem(VRM.VRMVersion.MENU + "/VRM: Generate Deserializer")]
static void GenerateSerializer()
{
var info = new UniGLTF.ObjectSerialization(typeof(glTF_VRM_extensions), "vrm");
Debug.Log(info);
using (var s = File.Open(OutPath, FileMode.Create))
using (var w = new StreamWriter(s, Encoding.UTF8))
{
// header
w.Write(@"
using UniJSON;
using System;
using System.Collections.Generic;
using VRM;
using UnityEngine;
namespace VRM {
public static class VrmDeserializer
{
");
info.GenerateDeserializer(w, "Deserialize");
// footer
w.Write(@"
} // VrmfDeserializer
} // VRM
");
Debug.LogFormat("write: {0}", OutPath);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fccecb79adf40a948b2c218b4e7703b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7d3f5617d4d8fd74494cab1e56d6b001
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,6 +5,7 @@ using UniGLTF;
using UnityEngine;
using System.IO;
using System.Collections;
using UniJSON;
namespace VRM
{
@ -13,13 +14,7 @@ namespace VRM
const string HUMANOID_KEY = "humanoid";
const string MATERIAL_KEY = "materialProperties";
public VRM.glTF_VRM_extensions VRM
{
get
{
throw new NotImplementedException();
}
}
public VRM.glTF_VRM_extensions VRM { get; private set; }
public VRMImporterContext()
{
@ -42,7 +37,25 @@ namespace VRM
public override void ParseJson(string json, IStorage storage)
{
// parse GLTF part(core + unlit, textureTransform, targetNames)
base.ParseJson(json, storage);
// parse VRM part
if (GLTF.extensions != null && GLTF.extensions is ListTreeNode<JsonValue> vrmJson)
{
if (vrmJson.Value.ValueType == ValueNodeType.Object)
{
foreach (var kv in vrmJson.ObjectItems())
{
if (kv.Key.GetString() == "VRM")
{
VRM = VrmDeserializer.Deserialize(kv.Value);
break;
}
}
}
}
SetMaterialImporter(new VRMMaterialImporter(this, glTF_VRM_Material.Parse(Json)));
}