From 8324b5c0376cf09ecb2e6bdbda8e9e4339589113 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 7 Jun 2018 17:10:48 +0900 Subject: [PATCH] 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: