From e6278f8549f2af682a70f19524bcc2e04e446285 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 21 Aug 2018 20:43:35 +0900 Subject: [PATCH] VRMVersionMenu.SplitAndWriteJson --- Scripts/Format/Editor/VRMVersionMenu.cs | 106 +++++++++- Scripts/Format/VRMFormat.cs | 5 +- Scripts/Format/glTF_VRM_BlendShape.cs | 3 +- Scripts/Format/glTF_VRM_FirstPerson.cs | 6 +- Scripts/Format/glTF_VRM_Humanoid.cs | 7 +- Scripts/Format/glTF_VRM_Material.cs | 1 + Scripts/Format/glTF_VRM_Meta.cs | 3 +- Scripts/Format/glTF_VRM_SecondaryAnimation.cs | 2 + UniGLTF | 2 +- .../schema/vrm.blendshapemaster.schema.json | 9 + .../vrm.blendshapemaster.schema.json.meta | 8 + .../0.0/schema/vrm.firstperson.schema.json | 74 +++++++ .../schema/vrm.firstperson.schema.json.meta | 8 + .../0.0/schema/vrm.humanoid.schema.json | 33 ++++ .../0.0/schema/vrm.humanoid.schema.json.meta | 8 + specification/0.0/schema/vrm.meta.schema.json | 45 +++++ .../0.0/schema/vrm.meta.schema.json.meta | 8 + specification/0.0/schema/vrm.schema.json | 187 ++---------------- .../schema/vrm.secondaryanimation.schema.json | 12 ++ .../vrm.secondaryanimation.schema.json.meta | 8 + 20 files changed, 349 insertions(+), 186 deletions(-) create mode 100644 specification/0.0/schema/vrm.blendshapemaster.schema.json create mode 100644 specification/0.0/schema/vrm.blendshapemaster.schema.json.meta create mode 100644 specification/0.0/schema/vrm.firstperson.schema.json create mode 100644 specification/0.0/schema/vrm.firstperson.schema.json.meta create mode 100644 specification/0.0/schema/vrm.humanoid.schema.json create mode 100644 specification/0.0/schema/vrm.humanoid.schema.json.meta create mode 100644 specification/0.0/schema/vrm.meta.schema.json create mode 100644 specification/0.0/schema/vrm.meta.schema.json.meta create mode 100644 specification/0.0/schema/vrm.secondaryanimation.schema.json create mode 100644 specification/0.0/schema/vrm.secondaryanimation.schema.json.meta diff --git a/Scripts/Format/Editor/VRMVersionMenu.cs b/Scripts/Format/Editor/VRMVersionMenu.cs index af9cc3400..a30112685 100644 --- a/Scripts/Format/Editor/VRMVersionMenu.cs +++ b/Scripts/Format/Editor/VRMVersionMenu.cs @@ -1,10 +1,12 @@ -using System.IO; +using System; +using System.IO; using System.Text; using UniGLTF; using UniJSON; using UnityEditor; using UnityEngine; + namespace VRM { public static class VRMVersionMenu @@ -43,22 +45,110 @@ namespace VRM AssetDatabase.Refresh(); } + static string GetTitle(JsonNode node) + { + try + { + var titleNode = node["title"]; + if (titleNode.Value.ValueType == JsonValueType.String) + { + return titleNode.Value.GetString(); + } + } + catch(Exception) + { + } + return ""; + } + + static void Traverse(JsonNode node, JsonFormatter f, UnityPath dir) + { + switch(node.Value.ValueType) + { + case JsonValueType.Array: + f.BeginList(); + foreach(var x in node.ArrayItems) + { + Traverse(x, f, dir); + } + f.EndList(); + break; + + case JsonValueType.Object: + //Debug.LogFormat("title: {0}", title); + { + f.BeginMap(); + foreach (var kv in node.ObjectItems) + { + f.Key(kv.Key); + var title = GetTitle(kv.Value); + if (string.IsNullOrEmpty(title)) + { + Traverse(kv.Value, f, dir); + } + else + { + // ref + f.BeginMap(); + f.Key("$ref"); + var fileName = string.Format("{0}.schema.json", title); + f.Value(fileName); + f.EndMap(); + + // new formatter + { + var subFormatter = new JsonFormatter(4); + + subFormatter.BeginMap(); + foreach (var _kv in kv.Value.ObjectItems) + { + subFormatter.Key(_kv.Key); + Traverse(_kv.Value, subFormatter, dir); + } + subFormatter.EndMap(); + + var subJson = subFormatter.ToString(); + var path = dir.Child(fileName); + File.WriteAllText(path.FullPath, subJson, Encoding.UTF8); + } + } + } + f.EndMap(); + } + break; + + default: + f.Value(node); + break; + } + } + + static UnityPath SplitAndWriteJson(JsonNode parsed, UnityPath dir) + { + var f = new JsonFormatter(4); + Traverse(parsed, f, dir); + var json = f.ToString(); + + var path = dir.Child("vrm.schema.json"); + Debug.LogFormat("write JsonSchema: {0}", path.FullPath); + File.WriteAllText(path.FullPath, json, Encoding.UTF8); + return path; + } + #if VRM_DEVELOP [MenuItem(VRMVersion.VRM_VERSION + "/Export JsonSchema")] #endif static void ExportJsonSchema() { - var dir = UnityPath.FromFullpath(Application.dataPath + "/VRM/specification/0.0/schema"); - dir.EnsureFolder(); - - var path = dir.Child("vrm.schema.json"); - - Debug.LogFormat("write SsonSchema: {0}", path.FullPath); var schema = JsonSchema.FromType(); var f = new JsonFormatter(2); schema.ToJson(f); var json = f.ToString(); - File.WriteAllText(path.FullPath, json, Encoding.UTF8); + + var dir = UnityPath.FromFullpath(Application.dataPath + "/VRM/specification/0.0/schema"); + dir.EnsureFolder(); + + var path = SplitAndWriteJson(JsonParser.Parse(json), dir); Selection.activeObject = AssetDatabase.LoadAssetAtPath(path.Value); } diff --git a/Scripts/Format/VRMFormat.cs b/Scripts/Format/VRMFormat.cs index 6408d4d2b..a37b9d9d2 100644 --- a/Scripts/Format/VRMFormat.cs +++ b/Scripts/Format/VRMFormat.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using UniGLTF; - +using UniJSON; namespace UniGLTF { @@ -33,6 +33,9 @@ namespace UniGLTF namespace VRM { [Serializable] + [JsonSchema(Title = "vrm", Description = @" +VRM extension is for 3d humanoid avatars (and models) in VR applications. +")] public class glTF_VRM_extensions : JsonSerializableBase { public string exporterVersion = "UniVRM-" + VRMVersion.VERSION; diff --git a/Scripts/Format/glTF_VRM_BlendShape.cs b/Scripts/Format/glTF_VRM_BlendShape.cs index 1026b4485..8d3c5238b 100644 --- a/Scripts/Format/glTF_VRM_BlendShape.cs +++ b/Scripts/Format/glTF_VRM_BlendShape.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Collections.Generic; using UniGLTF; using UnityEngine; - +using UniJSON; namespace VRM { @@ -100,6 +100,7 @@ namespace VRM } [Serializable] + [JsonSchema(Title = "vrm.blendshapemaster")] public class glTF_VRM_BlendShapeMaster : UniGLTF.JsonSerializableBase { public List blendShapeGroups = new List(); diff --git a/Scripts/Format/glTF_VRM_FirstPerson.cs b/Scripts/Format/glTF_VRM_FirstPerson.cs index 9e7be4cf2..a92e75111 100644 --- a/Scripts/Format/glTF_VRM_FirstPerson.cs +++ b/Scripts/Format/glTF_VRM_FirstPerson.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Collections.Generic; using UniGLTF; using UnityEngine; - +using UniJSON; namespace VRM { @@ -63,6 +63,7 @@ namespace VRM } [Serializable] + [JsonSchema(Title = "vrm.firstperson")] public class glTF_VRM_Firstperson : UniGLTF.JsonSerializableBase { public int firstPersonBone = -1; @@ -75,7 +76,8 @@ namespace VRM public string lookAtTypeName = "Bone"; public LookAtType lookAtType { - get { + get + { return EnumUtil.TryParseOrDefault(lookAtTypeName); } set { lookAtTypeName = value.ToString(); } diff --git a/Scripts/Format/glTF_VRM_Humanoid.cs b/Scripts/Format/glTF_VRM_Humanoid.cs index 50a1b3853..8d1d6d83a 100644 --- a/Scripts/Format/glTF_VRM_Humanoid.cs +++ b/Scripts/Format/glTF_VRM_Humanoid.cs @@ -4,7 +4,7 @@ using System.Linq; using UniGLTF; using UnityEngine; using UniHumanoid; - +using UniJSON; namespace VRM { @@ -127,6 +127,7 @@ namespace VRM } [Serializable] + [JsonSchema(Title = "vrm.humanoid")] public class glTF_VRM_Humanoid : JsonSerializableBase { public List humanBones = new List(); @@ -222,9 +223,9 @@ namespace VRM center = x.center, min = x.min, max = x.max, - humanBone = x.vrmBone.ToHumanBodyBone(), + humanBone = x.vrmBone.ToHumanBodyBone(), }) - .Where(x => x.humanBone!= HumanBodyBones.LastBone) + .Where(x => x.humanBone != HumanBodyBones.LastBone) .ToArray(); return description; } diff --git a/Scripts/Format/glTF_VRM_Material.cs b/Scripts/Format/glTF_VRM_Material.cs index e838b7e6a..532f5f4ae 100644 --- a/Scripts/Format/glTF_VRM_Material.cs +++ b/Scripts/Format/glTF_VRM_Material.cs @@ -9,6 +9,7 @@ using UniGLTF.ShaderPropExporter; namespace VRM { [Serializable] + [JsonSchema(Title = "vrm.material")] public class glTF_VRM_Material : JsonSerializableBase { public string name; diff --git a/Scripts/Format/glTF_VRM_Meta.cs b/Scripts/Format/glTF_VRM_Meta.cs index 0907ab23a..0c3d1b30b 100644 --- a/Scripts/Format/glTF_VRM_Meta.cs +++ b/Scripts/Format/glTF_VRM_Meta.cs @@ -1,6 +1,6 @@ using System; using UniGLTF; - +using UniJSON; namespace VRM { @@ -31,6 +31,7 @@ namespace VRM } [Serializable] + [JsonSchema(Title = "vrm.meta")] public class glTF_VRM_Meta : JsonSerializableBase { static UssageLicense FromString(string src) diff --git a/Scripts/Format/glTF_VRM_SecondaryAnimation.cs b/Scripts/Format/glTF_VRM_SecondaryAnimation.cs index 7a35b4f31..c5f091a8f 100644 --- a/Scripts/Format/glTF_VRM_SecondaryAnimation.cs +++ b/Scripts/Format/glTF_VRM_SecondaryAnimation.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using UniGLTF; +using UniJSON; using UnityEngine; @@ -61,6 +62,7 @@ namespace VRM } [Serializable] + [JsonSchema(Title = "vrm.secondaryanimation")] public class glTF_VRM_SecondaryAnimation : JsonSerializableBase { public List boneGroups = new List(); diff --git a/UniGLTF b/UniGLTF index c56f23707..9e92e665a 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit c56f2370785b30b927a8952795f2f331ee8952b1 +Subproject commit 9e92e665ae0333f3e669b1473ae9eecd584b3f1f diff --git a/specification/0.0/schema/vrm.blendshapemaster.schema.json b/specification/0.0/schema/vrm.blendshapemaster.schema.json new file mode 100644 index 000000000..1489993fc --- /dev/null +++ b/specification/0.0/schema/vrm.blendshapemaster.schema.json @@ -0,0 +1,9 @@ +{ + "title":"vrm.blendshapemaster", + "type":"object", + "properties":{ + "blendShapeGroups":{ + "type":"array" + } + } +} \ No newline at end of file diff --git a/specification/0.0/schema/vrm.blendshapemaster.schema.json.meta b/specification/0.0/schema/vrm.blendshapemaster.schema.json.meta new file mode 100644 index 000000000..f42c56bac --- /dev/null +++ b/specification/0.0/schema/vrm.blendshapemaster.schema.json.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7d7e602351f4ab24eaad71cc5d8f6945 +timeCreated: 1534850992 +licenseType: Free +TextScriptImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/specification/0.0/schema/vrm.firstperson.schema.json b/specification/0.0/schema/vrm.firstperson.schema.json new file mode 100644 index 000000000..724348c7a --- /dev/null +++ b/specification/0.0/schema/vrm.firstperson.schema.json @@ -0,0 +1,74 @@ +{ + "title":"vrm.firstperson", + "type":"object", + "properties":{ + "firstPersonBone":{ + "type":"integer" + }, + "firstPersonBoneOffset":{ + "type":"array" + }, + "meshAnnotations":{ + "type":"array" + }, + "lookAtTypeName":{ + "type":"string" + }, + "lookAtHorizontalInner":{ + "type":"object", + "properties":{ + "curve":{ + "type":"array" + }, + "xRange":{ + "type":"number" + }, + "yRange":{ + "type":"number" + } + } + }, + "lookAtHorizontalOuter":{ + "type":"object", + "properties":{ + "curve":{ + "type":"array" + }, + "xRange":{ + "type":"number" + }, + "yRange":{ + "type":"number" + } + } + }, + "lookAtVerticalDown":{ + "type":"object", + "properties":{ + "curve":{ + "type":"array" + }, + "xRange":{ + "type":"number" + }, + "yRange":{ + "type":"number" + } + } + }, + "lookAtVerticalUp":{ + "type":"object", + "properties":{ + "curve":{ + "type":"array" + }, + "xRange":{ + "type":"number" + }, + "yRange":{ + "type":"number" + } + } + } + } +} \ No newline at end of file diff --git a/specification/0.0/schema/vrm.firstperson.schema.json.meta b/specification/0.0/schema/vrm.firstperson.schema.json.meta new file mode 100644 index 000000000..3eb1e04c0 --- /dev/null +++ b/specification/0.0/schema/vrm.firstperson.schema.json.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f877e4bffde37d743af5ad4414dada9f +timeCreated: 1534850992 +licenseType: Free +TextScriptImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/specification/0.0/schema/vrm.humanoid.schema.json b/specification/0.0/schema/vrm.humanoid.schema.json new file mode 100644 index 000000000..598750e74 --- /dev/null +++ b/specification/0.0/schema/vrm.humanoid.schema.json @@ -0,0 +1,33 @@ +{ + "title":"vrm.humanoid", + "type":"object", + "properties":{ + "humanBones":{ + "type":"array" + }, + "armStretch":{ + "type":"number" + }, + "legStretch":{ + "type":"number" + }, + "upperArmTwist":{ + "type":"number" + }, + "lowerArmTwist":{ + "type":"number" + }, + "upperLegTwist":{ + "type":"number" + }, + "lowerLegTwist":{ + "type":"number" + }, + "feetSpacing":{ + "type":"number" + }, + "hasTranslationDoF":{ + "type":"bool" + } + } +} \ No newline at end of file diff --git a/specification/0.0/schema/vrm.humanoid.schema.json.meta b/specification/0.0/schema/vrm.humanoid.schema.json.meta new file mode 100644 index 000000000..13eefa4d6 --- /dev/null +++ b/specification/0.0/schema/vrm.humanoid.schema.json.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 31ac48d6b0a054d47bc138b4895b9e5c +timeCreated: 1534850992 +licenseType: Free +TextScriptImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/specification/0.0/schema/vrm.meta.schema.json b/specification/0.0/schema/vrm.meta.schema.json new file mode 100644 index 000000000..0a85f3116 --- /dev/null +++ b/specification/0.0/schema/vrm.meta.schema.json @@ -0,0 +1,45 @@ +{ + "title":"vrm.meta", + "type":"object", + "properties":{ + "title":{ + "type":"string" + }, + "version":{ + "type":"string" + }, + "author":{ + "type":"string" + }, + "contactInformation":{ + "type":"string" + }, + "reference":{ + "type":"string" + }, + "texture":{ + "type":"integer" + }, + "allowedUserName":{ + "type":"string" + }, + "violentUssageName":{ + "type":"string" + }, + "sexualUssageName":{ + "type":"string" + }, + "commercialUssageName":{ + "type":"string" + }, + "otherPermissionUrl":{ + "type":"string" + }, + "licenseName":{ + "type":"string" + }, + "otherLicenseUrl":{ + "type":"string" + } + } +} \ No newline at end of file diff --git a/specification/0.0/schema/vrm.meta.schema.json.meta b/specification/0.0/schema/vrm.meta.schema.json.meta new file mode 100644 index 000000000..27e49580b --- /dev/null +++ b/specification/0.0/schema/vrm.meta.schema.json.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3ca95771dc3d93c4a9471fc18de615a8 +timeCreated: 1534850992 +licenseType: Free +TextScriptImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/specification/0.0/schema/vrm.schema.json b/specification/0.0/schema/vrm.schema.json index 2eeca7a2f..9e7b71d43 100644 --- a/specification/0.0/schema/vrm.schema.json +++ b/specification/0.0/schema/vrm.schema.json @@ -1,179 +1,28 @@ { - "type":"object", - "properties":{ - "exporterVersion":{ - "type":"string" - }, - "meta":{ - "type":"object", - "properties":{ - "title":{ - "type":"string" + "title":"vrm", + "description":"VRM extension is for 3d humanoid avatars (and models) in VR applications.", + "type":"object", + "properties":{ + "exporterVersion":{ + "type":"string" }, - "version":{ - "type":"string" + "meta":{ + "$ref":"vrm.meta.schema.json" }, - "author":{ - "type":"string" + "humanoid":{ + "$ref":"vrm.humanoid.schema.json" }, - "contactInformation":{ - "type":"string" + "firstPerson":{ + "$ref":"vrm.firstperson.schema.json" }, - "reference":{ - "type":"string" + "blendShapeMaster":{ + "$ref":"vrm.blendshapemaster.schema.json" }, - "texture":{ - "type":"integer" + "secondaryAnimation":{ + "$ref":"vrm.secondaryanimation.schema.json" }, - "allowedUserName":{ - "type":"string" - }, - "violentUssageName":{ - "type":"string" - }, - "sexualUssageName":{ - "type":"string" - }, - "commercialUssageName":{ - "type":"string" - }, - "otherPermissionUrl":{ - "type":"string" - }, - "licenseName":{ - "type":"string" - }, - "otherLicenseUrl":{ - "type":"string" + "materialProperties":{ + "type":"array" } - } - }, - "humanoid":{ - "type":"object", - "properties":{ - "humanBones":{ - "type":"array" - }, - "armStretch":{ - "type":"number" - }, - "legStretch":{ - "type":"number" - }, - "upperArmTwist":{ - "type":"number" - }, - "lowerArmTwist":{ - "type":"number" - }, - "upperLegTwist":{ - "type":"number" - }, - "lowerLegTwist":{ - "type":"number" - }, - "feetSpacing":{ - "type":"number" - }, - "hasTranslationDoF":{ - "type":"bool" - } - } - }, - "firstPerson":{ - "type":"object", - "properties":{ - "firstPersonBone":{ - "type":"integer" - }, - "firstPersonBoneOffset":{ - "type":"array" - }, - "meshAnnotations":{ - "type":"array" - }, - "lookAtTypeName":{ - "type":"string" - }, - "lookAtHorizontalInner":{ - "type":"object", - "properties":{ - "curve":{ - "type":"array" - }, - "xRange":{ - "type":"number" - }, - "yRange":{ - "type":"number" - } - } - }, - "lookAtHorizontalOuter":{ - "type":"object", - "properties":{ - "curve":{ - "type":"array" - }, - "xRange":{ - "type":"number" - }, - "yRange":{ - "type":"number" - } - } - }, - "lookAtVerticalDown":{ - "type":"object", - "properties":{ - "curve":{ - "type":"array" - }, - "xRange":{ - "type":"number" - }, - "yRange":{ - "type":"number" - } - } - }, - "lookAtVerticalUp":{ - "type":"object", - "properties":{ - "curve":{ - "type":"array" - }, - "xRange":{ - "type":"number" - }, - "yRange":{ - "type":"number" - } - } - } - } - }, - "blendShapeMaster":{ - "type":"object", - "properties":{ - "blendShapeGroups":{ - "type":"array" - } - } - }, - "secondaryAnimation":{ - "type":"object", - "properties":{ - "boneGroups":{ - "type":"array" - }, - "colliderGroups":{ - "type":"array" - } - } - }, - "materialProperties":{ - "type":"array" } - } } \ No newline at end of file diff --git a/specification/0.0/schema/vrm.secondaryanimation.schema.json b/specification/0.0/schema/vrm.secondaryanimation.schema.json new file mode 100644 index 000000000..0820cba73 --- /dev/null +++ b/specification/0.0/schema/vrm.secondaryanimation.schema.json @@ -0,0 +1,12 @@ +{ + "title":"vrm.secondaryanimation", + "type":"object", + "properties":{ + "boneGroups":{ + "type":"array" + }, + "colliderGroups":{ + "type":"array" + } + } +} \ No newline at end of file diff --git a/specification/0.0/schema/vrm.secondaryanimation.schema.json.meta b/specification/0.0/schema/vrm.secondaryanimation.schema.json.meta new file mode 100644 index 000000000..aa0d86548 --- /dev/null +++ b/specification/0.0/schema/vrm.secondaryanimation.schema.json.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0d7fef398632ca44089cc531445bc680 +timeCreated: 1534850992 +licenseType: Free +TextScriptImporter: + userData: + assetBundleName: + assetBundleVariant: