summaryrefslogtreecommitdiff
path: root/Assets/MeshUtility/Runtime/HumanoidLoader.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-11 20:00:58 +0800
committerchai <chaifix@163.com>2020-10-11 20:00:58 +0800
commit8b384dffa0d9c63c7a657c6e567c2ddefbf046cd (patch)
tree3f4d669b73b6622aa49627c4ccb3c78d51a82bde /Assets/MeshUtility/Runtime/HumanoidLoader.cs
parentcd3aee8d640f6abcc82802ca7abbcdfa031c20d3 (diff)
+Saionji show off scene
Diffstat (limited to 'Assets/MeshUtility/Runtime/HumanoidLoader.cs')
-rw-r--r--Assets/MeshUtility/Runtime/HumanoidLoader.cs60
1 files changed, 60 insertions, 0 deletions
diff --git a/Assets/MeshUtility/Runtime/HumanoidLoader.cs b/Assets/MeshUtility/Runtime/HumanoidLoader.cs
new file mode 100644
index 00000000..2a5d5252
--- /dev/null
+++ b/Assets/MeshUtility/Runtime/HumanoidLoader.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEngine;
+
+namespace MeshUtility
+{
+ public static class HumanoidLoader
+ {
+ public static Avatar LoadHumanoidAvatar(Transform root, IEnumerable<(Transform, HumanBodyBones)> boneMap)
+ {
+ var description = new HumanDescription
+ {
+ skeleton = root.GetComponentsInChildren<Transform>()
+ .Select(x => x.ToSkeletonBone()).ToArray(),
+ human = boneMap
+ .Select(x => new HumanBone
+ {
+ boneName = x.Item1.name,
+ humanName = s_humanTranitBoneNameMap[x.Item2],
+ limit = new HumanLimit
+ {
+ useDefaultValues = true,
+ }
+ }).ToArray(),
+
+ armStretch = 0.05f,
+ legStretch = 0.05f,
+ upperArmTwist = 0.5f,
+ lowerArmTwist = 0.5f,
+ upperLegTwist = 0.5f,
+ lowerLegTwist = 0.5f,
+ feetSpacing = 0,
+ hasTranslationDoF = false,
+ };
+
+ return AvatarBuilder.BuildHumanAvatar(root.gameObject, description);
+ }
+
+ static SkeletonBone ToSkeletonBone(this Transform t)
+ {
+ var sb = new SkeletonBone();
+ sb.name = t.name;
+ sb.position = t.localPosition;
+ sb.rotation = t.localRotation;
+ sb.scale = t.localScale;
+ return sb;
+ }
+
+ static HumanBodyBones TraitToHumanBone(string x)
+ {
+ return (HumanBodyBones)Enum.Parse(typeof(HumanBodyBones), x.Replace(" ", ""), true);
+ }
+
+ static readonly Dictionary<HumanBodyBones, string> s_humanTranitBoneNameMap =
+ HumanTrait.BoneName.ToDictionary(
+ x => TraitToHumanBone(x),
+ x => x);
+ }
+}