Move ExportSecondary

This commit is contained in:
ousttrue 2018-06-07 17:10:48 +09:00
parent ca41dd359d
commit 8324b5c037
3 changed files with 82 additions and 58 deletions

View File

@ -40,64 +40,6 @@ namespace VRM
return gltf;
}
static void ExportSecondary(Transform root, List<Transform> nodes,
Action<glTF_VRM_SecondaryAnimationColliderGroup> addSecondaryColliderGroup,
Action<glTF_VRM_SecondaryAnimationGroup> addSecondaryGroup)
{
var colliders = new List<VRMSpringBoneColliderGroup>();
foreach (var vrmColliderGroup in root.Traverse()
.Select(x => x.GetComponent<VRMSpringBoneColliderGroup>())
.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<VRMSpringBone>())
.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);

View File

@ -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<Transform> nodes,
Action<glTF_VRM_SecondaryAnimationColliderGroup> addSecondaryColliderGroup,
Action<glTF_VRM_SecondaryAnimationGroup> addSecondaryGroup)
{
var colliders = new List<VRMSpringBoneColliderGroup>();
foreach (var vrmColliderGroup in root.Traverse()
.Select(x => x.GetComponent<VRMSpringBoneColliderGroup>())
.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<VRMSpringBone>())
.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(),
});
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 42564d357aca11d4882ab504d7f99166
timeCreated: 1528358605
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: