mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 14:29:52 -05:00
Move ExportSecondary
This commit is contained in:
parent
ca41dd359d
commit
8324b5c037
|
|
@ -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);
|
||||
|
|
|
|||
70
Scripts/SpringBone/VRMSpringUtility.cs
Normal file
70
Scripts/SpringBone/VRMSpringUtility.cs
Normal 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(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Scripts/SpringBone/VRMSpringUtility.cs.meta
Normal file
12
Scripts/SpringBone/VRMSpringUtility.cs.meta
Normal 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:
|
||||
Loading…
Reference in New Issue
Block a user