mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-07 11:28:35 -05:00
VRMVersionMenu.SplitAndWriteJson
This commit is contained in:
@@ -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<glTF_VRM_extensions>();
|
||||
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<UnityEngine.Object>(path.Value);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<glTF_VRM_BlendShapeGroup> blendShapeGroups = new List<glTF_VRM_BlendShapeGroup>();
|
||||
|
||||
@@ -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<LookAtType>(lookAtTypeName);
|
||||
}
|
||||
set { lookAtTypeName = value.ToString(); }
|
||||
|
||||
@@ -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<glTF_VRM_HumanoidBone> humanBones = new List<glTF_VRM_HumanoidBone>();
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using UniGLTF.ShaderPropExporter;
|
||||
namespace VRM
|
||||
{
|
||||
[Serializable]
|
||||
[JsonSchema(Title = "vrm.material")]
|
||||
public class glTF_VRM_Material : JsonSerializableBase
|
||||
{
|
||||
public string name;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<glTF_VRM_SecondaryAnimationGroup> boneGroups = new List<glTF_VRM_SecondaryAnimationGroup>();
|
||||
|
||||
Reference in New Issue
Block a user