mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-09 12:11:35 -05:00
コメント追加。Enum.Parse を初期化に移動。
This commit is contained in:
parent
a0ad60240b
commit
1ef079ca58
|
|
@ -9,6 +9,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace UniHumanoid
|
||||
{
|
||||
// TODO: BoneLimit.cs に分ける(v0.104以降)
|
||||
[Serializable]
|
||||
public struct BoneLimit
|
||||
{
|
||||
|
|
@ -20,17 +21,33 @@ namespace UniHumanoid
|
|||
public Vector3 center;
|
||||
public float axisLength;
|
||||
|
||||
// HumanTrait.BoneName 呼び出し毎にGCが発生
|
||||
|
||||
// HumanTrait.BoneName は HumanBodyBones.ToString とほぼ一対一に対応するが、
|
||||
// 指のボーンについては " " の有無という微妙な違いがある。
|
||||
// このスペースは AvatarBuilder.BuildHumanAvatar において必用であり、
|
||||
// HumanBodyBones.ToString と区別する必要がある。
|
||||
//
|
||||
// また、下記についてGCが発生するのでキャッシュします。
|
||||
// * HumanTrait.BoneName
|
||||
// * traitName.Replace
|
||||
// * Enum.Parse
|
||||
//
|
||||
private static readonly Dictionary<HumanBodyBones, string> cachedHumanBodyBonesToBoneTraitNameMap =
|
||||
HumanTrait.BoneName.ToDictionary(
|
||||
traitName => (HumanBodyBones)Enum.Parse(typeof(HumanBodyBones), traitName.Replace(" ", "")),
|
||||
traitName => traitName);
|
||||
|
||||
// 逆引き
|
||||
private static readonly Dictionary<string, HumanBodyBones> cachedBoneTraitNameToHumanBodyBonesMap =
|
||||
HumanTrait.BoneName.ToDictionary(
|
||||
traitName => traitName,
|
||||
traitName => (HumanBodyBones)Enum.Parse(typeof(HumanBodyBones), traitName.Replace(" ", "")));
|
||||
|
||||
public static BoneLimit From(HumanBone bone)
|
||||
{
|
||||
return new BoneLimit
|
||||
{
|
||||
humanBone = (HumanBodyBones)Enum.Parse(typeof(HumanBodyBones), bone.humanName.Replace(" ", ""), true),
|
||||
humanBone = cachedBoneTraitNameToHumanBodyBonesMap[bone.humanName],
|
||||
boneName = bone.boneName,
|
||||
useDefaultValues = bone.limit.useDefaultValues,
|
||||
min = bone.limit.min,
|
||||
|
|
@ -40,17 +57,12 @@ namespace UniHumanoid
|
|||
};
|
||||
}
|
||||
|
||||
public static String ToHumanBoneTraitName(HumanBodyBones b)
|
||||
{
|
||||
return cachedHumanBodyBonesToBoneTraitNameMap[b];
|
||||
}
|
||||
|
||||
public HumanBone ToHumanBone()
|
||||
{
|
||||
return new HumanBone
|
||||
{
|
||||
boneName = boneName,
|
||||
humanName = ToHumanBoneTraitName(humanBone),
|
||||
humanName = cachedHumanBodyBonesToBoneTraitNameMap[humanBone],
|
||||
limit = new HumanLimit
|
||||
{
|
||||
useDefaultValues = useDefaultValues,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user