From 7942ba7dd5047945de1f4fde59f54042578155ad Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 1 Jun 2018 18:15:31 +0900 Subject: [PATCH 01/22] Fix UnitTest --- Scripts/Editor/VRMTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Editor/VRMTest.cs b/Scripts/Editor/VRMTest.cs index f62f0a32b..282629fda 100644 --- a/Scripts/Editor/VRMTest.cs +++ b/Scripts/Editor/VRMTest.cs @@ -59,7 +59,7 @@ public class VRMTest exporter.Export(); // import - context.Json = gltf.ToJson(); + context.ParseJson(gltf.ToJson(), new ArraySegment()); Debug.LogFormat("{0}", context.Json); gltfImporter.Import(context); From e7c679c42b1f77e96678d309f715a018c8ff8605 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 7 Jun 2018 16:28:13 +0900 Subject: [PATCH 02/22] Incremental version --- Scripts/Format/VRMVersion.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Scripts/Format/VRMVersion.cs b/Scripts/Format/VRMVersion.cs index 37a6613a5..a095fee18 100644 --- a/Scripts/Format/VRMVersion.cs +++ b/Scripts/Format/VRMVersion.cs @@ -4,11 +4,11 @@ namespace VRM public static partial class VRMVersion { public const int MAJOR = 0; - public const int MINOR = 38; + public const int MINOR = 39; - public const string VERSION = "0.38"; + public const string VERSION = "0.39"; - public const string DecrementMenuName = "VRM/Version(0.38) Decrement"; - public const string IncrementMenuName = "VRM/Version(0.38) Increment"; + public const string DecrementMenuName = "VRM/Version(0.39) Decrement"; + public const string IncrementMenuName = "VRM/Version(0.39) Increment"; } } From 168b4bce6963a7037ba63649efbfc0bd23bac46f Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 7 Jun 2018 16:29:42 +0900 Subject: [PATCH 03/22] Update UniGLTF. Add sparse accessor experiment to VRMExporter --- Scripts/Format/VRMExporter.cs | 8 +++++++- Scripts/Format/VRMImporter.cs | 4 ++-- UniGLTF | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Scripts/Format/VRMExporter.cs b/Scripts/Format/VRMExporter.cs index abdc32d42..7c749ebe6 100644 --- a/Scripts/Format/VRMExporter.cs +++ b/Scripts/Format/VRMExporter.cs @@ -16,7 +16,13 @@ namespace VRM { var gltf = new glTF_VRM(); gltf.asset.generator = string.Format("UniVRM-{0}.{1}", VRMVersion.MAJOR, VRMVersion.MINOR); - using (var exporter = new VRMExporter(gltf)) + using (var exporter = new VRMExporter(gltf) + { +#if VRM_EXPORTER_USE_SPARSE + // experimental + UseSparseAccessorForBlendShape=true +#endif + }) { _Export(gltf, exporter, go); diff --git a/Scripts/Format/VRMImporter.cs b/Scripts/Format/VRMImporter.cs index 18b8ca90a..cd79f8e14 100644 --- a/Scripts/Format/VRMImporter.cs +++ b/Scripts/Format/VRMImporter.cs @@ -78,8 +78,8 @@ namespace VRM public static CreateMaterialFunc GetMaterialFunc(List materials) { - var CreateDefault = gltfImporter.CreateMaterialFuncFromShader(Shader.Find("VRM/UnlitTexture")); - var CreateZWrite = gltfImporter.CreateMaterialFuncFromShader(Shader.Find("VRM/UnlitTransparentZWrite")); + var CreateDefault = gltfImporter.CreateMaterialFuncFromShader(new ShaderStore("VRM/UnlitTexture")); + var CreateZWrite = gltfImporter.CreateMaterialFuncFromShader(new ShaderStore("VRM/UnlitTransparentZWrite")); CreateMaterialFunc fallback = (ctx, i) => { var vrm = ctx.GLTF as glTF_VRM; diff --git a/UniGLTF b/UniGLTF index c8b19d3b8..ea5b240c0 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit c8b19d3b8332cadff434a58646610abe2618f3c8 +Subproject commit ea5b240c079de93a36acc6ae187a488f6c2b7f01 From 5f256042d420713e3a6fabe2c8980d5f5239f3dd Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 7 Jun 2018 16:46:59 +0900 Subject: [PATCH 04/22] Separate ExportSecondary from VRMExporter --- Scripts/Format/VRMExporter.cs | 116 ++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/Scripts/Format/VRMExporter.cs b/Scripts/Format/VRMExporter.cs index 7c749ebe6..82ff08e36 100644 --- a/Scripts/Format/VRMExporter.cs +++ b/Scripts/Format/VRMExporter.cs @@ -40,6 +40,64 @@ namespace VRM return gltf; } + static void ExportSecondary(Transform root, List nodes, + Action addSecondaryColliderGroup, + Action addSecondaryGroup) + { + var colliders = new List(); + foreach (var vrmColliderGroup in root.Traverse() + .Select(x => x.GetComponent()) + .Where(x => x != null)) + { + colliders.Add(vrmColliderGroup); + + var colliderGroup = new glTF_VRM_SecondaryAnimationColliderGroup + { + node = nodes.IndexOf(vrmColliderGroup.transform) + }; + + colliderGroup.colliders = vrmColliderGroup.Colliders.Select(x => + { + return new glTF_VRM_SecondaryAnimationCollider + { + offset = x.Offset, + radius = x.Radius, + }; + + }).ToList(); + + addSecondaryColliderGroup(colliderGroup); + } + + foreach (var spring in root.Traverse() + .Select(x => x.GetComponent()) + .Where(x => x != null)) + { + addSecondaryGroup(new glTF_VRM_SecondaryAnimationGroup + { + comment = spring.m_comment, + center = nodes.IndexOf(spring.m_center), + dragForce = spring.m_dragForce, + gravityDir = spring.m_gravityDir, + gravityPower = spring.m_gravityPower, + stiffiness = spring.m_stiffnessForce, + hitRadius = spring.m_hitRadius, + colliderGroups = spring.ColliderGroups + .Select(x => + { + var index = colliders.IndexOf(x); + if (index == -1) + { + throw new IndexOutOfRangeException(); + } + return index; + }) + .ToArray(), + bones = spring.RootBones.Select(x => nodes.IndexOf(x)).ToArray(), + }); + } + } + public static void _Export(glTF_VRM gltf, VRMExporter exporter, GameObject go) { exporter.Prepare(go); @@ -105,60 +163,10 @@ namespace VRM } // secondary - var secondary = exporter.Copy.transform.Find("secondary"); - if (secondary == null) - { - secondary = exporter.Copy.transform; - } - - var colliders = new List(); - foreach (var vrmColliderGroup in exporter.Copy.transform.Traverse().Select(x => x.GetComponent()).Where(x => x != null)) - { - colliders.Add(vrmColliderGroup); - - var colliderGroup = new glTF_VRM_SecondaryAnimationColliderGroup - { - node = exporter.Nodes.IndexOf(vrmColliderGroup.transform) - }; - - colliderGroup.colliders = vrmColliderGroup.Colliders.Select(x => - { - return new glTF_VRM_SecondaryAnimationCollider - { - offset = x.Offset, - radius = x.Radius, - }; - - }).ToList(); - - gltf.extensions.VRM.secondaryAnimation.colliderGroups.Add(colliderGroup); - } - - foreach (var spring in secondary.GetComponents()) - { - gltf.extensions.VRM.secondaryAnimation.boneGroups.Add(new glTF_VRM_SecondaryAnimationGroup - { - comment = spring.m_comment, - center = exporter.Nodes.IndexOf(spring.m_center), - dragForce = spring.m_dragForce, - gravityDir = spring.m_gravityDir, - gravityPower = spring.m_gravityPower, - stiffiness = spring.m_stiffnessForce, - hitRadius = spring.m_hitRadius, - colliderGroups = spring.ColliderGroups - .Select(x => - { - var index = colliders.IndexOf(x); - if (index == -1) - { - throw new IndexOutOfRangeException(); - } - return index; - }) - .ToArray(), - bones = spring.RootBones.Select(x => exporter.Nodes.IndexOf(x)).ToArray(), - }); - } + ExportSecondary(exporter.Copy.transform, exporter.Nodes, + x => gltf.extensions.VRM.secondaryAnimation.colliderGroups.Add(x), + x => gltf.extensions.VRM.secondaryAnimation.boneGroups.Add(x) + ); // meta(obsolete) { From ca41dd359d21ac73f61e4fa44ea745f0183334ff Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 7 Jun 2018 17:05:45 +0900 Subject: [PATCH 05/22] Comment out Debug.Log --- Scripts/BlendShape/Editor/PreviewEditor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/BlendShape/Editor/PreviewEditor.cs b/Scripts/BlendShape/Editor/PreviewEditor.cs index aba657e78..65c348b31 100644 --- a/Scripts/BlendShape/Editor/PreviewEditor.cs +++ b/Scripts/BlendShape/Editor/PreviewEditor.cs @@ -84,7 +84,7 @@ namespace VRM { if (m_scene != null) { - Debug.Log("Bake"); + //Debug.Log("Bake"); m_scene.Bake(values, materialValues, weight); } } From 8324b5c0376cf09ecb2e6bdbda8e9e4339589113 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 7 Jun 2018 17:10:48 +0900 Subject: [PATCH 06/22] Move ExportSecondary --- Scripts/Format/VRMExporter.cs | 58 ----------------- Scripts/SpringBone/VRMSpringUtility.cs | 70 +++++++++++++++++++++ Scripts/SpringBone/VRMSpringUtility.cs.meta | 12 ++++ 3 files changed, 82 insertions(+), 58 deletions(-) create mode 100644 Scripts/SpringBone/VRMSpringUtility.cs create mode 100644 Scripts/SpringBone/VRMSpringUtility.cs.meta diff --git a/Scripts/Format/VRMExporter.cs b/Scripts/Format/VRMExporter.cs index 82ff08e36..eb9f50057 100644 --- a/Scripts/Format/VRMExporter.cs +++ b/Scripts/Format/VRMExporter.cs @@ -40,64 +40,6 @@ namespace VRM return gltf; } - static void ExportSecondary(Transform root, List nodes, - Action addSecondaryColliderGroup, - Action addSecondaryGroup) - { - var colliders = new List(); - foreach (var vrmColliderGroup in root.Traverse() - .Select(x => x.GetComponent()) - .Where(x => x != null)) - { - colliders.Add(vrmColliderGroup); - - var colliderGroup = new glTF_VRM_SecondaryAnimationColliderGroup - { - node = nodes.IndexOf(vrmColliderGroup.transform) - }; - - colliderGroup.colliders = vrmColliderGroup.Colliders.Select(x => - { - return new glTF_VRM_SecondaryAnimationCollider - { - offset = x.Offset, - radius = x.Radius, - }; - - }).ToList(); - - addSecondaryColliderGroup(colliderGroup); - } - - foreach (var spring in root.Traverse() - .Select(x => x.GetComponent()) - .Where(x => x != null)) - { - addSecondaryGroup(new glTF_VRM_SecondaryAnimationGroup - { - comment = spring.m_comment, - center = nodes.IndexOf(spring.m_center), - dragForce = spring.m_dragForce, - gravityDir = spring.m_gravityDir, - gravityPower = spring.m_gravityPower, - stiffiness = spring.m_stiffnessForce, - hitRadius = spring.m_hitRadius, - colliderGroups = spring.ColliderGroups - .Select(x => - { - var index = colliders.IndexOf(x); - if (index == -1) - { - throw new IndexOutOfRangeException(); - } - return index; - }) - .ToArray(), - bones = spring.RootBones.Select(x => nodes.IndexOf(x)).ToArray(), - }); - } - } - public static void _Export(glTF_VRM gltf, VRMExporter exporter, GameObject go) { exporter.Prepare(go); diff --git a/Scripts/SpringBone/VRMSpringUtility.cs b/Scripts/SpringBone/VRMSpringUtility.cs new file mode 100644 index 000000000..8e54beddc --- /dev/null +++ b/Scripts/SpringBone/VRMSpringUtility.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UniGLTF; +using UnityEngine; + + +namespace VRM +{ + public static class VRMSpringUtility + { + public static void ExportSecondary(Transform root, List nodes, + Action addSecondaryColliderGroup, + Action addSecondaryGroup) + { + var colliders = new List(); + foreach (var vrmColliderGroup in root.Traverse() + .Select(x => x.GetComponent()) + .Where(x => x != null)) + { + colliders.Add(vrmColliderGroup); + + var colliderGroup = new glTF_VRM_SecondaryAnimationColliderGroup + { + node = nodes.IndexOf(vrmColliderGroup.transform) + }; + + colliderGroup.colliders = vrmColliderGroup.Colliders.Select(x => + { + return new glTF_VRM_SecondaryAnimationCollider + { + offset = x.Offset, + radius = x.Radius, + }; + + }).ToList(); + + addSecondaryColliderGroup(colliderGroup); + } + + foreach (var spring in root.Traverse() + .Select(x => x.GetComponent()) + .Where(x => x != null)) + { + addSecondaryGroup(new glTF_VRM_SecondaryAnimationGroup + { + comment = spring.m_comment, + center = nodes.IndexOf(spring.m_center), + dragForce = spring.m_dragForce, + gravityDir = spring.m_gravityDir, + gravityPower = spring.m_gravityPower, + stiffiness = spring.m_stiffnessForce, + hitRadius = spring.m_hitRadius, + colliderGroups = spring.ColliderGroups + .Select(x => + { + var index = colliders.IndexOf(x); + if (index == -1) + { + throw new IndexOutOfRangeException(); + } + return index; + }) + .ToArray(), + bones = spring.RootBones.Select(x => nodes.IndexOf(x)).ToArray(), + }); + } + } + } +} diff --git a/Scripts/SpringBone/VRMSpringUtility.cs.meta b/Scripts/SpringBone/VRMSpringUtility.cs.meta new file mode 100644 index 000000000..773a15d4c --- /dev/null +++ b/Scripts/SpringBone/VRMSpringUtility.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 42564d357aca11d4882ab504d7f99166 +timeCreated: 1528358605 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 65d92144a72e6b68e3fd1fd3240b9513c9276b63 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 7 Jun 2018 17:45:21 +0900 Subject: [PATCH 07/22] Implement VRMSpringUtility.ExportSecondary and VRMSpringUtility.LoadSecondary --- Scripts/Format/VRMExporter.cs | 2 +- Scripts/Format/VRMImporter.cs | 56 +-------- Scripts/SpringBone/VRMSpringUtility.cs | 167 +++++++++++++++++++++++++ 3 files changed, 170 insertions(+), 55 deletions(-) diff --git a/Scripts/Format/VRMExporter.cs b/Scripts/Format/VRMExporter.cs index eb9f50057..49c5e7f59 100644 --- a/Scripts/Format/VRMExporter.cs +++ b/Scripts/Format/VRMExporter.cs @@ -105,7 +105,7 @@ namespace VRM } // secondary - ExportSecondary(exporter.Copy.transform, exporter.Nodes, + VRMSpringUtility.ExportSecondary(exporter.Copy.transform, exporter.Nodes, x => gltf.extensions.VRM.secondaryAnimation.colliderGroups.Add(x), x => gltf.extensions.VRM.secondaryAnimation.boneGroups.Add(x) ); diff --git a/Scripts/Format/VRMImporter.cs b/Scripts/Format/VRMImporter.cs index cd79f8e14..9fc4f5bb2 100644 --- a/Scripts/Format/VRMImporter.cs +++ b/Scripts/Format/VRMImporter.cs @@ -183,7 +183,8 @@ namespace VRM } LoadBlendShapeMaster(context); - LoadSecondaryMotions(context); + VRMSpringUtility.LoadSecondary(context.Root.transform, context.Nodes, + context.VRM.extensions.VRM.secondaryAnimation); LoadFirstPerson(context); return Unit.Default; @@ -230,59 +231,6 @@ namespace VRM lookAtHead.OnImported(context); } - static void LoadSecondaryMotions(VRMImporterContext context) - { - var secondary = context.Root.transform.Find("secondary"); - if (secondary == null) - { - secondary = new GameObject("secondary").transform; - secondary.SetParent(context.Root.transform, false); - } - - var secondaryAnimation = context.VRM.extensions.VRM.secondaryAnimation; - var colliders = new List(); - foreach (var colliderGroup in secondaryAnimation.colliderGroups) - { - var vrmGroup = context.Nodes[colliderGroup.node].gameObject.AddComponent(); - vrmGroup.Colliders = colliderGroup.colliders.Select(x => - { - return new VRMSpringBoneColliderGroup.SphereCollider - { - Offset = x.offset, - Radius = x.radius - }; - }).ToArray(); - colliders.Add(vrmGroup); - } - - if (secondaryAnimation.boneGroups.Count > 0) - { - foreach (var boneGroup in secondaryAnimation.boneGroups) - { - var vrmBoneGroup = secondary.gameObject.AddComponent(); - if (boneGroup.center != -1) - { - vrmBoneGroup.m_center = context.Nodes[boneGroup.center]; - } - vrmBoneGroup.m_comment = boneGroup.comment; - vrmBoneGroup.m_dragForce = boneGroup.dragForce; - vrmBoneGroup.m_gravityDir = boneGroup.gravityDir; - vrmBoneGroup.m_gravityPower = boneGroup.gravityPower; - vrmBoneGroup.m_hitRadius = boneGroup.hitRadius; - vrmBoneGroup.m_stiffnessForce = boneGroup.stiffiness; - if (boneGroup.colliderGroups != null && boneGroup.colliderGroups.Any()) - { - vrmBoneGroup.ColliderGroups = boneGroup.colliderGroups.Select(x => colliders[x]).ToArray(); - } - vrmBoneGroup.RootBones = boneGroup.bones.Select(x => context.Nodes[x]).ToList(); - } - } - else - { - secondary.gameObject.AddComponent(); - } - } - static void LoadBlendShapeMaster(VRMImporterContext context) { context.BlendShapeAvatar = ScriptableObject.CreateInstance(); diff --git a/Scripts/SpringBone/VRMSpringUtility.cs b/Scripts/SpringBone/VRMSpringUtility.cs index 8e54beddc..56851b5ba 100644 --- a/Scripts/SpringBone/VRMSpringUtility.cs +++ b/Scripts/SpringBone/VRMSpringUtility.cs @@ -3,12 +3,107 @@ using System.Collections.Generic; using System.Linq; using UniGLTF; using UnityEngine; +using System.IO; +using System.Text; +#if UNITY_EDITOR +using UnityEditor; +#endif namespace VRM { public static class VRMSpringUtility { +#if UNITY_EDITOR + #region save + [MenuItem("VRM/SaveSpringBoneToJSON", validate = true)] + static bool SaveSpringBoneToJSONIsEnable() + { + var root = Selection.activeObject as GameObject; + if (root == null) + { + return false; + } + + var animator = root.GetComponent(); + if (animator == null) + { + return false; + } + + return true; + } + + [MenuItem("VRM/SaveSpringBoneToJSON")] + static void SaveSpringBoneToJSON() + { + var path = EditorUtility.SaveFilePanel( + "Save spring to json", + null, + "VRMSpring.json", + "json"); + if (string.IsNullOrEmpty(path)) + { + return; + } + + var go = Selection.activeObject as GameObject; + var root = go.transform; + var nodes = root.Traverse().Skip(1).ToList(); + var spring = new glTF_VRM_SecondaryAnimation(); + ExportSecondary(root, nodes, + spring.colliderGroups.Add, + spring.boneGroups.Add + ); + + File.WriteAllText(path, spring.ToJson(), Encoding.UTF8); + } + + #endregion + + #region load + [MenuItem("VRM/LoadSpringBoneFromJSON", true)] + static bool LoadSpringBoneFromJSONIsEnable() + { + var root = Selection.activeObject as GameObject; + if (root == null) + { + return false; + } + + var animator = root.GetComponent(); + if (animator == null) + { + return false; + } + + return true; + } + + [MenuItem("VRM/LoadSpringBoneFromJSON")] + static void LoadSpringBoneFromJSON() + { + var path = EditorUtility.OpenFilePanel( + "Load spring from json", + null, + "json"); + if (string.IsNullOrEmpty(path)) + { + return; + } + + var json = File.ReadAllText(path, Encoding.UTF8); + var spring = JsonUtility.FromJson(json); + + var go = Selection.activeObject as GameObject; + var root = go.transform; + var nodes = root.Traverse().Skip(1).ToList(); + + LoadSecondary(root, nodes, spring); + } + #endregion +#endif + public static void ExportSecondary(Transform root, List nodes, Action addSecondaryColliderGroup, Action addSecondaryGroup) @@ -66,5 +161,77 @@ namespace VRM }); } } + + public static void LoadSecondary(Transform root, List nodes, + glTF_VRM_SecondaryAnimation secondaryAnimation) + { + var secondary = root.Find("secondary"); + if (secondary == null) + { + secondary = new GameObject("secondary").transform; + secondary.SetParent(root, false); + } + + // clear components + var remove = root.Traverse() + .SelectMany(x => x.GetComponents()) + .Where(x => x is VRMSpringBone || x is VRMSpringBoneColliderGroup) + .ToArray(); + foreach(var x in remove) + { + if (Application.isPlaying) + { + GameObject.Destroy(x); + } + else + { + GameObject.DestroyImmediate(x); + } + } + + //var secondaryAnimation = context.VRM.extensions.VRM.secondaryAnimation; + var colliders = new List(); + foreach (var colliderGroup in secondaryAnimation.colliderGroups) + { + var vrmGroup = nodes[colliderGroup.node].gameObject.AddComponent(); + vrmGroup.Colliders = colliderGroup.colliders.Select(x => + { + return new VRMSpringBoneColliderGroup.SphereCollider + { + Offset = x.offset, + Radius = x.radius + }; + }).ToArray(); + colliders.Add(vrmGroup); + } + + if (secondaryAnimation.boneGroups.Count > 0) + { + foreach (var boneGroup in secondaryAnimation.boneGroups) + { + var vrmBoneGroup = secondary.gameObject.AddComponent(); + if (boneGroup.center != -1) + { + vrmBoneGroup.m_center = nodes[boneGroup.center]; + } + vrmBoneGroup.m_comment = boneGroup.comment; + vrmBoneGroup.m_dragForce = boneGroup.dragForce; + vrmBoneGroup.m_gravityDir = boneGroup.gravityDir; + vrmBoneGroup.m_gravityPower = boneGroup.gravityPower; + vrmBoneGroup.m_hitRadius = boneGroup.hitRadius; + vrmBoneGroup.m_stiffnessForce = boneGroup.stiffiness; + if (boneGroup.colliderGroups != null && boneGroup.colliderGroups.Any()) + { + vrmBoneGroup.ColliderGroups = boneGroup.colliderGroups.Select(x => colliders[x]).ToArray(); + } + vrmBoneGroup.RootBones = boneGroup.bones.Select(x => nodes[x]).ToList(); + } + } + else + { + secondary.gameObject.AddComponent(); + } + } + } } From 9c488c7e383ea0703ffb7493044f1f2264ca26c5 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 7 Jun 2018 20:45:24 +0900 Subject: [PATCH 08/22] Update UniGLTF --- UniGLTF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UniGLTF b/UniGLTF index ea5b240c0..d162fc6f4 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit ea5b240c079de93a36acc6ae187a488f6c2b7f01 +Subproject commit d162fc6f45906a0fa84d8e4c0d5d31d3d5661dd3 From 91caa979f04017ebc6c2a4d542fbe8568a8d848f Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 18 Jun 2018 22:40:44 +0900 Subject: [PATCH 09/22] Updated UniGLTF --- UniGLTF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UniGLTF b/UniGLTF index d162fc6f4..fb17653c8 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit d162fc6f45906a0fa84d8e4c0d5d31d3d5661dd3 +Subproject commit fb17653c83e7942c0d1bd53305fdc875fa1a6eb2 From 98193ab7562bd8bb344747953d8657c9fa24c816 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 18 Jun 2018 22:51:37 +0900 Subject: [PATCH 10/22] Modified storage interface --- Scripts/Editor/VRMTest.cs | 2 +- Scripts/Format/VRMImporter.cs | 6 +++--- Scripts/Format/VRMImporterContext.cs | 2 +- UniGLTF | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Scripts/Editor/VRMTest.cs b/Scripts/Editor/VRMTest.cs index 282629fda..ffc3ef331 100644 --- a/Scripts/Editor/VRMTest.cs +++ b/Scripts/Editor/VRMTest.cs @@ -59,7 +59,7 @@ public class VRMTest exporter.Export(); // import - context.ParseJson(gltf.ToJson(), new ArraySegment()); + context.ParseJson(gltf.ToJson(), new SimpleStorage()); Debug.LogFormat("{0}", context.Json); gltfImporter.Import(context); diff --git a/Scripts/Format/VRMImporter.cs b/Scripts/Format/VRMImporter.cs index 9fc4f5bb2..4bae71ed8 100644 --- a/Scripts/Format/VRMImporter.cs +++ b/Scripts/Format/VRMImporter.cs @@ -405,12 +405,12 @@ namespace VRM #endregion #region LoadVrmAsync - static IEnumerator LoadTextures(VRMImporterContext context) + static IEnumerator LoadTextures(VRMImporterContext context, IStorage storage) { for(int i=0; i { var texture = new TextureItem(ctx.GLTF, index); - texture.Process(); + texture.Process(ctx.Storage); return texture; }) .ContinueWith(Scheduler.ThreadPool, x => ctx.Textures.Add(x)); diff --git a/Scripts/Format/VRMImporterContext.cs b/Scripts/Format/VRMImporterContext.cs index 20acf4a93..ef74c3357 100644 --- a/Scripts/Format/VRMImporterContext.cs +++ b/Scripts/Format/VRMImporterContext.cs @@ -58,7 +58,7 @@ namespace VRM if(gltfMeta.texture >= 0 && gltfMeta.texture < VRM.textures.Count) { var t = new TextureItem(VRM, gltfMeta.texture); - t.Process(); + t.Process(Storage); meta.Thumbnail=t.Texture; } } diff --git a/UniGLTF b/UniGLTF index fb17653c8..673a00366 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit fb17653c83e7942c0d1bd53305fdc875fa1a6eb2 +Subproject commit 673a003669e78333cfc27c78417c797784fe9a36 From 922f07670312bf41652d7bae26aad5bfebb4f26f Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 18 Jun 2018 22:57:16 +0900 Subject: [PATCH 11/22] Added errorHandler argument to LoadVrmAsync --- Scripts/Format/VRMImporter.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Scripts/Format/VRMImporter.cs b/Scripts/Format/VRMImporter.cs index 4bae71ed8..5ba2f2abb 100644 --- a/Scripts/Format/VRMImporter.cs +++ b/Scripts/Format/VRMImporter.cs @@ -524,9 +524,14 @@ namespace VRM } public static void LoadVrmAsync(VRMImporterContext ctx, Action onLoaded) + { + LoadVrmAsync(ctx, onLoaded, Debug.LogError); + } + + public static void LoadVrmAsync(VRMImporterContext ctx, Action onLoaded, Action onError) { LoadVrmAsyncInternal(ctx) - .Subscribe(Scheduler.MainThread, onLoaded, Debug.LogError); + .Subscribe(Scheduler.MainThread, onLoaded, onError); } private static Schedulable LoadVrmAsyncInternal(VRMImporterContext ctx) From 43777d9a66de44c84db2b99cfeb527ed060d6a43 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 18 Jun 2018 23:16:16 +0900 Subject: [PATCH 12/22] Added errorHandler to VRMImporter.LoadVrmAsync --- Scripts/Format/VRMImporter.cs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Scripts/Format/VRMImporter.cs b/Scripts/Format/VRMImporter.cs index 5ba2f2abb..9b8230f48 100644 --- a/Scripts/Format/VRMImporter.cs +++ b/Scripts/Format/VRMImporter.cs @@ -183,7 +183,7 @@ namespace VRM } LoadBlendShapeMaster(context); - VRMSpringUtility.LoadSecondary(context.Root.transform, context.Nodes, + VRMSpringUtility.LoadSecondary(context.Root.transform, context.Nodes, context.VRM.extensions.VRM.secondaryAnimation); LoadFirstPerson(context); @@ -407,7 +407,7 @@ namespace VRM #region LoadVrmAsync static IEnumerator LoadTextures(VRMImporterContext context, IStorage storage) { - for(int i=0; i onLoaded) + public static void LoadVrmAsync(string path, Action onLoaded, Action onError = null) { var context = new VRMImporterContext(path); context.ParseVrm(File.ReadAllBytes(path)); - LoadVrmAsync(context, onLoaded); + LoadVrmAsync(context, onLoaded, onError); } - public static void LoadVrmAsync(Byte[] bytes, Action onLoaded) + public static void LoadVrmAsync(Byte[] bytes, Action onLoaded, Action onError = null) { var context = new VRMImporterContext(); context.ParseVrm(bytes); - LoadVrmAsync(context, onLoaded); + LoadVrmAsync(context, onLoaded, onError); } - public static void LoadVrmAsync(VRMImporterContext ctx, Action onLoaded) - { - LoadVrmAsync(ctx, onLoaded, Debug.LogError); - } - - public static void LoadVrmAsync(VRMImporterContext ctx, Action onLoaded, Action onError) + public static void LoadVrmAsync(VRMImporterContext ctx, Action onLoaded, Action onError = null) { + if (onError == null) + { + onError = Debug.LogError; + } LoadVrmAsyncInternal(ctx) .Subscribe(Scheduler.MainThread, onLoaded, onError); } From e60723ba31e03649e30efd162137bb96c7cf0904 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 18 Jun 2018 23:17:54 +0900 Subject: [PATCH 13/22] Blinker to protected --- Scripts/BlendShape/Blinker.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Scripts/BlendShape/Blinker.cs b/Scripts/BlendShape/Blinker.cs index 3527f285f..4d66dd34c 100644 --- a/Scripts/BlendShape/Blinker.cs +++ b/Scripts/BlendShape/Blinker.cs @@ -25,7 +25,7 @@ namespace VRM [SerializeField] float m_closeSeconds = 0.1f; - Coroutine m_coroutine; + protected Coroutine m_coroutine; //static readonly string BLINK_NAME = BlendShapePreset.Blink.ToString(); @@ -45,7 +45,7 @@ namespace VRM } } - IEnumerator BlinkRoutine() + protected IEnumerator BlinkRoutine() { while (true) { From b8b306651381894356d7a44dfaff59f10b4cf0e9 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 21 Jun 2018 22:20:49 +0900 Subject: [PATCH 14/22] Updated UniGLTF --- Scripts/Format/VRMImporter.cs | 4 ++-- Scripts/Format/VRMImporterContext.cs | 2 +- Scripts/Format/glTF_VRM_Material.cs | 2 +- UniGLTF | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Scripts/Format/VRMImporter.cs b/Scripts/Format/VRMImporter.cs index 9b8230f48..8f10fb7e5 100644 --- a/Scripts/Format/VRMImporter.cs +++ b/Scripts/Format/VRMImporter.cs @@ -410,7 +410,7 @@ namespace VRM for (int i = 0; i < context.GLTF.textures.Count; ++i) { var x = new TextureItem(context.GLTF, i); - x.Process(storage); + x.Process(context.GLTF, storage); context.Textures.Add(x); yield return null; } @@ -562,7 +562,7 @@ namespace VRM () => { var texture = new TextureItem(ctx.GLTF, index); - texture.Process(ctx.Storage); + texture.Process(ctx.GLTF, ctx.Storage); return texture; }) .ContinueWith(Scheduler.ThreadPool, x => ctx.Textures.Add(x)); diff --git a/Scripts/Format/VRMImporterContext.cs b/Scripts/Format/VRMImporterContext.cs index ef74c3357..a341fb1ee 100644 --- a/Scripts/Format/VRMImporterContext.cs +++ b/Scripts/Format/VRMImporterContext.cs @@ -58,7 +58,7 @@ namespace VRM if(gltfMeta.texture >= 0 && gltfMeta.texture < VRM.textures.Count) { var t = new TextureItem(VRM, gltfMeta.texture); - t.Process(Storage); + t.Process(VRM, Storage); meta.Thumbnail=t.Texture; } } diff --git a/Scripts/Format/glTF_VRM_Material.cs b/Scripts/Format/glTF_VRM_Material.cs index 8ed73b21f..a7eeecfae 100644 --- a/Scripts/Format/glTF_VRM_Material.cs +++ b/Scripts/Format/glTF_VRM_Material.cs @@ -98,7 +98,7 @@ namespace VRM return materials; } - public static glTF_VRM_Material CreateFromMaterial(Material m, List textures) + public static glTF_VRM_Material CreateFromMaterial(Material m, List textures) { var material = new glTF_VRM_Material { diff --git a/UniGLTF b/UniGLTF index 673a00366..debe1dcbe 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit 673a003669e78333cfc27c78417c797784fe9a36 +Subproject commit debe1dcbe02438413f1cc54c19f677fe44b01f05 From 2cea86d50060979483f3486eeea88d72dc2203e1 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 21 Jun 2018 23:10:00 +0900 Subject: [PATCH 15/22] Updated UniGLTF --- UniGLTF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UniGLTF b/UniGLTF index debe1dcbe..ff9991e92 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit debe1dcbe02438413f1cc54c19f677fe44b01f05 +Subproject commit ff9991e92f5716f584cf4d57ac5519084a0c6c2f From a3a2ded9086fd5740cf236f013581f94bd7c9b35 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 28 Jun 2018 15:05:50 +0900 Subject: [PATCH 16/22] Allow Texture not Texture2D --- Scripts/Format/glTF_VRM_Material.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Format/glTF_VRM_Material.cs b/Scripts/Format/glTF_VRM_Material.cs index a7eeecfae..5f88974c0 100644 --- a/Scripts/Format/glTF_VRM_Material.cs +++ b/Scripts/Format/glTF_VRM_Material.cs @@ -131,7 +131,7 @@ namespace VRM case ShaderUtil.ShaderPropertyType.TexEnv: { - var texture = m.GetTexture(name) as Texture2D; + var texture = m.GetTexture(name); if (texture != null) { var value = textures.IndexOf(texture); From 063b723e598341308e8a77497d9c68eb3980ebe1 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 28 Jun 2018 15:50:25 +0900 Subject: [PATCH 17/22] Fixed SpringBone export --- Scripts/SpringBone/VRMSpringUtility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/SpringBone/VRMSpringUtility.cs b/Scripts/SpringBone/VRMSpringUtility.cs index 56851b5ba..a22677dcb 100644 --- a/Scripts/SpringBone/VRMSpringUtility.cs +++ b/Scripts/SpringBone/VRMSpringUtility.cs @@ -134,7 +134,7 @@ namespace VRM } foreach (var spring in root.Traverse() - .Select(x => x.GetComponent()) + .SelectMany(x => x.GetComponents()) .Where(x => x != null)) { addSecondaryGroup(new glTF_VRM_SecondaryAnimationGroup From 857aa17ff69450ab3fb88f54f8e4145f76391a83 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 28 Jun 2018 15:51:01 +0900 Subject: [PATCH 18/22] Fixed SpringBone copy when Normalize --- Scripts/Format/Editor/VRMHumanoidNormalizerMenu.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Format/Editor/VRMHumanoidNormalizerMenu.cs b/Scripts/Format/Editor/VRMHumanoidNormalizerMenu.cs index 183f33616..8d988c774 100644 --- a/Scripts/Format/Editor/VRMHumanoidNormalizerMenu.cs +++ b/Scripts/Format/Editor/VRMHumanoidNormalizerMenu.cs @@ -100,7 +100,7 @@ namespace VRM }).ToArray(); } - foreach (var src in secondary.GetComponents()) + foreach (var src in go.transform.Traverse().SelectMany(x => x.GetComponents())) { var dst = dstSecondary.gameObject.AddComponent(); dst.m_comment = src.m_comment; From e03e51b7df6338f8304912d74b0327b078c7ab9e Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 11 Jul 2018 21:22:09 +0900 Subject: [PATCH 19/22] Fixed boneweights for mesh without boneweights in normalization --- .../Editor/BoneNormalizer.cs | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Scripts/SkinnedMeshUtility/Editor/BoneNormalizer.cs b/Scripts/SkinnedMeshUtility/Editor/BoneNormalizer.cs index 09d7bd788..ad297ebf8 100644 --- a/Scripts/SkinnedMeshUtility/Editor/BoneNormalizer.cs +++ b/Scripts/SkinnedMeshUtility/Editor/BoneNormalizer.cs @@ -170,7 +170,30 @@ namespace VRM { mesh.SetIndices(srcMesh.GetIndices(i), srcMesh.GetTopology(i), i); } - mesh.boneWeights = srcMesh.boneWeights; + + // boneweights + var bones = srcRenderer.bones.Select(x => boneMap[x]).ToArray(); + if (bones.Length > 0) + { + mesh.boneWeights = srcMesh.boneWeights; + } + else + { + Debug.LogFormat("no weight: {0}", srcMesh.name); + bones = new[] { boneMap[srcRenderer.transform] }; + var bw = new BoneWeight + { + boneIndex0 = 0, + boneIndex1 = 0, + boneIndex2 = 0, + boneIndex3 = 0, + weight0 = 1.0f, + weight1 = 0.0f, + weight2 = 0.0f, + weight3 = 0.0f, + }; + mesh.boneWeights = Enumerable.Range(0, srcMesh.vertexCount).Select(x => bw).ToArray(); + } var meshVertices = mesh.vertices; var meshNormals = mesh.normals; @@ -270,7 +293,6 @@ namespace VRM } // recalc bindposes - var bones = srcRenderer.bones.Select(x => boneMap[x]).ToArray(); mesh.bindposes = bones.Select(x => x.worldToLocalMatrix * dst.transform.localToWorldMatrix).ToArray(); From 06a9bb77c70e68b085d6e91123b7cbee500c6807 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 11 Jul 2018 21:30:58 +0900 Subject: [PATCH 20/22] Added SerializableAttribute to glTF_VRM_Material --- Scripts/Format/glTF_VRM_Material.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Scripts/Format/glTF_VRM_Material.cs b/Scripts/Format/glTF_VRM_Material.cs index 5f88974c0..7e85cbdfc 100644 --- a/Scripts/Format/glTF_VRM_Material.cs +++ b/Scripts/Format/glTF_VRM_Material.cs @@ -10,6 +10,7 @@ using UnityEditor; namespace VRM { + [Serializable] public class glTF_VRM_Material : UniGLTF.JsonSerializableBase { public string name; From f078a38f169c610e3b0adfcbc9d1ed9089ede6af Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 11 Jul 2018 21:32:37 +0900 Subject: [PATCH 21/22] Added VRM_STOP_ASSETPOSTPROCESSOR symbol --- Scripts/Format/Editor/vrmAssetPostprocessor.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Scripts/Format/Editor/vrmAssetPostprocessor.cs b/Scripts/Format/Editor/vrmAssetPostprocessor.cs index 6eb821a50..771e608c3 100644 --- a/Scripts/Format/Editor/vrmAssetPostprocessor.cs +++ b/Scripts/Format/Editor/vrmAssetPostprocessor.cs @@ -6,6 +6,7 @@ using UnityEditor; namespace VRM { +#if !VRM_STOP_ASSETPOSTPROCESSOR public class vrmAssetPostprocessor : AssetPostprocessor { static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) @@ -59,4 +60,5 @@ namespace VRM } } } +#endif } From b69a33634a262a4641d6e825f179584a4ca8ae18 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 12 Jul 2018 17:08:11 +0900 Subject: [PATCH 22/22] Updated UniGLTF --- UniGLTF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UniGLTF b/UniGLTF index ff9991e92..1d41ff08c 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit ff9991e92f5716f584cf4d57ac5519084a0c6c2f +Subproject commit 1d41ff08c25707e9b789997368bac2971f2cd78e