UniVRM/Assets/UniGLTF/Runtime/UniHumanoid/HumanoidLoader.cs
ousttrue 29545202d3 UniHumanoid のフォルダ構成を整理し、不要になった asmdef を削除した。Resource/test_motion.txt の場所が変更になるのに注意。
* Assets/UniHumanoid/Scripts => Assets/UniGLTF/Runtime/Humanoid
* Assets/UniHumanoid/Editor => Assets/UniGLTF/Editor/Humanoid
* Assets/UniHumanoid/Editor/Tests => Assets/UniGLTF/Tests/Humanoid
* => docs/unihumanoid/index.md
2021-12-06 16:22:25 +09:00

51 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UniHumanoid
{
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 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);
}
}