-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AvatarBuilder.BuildHumanAvatar には隠れたボーン名 HumanTrait.BoneName が必用 #1800
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
namespace UniHumanoid | ||
{ | ||
// TODO: BoneLimit.cs に分ける(v0.104以降) | ||
[Serializable] | ||
public struct BoneLimit | ||
{ | ||
|
@@ -19,26 +20,34 @@ public struct BoneLimit | |
public Vector3 max; | ||
public Vector3 center; | ||
public float axisLength; | ||
private static string[] cashedHumanTraitBoneName = null; | ||
private static readonly Dictionary<HumanBodyBones, string> cachedHumanBodyBonesToBoneNameMap = | ||
new Dictionary<HumanBodyBones, string>(); | ||
|
||
static BoneLimit() | ||
{ | ||
// 呼び出し毎にGCが発生するのでキャッシュする | ||
string[] boneNames = HumanTrait.BoneName; | ||
cashedHumanTraitBoneName = new string[boneNames.Length]; | ||
for (var i = 0; i < boneNames.Length; i++) | ||
{ | ||
cashedHumanTraitBoneName[i] = boneNames[i].Replace(" ", ""); | ||
} | ||
} | ||
|
||
// HumanTrait.BoneName は HumanBodyBones.ToString とほぼ一対一に対応するが、 | ||
// 指のボーンについては " " の有無という微妙な違いがある。 | ||
// このスペースは AvatarBuilder.BuildHumanAvatar において必用であり、 | ||
// HumanBodyBones.ToString と区別する必要がある。 | ||
// | ||
// また、下記についてGCが発生するのでキャッシュします。 | ||
// * HumanTrait.BoneName | ||
// * traitName.Replace | ||
// * Enum.Parse | ||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HumanTrait.BoneName が問題の根源 |
||
private static readonly Dictionary<HumanBodyBones, string> cachedHumanBodyBonesToBoneTraitNameMap = | ||
HumanTrait.BoneName.ToDictionary( | ||
traitName => (HumanBodyBones)Enum.Parse(typeof(HumanBodyBones), traitName.Replace(" ", "")), | ||
traitName => traitName); | ||
|
||
// 逆引き | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enum.Parse がGC出ると書いた手前、逆引きもキャッシュすることにした |
||
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, | ||
|
@@ -48,32 +57,12 @@ public static BoneLimit From(HumanBone bone) | |
}; | ||
} | ||
|
||
public static String ToHumanBoneName(HumanBodyBones b) | ||
{ | ||
if (cachedHumanBodyBonesToBoneNameMap.TryGetValue(b, out string result)) | ||
{ | ||
return result; | ||
} | ||
|
||
var bs = b.ToString(); | ||
foreach (var x in cashedHumanTraitBoneName) | ||
{ | ||
if (x == bs) | ||
{ | ||
cachedHumanBodyBonesToBoneNameMap[b] = x; | ||
return x; | ||
} | ||
} | ||
|
||
throw new KeyNotFoundException(); | ||
} | ||
|
||
public HumanBone ToHumanBone() | ||
{ | ||
return new HumanBone | ||
{ | ||
boneName = boneName, | ||
humanName = ToHumanBoneName(humanBone), | ||
humanName = cachedHumanBodyBonesToBoneTraitNameMap[humanBone], | ||
limit = new HumanLimit | ||
{ | ||
useDefaultValues = useDefaultValues, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff が分かりにくくなるので、あとで