From bf39155bf3ea2879fa7930fae1716fe7309f3f17 Mon Sep 17 00:00:00 2001 From: tymmkang Date: Sun, 1 Feb 2026 19:20:25 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8F=AC=EB=A7=A4=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProfileSaver/Script/BaseKey3.cs | 20 +- .../ProfileSaver/Script/BoneData.cs | 22 +- .../ProfileSaver/Script/BoneSpatialData.cs | 9 +- .../Script/EdenAutoMorpher_ProfileSaver.cs | 615 ++++++++--------- .../ProfileSaver/Script/PCAData.cs | 10 +- .../ProfileSaver/Script/ProfileBVH.cs | 11 +- .../Script/ProfileBakedBodyMesh.cs | 150 ++-- .../ProfileSaver/Script/ProfileData.cs | 125 ++-- .../Script/ProfileUtil_IndexUtil.cs | 455 ++++++------ .../ProfileSaver/Script/ProfileUtils.cs | 99 ++- .../Script/ProfileUtils_BVHUtil.cs | 527 +++++++------- .../Script/ProfileUtils_BoneUtil.cs | 653 +++++++++--------- .../Script/ProfileUtils_PCAUtil.cs | 303 ++++---- .../Script/ProfileUtils_PoseUtil.cs | 267 ++++--- .../Script/ProfileUtils_VertexUtil.cs | 133 ++-- .../Script/ProfileUtils_VolumeUtil.cs | 141 ++-- .../ProfileSaver/Script/VolumeData.cs | 20 +- .../ProfileSaver/Script/profileBVHData.cs | 8 +- .../ProfileSaver/Script/profileBVHNode.cs | 14 +- 19 files changed, 1785 insertions(+), 1797 deletions(-) diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BaseKey3.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BaseKey3.cs index e682d4b..1a3fd5a 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BaseKey3.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BaseKey3.cs @@ -1,17 +1,17 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.BaseKey3 public struct BaseKey3 { - public uint x; + public uint x; - public uint y; + public uint y; - public uint z; + public uint z; - public BaseKey3(uint x, uint y, uint z) - { - this.x = x; - this.y = y; - this.z = z; - } + public BaseKey3(uint x, uint y, uint z) + { + this.x = x; + this.y = y; + this.z = z; + } } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BoneData.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BoneData.cs index 4265a9d..12b8ba7 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BoneData.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BoneData.cs @@ -1,4 +1,4 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.BoneData using System; using System.Collections.Generic; @@ -7,23 +7,23 @@ using UnityEngine; [Serializable] public class BoneData { - public int id; + public int id; - public string boneName; + public string boneName; - public string parentName; + public string parentName; - public string hierarchyPath; + public string hierarchyPath; - public HumanBodyBones hBone; + public HumanBodyBones hBone; - public int parentId; + public int parentId; - public List childrenIds; + public List childrenIds; - public Vector3 rootLocalPosition; + public Vector3 rootLocalPosition; - public Quaternion rootLocalRotation; + public Quaternion rootLocalRotation; - public Vector3 rootLocalScale; + public Vector3 rootLocalScale; } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BoneSpatialData.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BoneSpatialData.cs index ebeb3a8..aa6a930 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BoneSpatialData.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/BoneSpatialData.cs @@ -1,15 +1,14 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.BoneSpatialData using System; -using Eden.AutoMorpher.profile; using UnityEngine; [Serializable] public class BoneSpatialData { - public HumanBodyBones refBone; + public HumanBodyBones refBone; - public PCAData pcaData; + public PCAData pcaData; - public VolumeData volumeData; + public VolumeData volumeData; } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/EdenAutoMorpher_ProfileSaver.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/EdenAutoMorpher_ProfileSaver.cs index 66f312d..72acd42 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/EdenAutoMorpher_ProfileSaver.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/EdenAutoMorpher_ProfileSaver.cs @@ -1,327 +1,326 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.EdenAutoMorpher_ProfileSaver using System.Collections.Generic; using System.IO; using System.Linq; -using Eden.AutoMorpher.profile; using UnityEditor; using UnityEngine; public class EdenAutoMorpher_ProfileSaver : MonoBehaviour { - public Transform sourceAvatar; + public Transform sourceAvatar; - public List sourceBodyMeshes = new List(); + public List sourceBodyMeshes = new List(); - public string profileName; + public string profileName; - private const float adjustHigh = 1.5f; + private const float adjustHigh = 1.5f; - [ContextMenu("SaveProfile")] - public void SaveProfile() - { - Vector3 position = sourceAvatar.position; - Quaternion rotation = sourceAvatar.rotation; - Vector3 localScale = sourceAvatar.localScale; - Transform parent = sourceAvatar.parent; - sourceAvatar.SetParent(null); - sourceAvatar.position = Vector3.zero; - sourceAvatar.rotation = Quaternion.identity; - sourceAvatar.localScale = Vector3.one; - ProfileData newProfileData = new ProfileData(); - ProfileUtils profileUtils = new ProfileUtils(); - newProfileData.version = profileUtils.GetProfileVersion(); - Animator component = sourceAvatar.GetComponent(); - if (component == null) - { - Debug.LogError("[EdenAutoMorpher_ProfileSaver] Source Avatar Has No Animator\nSet Animator to Source Avatar " + sourceAvatar.name); - } - Dictionary> humanoidMeshBoneMap = profileUtils.GetHumanoidMeshBoneMap(component, sourceBodyMeshes); - List list = new List(); - foreach (SkinnedMeshRenderer sourceBodyMesh in sourceBodyMeshes) - { - list.Add(new ProfileBakedBodyMesh(sourceBodyMesh)); - } - SaveBoneData(ref newProfileData, sourceAvatar, humanoidMeshBoneMap, list); - ProfileUtils_BVHUtil profileUtils_BVHUtil = new ProfileUtils_BVHUtil(); - ProfileBVH bVHData = profileUtils_BVHUtil.GetBVHData(sourceAvatar, list); - profileUtils_BVHUtil.SaveProfileBVH(bVHData, Path.Combine(profileUtils.GetProfileBasePath(), profileName), profileName); - newProfileData.neckTargetHeight = 1.5f; - AdjustAvatarHigh(sourceAvatar, humanoidMeshBoneMap, 1.5f); - foreach (ProfileBakedBodyMesh item in list) - { - item.ReBakeMesh(); - } - SaveSpatialData(ref newProfileData, humanoidMeshBoneMap, list); - SaveProfileToJson(newProfileData, Path.Combine(profileUtils.GetProfileBasePath(), profileName), profileName); - sourceAvatar.SetParent(parent); - sourceAvatar.position = position; - sourceAvatar.rotation = rotation; - sourceAvatar.localScale = localScale; - } + [ContextMenu("SaveProfile")] + public void SaveProfile() + { + Vector3 position = this.sourceAvatar.position; + Quaternion rotation = this.sourceAvatar.rotation; + Vector3 localScale = this.sourceAvatar.localScale; + Transform parent = this.sourceAvatar.parent; + this.sourceAvatar.SetParent(null); + this.sourceAvatar.position = Vector3.zero; + this.sourceAvatar.rotation = Quaternion.identity; + this.sourceAvatar.localScale = Vector3.one; + ProfileData newProfileData = new ProfileData(); + ProfileUtils profileUtils = new ProfileUtils(); + newProfileData.version = profileUtils.GetProfileVersion(); + Animator component = this.sourceAvatar.GetComponent(); + if (component == null) + { + Debug.LogError("[EdenAutoMorpher_ProfileSaver] Source Avatar Has No Animator\nSet Animator to Source Avatar " + this.sourceAvatar.name); + } + Dictionary> humanoidMeshBoneMap = profileUtils.GetHumanoidMeshBoneMap(component, this.sourceBodyMeshes); + List list = new List(); + foreach (SkinnedMeshRenderer sourceBodyMesh in this.sourceBodyMeshes) + { + list.Add(new ProfileBakedBodyMesh(sourceBodyMesh)); + } + this.SaveBoneData(ref newProfileData, this.sourceAvatar, humanoidMeshBoneMap, list); + ProfileUtils_BVHUtil profileUtils_BVHUtil = new ProfileUtils_BVHUtil(); + ProfileBVH bVHData = profileUtils_BVHUtil.GetBVHData(this.sourceAvatar, list); + profileUtils_BVHUtil.SaveProfileBVH(bVHData, Path.Combine(profileUtils.GetProfileBasePath(), this.profileName), this.profileName); + newProfileData.neckTargetHeight = 1.5f; + this.AdjustAvatarHigh(this.sourceAvatar, humanoidMeshBoneMap, 1.5f); + foreach (ProfileBakedBodyMesh item in list) + { + item.ReBakeMesh(); + } + this.SaveSpatialData(ref newProfileData, humanoidMeshBoneMap, list); + this.SaveProfileToJson(newProfileData, Path.Combine(profileUtils.GetProfileBasePath(), this.profileName), this.profileName); + this.sourceAvatar.SetParent(parent); + this.sourceAvatar.position = position; + this.sourceAvatar.rotation = rotation; + this.sourceAvatar.localScale = localScale; + } - public void SaveSpatialData(ref ProfileData newProfileData, Dictionary> sourceBoneMap, List sourceBodyBakedMeshes) - { - ProfileUtils profileUtils = new ProfileUtils(); - HumanBodyBones[] influencedBones = new HumanBodyBones[1] { HumanBodyBones.Neck }; - newProfileData.NeckSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Neck, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.LeftUpperArm, - HumanBodyBones.LeftLowerArm, - HumanBodyBones.LeftHand - }; - newProfileData.LeftUpperArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftUpperArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.RightUpperArm, - HumanBodyBones.RightLowerArm, - HumanBodyBones.RightHand - }; - newProfileData.RightUpperArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightUpperArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLowerArm }; - newProfileData.LeftLowerArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLowerArm }; - newProfileData.RightLowerArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftHand }; - newProfileData.LeftLowerArm_HandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightHand }; - newProfileData.RightLowerArm_HandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[2] - { - HumanBodyBones.LeftUpperLeg, - HumanBodyBones.LeftLowerLeg - }; - newProfileData.LeftUpperLegSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftUpperLeg, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[2] - { - HumanBodyBones.RightUpperLeg, - HumanBodyBones.RightLowerLeg - }; - newProfileData.RightUpperLegSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightUpperLeg, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftFoot }; - newProfileData.LeftFootSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftFoot, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightFoot }; - newProfileData.RightFootSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightFoot, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.Chest }; - newProfileData.ChestSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Chest, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.UpperChest }; - newProfileData.UpperChestSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.UpperChest, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[2] - { - HumanBodyBones.Chest, - HumanBodyBones.UpperChest - }; - newProfileData.IntegratedChestSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Chest, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.Spine }; - newProfileData.SpineSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Spine, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftHand }; - newProfileData.LeftHandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftHand, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.LeftThumbProximal, - HumanBodyBones.LeftThumbIntermediate, - HumanBodyBones.LeftThumbDistal - }; - newProfileData.LeftHandThumbSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftThumbProximal }; - newProfileData.LeftHandThumbProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftThumbIntermediate }; - newProfileData.LeftHandThumbIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftThumbDistal }; - newProfileData.LeftHandThumbDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.LeftIndexProximal, - HumanBodyBones.LeftIndexIntermediate, - HumanBodyBones.LeftIndexDistal - }; - newProfileData.LeftHandIndexSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftIndexProximal }; - newProfileData.LeftHandIndexProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftIndexIntermediate }; - newProfileData.LeftHandIndexIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftIndexDistal }; - newProfileData.LeftHandIndexDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.LeftMiddleProximal, - HumanBodyBones.LeftMiddleIntermediate, - HumanBodyBones.LeftMiddleDistal - }; - newProfileData.LeftHandMiddleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftMiddleProximal }; - newProfileData.LeftHandMiddleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftMiddleIntermediate }; - newProfileData.LeftHandMiddleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftMiddleDistal }; - newProfileData.LeftHandMiddleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.LeftRingProximal, - HumanBodyBones.LeftRingIntermediate, - HumanBodyBones.LeftRingDistal - }; - newProfileData.LeftHandRingSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftRingProximal }; - newProfileData.LeftHandRingProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftRingIntermediate }; - newProfileData.LeftHandRingIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftRingDistal }; - newProfileData.LeftHandRingDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.LeftLittleProximal, - HumanBodyBones.LeftLittleIntermediate, - HumanBodyBones.LeftLittleDistal - }; - newProfileData.LeftHandLittleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLittleProximal }; - newProfileData.LeftHandLittleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLittleIntermediate }; - newProfileData.LeftHandLittleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLittleDistal }; - newProfileData.LeftHandLittleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightHand }; - newProfileData.RightHandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightHand, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.RightThumbProximal, - HumanBodyBones.RightThumbIntermediate, - HumanBodyBones.RightThumbDistal - }; - newProfileData.RightHandThumbSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightThumbProximal }; - newProfileData.RightHandThumbProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightThumbIntermediate }; - newProfileData.RightHandThumbIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightThumbDistal }; - newProfileData.RightHandThumbDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.RightIndexProximal, - HumanBodyBones.RightIndexIntermediate, - HumanBodyBones.RightIndexDistal - }; - newProfileData.RightHandIndexSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightIndexProximal }; - newProfileData.RightHandIndexProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightIndexIntermediate }; - newProfileData.RightHandIndexIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightIndexDistal }; - newProfileData.RightHandIndexDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.RightMiddleProximal, - HumanBodyBones.RightMiddleIntermediate, - HumanBodyBones.RightMiddleDistal - }; - newProfileData.RightHandMiddleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightMiddleProximal }; - newProfileData.RightHandMiddleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightMiddleIntermediate }; - newProfileData.RightHandMiddleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightMiddleDistal }; - newProfileData.RightHandMiddleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.RightRingProximal, - HumanBodyBones.RightRingIntermediate, - HumanBodyBones.RightRingDistal - }; - newProfileData.RightHandRingSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightRingProximal }; - newProfileData.RightHandRingProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightRingIntermediate }; - newProfileData.RightHandRingIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightRingDistal }; - newProfileData.RightHandRingDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[3] - { - HumanBodyBones.RightLittleProximal, - HumanBodyBones.RightLittleIntermediate, - HumanBodyBones.RightLittleDistal - }; - newProfileData.RightHandLittleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLittleProximal }; - newProfileData.RightHandLittleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLittleIntermediate }; - newProfileData.RightHandLittleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLittleDistal }; - newProfileData.RightHandLittleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); - } + public void SaveSpatialData(ref ProfileData newProfileData, Dictionary> sourceBoneMap, List sourceBodyBakedMeshes) + { + ProfileUtils profileUtils = new ProfileUtils(); + HumanBodyBones[] influencedBones = new HumanBodyBones[1] { HumanBodyBones.Neck }; + newProfileData.NeckSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Neck, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.LeftUpperArm, + HumanBodyBones.LeftLowerArm, + HumanBodyBones.LeftHand + }; + newProfileData.LeftUpperArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftUpperArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.RightUpperArm, + HumanBodyBones.RightLowerArm, + HumanBodyBones.RightHand + }; + newProfileData.RightUpperArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightUpperArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLowerArm }; + newProfileData.LeftLowerArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLowerArm }; + newProfileData.RightLowerArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftHand }; + newProfileData.LeftLowerArm_HandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightHand }; + newProfileData.RightLowerArm_HandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[2] + { + HumanBodyBones.LeftUpperLeg, + HumanBodyBones.LeftLowerLeg + }; + newProfileData.LeftUpperLegSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftUpperLeg, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[2] + { + HumanBodyBones.RightUpperLeg, + HumanBodyBones.RightLowerLeg + }; + newProfileData.RightUpperLegSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightUpperLeg, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftFoot }; + newProfileData.LeftFootSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftFoot, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightFoot }; + newProfileData.RightFootSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightFoot, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.Chest }; + newProfileData.ChestSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Chest, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.UpperChest }; + newProfileData.UpperChestSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.UpperChest, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[2] + { + HumanBodyBones.Chest, + HumanBodyBones.UpperChest + }; + newProfileData.IntegratedChestSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Chest, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.Spine }; + newProfileData.SpineSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Spine, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftHand }; + newProfileData.LeftHandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftHand, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.LeftThumbProximal, + HumanBodyBones.LeftThumbIntermediate, + HumanBodyBones.LeftThumbDistal + }; + newProfileData.LeftHandThumbSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftThumbProximal }; + newProfileData.LeftHandThumbProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftThumbIntermediate }; + newProfileData.LeftHandThumbIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftThumbDistal }; + newProfileData.LeftHandThumbDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.LeftIndexProximal, + HumanBodyBones.LeftIndexIntermediate, + HumanBodyBones.LeftIndexDistal + }; + newProfileData.LeftHandIndexSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftIndexProximal }; + newProfileData.LeftHandIndexProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftIndexIntermediate }; + newProfileData.LeftHandIndexIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftIndexDistal }; + newProfileData.LeftHandIndexDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.LeftMiddleProximal, + HumanBodyBones.LeftMiddleIntermediate, + HumanBodyBones.LeftMiddleDistal + }; + newProfileData.LeftHandMiddleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftMiddleProximal }; + newProfileData.LeftHandMiddleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftMiddleIntermediate }; + newProfileData.LeftHandMiddleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftMiddleDistal }; + newProfileData.LeftHandMiddleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.LeftRingProximal, + HumanBodyBones.LeftRingIntermediate, + HumanBodyBones.LeftRingDistal + }; + newProfileData.LeftHandRingSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftRingProximal }; + newProfileData.LeftHandRingProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftRingIntermediate }; + newProfileData.LeftHandRingIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftRingDistal }; + newProfileData.LeftHandRingDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.LeftLittleProximal, + HumanBodyBones.LeftLittleIntermediate, + HumanBodyBones.LeftLittleDistal + }; + newProfileData.LeftHandLittleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLittleProximal }; + newProfileData.LeftHandLittleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLittleIntermediate }; + newProfileData.LeftHandLittleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLittleDistal }; + newProfileData.LeftHandLittleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightHand }; + newProfileData.RightHandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightHand, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.RightThumbProximal, + HumanBodyBones.RightThumbIntermediate, + HumanBodyBones.RightThumbDistal + }; + newProfileData.RightHandThumbSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightThumbProximal }; + newProfileData.RightHandThumbProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightThumbIntermediate }; + newProfileData.RightHandThumbIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightThumbDistal }; + newProfileData.RightHandThumbDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.RightIndexProximal, + HumanBodyBones.RightIndexIntermediate, + HumanBodyBones.RightIndexDistal + }; + newProfileData.RightHandIndexSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightIndexProximal }; + newProfileData.RightHandIndexProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightIndexIntermediate }; + newProfileData.RightHandIndexIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightIndexDistal }; + newProfileData.RightHandIndexDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.RightMiddleProximal, + HumanBodyBones.RightMiddleIntermediate, + HumanBodyBones.RightMiddleDistal + }; + newProfileData.RightHandMiddleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightMiddleProximal }; + newProfileData.RightHandMiddleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightMiddleIntermediate }; + newProfileData.RightHandMiddleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightMiddleDistal }; + newProfileData.RightHandMiddleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.RightRingProximal, + HumanBodyBones.RightRingIntermediate, + HumanBodyBones.RightRingDistal + }; + newProfileData.RightHandRingSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightRingProximal }; + newProfileData.RightHandRingProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightRingIntermediate }; + newProfileData.RightHandRingIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightRingDistal }; + newProfileData.RightHandRingDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[3] + { + HumanBodyBones.RightLittleProximal, + HumanBodyBones.RightLittleIntermediate, + HumanBodyBones.RightLittleDistal + }; + newProfileData.RightHandLittleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLittleProximal }; + newProfileData.RightHandLittleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLittleIntermediate }; + newProfileData.RightHandLittleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLittleDistal }; + newProfileData.RightHandLittleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes); + } - public void SaveBoneData(ref ProfileData newProfileData, Transform sourceAvatar, Dictionary> sourceBoneMap, List sourceBodyBakedMeshes) - { - ProfileUtils profileUtils = new ProfileUtils(); - HashSet hashSet = new HashSet(); - foreach (ProfileBakedBodyMesh sourceBodyBakedMesh in sourceBodyBakedMeshes) - { - foreach (Transform bodyMeshBone in profileUtils.GetBodyMeshBones(sourceBodyBakedMesh.smr)) - { - hashSet.Add(bodyMeshBone); - } - } - if (hashSet.Count == 0) - { - Debug.LogWarning("[EdenAutoMorpher_ProfileSaver] SaveBoneData - avatarBones is empty."); - newProfileData.boneRootId = -1; - newProfileData.bones = new List(); - } - else - { - newProfileData.boneRootId = 0; - newProfileData.bones = profileUtils.GetBoneDatas(sourceAvatar, hashSet, sourceBoneMap); - } - } + public void SaveBoneData(ref ProfileData newProfileData, Transform sourceAvatar, Dictionary> sourceBoneMap, List sourceBodyBakedMeshes) + { + ProfileUtils profileUtils = new ProfileUtils(); + HashSet hashSet = new HashSet(); + foreach (ProfileBakedBodyMesh sourceBodyBakedMesh in sourceBodyBakedMeshes) + { + foreach (Transform bodyMeshBone in profileUtils.GetBodyMeshBones(sourceBodyBakedMesh.smr)) + { + hashSet.Add(bodyMeshBone); + } + } + if (hashSet.Count == 0) + { + Debug.LogWarning("[EdenAutoMorpher_ProfileSaver] SaveBoneData - avatarBones is empty."); + newProfileData.boneRootId = -1; + newProfileData.bones = new List(); + } + else + { + newProfileData.boneRootId = 0; + newProfileData.bones = profileUtils.GetBoneDatas(sourceAvatar, hashSet, sourceBoneMap); + } + } - private void AdjustAvatarHigh(Transform sourceRoot, Dictionary> sourceBoneMap, float targetHeight) - { - if (!sourceBoneMap.TryGetValue(HumanBodyBones.Neck, out var value) || value.Count == 0) - { - Debug.LogError("[EdenAutoMorpher_ProfileSaver] Can't Find Neck Bones"); - return; - } - float num = value.FirstOrDefault().position.y - sourceRoot.position.y; - if (Mathf.Approximately(num, 0f)) - { - Debug.LogWarning($"[EdenAutoMorpher_ProfileSaver] {sourceRoot.name} Neck Y가 0에 가까워 스케일 계산을 건너뜁니다. (neckY = {num})"); - return; - } - float num2 = targetHeight / num; - Vector3 localScale = sourceRoot.localScale; - localScale *= num2; - sourceRoot.localScale = localScale; - } + private void AdjustAvatarHigh(Transform sourceRoot, Dictionary> sourceBoneMap, float targetHeight) + { + if (!sourceBoneMap.TryGetValue(HumanBodyBones.Neck, out var value) || value.Count == 0) + { + Debug.LogError("[EdenAutoMorpher_ProfileSaver] Can't Find Neck Bones"); + return; + } + float num = value.FirstOrDefault().position.y - sourceRoot.position.y; + if (Mathf.Approximately(num, 0f)) + { + Debug.LogWarning($"[EdenAutoMorpher_ProfileSaver] {sourceRoot.name} Neck Y가 0에 가까워 스케일 계산을 건너뜁니다. (neckY = {num})"); + return; + } + float num2 = targetHeight / num; + Vector3 localScale = sourceRoot.localScale; + localScale *= num2; + sourceRoot.localScale = localScale; + } - private void SaveProfileToJson(ProfileData profileData, string savePath, string profileName) - { - if (profileData == null) - { - Debug.LogError("[EdenAutoMorpher_ProfileSaver] ProfileData is null. Abort save."); - return; - } - if (string.IsNullOrEmpty(profileName)) - { - Debug.LogError("[EdenAutoMorpher_ProfileSaver] profileName is empty."); - return; - } - string path = (profileName.EndsWith(".json") ? profileName : (profileName + ".json")); - string text = Path.Combine(Application.dataPath, savePath ?? string.Empty); - if (!Directory.Exists(text)) - { - Directory.CreateDirectory(text); - } - string text2 = Path.Combine(text, path); - string contents = JsonUtility.ToJson(profileData, prettyPrint: true); - File.WriteAllText(text2, contents); - Debug.Log("[EdenAutoMorpher_ProfileSaver] Profile saved successfully.\nPath: " + text2); - AssetDatabase.Refresh(); - } + private void SaveProfileToJson(ProfileData profileData, string savePath, string profileName) + { + if (profileData == null) + { + Debug.LogError("[EdenAutoMorpher_ProfileSaver] ProfileData is null. Abort save."); + return; + } + if (string.IsNullOrEmpty(profileName)) + { + Debug.LogError("[EdenAutoMorpher_ProfileSaver] profileName is empty."); + return; + } + string path = (profileName.EndsWith(".json") ? profileName : (profileName + ".json")); + string text = Path.Combine(Application.dataPath, savePath ?? string.Empty); + if (!Directory.Exists(text)) + { + Directory.CreateDirectory(text); + } + string text2 = Path.Combine(text, path); + string contents = JsonUtility.ToJson(profileData, prettyPrint: true); + File.WriteAllText(text2, contents); + Debug.Log("[EdenAutoMorpher_ProfileSaver] Profile saved successfully.\nPath: " + text2); + AssetDatabase.Refresh(); + } - public bool IsExistBaseData() - { - ProfileUtils profileUtils = new ProfileUtils(); - return File.Exists(Path.Combine(Application.dataPath, profileUtils.GetBaseDataPath())); - } + public bool IsExistBaseData() + { + ProfileUtils profileUtils = new ProfileUtils(); + return File.Exists(Path.Combine(Application.dataPath, profileUtils.GetBaseDataPath())); + } } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/PCAData.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/PCAData.cs index 1dd77c9..7f436a3 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/PCAData.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/PCAData.cs @@ -1,4 +1,4 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.PCAData using System; using UnityEngine; @@ -6,11 +6,11 @@ using UnityEngine; [Serializable] public class PCAData { - public Vector3 pcaCenter; + public Vector3 pcaCenter; - public Vector3 pcaPrincipalAxis; + public Vector3 pcaPrincipalAxis; - public float pcaLength; + public float pcaLength; - public float pcaAvgRadius; + public float pcaAvgRadius; } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileBVH.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileBVH.cs index 8a07ebf..134567f 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileBVH.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileBVH.cs @@ -1,16 +1,15 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.ProfileBVH using System.Collections.Generic; -using Eden.AutoMorpher.profile; using UnityEngine; public class ProfileBVH { - public List vertices; + public List vertices; - public profileBVHData[] datas; + public profileBVHData[] datas; - public profileBVHNode[] nodes; + public profileBVHNode[] nodes; - public int[] dataIndices; + public int[] dataIndices; } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileBakedBodyMesh.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileBakedBodyMesh.cs index 18f0241..f9b8498 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileBakedBodyMesh.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileBakedBodyMesh.cs @@ -1,89 +1,89 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.ProfileBakedBodyMesh using UnityEngine; public class ProfileBakedBodyMesh { - public SkinnedMeshRenderer smr; + public SkinnedMeshRenderer smr; - public Mesh bakedMesh; + public Mesh bakedMesh; - public Vector3[] worldVertices; + public Vector3[] worldVertices; - public BoneWeight[] boneWeights - { - get - { - if (!(smr != null)) - { - return null; - } - return smr.sharedMesh.boneWeights; - } - } + public BoneWeight[] boneWeights + { + get + { + if (!(this.smr != null)) + { + return null; + } + return this.smr.sharedMesh.boneWeights; + } + } - public Transform[] bones - { - get - { - if (!(smr != null)) - { - return null; - } - return smr.bones; - } - } + public Transform[] bones + { + get + { + if (!(this.smr != null)) + { + return null; + } + return this.smr.bones; + } + } - public ProfileBakedBodyMesh(SkinnedMeshRenderer _smr) - { - if (_smr == null) - { - Debug.LogError("[ProfileUtil - ProfileBakedBodyMesh] BakeBodyMesh Init : SkinnedMeshRenderer " + _smr.gameObject.name + " is null"); - } - smr = _smr; - if (_smr.sharedMesh == null) - { - Debug.LogError("[ProfileUtil - ProfileBakedBodyMesh] BakeBodyMesh Init : SkinnedMeshRenderer " + _smr.gameObject.name + " has null sharedMesh."); - } - bakedMesh = new Mesh(); - smr.BakeMesh(bakedMesh); - worldVertices = CalculateWorldVertices(smr, bakedMesh); - } + public ProfileBakedBodyMesh(SkinnedMeshRenderer _smr) + { + if (_smr == null) + { + Debug.LogError("[ProfileUtil - ProfileBakedBodyMesh] BakeBodyMesh Init : SkinnedMeshRenderer " + _smr.gameObject.name + " is null"); + } + this.smr = _smr; + if (_smr.sharedMesh == null) + { + Debug.LogError("[ProfileUtil - ProfileBakedBodyMesh] BakeBodyMesh Init : SkinnedMeshRenderer " + _smr.gameObject.name + " has null sharedMesh."); + } + this.bakedMesh = new Mesh(); + this.smr.BakeMesh(this.bakedMesh); + this.worldVertices = this.CalculateWorldVertices(this.smr, this.bakedMesh); + } - public void ReBakeMesh() - { - smr.BakeMesh(bakedMesh); - worldVertices = CalculateWorldVertices(smr, bakedMesh); - } + public void ReBakeMesh() + { + this.smr.BakeMesh(this.bakedMesh); + this.worldVertices = this.CalculateWorldVertices(this.smr, this.bakedMesh); + } - ~ProfileBakedBodyMesh() - { - smr = null; - bakedMesh = null; - } + ~ProfileBakedBodyMesh() + { + this.smr = null; + this.bakedMesh = null; + } - private Vector3[] CalculateWorldVertices(SkinnedMeshRenderer smr, Mesh bakedMesh) - { - if (smr == null) - { - Debug.LogError("[ProfileUtil - ProfileBakedBodyMesh] CalculateWorldVertices: smr " + smr.gameObject.name + " == null"); - return null; - } - if (bakedMesh == null) - { - return null; - } - Transform transform = smr.transform; - Vector3 lossyScale = transform.lossyScale; - Vector3 vector = new Vector3(1f / Mathf.Max(lossyScale.x, 1E-08f), 1f / Mathf.Max(lossyScale.y, 1E-08f), 1f / Mathf.Max(lossyScale.z, 1E-08f)); - Matrix4x4 matrix4x = transform.localToWorldMatrix * Matrix4x4.Scale(vector); - Vector3[] vertices = bakedMesh.vertices; - int num = vertices.Length; - Vector3[] array = new Vector3[num]; - for (int i = 0; i < num; i++) - { - array[i] = matrix4x.MultiplyPoint3x4(vertices[i]); - } - return array; - } + private Vector3[] CalculateWorldVertices(SkinnedMeshRenderer smr, Mesh bakedMesh) + { + if (smr == null) + { + Debug.LogError("[ProfileUtil - ProfileBakedBodyMesh] CalculateWorldVertices: smr " + smr.gameObject.name + " == null"); + return null; + } + if (bakedMesh == null) + { + return null; + } + Transform transform = smr.transform; + Vector3 lossyScale = transform.lossyScale; + Vector3 vector = new Vector3(1f / Mathf.Max(lossyScale.x, 1E-08f), 1f / Mathf.Max(lossyScale.y, 1E-08f), 1f / Mathf.Max(lossyScale.z, 1E-08f)); + Matrix4x4 matrix4x = transform.localToWorldMatrix * Matrix4x4.Scale(vector); + Vector3[] vertices = bakedMesh.vertices; + int num = vertices.Length; + Vector3[] array = new Vector3[num]; + for (int i = 0; i < num; i++) + { + array[i] = matrix4x.MultiplyPoint3x4(vertices[i]); + } + return array; + } } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileData.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileData.cs index 8e9a5f5..cfe5183 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileData.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileData.cs @@ -1,131 +1,130 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.ProfileData using System; using System.Collections.Generic; -using Eden.AutoMorpher.profile; [Serializable] public class ProfileData { - public int version = 1; + public int version = 1; - public float neckTargetHeight = 1.5f; + public float neckTargetHeight = 1.5f; - public BoneSpatialData NeckSpatialData; + public BoneSpatialData NeckSpatialData; - public BoneSpatialData LeftUpperArmSpatialData; + public BoneSpatialData LeftUpperArmSpatialData; - public BoneSpatialData RightUpperArmSpatialData; + public BoneSpatialData RightUpperArmSpatialData; - public BoneSpatialData LeftLowerArmSpatialData; + public BoneSpatialData LeftLowerArmSpatialData; - public BoneSpatialData RightLowerArmSpatialData; + public BoneSpatialData RightLowerArmSpatialData; - public BoneSpatialData LeftLowerArm_HandSpatialData; + public BoneSpatialData LeftLowerArm_HandSpatialData; - public BoneSpatialData RightLowerArm_HandSpatialData; + public BoneSpatialData RightLowerArm_HandSpatialData; - public BoneSpatialData LeftUpperLegSpatialData; + public BoneSpatialData LeftUpperLegSpatialData; - public BoneSpatialData RightUpperLegSpatialData; + public BoneSpatialData RightUpperLegSpatialData; - public BoneSpatialData LeftFootSpatialData; + public BoneSpatialData LeftFootSpatialData; - public BoneSpatialData RightFootSpatialData; + public BoneSpatialData RightFootSpatialData; - public BoneSpatialData ChestSpatialData; + public BoneSpatialData ChestSpatialData; - public BoneSpatialData UpperChestSpatialData; + public BoneSpatialData UpperChestSpatialData; - public BoneSpatialData IntegratedChestSpatialData; + public BoneSpatialData IntegratedChestSpatialData; - public BoneSpatialData SpineSpatialData; + public BoneSpatialData SpineSpatialData; - public BoneSpatialData LeftHandSpatialData; + public BoneSpatialData LeftHandSpatialData; - public BoneSpatialData LeftHandThumbSpatialData; + public BoneSpatialData LeftHandThumbSpatialData; - public BoneSpatialData LeftHandThumbProximalSpatialData; + public BoneSpatialData LeftHandThumbProximalSpatialData; - public BoneSpatialData LeftHandThumbIntermediateSpatialData; + public BoneSpatialData LeftHandThumbIntermediateSpatialData; - public BoneSpatialData LeftHandThumbDistalSpatialData; + public BoneSpatialData LeftHandThumbDistalSpatialData; - public BoneSpatialData LeftHandIndexSpatialData; + public BoneSpatialData LeftHandIndexSpatialData; - public BoneSpatialData LeftHandIndexProximalSpatialData; + public BoneSpatialData LeftHandIndexProximalSpatialData; - public BoneSpatialData LeftHandIndexIntermediateSpatialData; + public BoneSpatialData LeftHandIndexIntermediateSpatialData; - public BoneSpatialData LeftHandIndexDistalSpatialData; + public BoneSpatialData LeftHandIndexDistalSpatialData; - public BoneSpatialData LeftHandMiddleSpatialData; + public BoneSpatialData LeftHandMiddleSpatialData; - public BoneSpatialData LeftHandMiddleProximalSpatialData; + public BoneSpatialData LeftHandMiddleProximalSpatialData; - public BoneSpatialData LeftHandMiddleIntermediateSpatialData; + public BoneSpatialData LeftHandMiddleIntermediateSpatialData; - public BoneSpatialData LeftHandMiddleDistalSpatialData; + public BoneSpatialData LeftHandMiddleDistalSpatialData; - public BoneSpatialData LeftHandRingSpatialData; + public BoneSpatialData LeftHandRingSpatialData; - public BoneSpatialData LeftHandRingProximalSpatialData; + public BoneSpatialData LeftHandRingProximalSpatialData; - public BoneSpatialData LeftHandRingIntermediateSpatialData; + public BoneSpatialData LeftHandRingIntermediateSpatialData; - public BoneSpatialData LeftHandRingDistalSpatialData; + public BoneSpatialData LeftHandRingDistalSpatialData; - public BoneSpatialData LeftHandLittleSpatialData; + public BoneSpatialData LeftHandLittleSpatialData; - public BoneSpatialData LeftHandLittleProximalSpatialData; + public BoneSpatialData LeftHandLittleProximalSpatialData; - public BoneSpatialData LeftHandLittleIntermediateSpatialData; + public BoneSpatialData LeftHandLittleIntermediateSpatialData; - public BoneSpatialData LeftHandLittleDistalSpatialData; + public BoneSpatialData LeftHandLittleDistalSpatialData; - public BoneSpatialData RightHandSpatialData; + public BoneSpatialData RightHandSpatialData; - public BoneSpatialData RightHandThumbSpatialData; + public BoneSpatialData RightHandThumbSpatialData; - public BoneSpatialData RightHandThumbProximalSpatialData; + public BoneSpatialData RightHandThumbProximalSpatialData; - public BoneSpatialData RightHandThumbIntermediateSpatialData; + public BoneSpatialData RightHandThumbIntermediateSpatialData; - public BoneSpatialData RightHandThumbDistalSpatialData; + public BoneSpatialData RightHandThumbDistalSpatialData; - public BoneSpatialData RightHandIndexSpatialData; + public BoneSpatialData RightHandIndexSpatialData; - public BoneSpatialData RightHandIndexProximalSpatialData; + public BoneSpatialData RightHandIndexProximalSpatialData; - public BoneSpatialData RightHandIndexIntermediateSpatialData; + public BoneSpatialData RightHandIndexIntermediateSpatialData; - public BoneSpatialData RightHandIndexDistalSpatialData; + public BoneSpatialData RightHandIndexDistalSpatialData; - public BoneSpatialData RightHandMiddleSpatialData; + public BoneSpatialData RightHandMiddleSpatialData; - public BoneSpatialData RightHandMiddleProximalSpatialData; + public BoneSpatialData RightHandMiddleProximalSpatialData; - public BoneSpatialData RightHandMiddleIntermediateSpatialData; + public BoneSpatialData RightHandMiddleIntermediateSpatialData; - public BoneSpatialData RightHandMiddleDistalSpatialData; + public BoneSpatialData RightHandMiddleDistalSpatialData; - public BoneSpatialData RightHandRingSpatialData; + public BoneSpatialData RightHandRingSpatialData; - public BoneSpatialData RightHandRingProximalSpatialData; + public BoneSpatialData RightHandRingProximalSpatialData; - public BoneSpatialData RightHandRingIntermediateSpatialData; + public BoneSpatialData RightHandRingIntermediateSpatialData; - public BoneSpatialData RightHandRingDistalSpatialData; + public BoneSpatialData RightHandRingDistalSpatialData; - public BoneSpatialData RightHandLittleSpatialData; + public BoneSpatialData RightHandLittleSpatialData; - public BoneSpatialData RightHandLittleProximalSpatialData; + public BoneSpatialData RightHandLittleProximalSpatialData; - public BoneSpatialData RightHandLittleIntermediateSpatialData; + public BoneSpatialData RightHandLittleIntermediateSpatialData; - public BoneSpatialData RightHandLittleDistalSpatialData; + public BoneSpatialData RightHandLittleDistalSpatialData; - public int boneRootId; + public int boneRootId; - public List bones; + public List bones; } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtil_IndexUtil.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtil_IndexUtil.cs index 6244f26..ec3f50c 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtil_IndexUtil.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtil_IndexUtil.cs @@ -1,265 +1,264 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.ProfileUtil_IndexUtil -using Eden.AutoMorpher.profile; using UnityEngine; public class ProfileUtil_IndexUtil { - public class BlockPermutations - { - private struct XorShift32 - { - private uint _state; + public class BlockPermutations + { + private struct XorShift32 + { + private uint _state; - public XorShift32(uint seed) - { - _state = ((seed != 0) ? seed : 1831565813u); - } + public XorShift32(uint seed) + { + this._state = ((seed != 0) ? seed : 1831565813u); + } - public uint NextUInt() - { - uint state = _state; - state ^= state << 13; - state ^= state >> 17; - return _state = state ^ (state << 5); - } + public uint NextUInt() + { + uint state = this._state; + state ^= state << 13; + state ^= state >> 17; + return this._state = state ^ (state << 5); + } - public int NextInt(int maxExclusive) - { - return (int)(NextUInt() % (uint)maxExclusive); - } - } + public int NextInt(int maxExclusive) + { + return (int)(this.NextUInt() % (uint)maxExclusive); + } + } - private readonly int _blockSize; + private readonly int _blockSize; - private int[] _px; + private int[] _px; - private int[] _py; + private int[] _py; - private int[] _pz; + private int[] _pz; - private int[] _pall; + private int[] _pall; - private uint _checksum; + private uint _checksum; - private int _cachedLen = -1; + private int _cachedLen = -1; - private int[] _pxLen; + private int[] _pxLen; - private int[] _pyLen; + private int[] _pyLen; - private int[] _pzLen; + private int[] _pzLen; - private int[] _pallLen; + private int[] _pallLen; - public BlockPermutations(int blockSize) - { - _blockSize = blockSize; - } + public BlockPermutations(int blockSize) + { + this._blockSize = blockSize; + } - public void Build(int seed) - { - if (_blockSize <= 1) - { - Debug.LogError("[ProfileUtil_IndexUtil] BlockPermutations.Build - invalid blockSize"); - return; - } - XorShift32 rng = new XorShift32((uint)(seed ^ -1556008596)); - XorShift32 rng2 = new XorShift32((uint)(seed ^ -939442524)); - XorShift32 rng3 = new XorShift32((uint)(seed ^ -1383041155)); - XorShift32 rng4 = new XorShift32((uint)(seed ^ 0x7E95761E)); - _px = MakePermutation(_blockSize, ref rng); - _py = MakePermutation(_blockSize, ref rng2); - _pz = MakePermutation(_blockSize, ref rng3); - _pall = MakePermutation(_blockSize, ref rng4); - _checksum = ComputeChecksum(_px, _py, _pz, _pall); - _cachedLen = -1; - _pxLen = (_pyLen = (_pzLen = (_pallLen = null))); - } + public void Build(int seed) + { + if (this._blockSize <= 1) + { + Debug.LogError("[ProfileUtil_IndexUtil] BlockPermutations.Build - invalid blockSize"); + return; + } + XorShift32 rng = new XorShift32((uint)(seed ^ -1556008596)); + XorShift32 rng2 = new XorShift32((uint)(seed ^ -939442524)); + XorShift32 rng3 = new XorShift32((uint)(seed ^ -1383041155)); + XorShift32 rng4 = new XorShift32((uint)(seed ^ 0x7E95761E)); + this._px = this.MakePermutation(this._blockSize, ref rng); + this._py = this.MakePermutation(this._blockSize, ref rng2); + this._pz = this.MakePermutation(this._blockSize, ref rng3); + this._pall = this.MakePermutation(this._blockSize, ref rng4); + this._checksum = this.ComputeChecksum(this._px, this._py, this._pz, this._pall); + this._cachedLen = -1; + this._pxLen = (this._pyLen = (this._pzLen = (this._pallLen = null))); + } - public bool ValidateRebuild(int seed) - { - uint checksum = _checksum; - BlockPermutations blockPermutations = new BlockPermutations(_blockSize); - blockPermutations.Build(seed); - return blockPermutations._checksum == checksum; - } + public bool ValidateRebuild(int seed) + { + uint checksum = this._checksum; + BlockPermutations blockPermutations = new BlockPermutations(this._blockSize); + blockPermutations.Build(seed); + return blockPermutations._checksum == checksum; + } - public void GetPermutationsForLen(int len, out int[] pxUse, out int[] pyUse, out int[] pzUse, out int[] pallUse) - { - if (len == _blockSize) - { - pxUse = _px; - pyUse = _py; - pzUse = _pz; - pallUse = _pall; - return; - } - if (_cachedLen != len) - { - _cachedLen = len; - _pxLen = MakeSubPermutation(_px, len); - _pyLen = MakeSubPermutation(_py, len); - _pzLen = MakeSubPermutation(_pz, len); - _pallLen = MakeSubPermutation(_pall, len); - } - pxUse = _pxLen; - pyUse = _pyLen; - pzUse = _pzLen; - pallUse = _pallLen; - } + public void GetPermutationsForLen(int len, out int[] pxUse, out int[] pyUse, out int[] pzUse, out int[] pallUse) + { + if (len == this._blockSize) + { + pxUse = this._px; + pyUse = this._py; + pzUse = this._pz; + pallUse = this._pall; + return; + } + if (this._cachedLen != len) + { + this._cachedLen = len; + this._pxLen = this.MakeSubPermutation(this._px, len); + this._pyLen = this.MakeSubPermutation(this._py, len); + this._pzLen = this.MakeSubPermutation(this._pz, len); + this._pallLen = this.MakeSubPermutation(this._pall, len); + } + pxUse = this._pxLen; + pyUse = this._pyLen; + pzUse = this._pzLen; + pallUse = this._pallLen; + } - private int[] MakeSubPermutation(int[] fullPerm, int len) - { - int[] array = new int[len]; - int num = 0; - for (int i = 0; i < fullPerm.Length; i++) - { - if (num >= len) - { - break; - } - int num2 = fullPerm[i]; - if (num2 < len) - { - array[num++] = num2; - } - } - return array; - } + private int[] MakeSubPermutation(int[] fullPerm, int len) + { + int[] array = new int[len]; + int num = 0; + for (int i = 0; i < fullPerm.Length; i++) + { + if (num >= len) + { + break; + } + int num2 = fullPerm[i]; + if (num2 < len) + { + array[num++] = num2; + } + } + return array; + } - private int[] MakePermutation(int n, ref XorShift32 rng) - { - int[] array = new int[n]; - for (int i = 0; i < n; i++) - { - array[i] = i; - } - for (int num = n - 1; num > 0; num--) - { - int num2 = rng.NextInt(num + 1); - ref int reference = ref array[num]; - ref int reference2 = ref array[num2]; - int num3 = array[num2]; - int num4 = array[num]; - reference = num3; - reference2 = num4; - } - return array; - } + private int[] MakePermutation(int n, ref XorShift32 rng) + { + int[] array = new int[n]; + for (int i = 0; i < n; i++) + { + array[i] = i; + } + for (int num = n - 1; num > 0; num--) + { + int num2 = rng.NextInt(num + 1); + ref int reference = ref array[num]; + ref int reference2 = ref array[num2]; + int num3 = array[num2]; + int num4 = array[num]; + reference = num3; + reference2 = num4; + } + return array; + } - private uint ComputeChecksum(int[] a, int[] b, int[] c, int[] d) - { - uint h = 2166136261u; - MixArray(ref h, a); - MixArray(ref h, b); - MixArray(ref h, c); - MixArray(ref h, d); - return h; - } + private uint ComputeChecksum(int[] a, int[] b, int[] c, int[] d) + { + uint h = 2166136261u; + this.MixArray(ref h, a); + this.MixArray(ref h, b); + this.MixArray(ref h, c); + this.MixArray(ref h, d); + return h; + } - private void MixArray(ref uint h, int[] arr) - { - for (int i = 0; i < arr.Length; i++) - { - uint num = (uint)arr[i]; - h ^= num; - h *= 16777619u; - } - } - } + private void MixArray(ref uint h, int[] arr) + { + for (int i = 0; i < arr.Length; i++) + { + uint num = (uint)arr[i]; + h ^= num; + h *= 16777619u; + } + } + } - public readonly int blockSize = 9783; + public readonly int blockSize = 9783; - private readonly BlockPermutations _perm; + private readonly BlockPermutations _perm; - private float[] _xTmp; + private float[] _xTmp; - private float[] _yTmp; + private float[] _yTmp; - private float[] _zTmp; + private float[] _zTmp; - public ProfileUtil_IndexUtil(int blockSize = 9783) - { - this.blockSize = blockSize; - _perm = new BlockPermutations(blockSize); - _xTmp = new float[blockSize]; - _yTmp = new float[blockSize]; - _zTmp = new float[blockSize]; - } + public ProfileUtil_IndexUtil(int blockSize = 9783) + { + this.blockSize = blockSize; + this._perm = new BlockPermutations(blockSize); + this._xTmp = new float[blockSize]; + this._yTmp = new float[blockSize]; + this._zTmp = new float[blockSize]; + } - public void Build(int seed) - { - _perm.Build(seed); - } + public void Build(int seed) + { + this._perm.Build(seed); + } - public void EncodeInto(Vector3[] input, Vector3[] output) - { - if (input == null || output == null) - { - Debug.LogError("[ProfileUtil_IndexUtil] EncodeInto - null args"); - return; - } - if (output.Length < input.Length) - { - Debug.LogError("[ProfileUtil_IndexUtil] EncodeInto - output too small"); - return; - } - int num = input.Length; - int num2 = blockSize; - int num3 = (num + num2 - 1) / num2; - for (int i = 0; i < num3; i++) - { - int num4 = i * num2; - int num5 = Mathf.Min(num2, num - num4); - _perm.GetPermutationsForLen(num5, out var pxUse, out var pyUse, out var pzUse, out var pallUse); - for (int j = 0; j < num5; j++) - { - Vector3 vector = input[num4 + j]; - _xTmp[pxUse[j]] = vector.x; - _yTmp[pyUse[j]] = vector.y; - _zTmp[pzUse[j]] = vector.z; - } - for (int k = 0; k < num5; k++) - { - int num6 = pallUse[k]; - output[num4 + num6] = new Vector3(_xTmp[k], _yTmp[k], _zTmp[k]); - } - } - } + public void EncodeInto(Vector3[] input, Vector3[] output) + { + if (input == null || output == null) + { + Debug.LogError("[ProfileUtil_IndexUtil] EncodeInto - null args"); + return; + } + if (output.Length < input.Length) + { + Debug.LogError("[ProfileUtil_IndexUtil] EncodeInto - output too small"); + return; + } + int num = input.Length; + int num2 = this.blockSize; + int num3 = (num + num2 - 1) / num2; + for (int i = 0; i < num3; i++) + { + int num4 = i * num2; + int num5 = Mathf.Min(num2, num - num4); + this._perm.GetPermutationsForLen(num5, out var pxUse, out var pyUse, out var pzUse, out var pallUse); + for (int j = 0; j < num5; j++) + { + Vector3 vector = input[num4 + j]; + this._xTmp[pxUse[j]] = vector.x; + this._yTmp[pyUse[j]] = vector.y; + this._zTmp[pzUse[j]] = vector.z; + } + for (int k = 0; k < num5; k++) + { + int num6 = pallUse[k]; + output[num4 + num6] = new Vector3(this._xTmp[k], this._yTmp[k], this._zTmp[k]); + } + } + } - public void DecodeInto(Vector3[] encoded, Vector3[] output) - { - if (encoded == null || output == null) - { - Debug.LogError("[ProfileUtil_IndexUtil] DecodeInto - null args"); - return; - } - if (output.Length < encoded.Length) - { - Debug.LogError("[ProfileUtil_IndexUtil] DecodeInto - output too small"); - return; - } - int num = encoded.Length; - int num2 = blockSize; - int num3 = (num + num2 - 1) / num2; - for (int i = 0; i < num3; i++) - { - int num4 = i * num2; - int num5 = Mathf.Min(num2, num - num4); - _perm.GetPermutationsForLen(num5, out var pxUse, out var pyUse, out var pzUse, out var pallUse); - for (int j = 0; j < num5; j++) - { - int num6 = pallUse[j]; - Vector3 vector = encoded[num4 + num6]; - _xTmp[j] = vector.x; - _yTmp[j] = vector.y; - _zTmp[j] = vector.z; - } - for (int k = 0; k < num5; k++) - { - output[num4 + k] = new Vector3(_xTmp[pxUse[k]], _yTmp[pyUse[k]], _zTmp[pzUse[k]]); - } - } - } + public void DecodeInto(Vector3[] encoded, Vector3[] output) + { + if (encoded == null || output == null) + { + Debug.LogError("[ProfileUtil_IndexUtil] DecodeInto - null args"); + return; + } + if (output.Length < encoded.Length) + { + Debug.LogError("[ProfileUtil_IndexUtil] DecodeInto - output too small"); + return; + } + int num = encoded.Length; + int num2 = this.blockSize; + int num3 = (num + num2 - 1) / num2; + for (int i = 0; i < num3; i++) + { + int num4 = i * num2; + int num5 = Mathf.Min(num2, num - num4); + this._perm.GetPermutationsForLen(num5, out var pxUse, out var pyUse, out var pzUse, out var pallUse); + for (int j = 0; j < num5; j++) + { + int num6 = pallUse[j]; + Vector3 vector = encoded[num4 + num6]; + this._xTmp[j] = vector.x; + this._yTmp[j] = vector.y; + this._zTmp[j] = vector.z; + } + for (int k = 0; k < num5; k++) + { + output[num4 + k] = new Vector3(this._xTmp[pxUse[k]], this._yTmp[pyUse[k]], this._zTmp[pzUse[k]]); + } + } + } } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils.cs index ec7f38e..6173389 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils.cs @@ -1,73 +1,72 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.ProfileUtils using System.Collections.Generic; -using Eden.AutoMorpher.profile; using UnityEngine; public class ProfileUtils { - private ProfileUtils_BoneUtil boneUtil; + private ProfileUtils_BoneUtil boneUtil; - private ProfileUtils_PoseUtil poseUtil; + private ProfileUtils_PoseUtil poseUtil; - private string profileBasePath = "@Eden_Tools\\Eden_AutoMorpher\\Profiles"; + private string profileBasePath = "@Eden_Tools\\Eden_AutoMorpher\\Profiles"; - private string baseDataPath = "@Eden_Tools\\Eden_AutoMorpher\\ProfileSaver\\BaseData\\base.vb"; + private string baseDataPath = "@Eden_Tools\\Eden_AutoMorpher\\ProfileSaver\\BaseData\\base.vb"; - private int profileVersion = 1; + private int profileVersion = 1; - private string profileMagic = "PBVH"; + private string profileMagic = "PBVH"; - private string baseMagic = "PVTB"; + private string baseMagic = "PVTB"; - public ProfileUtils() - { - boneUtil = new ProfileUtils_BoneUtil(); - poseUtil = new ProfileUtils_PoseUtil(); - } + public ProfileUtils() + { + this.boneUtil = new ProfileUtils_BoneUtil(); + this.poseUtil = new ProfileUtils_PoseUtil(); + } - public string GetProfileBasePath() - { - return profileBasePath; - } + public string GetProfileBasePath() + { + return this.profileBasePath; + } - public string GetBaseDataPath() - { - return baseDataPath; - } + public string GetBaseDataPath() + { + return this.baseDataPath; + } - public int GetProfileVersion() - { - return profileVersion; - } + public int GetProfileVersion() + { + return this.profileVersion; + } - public string GetProfileMagic() - { - return profileMagic; - } + public string GetProfileMagic() + { + return this.profileMagic; + } - public string GetBaseMagic() - { - return baseMagic; - } + public string GetBaseMagic() + { + return this.baseMagic; + } - public Dictionary> GetHumanoidMeshBoneMap(Animator animator, IReadOnlyList bodyMeshes, float posTolerance = 0.0001f, float weightThreshold = 0.0001f) - { - return boneUtil.GetHumanoidMeshBoneMap(animator, bodyMeshes, posTolerance, weightThreshold); - } + public Dictionary> GetHumanoidMeshBoneMap(Animator animator, IReadOnlyList bodyMeshes, float posTolerance = 0.0001f, float weightThreshold = 0.0001f) + { + return this.boneUtil.GetHumanoidMeshBoneMap(animator, bodyMeshes, posTolerance, weightThreshold); + } - public BoneSpatialData GetBoneSpatialData(HumanBodyBones refBone, HumanBodyBones[] influencedBones, Dictionary> boneMap, List sourceBodyBakedMeshes, bool addChildBones = false) - { - return poseUtil.GetBoneSpatialData(refBone, influencedBones, boneMap, sourceBodyBakedMeshes, addChildBones); - } + public BoneSpatialData GetBoneSpatialData(HumanBodyBones refBone, HumanBodyBones[] influencedBones, Dictionary> boneMap, List sourceBodyBakedMeshes, bool addChildBones = false) + { + return this.poseUtil.GetBoneSpatialData(refBone, influencedBones, boneMap, sourceBodyBakedMeshes, addChildBones); + } - public HashSet GetBodyMeshBones(SkinnedMeshRenderer smr, float weightThreshold = 0.0001f) - { - return boneUtil.GetBodyMeshBones(smr, weightThreshold); - } + public HashSet GetBodyMeshBones(SkinnedMeshRenderer smr, float weightThreshold = 0.0001f) + { + return this.boneUtil.GetBodyMeshBones(smr, weightThreshold); + } - public List GetBoneDatas(Transform rootTransform, HashSet avatarBones, Dictionary> sourceBoneMap) - { - return boneUtil.GetBoneDatas(rootTransform, avatarBones, sourceBoneMap); - } + public List GetBoneDatas(Transform rootTransform, HashSet avatarBones, Dictionary> sourceBoneMap) + { + return this.boneUtil.GetBoneDatas(rootTransform, avatarBones, sourceBoneMap); + } } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_BVHUtil.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_BVHUtil.cs index 2b96ec5..9e8085a 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_BVHUtil.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_BVHUtil.cs @@ -1,284 +1,283 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.ProfileUtils_BVHUtil using System; using System.Collections.Generic; using System.IO; using System.Text; -using Eden.AutoMorpher.profile; using UnityEngine; public class ProfileUtils_BVHUtil { - private const int LeafMaxTriangles = 4; + private const int LeafMaxTriangles = 4; - public ProfileBVH GetBVHData(Transform rootTransform, List bakedBodyMeshes) - { - return BuildFromSkinnedMeshes(rootTransform, bakedBodyMeshes); - } + public ProfileBVH GetBVHData(Transform rootTransform, List bakedBodyMeshes) + { + return this.BuildFromSkinnedMeshes(rootTransform, bakedBodyMeshes); + } - public ProfileBVH BuildFromSkinnedMeshes(Transform rootTransform, List bakedBodyMeshes) - { - ProfileBVH profileBVH = new ProfileBVH - { - vertices = new List(1024) - }; - int num = 0; - foreach (ProfileBakedBodyMesh bakedBodyMesh in bakedBodyMeshes) - { - if (bakedBodyMesh != null && !(bakedBodyMesh.smr == null) && !(bakedBodyMesh.smr.sharedMesh == null)) - { - num += bakedBodyMesh.smr.sharedMesh.triangles.Length / 3; - } - } - if (num == 0) - { - return null; - } - profileBVH.datas = new profileBVHData[num]; - Matrix4x4 worldToLocalMatrix = rootTransform.worldToLocalMatrix; - int num2 = 0; - foreach (ProfileBakedBodyMesh bakedBodyMesh2 in bakedBodyMeshes) - { - if (bakedBodyMesh2 != null && !(bakedBodyMesh2.smr == null) && !(bakedBodyMesh2.smr.sharedMesh == null)) - { - int count = profileBVH.vertices.Count; - for (int i = 0; i < bakedBodyMesh2.worldVertices.Length; i++) - { - Vector3 item = worldToLocalMatrix.MultiplyPoint3x4(bakedBodyMesh2.worldVertices[i]); - profileBVH.vertices.Add(item); - } - int[] triangles = bakedBodyMesh2.smr.sharedMesh.triangles; - int num3 = triangles.Length / 3; - for (int j = 0; j < num3; j++) - { - int num4 = triangles[j * 3]; - int num5 = triangles[j * 3 + 1]; - int num6 = triangles[j * 3 + 2]; - profileBVH.datas[num2++] = new profileBVHData - { - verA = count + num4, - verB = count + num5, - verC = count + num6 - }; - } - } - } - int num7 = num; - int[] array = new int[num7]; - for (int k = 0; k < num7; k++) - { - array[k] = k; - } - profileBVH.dataIndices = array; - List list = new List(); - BuildRecursive(profileBVH, array, 0, num7, list); - profileBVH.nodes = list.ToArray(); - return profileBVH; - } + public ProfileBVH BuildFromSkinnedMeshes(Transform rootTransform, List bakedBodyMeshes) + { + ProfileBVH profileBVH = new ProfileBVH + { + vertices = new List(1024) + }; + int num = 0; + foreach (ProfileBakedBodyMesh bakedBodyMesh in bakedBodyMeshes) + { + if (bakedBodyMesh != null && !(bakedBodyMesh.smr == null) && !(bakedBodyMesh.smr.sharedMesh == null)) + { + num += bakedBodyMesh.smr.sharedMesh.triangles.Length / 3; + } + } + if (num == 0) + { + return null; + } + profileBVH.datas = new profileBVHData[num]; + Matrix4x4 worldToLocalMatrix = rootTransform.worldToLocalMatrix; + int num2 = 0; + foreach (ProfileBakedBodyMesh bakedBodyMesh2 in bakedBodyMeshes) + { + if (bakedBodyMesh2 != null && !(bakedBodyMesh2.smr == null) && !(bakedBodyMesh2.smr.sharedMesh == null)) + { + int count = profileBVH.vertices.Count; + for (int i = 0; i < bakedBodyMesh2.worldVertices.Length; i++) + { + Vector3 item = worldToLocalMatrix.MultiplyPoint3x4(bakedBodyMesh2.worldVertices[i]); + profileBVH.vertices.Add(item); + } + int[] triangles = bakedBodyMesh2.smr.sharedMesh.triangles; + int num3 = triangles.Length / 3; + for (int j = 0; j < num3; j++) + { + int num4 = triangles[j * 3]; + int num5 = triangles[j * 3 + 1]; + int num6 = triangles[j * 3 + 2]; + profileBVH.datas[num2++] = new profileBVHData + { + verA = count + num4, + verB = count + num5, + verC = count + num6 + }; + } + } + } + int num7 = num; + int[] array = new int[num7]; + for (int k = 0; k < num7; k++) + { + array[k] = k; + } + profileBVH.dataIndices = array; + List list = new List(); + this.BuildRecursive(profileBVH, array, 0, num7, list); + profileBVH.nodes = list.ToArray(); + return profileBVH; + } - private int BuildRecursive(ProfileBVH bvh, int[] triIndices, int start, int count, List outNodes) - { - int count2 = outNodes.Count; - profileBVHNode profileBVHNode2 = new profileBVHNode(); - Bounds bounds = default(Bounds); - bool flag = true; - for (int i = start; i < start + count; i++) - { - profileBVHData profileBVHData2 = bvh.datas[triIndices[i]]; - Vector3 vector = bvh.vertices[profileBVHData2.verA]; - Vector3 point = bvh.vertices[profileBVHData2.verB]; - Vector3 point2 = bvh.vertices[profileBVHData2.verC]; - if (flag) - { - bounds = new Bounds(vector, Vector3.zero); - bounds.Encapsulate(point); - bounds.Encapsulate(point2); - flag = false; - } - else - { - bounds.Encapsulate(vector); - bounds.Encapsulate(point); - bounds.Encapsulate(point2); - } - } - profileBVHNode2.bounds = bounds; - if (count <= 4) - { - profileBVHNode2.isLeaf = true; - profileBVHNode2.start = start; - profileBVHNode2.count = count; - profileBVHNode2.leftChild = -1; - profileBVHNode2.rightChild = -1; - outNodes.Add(profileBVHNode2); - return count2; - } - Vector3 size = bounds.size; - int num = 0; - if (size.y > size.x && size.y > size.z) - { - num = 1; - } - else if (size.z > size.x && size.z > size.y) - { - num = 2; - } - float num2 = 0f; - for (int j = start; j < start + count; j++) - { - profileBVHData profileBVHData3 = bvh.datas[triIndices[j]]; - Vector3 vector2 = bvh.vertices[profileBVHData3.verA]; - Vector3 vector3 = bvh.vertices[profileBVHData3.verB]; - Vector3 vector4 = bvh.vertices[profileBVHData3.verC]; - num2 += ((vector2 + vector3 + vector4) / 3f)[num]; - } - num2 /= (float)count; - int num3 = Partition(bvh, triIndices, start, count, num, num2); - if (num3 == start || num3 == start + count) - { - num3 = start + count / 2; - } - profileBVHNode2.isLeaf = false; - profileBVHNode2.start = -1; - profileBVHNode2.count = 0; - outNodes.Add(profileBVHNode2); - int leftChild = BuildRecursive(bvh, triIndices, start, num3 - start, outNodes); - int rightChild = BuildRecursive(bvh, triIndices, num3, start + count - num3, outNodes); - profileBVHNode2.leftChild = leftChild; - profileBVHNode2.rightChild = rightChild; - outNodes[count2] = profileBVHNode2; - return count2; - } + private int BuildRecursive(ProfileBVH bvh, int[] triIndices, int start, int count, List outNodes) + { + int count2 = outNodes.Count; + profileBVHNode profileBVHNode2 = new profileBVHNode(); + Bounds bounds = default(Bounds); + bool flag = true; + for (int i = start; i < start + count; i++) + { + profileBVHData profileBVHData2 = bvh.datas[triIndices[i]]; + Vector3 vector = bvh.vertices[profileBVHData2.verA]; + Vector3 point = bvh.vertices[profileBVHData2.verB]; + Vector3 point2 = bvh.vertices[profileBVHData2.verC]; + if (flag) + { + bounds = new Bounds(vector, Vector3.zero); + bounds.Encapsulate(point); + bounds.Encapsulate(point2); + flag = false; + } + else + { + bounds.Encapsulate(vector); + bounds.Encapsulate(point); + bounds.Encapsulate(point2); + } + } + profileBVHNode2.bounds = bounds; + if (count <= 4) + { + profileBVHNode2.isLeaf = true; + profileBVHNode2.start = start; + profileBVHNode2.count = count; + profileBVHNode2.leftChild = -1; + profileBVHNode2.rightChild = -1; + outNodes.Add(profileBVHNode2); + return count2; + } + Vector3 size = bounds.size; + int num = 0; + if (size.y > size.x && size.y > size.z) + { + num = 1; + } + else if (size.z > size.x && size.z > size.y) + { + num = 2; + } + float num2 = 0f; + for (int j = start; j < start + count; j++) + { + profileBVHData profileBVHData3 = bvh.datas[triIndices[j]]; + Vector3 vector2 = bvh.vertices[profileBVHData3.verA]; + Vector3 vector3 = bvh.vertices[profileBVHData3.verB]; + Vector3 vector4 = bvh.vertices[profileBVHData3.verC]; + num2 += ((vector2 + vector3 + vector4) / 3f)[num]; + } + num2 /= (float)count; + int num3 = this.Partition(bvh, triIndices, start, count, num, num2); + if (num3 == start || num3 == start + count) + { + num3 = start + count / 2; + } + profileBVHNode2.isLeaf = false; + profileBVHNode2.start = -1; + profileBVHNode2.count = 0; + outNodes.Add(profileBVHNode2); + int leftChild = this.BuildRecursive(bvh, triIndices, start, num3 - start, outNodes); + int rightChild = this.BuildRecursive(bvh, triIndices, num3, start + count - num3, outNodes); + profileBVHNode2.leftChild = leftChild; + profileBVHNode2.rightChild = rightChild; + outNodes[count2] = profileBVHNode2; + return count2; + } - private int Partition(ProfileBVH bvh, int[] triIndices, int start, int count, int axis, float splitPos) - { - int num = start; - int num2 = start + count - 1; - while (num <= num2) - { - profileBVHData profileBVHData2 = bvh.datas[triIndices[num]]; - profileBVHData profileBVHData3 = bvh.datas[triIndices[num2]]; - Vector3 vector = bvh.vertices[profileBVHData2.verA]; - Vector3 vector2 = bvh.vertices[profileBVHData2.verB]; - Vector3 vector3 = bvh.vertices[profileBVHData2.verC]; - Vector3 vector4 = bvh.vertices[profileBVHData3.verA]; - Vector3 vector5 = bvh.vertices[profileBVHData3.verB]; - Vector3 vector6 = bvh.vertices[profileBVHData3.verC]; - float num3 = (vector[axis] + vector2[axis] + vector3[axis]) / 3f; - _ = (vector4[axis] + vector5[axis] + vector6[axis]) / 3f; - if (num3 < splitPos) - { - num++; - continue; - } - ref int reference = ref triIndices[num]; - ref int reference2 = ref triIndices[num2]; - int num4 = triIndices[num2]; - int num5 = triIndices[num]; - reference = num4; - reference2 = num5; - num2--; - } - return num; - } + private int Partition(ProfileBVH bvh, int[] triIndices, int start, int count, int axis, float splitPos) + { + int num = start; + int num2 = start + count - 1; + while (num <= num2) + { + profileBVHData profileBVHData2 = bvh.datas[triIndices[num]]; + profileBVHData profileBVHData3 = bvh.datas[triIndices[num2]]; + Vector3 vector = bvh.vertices[profileBVHData2.verA]; + Vector3 vector2 = bvh.vertices[profileBVHData2.verB]; + Vector3 vector3 = bvh.vertices[profileBVHData2.verC]; + Vector3 vector4 = bvh.vertices[profileBVHData3.verA]; + Vector3 vector5 = bvh.vertices[profileBVHData3.verB]; + Vector3 vector6 = bvh.vertices[profileBVHData3.verC]; + float num3 = (vector[axis] + vector2[axis] + vector3[axis]) / 3f; + _ = (vector4[axis] + vector5[axis] + vector6[axis]) / 3f; + if (num3 < splitPos) + { + num++; + continue; + } + ref int reference = ref triIndices[num]; + ref int reference2 = ref triIndices[num2]; + int num4 = triIndices[num2]; + int num5 = triIndices[num]; + reference = num4; + reference2 = num5; + num2--; + } + return num; + } - public void SaveProfileBVH(ProfileBVH bvh, string savePath, string profileName) - { - if (bvh == null || bvh.vertices == null || bvh.datas == null || bvh.nodes == null || bvh.dataIndices == null) - { - Debug.LogError("[ProfileUtils_BVHUtil] SaveProfileBVH - bvh or fields are null"); - return; - } - ProfileUtils profileUtils = new ProfileUtils(); - int num = new System.Random().Next(int.MinValue, int.MaxValue); - int count = bvh.vertices.Count; - int version; - int countInFile; - BaseKey3[] array = new ProfileUtils_VertexUtil().LoadTable(profileUtils.GetBaseDataPath(), out version, out countInFile); - if (array == null || array.Length == 0) - { - Debug.LogError("[ProfileUtils_BVHUtil] SaveProfileBVH - failed to load base vertex table"); - return; - } - Vector3[] array2 = bvh.vertices.ToArray(); - for (int i = 0; i < array2.Length; i++) - { - array2[i] = TransformVec3(array2[i], array[i % array.Length]); - } - ProfileUtil_IndexUtil profileUtil_IndexUtil = new ProfileUtil_IndexUtil(); - profileUtil_IndexUtil.Build(num); - Vector3[] array3 = new Vector3[array2.Length]; - profileUtil_IndexUtil.EncodeInto(array2, array3); - StringBuilder stringBuilder = new StringBuilder(1024); - stringBuilder.Append(profileUtils.GetProfileMagic()); - AppendHexInt(stringBuilder, profileUtils.GetProfileVersion()); - AppendHexInt(stringBuilder, num); - AppendHexInt(stringBuilder, count); - AppendHexInt(stringBuilder, bvh.datas.Length); - AppendHexInt(stringBuilder, bvh.nodes.Length); - AppendHexInt(stringBuilder, bvh.dataIndices.Length); - for (int j = 0; j < array3.Length; j++) - { - AppendHexVec3(stringBuilder, array3[j]); - } - for (int k = 0; k < bvh.datas.Length; k++) - { - profileBVHData profileBVHData2 = bvh.datas[k]; - AppendHexInt(stringBuilder, profileBVHData2.verA); - AppendHexInt(stringBuilder, profileBVHData2.verB); - AppendHexInt(stringBuilder, profileBVHData2.verC); - } - for (int l = 0; l < bvh.nodes.Length; l++) - { - profileBVHNode profileBVHNode2 = bvh.nodes[l]; - AppendHexVec3(stringBuilder, profileBVHNode2.bounds.center); - AppendHexVec3(stringBuilder, profileBVHNode2.bounds.extents); - AppendHexInt(stringBuilder, profileBVHNode2.leftChild); - AppendHexInt(stringBuilder, profileBVHNode2.rightChild); - AppendHexInt(stringBuilder, profileBVHNode2.start); - AppendHexInt(stringBuilder, profileBVHNode2.count); - stringBuilder.Append(profileBVHNode2.isLeaf ? '1' : '0'); - } - for (int m = 0; m < bvh.dataIndices.Length; m++) - { - AppendHexInt(stringBuilder, bvh.dataIndices[m]); - } - string path = (profileName.EndsWith(".eb") ? profileName : (profileName + ".eb")); - string text = Path.Combine(Application.dataPath, savePath ?? string.Empty); - if (!Directory.Exists(text)) - { - Directory.CreateDirectory(text); - } - File.WriteAllText(Path.Combine(text, path), stringBuilder.ToString(), Encoding.UTF8); - } + public void SaveProfileBVH(ProfileBVH bvh, string savePath, string profileName) + { + if (bvh == null || bvh.vertices == null || bvh.datas == null || bvh.nodes == null || bvh.dataIndices == null) + { + Debug.LogError("[ProfileUtils_BVHUtil] SaveProfileBVH - bvh or fields are null"); + return; + } + ProfileUtils profileUtils = new ProfileUtils(); + int num = new System.Random().Next(int.MinValue, int.MaxValue); + int count = bvh.vertices.Count; + int version; + int countInFile; + BaseKey3[] array = new ProfileUtils_VertexUtil().LoadTable(profileUtils.GetBaseDataPath(), out version, out countInFile); + if (array == null || array.Length == 0) + { + Debug.LogError("[ProfileUtils_BVHUtil] SaveProfileBVH - failed to load base vertex table"); + return; + } + Vector3[] array2 = bvh.vertices.ToArray(); + for (int i = 0; i < array2.Length; i++) + { + array2[i] = this.TransformVec3(array2[i], array[i % array.Length]); + } + ProfileUtil_IndexUtil profileUtil_IndexUtil = new ProfileUtil_IndexUtil(); + profileUtil_IndexUtil.Build(num); + Vector3[] array3 = new Vector3[array2.Length]; + profileUtil_IndexUtil.EncodeInto(array2, array3); + StringBuilder stringBuilder = new StringBuilder(1024); + stringBuilder.Append(profileUtils.GetProfileMagic()); + this.AppendHexInt(stringBuilder, profileUtils.GetProfileVersion()); + this.AppendHexInt(stringBuilder, num); + this.AppendHexInt(stringBuilder, count); + this.AppendHexInt(stringBuilder, bvh.datas.Length); + this.AppendHexInt(stringBuilder, bvh.nodes.Length); + this.AppendHexInt(stringBuilder, bvh.dataIndices.Length); + for (int j = 0; j < array3.Length; j++) + { + this.AppendHexVec3(stringBuilder, array3[j]); + } + for (int k = 0; k < bvh.datas.Length; k++) + { + profileBVHData profileBVHData2 = bvh.datas[k]; + this.AppendHexInt(stringBuilder, profileBVHData2.verA); + this.AppendHexInt(stringBuilder, profileBVHData2.verB); + this.AppendHexInt(stringBuilder, profileBVHData2.verC); + } + for (int l = 0; l < bvh.nodes.Length; l++) + { + profileBVHNode profileBVHNode2 = bvh.nodes[l]; + this.AppendHexVec3(stringBuilder, profileBVHNode2.bounds.center); + this.AppendHexVec3(stringBuilder, profileBVHNode2.bounds.extents); + this.AppendHexInt(stringBuilder, profileBVHNode2.leftChild); + this.AppendHexInt(stringBuilder, profileBVHNode2.rightChild); + this.AppendHexInt(stringBuilder, profileBVHNode2.start); + this.AppendHexInt(stringBuilder, profileBVHNode2.count); + stringBuilder.Append(profileBVHNode2.isLeaf ? '1' : '0'); + } + for (int m = 0; m < bvh.dataIndices.Length; m++) + { + this.AppendHexInt(stringBuilder, bvh.dataIndices[m]); + } + string path = (profileName.EndsWith(".eb") ? profileName : (profileName + ".eb")); + string text = Path.Combine(Application.dataPath, savePath ?? string.Empty); + if (!Directory.Exists(text)) + { + Directory.CreateDirectory(text); + } + File.WriteAllText(Path.Combine(text, path), stringBuilder.ToString(), Encoding.UTF8); + } - private void AppendHexVec3(StringBuilder sb, Vector3 v) - { - AppendHexFloat(sb, v.x); - AppendHexFloat(sb, v.y); - AppendHexFloat(sb, v.z); - } + private void AppendHexVec3(StringBuilder sb, Vector3 v) + { + this.AppendHexFloat(sb, v.x); + this.AppendHexFloat(sb, v.y); + this.AppendHexFloat(sb, v.z); + } - private void AppendHexFloat(StringBuilder sb, float v) - { - int num = BitConverter.SingleToInt32Bits(v); - uint num2 = (uint)num; - sb.Append(num2.ToString("X8")); - } + private void AppendHexFloat(StringBuilder sb, float v) + { + int num = BitConverter.SingleToInt32Bits(v); + uint num2 = (uint)num; + sb.Append(num2.ToString("X8")); + } - private void AppendHexInt(StringBuilder sb, int v) - { - uint num = (uint)v; - sb.Append(num.ToString("X8")); - } + private void AppendHexInt(StringBuilder sb, int v) + { + uint num = (uint)v; + sb.Append(num.ToString("X8")); + } - private Vector3 TransformVec3(Vector3 v, BaseKey3 k) - { - return new Vector3(TransformFloatBits(v.x, k.x), TransformFloatBits(v.y, k.y), TransformFloatBits(v.z, k.z)); - } + private Vector3 TransformVec3(Vector3 v, BaseKey3 k) + { + return new Vector3(this.TransformFloatBits(v.x, k.x), this.TransformFloatBits(v.y, k.y), this.TransformFloatBits(v.z, k.z)); + } - private float TransformFloatBits(float a, uint keyBits) - { - return BitConverter.Int32BitsToSingle(BitConverter.SingleToInt32Bits(a) ^ (int)keyBits); - } + private float TransformFloatBits(float a, uint keyBits) + { + return BitConverter.Int32BitsToSingle(BitConverter.SingleToInt32Bits(a) ^ (int)keyBits); + } } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_BoneUtil.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_BoneUtil.cs index cf513a4..159ed17 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_BoneUtil.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_BoneUtil.cs @@ -1,345 +1,344 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.ProfileUtils_BoneUtil using System; using System.Collections.Generic; using System.Linq; -using Eden.AutoMorpher.profile; using UnityEngine; public class ProfileUtils_BoneUtil { - public HashSet GetBodyMeshBones(SkinnedMeshRenderer smr, float weightThreshold = 0.0001f) - { - Mesh sharedMesh = smr.sharedMesh; - if (sharedMesh == null) - { - Debug.LogError("[ProfileUtils_BoneUtil] SkinnedMeshRenderer에 연결된 Mesh가 없습니다."); - return new HashSet(); - } - Transform[] bones = smr.bones; - BoneWeight[] boneWeights = sharedMesh.boneWeights; - HashSet hashSet = new HashSet(); - BoneWeight[] array = boneWeights; - for (int i = 0; i < array.Length; i++) - { - BoneWeight boneWeight = array[i]; - if (boneWeight.weight0 > weightThreshold) - { - hashSet.Add(boneWeight.boneIndex0); - } - if (boneWeight.weight1 > weightThreshold) - { - hashSet.Add(boneWeight.boneIndex1); - } - if (boneWeight.weight2 > weightThreshold) - { - hashSet.Add(boneWeight.boneIndex2); - } - if (boneWeight.weight3 > weightThreshold) - { - hashSet.Add(boneWeight.boneIndex3); - } - } - HashSet hashSet2 = new HashSet(); - foreach (int item in hashSet) - { - if (item >= 0 && item < bones.Length) - { - hashSet2.Add(bones[item]); - } - } - return hashSet2; - } + public HashSet GetBodyMeshBones(SkinnedMeshRenderer smr, float weightThreshold = 0.0001f) + { + Mesh sharedMesh = smr.sharedMesh; + if (sharedMesh == null) + { + Debug.LogError("[ProfileUtils_BoneUtil] SkinnedMeshRenderer에 연결된 Mesh가 없습니다."); + return new HashSet(); + } + Transform[] bones = smr.bones; + BoneWeight[] boneWeights = sharedMesh.boneWeights; + HashSet hashSet = new HashSet(); + BoneWeight[] array = boneWeights; + for (int i = 0; i < array.Length; i++) + { + BoneWeight boneWeight = array[i]; + if (boneWeight.weight0 > weightThreshold) + { + hashSet.Add(boneWeight.boneIndex0); + } + if (boneWeight.weight1 > weightThreshold) + { + hashSet.Add(boneWeight.boneIndex1); + } + if (boneWeight.weight2 > weightThreshold) + { + hashSet.Add(boneWeight.boneIndex2); + } + if (boneWeight.weight3 > weightThreshold) + { + hashSet.Add(boneWeight.boneIndex3); + } + } + HashSet hashSet2 = new HashSet(); + foreach (int item in hashSet) + { + if (item >= 0 && item < bones.Length) + { + hashSet2.Add(bones[item]); + } + } + return hashSet2; + } - public Dictionary> GetHumanoidMeshBoneMap(Animator animator, IReadOnlyList bodyMeshes, float posTolerance = 0.0001f, float weightThreshold = 0.0001f) - { - Dictionary> dictionary = new Dictionary>(); - if (animator == null) - { - Debug.LogError("[MeshHumanoidBoneMatcher] Animator is Empty"); - return dictionary; - } - HashSet hashSet = new HashSet(); - if (bodyMeshes != null) - { - foreach (SkinnedMeshRenderer bodyMesh in bodyMeshes) - { - if (bodyMesh == null) - { - continue; - } - foreach (Transform activeBone in GetActiveBones(bodyMesh, weightThreshold)) - { - if (activeBone != null) - { - hashSet.Add(activeBone); - } - } - } - } - for (int i = 0; i < 55; i++) - { - HumanBodyBones humanBodyBones = (HumanBodyBones)i; - Transform boneTransform = animator.GetBoneTransform(humanBodyBones); - if (boneTransform == null) - { - continue; - } - HashSet hashSet2 = new HashSet(); - hashSet2.Add(boneTransform); - foreach (Transform item in FindBonesByPosition(boneTransform, hashSet, posTolerance)) - { - hashSet2.Add(item); - } - dictionary[humanBodyBones] = hashSet2; - } - return dictionary; - } + public Dictionary> GetHumanoidMeshBoneMap(Animator animator, IReadOnlyList bodyMeshes, float posTolerance = 0.0001f, float weightThreshold = 0.0001f) + { + Dictionary> dictionary = new Dictionary>(); + if (animator == null) + { + Debug.LogError("[MeshHumanoidBoneMatcher] Animator is Empty"); + return dictionary; + } + HashSet hashSet = new HashSet(); + if (bodyMeshes != null) + { + foreach (SkinnedMeshRenderer bodyMesh in bodyMeshes) + { + if (bodyMesh == null) + { + continue; + } + foreach (Transform activeBone in this.GetActiveBones(bodyMesh, weightThreshold)) + { + if (activeBone != null) + { + hashSet.Add(activeBone); + } + } + } + } + for (int i = 0; i < 55; i++) + { + HumanBodyBones humanBodyBones = (HumanBodyBones)i; + Transform boneTransform = animator.GetBoneTransform(humanBodyBones); + if (boneTransform == null) + { + continue; + } + HashSet hashSet2 = new HashSet(); + hashSet2.Add(boneTransform); + foreach (Transform item in this.FindBonesByPosition(boneTransform, hashSet, posTolerance)) + { + hashSet2.Add(item); + } + dictionary[humanBodyBones] = hashSet2; + } + return dictionary; + } - public HashSet GetActiveBones(SkinnedMeshRenderer smr, float weightThreshold = 0.0001f) - { - Mesh sharedMesh = smr.sharedMesh; - if (sharedMesh == null) - { - Debug.LogError("SkinnedMeshRenderer에 연결된 Mesh가 없습니다."); - return new HashSet(); - } - Transform[] bones = smr.bones; - BoneWeight[] boneWeights = sharedMesh.boneWeights; - HashSet hashSet = new HashSet(); - BoneWeight[] array = boneWeights; - for (int i = 0; i < array.Length; i++) - { - BoneWeight boneWeight = array[i]; - if (boneWeight.weight0 > weightThreshold) - { - hashSet.Add(boneWeight.boneIndex0); - } - if (boneWeight.weight1 > weightThreshold) - { - hashSet.Add(boneWeight.boneIndex1); - } - if (boneWeight.weight2 > weightThreshold) - { - hashSet.Add(boneWeight.boneIndex2); - } - if (boneWeight.weight3 > weightThreshold) - { - hashSet.Add(boneWeight.boneIndex3); - } - } - HashSet hashSet2 = new HashSet(); - foreach (int item in hashSet) - { - if (item >= 0 && item < bones.Length) - { - hashSet2.Add(bones[item]); - } - } - return hashSet2; - } + public HashSet GetActiveBones(SkinnedMeshRenderer smr, float weightThreshold = 0.0001f) + { + Mesh sharedMesh = smr.sharedMesh; + if (sharedMesh == null) + { + Debug.LogError("SkinnedMeshRenderer에 연결된 Mesh가 없습니다."); + return new HashSet(); + } + Transform[] bones = smr.bones; + BoneWeight[] boneWeights = sharedMesh.boneWeights; + HashSet hashSet = new HashSet(); + BoneWeight[] array = boneWeights; + for (int i = 0; i < array.Length; i++) + { + BoneWeight boneWeight = array[i]; + if (boneWeight.weight0 > weightThreshold) + { + hashSet.Add(boneWeight.boneIndex0); + } + if (boneWeight.weight1 > weightThreshold) + { + hashSet.Add(boneWeight.boneIndex1); + } + if (boneWeight.weight2 > weightThreshold) + { + hashSet.Add(boneWeight.boneIndex2); + } + if (boneWeight.weight3 > weightThreshold) + { + hashSet.Add(boneWeight.boneIndex3); + } + } + HashSet hashSet2 = new HashSet(); + foreach (int item in hashSet) + { + if (item >= 0 && item < bones.Length) + { + hashSet2.Add(bones[item]); + } + } + return hashSet2; + } - private List FindBonesByPosition(Transform boneToCheck, HashSet smrBoneSet, float posTolerance = 0.0001f) - { - List list = new List(); - if (boneToCheck == null) - { - return list; - } - float num = posTolerance * posTolerance; - Vector3 position = boneToCheck.position; - foreach (Transform item in smrBoneSet) - { - if (!(item == null) && !(item == boneToCheck) && NameMatches(item.gameObject.name, boneToCheck.gameObject.name) && (item.position - position).sqrMagnitude <= num) - { - list.Add(item); - } - } - return list; - } + private List FindBonesByPosition(Transform boneToCheck, HashSet smrBoneSet, float posTolerance = 0.0001f) + { + List list = new List(); + if (boneToCheck == null) + { + return list; + } + float num = posTolerance * posTolerance; + Vector3 position = boneToCheck.position; + foreach (Transform item in smrBoneSet) + { + if (!(item == null) && !(item == boneToCheck) && this.NameMatches(item.gameObject.name, boneToCheck.gameObject.name) && (item.position - position).sqrMagnitude <= num) + { + list.Add(item); + } + } + return list; + } - private string[] TokenizeBoneName(string name) - { - if (string.IsNullOrWhiteSpace(name)) - { - return Array.Empty(); - } - char[] separator = new char[5] { '-', '_', ':', '.', '|' }; - name = name.Trim(); - return name.Split(separator, StringSplitOptions.RemoveEmptyEntries); - } + private string[] TokenizeBoneName(string name) + { + if (string.IsNullOrWhiteSpace(name)) + { + return Array.Empty(); + } + char[] separator = new char[5] { '-', '_', ':', '.', '|' }; + name = name.Trim(); + return name.Split(separator, StringSplitOptions.RemoveEmptyEntries); + } - private bool NameMatches(string boneToCheckName, string candidateName) - { - string[] array = TokenizeBoneName(boneToCheckName); - string[] array2 = TokenizeBoneName(candidateName); - if (array.Length == 0 || array2.Length == 0) - { - return false; - } - if (!array[0].Equals(array2[0], StringComparison.OrdinalIgnoreCase)) - { - return false; - } - if (array.Length > 1 && array2.Length > 1 && !array[1].Equals(array2[1], StringComparison.OrdinalIgnoreCase)) - { - return false; - } - return true; - } + private bool NameMatches(string boneToCheckName, string candidateName) + { + string[] array = this.TokenizeBoneName(boneToCheckName); + string[] array2 = this.TokenizeBoneName(candidateName); + if (array.Length == 0 || array2.Length == 0) + { + return false; + } + if (!array[0].Equals(array2[0], StringComparison.OrdinalIgnoreCase)) + { + return false; + } + if (array.Length > 1 && array2.Length > 1 && !array[1].Equals(array2[1], StringComparison.OrdinalIgnoreCase)) + { + return false; + } + return true; + } - public List GetBoneDatas(Transform rootTransform, HashSet avatarBones, Dictionary> sourceBoneMap) - { - Dictionary dictionary = new Dictionary(); - foreach (KeyValuePair> item2 in sourceBoneMap) - { - HumanBodyBones key = item2.Key; - HashSet value = item2.Value; - if (value == null) - { - continue; - } - foreach (Transform item3 in value) - { - if (!(item3 == null) && !dictionary.ContainsKey(item3)) - { - dictionary[item3] = key; - } - } - } - List list = new List(); - BoneData item = new BoneData - { - id = 0, - boneName = ((rootTransform != null) ? rootTransform.name : "Root"), - parentName = null, - hierarchyPath = "", - hBone = HumanBodyBones.LastBone, - parentId = -1, - childrenIds = new List(), - rootLocalPosition = Vector3.zero, - rootLocalRotation = Quaternion.identity, - rootLocalScale = Vector3.one - }; - list.Add(item); - List list2 = (from t in avatarBones - where t != null - orderby GetDepthFromSkeletonRoot(rootTransform, t), GetHierarchyPath(rootTransform, t) - select t).ToList(); - Dictionary dictionary2 = new Dictionary(list2.Count); - int num = 1; - foreach (Transform item4 in list2) - { - dictionary2[item4] = num++; - string hierarchyPath = GetHierarchyPath(rootTransform, item4); - HumanBodyBones value2; - HumanBodyBones hBone = (dictionary.TryGetValue(item4, out value2) ? value2 : HumanBodyBones.LastBone); - Vector3 rootLocalPosition = ((rootTransform != null) ? rootTransform.InverseTransformPoint(item4.position) : item4.position); - Quaternion rootLocalRotation = ((rootTransform != null) ? (Quaternion.Inverse(rootTransform.rotation) * item4.rotation) : item4.rotation); - Vector3 rootLocalScale = item4.lossyScale; - if (rootTransform != null) - { - Vector3 lossyScale = rootTransform.lossyScale; - rootLocalScale = new Vector3(SafeDiv(rootLocalScale.x, lossyScale.x), SafeDiv(rootLocalScale.y, lossyScale.y), SafeDiv(rootLocalScale.z, lossyScale.z)); - } - list.Add(new BoneData - { - id = dictionary2[item4], - boneName = item4.name, - parentName = ((item4.parent != null) ? item4.parent.name : ""), - hierarchyPath = hierarchyPath, - hBone = hBone, - parentId = -1, - childrenIds = new List(), - rootLocalPosition = rootLocalPosition, - rootLocalRotation = rootLocalRotation, - rootLocalScale = rootLocalScale - }); - } - Dictionary> dictionary3 = new Dictionary>(); - foreach (BoneData item5 in list) - { - dictionary3[item5.id] = new List(); - } - foreach (BoneData node in list.Where((BoneData n) => n.id != 0)) - { - Transform key2 = dictionary2.FirstOrDefault((KeyValuePair kv) => kv.Value == node.id).Key; - int num2 = 0; - if (key2 != null) - { - Transform parent = key2.parent; - while (parent != null) - { - if (dictionary2.TryGetValue(parent, out var value3)) - { - num2 = value3; - break; - } - if (parent == rootTransform) - { - num2 = 0; - break; - } - parent = parent.parent; - } - } - node.parentId = num2; - dictionary3[num2].Add(node.id); - } - foreach (BoneData item6 in list) - { - item6.childrenIds = dictionary3[item6.id]; - } - return list; - } + public List GetBoneDatas(Transform rootTransform, HashSet avatarBones, Dictionary> sourceBoneMap) + { + Dictionary dictionary = new Dictionary(); + foreach (KeyValuePair> item2 in sourceBoneMap) + { + HumanBodyBones key = item2.Key; + HashSet value = item2.Value; + if (value == null) + { + continue; + } + foreach (Transform item3 in value) + { + if (!(item3 == null) && !dictionary.ContainsKey(item3)) + { + dictionary[item3] = key; + } + } + } + List list = new List(); + BoneData item = new BoneData + { + id = 0, + boneName = ((rootTransform != null) ? rootTransform.name : "Root"), + parentName = null, + hierarchyPath = "", + hBone = HumanBodyBones.LastBone, + parentId = -1, + childrenIds = new List(), + rootLocalPosition = Vector3.zero, + rootLocalRotation = Quaternion.identity, + rootLocalScale = Vector3.one + }; + list.Add(item); + List list2 = (from t in avatarBones + where t != null + orderby this.GetDepthFromSkeletonRoot(rootTransform, t), this.GetHierarchyPath(rootTransform, t) + select t).ToList(); + Dictionary dictionary2 = new Dictionary(list2.Count); + int num = 1; + foreach (Transform item4 in list2) + { + dictionary2[item4] = num++; + string hierarchyPath = this.GetHierarchyPath(rootTransform, item4); + HumanBodyBones value2; + HumanBodyBones hBone = (dictionary.TryGetValue(item4, out value2) ? value2 : HumanBodyBones.LastBone); + Vector3 rootLocalPosition = ((rootTransform != null) ? rootTransform.InverseTransformPoint(item4.position) : item4.position); + Quaternion rootLocalRotation = ((rootTransform != null) ? (Quaternion.Inverse(rootTransform.rotation) * item4.rotation) : item4.rotation); + Vector3 rootLocalScale = item4.lossyScale; + if (rootTransform != null) + { + Vector3 lossyScale = rootTransform.lossyScale; + rootLocalScale = new Vector3(this.SafeDiv(rootLocalScale.x, lossyScale.x), this.SafeDiv(rootLocalScale.y, lossyScale.y), this.SafeDiv(rootLocalScale.z, lossyScale.z)); + } + list.Add(new BoneData + { + id = dictionary2[item4], + boneName = item4.name, + parentName = ((item4.parent != null) ? item4.parent.name : ""), + hierarchyPath = hierarchyPath, + hBone = hBone, + parentId = -1, + childrenIds = new List(), + rootLocalPosition = rootLocalPosition, + rootLocalRotation = rootLocalRotation, + rootLocalScale = rootLocalScale + }); + } + Dictionary> dictionary3 = new Dictionary>(); + foreach (BoneData item5 in list) + { + dictionary3[item5.id] = new List(); + } + foreach (BoneData node in list.Where((BoneData n) => n.id != 0)) + { + Transform key2 = dictionary2.FirstOrDefault((KeyValuePair kv) => kv.Value == node.id).Key; + int num2 = 0; + if (key2 != null) + { + Transform parent = key2.parent; + while (parent != null) + { + if (dictionary2.TryGetValue(parent, out var value3)) + { + num2 = value3; + break; + } + if (parent == rootTransform) + { + num2 = 0; + break; + } + parent = parent.parent; + } + } + node.parentId = num2; + dictionary3[num2].Add(node.id); + } + foreach (BoneData item6 in list) + { + item6.childrenIds = dictionary3[item6.id]; + } + return list; + } - private float SafeDiv(float a, float b) - { - if (!(Mathf.Abs(b) < 1E-08f)) - { - return a / b; - } - return 0f; - } + private float SafeDiv(float a, float b) + { + if (!(Mathf.Abs(b) < 1E-08f)) + { + return a / b; + } + return 0f; + } - private int GetDepthFromSkeletonRoot(Transform root, Transform t) - { - int num = 0; - Transform transform = t; - while (transform != null && transform != root) - { - num++; - transform = transform.parent; - } - return num; - } + private int GetDepthFromSkeletonRoot(Transform root, Transform t) + { + int num = 0; + Transform transform = t; + while (transform != null && transform != root) + { + num++; + transform = transform.parent; + } + return num; + } - private string GetHierarchyPath(Transform root, Transform t) - { - if (t == null) - { - return ""; - } - if (root == null) - { - return t.name; - } - if (!t.IsChildOf(root) && t != root) - { - Debug.LogError("[ProfileUtils_BoneUtil] GetHierarchyPath - bone " + t.name + " is not child of root " + root.name); - return ""; - } - if (t == root) - { - return ""; - } - Stack stack = new Stack(); - Transform transform = t; - while (transform != null && transform != root) - { - stack.Push(transform.name); - transform = transform.parent; - } - return string.Join("/", stack); - } + private string GetHierarchyPath(Transform root, Transform t) + { + if (t == null) + { + return ""; + } + if (root == null) + { + return t.name; + } + if (!t.IsChildOf(root) && t != root) + { + Debug.LogError("[ProfileUtils_BoneUtil] GetHierarchyPath - bone " + t.name + " is not child of root " + root.name); + return ""; + } + if (t == root) + { + return ""; + } + Stack stack = new Stack(); + Transform transform = t; + while (transform != null && transform != root) + { + stack.Push(transform.name); + transform = transform.parent; + } + return string.Join("/", stack); + } } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_PCAUtil.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_PCAUtil.cs index e262245..547c837 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_PCAUtil.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_PCAUtil.cs @@ -1,160 +1,159 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.ProfileUtils_PCAUtil using System.Collections.Generic; -using Eden.AutoMorpher.profile; using UnityEngine; public class ProfileUtils_PCAUtil { - public PCAData ComputeRegionStats(IList points) - { - PCAData pCAData = new PCAData(); - if (points == null || points.Count == 0) - { - return pCAData; - } - int count = points.Count; - Vector3 zero = Vector3.zero; - for (int i = 0; i < count; i++) - { - zero += points[i]; - } - zero /= (float)count; - float num = 0f; - float num2 = 0f; - float num3 = 0f; - float num4 = 0f; - float num5 = 0f; - float num6 = 0f; - for (int j = 0; j < count; j++) - { - Vector3 vector = points[j] - zero; - num += vector.x * vector.x; - num2 += vector.x * vector.y; - num3 += vector.x * vector.z; - num4 += vector.y * vector.y; - num5 += vector.y * vector.z; - num6 += vector.z * vector.z; - } - float num7 = 1f / (float)count; - num *= num7; - num2 *= num7; - num3 *= num7; - num4 *= num7; - num5 *= num7; - num6 *= num7; - JacobiEigenDecomposition3x3(num, num2, num3, num4, num5, num6, out var eigenValues, out var eigenVectors); - int num8 = 0; - if (eigenValues[1] > eigenValues[num8]) - { - num8 = 1; - } - if (eigenValues[2] > eigenValues[num8]) - { - num8 = 2; - } - Vector3 normalized = eigenVectors[num8].normalized; - float num9 = float.PositiveInfinity; - float num10 = float.NegativeInfinity; - float num11 = 0f; - for (int k = 0; k < count; k++) - { - float num12 = Vector3.Dot(points[k] - zero, normalized); - if (num12 < num9) - { - num9 = num12; - } - if (num12 > num10) - { - num10 = num12; - } - Vector3 vector2 = zero + normalized * num12; - float magnitude = (points[k] - vector2).magnitude; - num11 += magnitude; - } - pCAData.pcaCenter = zero; - pCAData.pcaPrincipalAxis = normalized; - pCAData.pcaLength = num10 - num9; - pCAData.pcaAvgRadius = num11 / (float)count; - return pCAData; - } + public PCAData ComputeRegionStats(IList points) + { + PCAData pCAData = new PCAData(); + if (points == null || points.Count == 0) + { + return pCAData; + } + int count = points.Count; + Vector3 zero = Vector3.zero; + for (int i = 0; i < count; i++) + { + zero += points[i]; + } + zero /= (float)count; + float num = 0f; + float num2 = 0f; + float num3 = 0f; + float num4 = 0f; + float num5 = 0f; + float num6 = 0f; + for (int j = 0; j < count; j++) + { + Vector3 vector = points[j] - zero; + num += vector.x * vector.x; + num2 += vector.x * vector.y; + num3 += vector.x * vector.z; + num4 += vector.y * vector.y; + num5 += vector.y * vector.z; + num6 += vector.z * vector.z; + } + float num7 = 1f / (float)count; + num *= num7; + num2 *= num7; + num3 *= num7; + num4 *= num7; + num5 *= num7; + num6 *= num7; + this.JacobiEigenDecomposition3x3(num, num2, num3, num4, num5, num6, out var eigenValues, out var eigenVectors); + int num8 = 0; + if (eigenValues[1] > eigenValues[num8]) + { + num8 = 1; + } + if (eigenValues[2] > eigenValues[num8]) + { + num8 = 2; + } + Vector3 normalized = eigenVectors[num8].normalized; + float num9 = float.PositiveInfinity; + float num10 = float.NegativeInfinity; + float num11 = 0f; + for (int k = 0; k < count; k++) + { + float num12 = Vector3.Dot(points[k] - zero, normalized); + if (num12 < num9) + { + num9 = num12; + } + if (num12 > num10) + { + num10 = num12; + } + Vector3 vector2 = zero + normalized * num12; + float magnitude = (points[k] - vector2).magnitude; + num11 += magnitude; + } + pCAData.pcaCenter = zero; + pCAData.pcaPrincipalAxis = normalized; + pCAData.pcaLength = num10 - num9; + pCAData.pcaAvgRadius = num11 / (float)count; + return pCAData; + } - private void JacobiEigenDecomposition3x3(float c00, float c01, float c02, float c11, float c12, float c22, out float[] eigenValues, out Vector3[] eigenVectors) - { - float[,] array = new float[3, 3] - { - { c00, c01, c02 }, - { c01, c11, c12 }, - { c02, c12, c22 } - }; - float[,] array2 = new float[3, 3] - { - { 1f, 0f, 0f }, - { 0f, 1f, 0f }, - { 0f, 0f, 1f } - }; - for (int i = 0; i < 32; i++) - { - int num = 0; - int num2 = 1; - float num3 = Mathf.Abs(array[0, 1]); - float num4 = Mathf.Abs(array[0, 2]); - if (num4 > num3) - { - num3 = num4; - num = 0; - num2 = 2; - } - float num5 = Mathf.Abs(array[1, 2]); - if (num5 > num3) - { - num3 = num5; - num = 1; - num2 = 2; - } - if (num3 < 1E-10f) - { - break; - } - float num6 = array[num, num]; - float num7 = array[num2, num2]; - float num8 = array[num, num2]; - float f = 0.5f * Mathf.Atan2(2f * num8, num7 - num6); - float num9 = Mathf.Cos(f); - float num10 = Mathf.Sin(f); - for (int j = 0; j < 3; j++) - { - if (j != num && j != num2) - { - float num11 = array[j, num]; - float num12 = array[j, num2]; - array[j, num] = num9 * num11 - num10 * num12; - array[num, j] = array[j, num]; - array[j, num2] = num10 * num11 + num9 * num12; - array[num2, j] = array[j, num2]; - } - } - float num13 = num9 * num9 * num6 - 2f * num10 * num9 * num8 + num10 * num10 * num7; - float num14 = num10 * num10 * num6 + 2f * num10 * num9 * num8 + num9 * num9 * num7; - array[num, num] = num13; - array[num2, num2] = num14; - array[num, num2] = 0f; - array[num2, num] = 0f; - for (int k = 0; k < 3; k++) - { - float num15 = array2[k, num]; - float num16 = array2[k, num2]; - array2[k, num] = num9 * num15 - num10 * num16; - array2[k, num2] = num10 * num15 + num9 * num16; - } - } - eigenValues = new float[3]; - eigenVectors = new Vector3[3]; - eigenValues[0] = array[0, 0]; - eigenValues[1] = array[1, 1]; - eigenValues[2] = array[2, 2]; - eigenVectors[0] = new Vector3(array2[0, 0], array2[1, 0], array2[2, 0]); - eigenVectors[1] = new Vector3(array2[0, 1], array2[1, 1], array2[2, 1]); - eigenVectors[2] = new Vector3(array2[0, 2], array2[1, 2], array2[2, 2]); - } + private void JacobiEigenDecomposition3x3(float c00, float c01, float c02, float c11, float c12, float c22, out float[] eigenValues, out Vector3[] eigenVectors) + { + float[,] array = new float[3, 3] + { + { c00, c01, c02 }, + { c01, c11, c12 }, + { c02, c12, c22 } + }; + float[,] array2 = new float[3, 3] + { + { 1f, 0f, 0f }, + { 0f, 1f, 0f }, + { 0f, 0f, 1f } + }; + for (int i = 0; i < 32; i++) + { + int num = 0; + int num2 = 1; + float num3 = Mathf.Abs(array[0, 1]); + float num4 = Mathf.Abs(array[0, 2]); + if (num4 > num3) + { + num3 = num4; + num = 0; + num2 = 2; + } + float num5 = Mathf.Abs(array[1, 2]); + if (num5 > num3) + { + num3 = num5; + num = 1; + num2 = 2; + } + if (num3 < 1E-10f) + { + break; + } + float num6 = array[num, num]; + float num7 = array[num2, num2]; + float num8 = array[num, num2]; + float f = 0.5f * Mathf.Atan2(2f * num8, num7 - num6); + float num9 = Mathf.Cos(f); + float num10 = Mathf.Sin(f); + for (int j = 0; j < 3; j++) + { + if (j != num && j != num2) + { + float num11 = array[j, num]; + float num12 = array[j, num2]; + array[j, num] = num9 * num11 - num10 * num12; + array[num, j] = array[j, num]; + array[j, num2] = num10 * num11 + num9 * num12; + array[num2, j] = array[j, num2]; + } + } + float num13 = num9 * num9 * num6 - 2f * num10 * num9 * num8 + num10 * num10 * num7; + float num14 = num10 * num10 * num6 + 2f * num10 * num9 * num8 + num9 * num9 * num7; + array[num, num] = num13; + array[num2, num2] = num14; + array[num, num2] = 0f; + array[num2, num] = 0f; + for (int k = 0; k < 3; k++) + { + float num15 = array2[k, num]; + float num16 = array2[k, num2]; + array2[k, num] = num9 * num15 - num10 * num16; + array2[k, num2] = num10 * num15 + num9 * num16; + } + } + eigenValues = new float[3]; + eigenVectors = new Vector3[3]; + eigenValues[0] = array[0, 0]; + eigenValues[1] = array[1, 1]; + eigenValues[2] = array[2, 2]; + eigenVectors[0] = new Vector3(array2[0, 0], array2[1, 0], array2[2, 0]); + eigenVectors[1] = new Vector3(array2[0, 1], array2[1, 1], array2[2, 1]); + eigenVectors[2] = new Vector3(array2[0, 2], array2[1, 2], array2[2, 2]); + } } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_PoseUtil.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_PoseUtil.cs index 79a9f3a..833dbe2 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_PoseUtil.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_PoseUtil.cs @@ -1,146 +1,145 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.ProfileUtils_PoseUtil using System.Collections.Generic; using System.Linq; -using Eden.AutoMorpher.profile; using UnityEngine; public class ProfileUtils_PoseUtil { - public BoneSpatialData GetBoneSpatialData(HumanBodyBones refBone, HumanBodyBones[] influencedBones, Dictionary> boneMap, List sourceBodyBakedMeshes, bool addChildBones = false) - { - BoneSpatialData boneSpatialData = new BoneSpatialData(); - boneSpatialData.refBone = refBone; - Transform baseBoneFromBoneMap = GetBaseBoneFromBoneMap(boneMap, refBone); - if (baseBoneFromBoneMap == null) - { - return null; - } - List refVertices = GetRefVertices(influencedBones, boneMap, sourceBodyBakedMeshes, addChildBones); - boneSpatialData.pcaData = GetPCAData(baseBoneFromBoneMap, refVertices); - Transform baseBoneFromBoneMap2 = GetBaseBoneFromBoneMap(boneMap, HumanBodyBones.Hips); - boneSpatialData.volumeData = GetVolumeData(baseBoneFromBoneMap, baseBoneFromBoneMap2, refVertices); - return boneSpatialData; - } + public BoneSpatialData GetBoneSpatialData(HumanBodyBones refBone, HumanBodyBones[] influencedBones, Dictionary> boneMap, List sourceBodyBakedMeshes, bool addChildBones = false) + { + BoneSpatialData boneSpatialData = new BoneSpatialData(); + boneSpatialData.refBone = refBone; + Transform baseBoneFromBoneMap = this.GetBaseBoneFromBoneMap(boneMap, refBone); + if (baseBoneFromBoneMap == null) + { + return null; + } + List refVertices = this.GetRefVertices(influencedBones, boneMap, sourceBodyBakedMeshes, addChildBones); + boneSpatialData.pcaData = this.GetPCAData(baseBoneFromBoneMap, refVertices); + Transform baseBoneFromBoneMap2 = this.GetBaseBoneFromBoneMap(boneMap, HumanBodyBones.Hips); + boneSpatialData.volumeData = this.GetVolumeData(baseBoneFromBoneMap, baseBoneFromBoneMap2, refVertices); + return boneSpatialData; + } - private List GetRefVertices(HumanBodyBones[] influencedBones, Dictionary> boneMap, List sourceBodyBakedMeshes, bool addChildBones = false, float weightThreshold = 0.15f, int sampleStep = 1) - { - List list = new List(); - HashSet targetBoneSet = new HashSet(); - foreach (HumanBodyBones key in influencedBones) - { - if (!boneMap.TryGetValue(key, out var value) || value == null) - { - continue; - } - foreach (Transform item in value) - { - if (item != null) - { - targetBoneSet.Add(item); - } - } - } - if (targetBoneSet.Count == 0) - { - string text = string.Join(", ", influencedBones.Select((HumanBodyBones b) => b.ToString())); - Debug.LogError("[ProfileSaver_PoseUtil] CollectBodyPartVerticesWorld: targetBoneSet is empty.\nMissing Humanoid Set : " + text); - return list; - } - if (addChildBones) - { - Transform[] array = targetBoneSet.ToArray(); - targetBoneSet.Clear(); - Transform[] array2 = array; - for (int i = 0; i < array2.Length; i++) - { - AddDescendants(array2[i]); - } - } - foreach (ProfileBakedBodyMesh sourceBodyBakedMesh in sourceBodyBakedMeshes) - { - BoneWeight[] boneWeights = sourceBodyBakedMesh.boneWeights; - Transform[] bones = sourceBodyBakedMesh.bones; - if (boneWeights == null || boneWeights.Length == 0 || bones == null || bones.Length == 0) - { - continue; - } - Vector3[] worldVertices = sourceBodyBakedMesh.worldVertices; - if (worldVertices == null || worldVertices.Length == 0) - { - continue; - } - int num = Mathf.Min(worldVertices.Length, boneWeights.Length); - for (int num2 = 0; num2 < num; num2 += sampleStep) - { - BoneWeight boneWeight = boneWeights[num2]; - float wSum = 0f; - Acc(boneWeight.boneIndex0, boneWeight.weight0); - Acc(boneWeight.boneIndex1, boneWeight.weight1); - Acc(boneWeight.boneIndex2, boneWeight.weight2); - Acc(boneWeight.boneIndex3, boneWeight.weight3); - if (!(wSum < weightThreshold)) - { - list.Add(worldVertices[num2]); - } - void Acc(int index, float w) - { - if (index >= 0 && index < bones.Length && !(w <= 0f)) - { - Transform transform = bones[index]; - if (transform != null && targetBoneSet.Contains(transform)) - { - wSum += w; - } - } - } - } - } - return list; - void AddDescendants(Transform t) - { - if (!(t == null) && targetBoneSet.Add(t)) - { - for (int j = 0; j < t.childCount; j++) - { - AddDescendants(t.GetChild(j)); - } - } - } - } + private List GetRefVertices(HumanBodyBones[] influencedBones, Dictionary> boneMap, List sourceBodyBakedMeshes, bool addChildBones = false, float weightThreshold = 0.15f, int sampleStep = 1) + { + List list = new List(); + HashSet targetBoneSet = new HashSet(); + foreach (HumanBodyBones key in influencedBones) + { + if (!boneMap.TryGetValue(key, out var value) || value == null) + { + continue; + } + foreach (Transform item in value) + { + if (item != null) + { + targetBoneSet.Add(item); + } + } + } + if (targetBoneSet.Count == 0) + { + string text = string.Join(", ", influencedBones.Select((HumanBodyBones b) => b.ToString())); + Debug.LogError("[ProfileSaver_PoseUtil] CollectBodyPartVerticesWorld: targetBoneSet is empty.\nMissing Humanoid Set : " + text); + return list; + } + if (addChildBones) + { + Transform[] array = targetBoneSet.ToArray(); + targetBoneSet.Clear(); + Transform[] array2 = array; + for (int i = 0; i < array2.Length; i++) + { + AddDescendants(array2[i]); + } + } + foreach (ProfileBakedBodyMesh sourceBodyBakedMesh in sourceBodyBakedMeshes) + { + BoneWeight[] boneWeights = sourceBodyBakedMesh.boneWeights; + Transform[] bones = sourceBodyBakedMesh.bones; + if (boneWeights == null || boneWeights.Length == 0 || bones == null || bones.Length == 0) + { + continue; + } + Vector3[] worldVertices = sourceBodyBakedMesh.worldVertices; + if (worldVertices == null || worldVertices.Length == 0) + { + continue; + } + int num = Mathf.Min(worldVertices.Length, boneWeights.Length); + for (int num2 = 0; num2 < num; num2 += sampleStep) + { + BoneWeight boneWeight = boneWeights[num2]; + float wSum = 0f; + Acc(boneWeight.boneIndex0, boneWeight.weight0); + Acc(boneWeight.boneIndex1, boneWeight.weight1); + Acc(boneWeight.boneIndex2, boneWeight.weight2); + Acc(boneWeight.boneIndex3, boneWeight.weight3); + if (!(wSum < weightThreshold)) + { + list.Add(worldVertices[num2]); + } + void Acc(int index, float w) + { + if (index >= 0 && index < bones.Length && !(w <= 0f)) + { + Transform transform = bones[index]; + if (transform != null && targetBoneSet.Contains(transform)) + { + wSum += w; + } + } + } + } + } + return list; + void AddDescendants(Transform t) + { + if (!(t == null) && targetBoneSet.Add(t)) + { + for (int j = 0; j < t.childCount; j++) + { + AddDescendants(t.GetChild(j)); + } + } + } + } - private PCAData GetPCAData(Transform originTransform, List points) - { - PCAData pCAData = new ProfileUtils_PCAUtil().ComputeRegionStats(points); - if (originTransform == null) - { - return pCAData; - } - PCAData result = new PCAData - { - pcaCenter = originTransform.InverseTransformPoint(pCAData.pcaCenter), - pcaPrincipalAxis = originTransform.InverseTransformDirection(pCAData.pcaPrincipalAxis).normalized, - pcaLength = pCAData.pcaLength, - pcaAvgRadius = pCAData.pcaAvgRadius - }; - if (Mathf.Abs(pCAData.pcaLength) < 0.0001f) - { - Debug.LogWarning("[ProfileUtils_PoseUtil] GetPCAData - " + originTransform.name + " Pca Length is to Small"); - } - return result; - } + private PCAData GetPCAData(Transform originTransform, List points) + { + PCAData pCAData = new ProfileUtils_PCAUtil().ComputeRegionStats(points); + if (originTransform == null) + { + return pCAData; + } + PCAData result = new PCAData + { + pcaCenter = originTransform.InverseTransformPoint(pCAData.pcaCenter), + pcaPrincipalAxis = originTransform.InverseTransformDirection(pCAData.pcaPrincipalAxis).normalized, + pcaLength = pCAData.pcaLength, + pcaAvgRadius = pCAData.pcaAvgRadius + }; + if (Mathf.Abs(pCAData.pcaLength) < 0.0001f) + { + Debug.LogWarning("[ProfileUtils_PoseUtil] GetPCAData - " + originTransform.name + " Pca Length is to Small"); + } + return result; + } - private VolumeData GetVolumeData(Transform originTransform, Transform axisTransform, List points) - { - return new ProfileUtils_VolumeUtil().GetVolumeData(originTransform, axisTransform, points); - } + private VolumeData GetVolumeData(Transform originTransform, Transform axisTransform, List points) + { + return new ProfileUtils_VolumeUtil().GetVolumeData(originTransform, axisTransform, points); + } - private Transform GetBaseBoneFromBoneMap(Dictionary> boneMap, HumanBodyBones bone) - { - if (boneMap == null || !boneMap.TryGetValue(bone, out var value) || value == null) - { - return null; - } - return value.FirstOrDefault(); - } + private Transform GetBaseBoneFromBoneMap(Dictionary> boneMap, HumanBodyBones bone) + { + if (boneMap == null || !boneMap.TryGetValue(bone, out var value) || value == null) + { + return null; + } + return value.FirstOrDefault(); + } } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_VertexUtil.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_VertexUtil.cs index 1e3a8bc..d494ca3 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_VertexUtil.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_VertexUtil.cs @@ -1,78 +1,77 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.ProfileUtils_VertexUtil using System; using System.IO; using System.Text; -using Eden.AutoMorpher.profile; using UnityEngine; public class ProfileUtils_VertexUtil { - public BaseKey3[] LoadTable(string path, out int version, out int countInFile) - { - version = 0; - countInFile = 0; - if (string.IsNullOrEmpty(path)) - { - Debug.LogError("[ProfileUtil_VertexUtil] LoadTable - path is null or empty"); - return null; - } - path = Path.Combine(Application.dataPath, path); - if (!File.Exists(path)) - { - Debug.LogError("[ProfileUtil_VertexUtil] LoadTable - file not found"); - return null; - } - string text; - try - { - text = File.ReadAllText(path, Encoding.UTF8); - } - catch (Exception ex) - { - Debug.LogError("[ProfileUtil_VertexUtil] LoadTable - read failed: " + ex.Message); - return null; - } - int num = 0; - string baseMagic = new ProfileUtils().GetBaseMagic(); - if (text.Length < 4 || text.Substring(0, 4) != baseMagic) - { - Debug.LogError("[ProfileUtil_VertexUtil] LoadTable - MAGIC mismatch"); - return null; - } - num += 4; - version = ReadHexIntSafe(text, ref num); - countInFile = ReadHexIntSafe(text, ref num); - if (countInFile <= 0) - { - Debug.LogError("[ProfileUtil_VertexUtil] LoadTable - invalid count"); - return null; - } - BaseKey3[] array = new BaseKey3[countInFile]; - for (int i = 0; i < countInFile; i++) - { - array[i] = ReadHexKey3Safe(text, ref num); - } - return array; - } + public BaseKey3[] LoadTable(string path, out int version, out int countInFile) + { + version = 0; + countInFile = 0; + if (string.IsNullOrEmpty(path)) + { + Debug.LogError("[ProfileUtil_VertexUtil] LoadTable - path is null or empty"); + return null; + } + path = Path.Combine(Application.dataPath, path); + if (!File.Exists(path)) + { + Debug.LogError("[ProfileUtil_VertexUtil] LoadTable - file not found"); + return null; + } + string text; + try + { + text = File.ReadAllText(path, Encoding.UTF8); + } + catch (Exception ex) + { + Debug.LogError("[ProfileUtil_VertexUtil] LoadTable - read failed: " + ex.Message); + return null; + } + int num = 0; + string baseMagic = new ProfileUtils().GetBaseMagic(); + if (text.Length < 4 || text.Substring(0, 4) != baseMagic) + { + Debug.LogError("[ProfileUtil_VertexUtil] LoadTable - MAGIC mismatch"); + return null; + } + num += 4; + version = this.ReadHexIntSafe(text, ref num); + countInFile = this.ReadHexIntSafe(text, ref num); + if (countInFile <= 0) + { + Debug.LogError("[ProfileUtil_VertexUtil] LoadTable - invalid count"); + return null; + } + BaseKey3[] array = new BaseKey3[countInFile]; + for (int i = 0; i < countInFile; i++) + { + array[i] = this.ReadHexKey3Safe(text, ref num); + } + return array; + } - private int ReadHexIntSafe(string s, ref int p) - { - if (p + 8 > s.Length) - { - Debug.LogError("[ProfileUtil_VertexUtil] ReadHexIntSafe - out of range"); - return 0; - } - string value = s.Substring(p, 8); - p += 8; - return (int)Convert.ToUInt32(value, 16); - } + private int ReadHexIntSafe(string s, ref int p) + { + if (p + 8 > s.Length) + { + Debug.LogError("[ProfileUtil_VertexUtil] ReadHexIntSafe - out of range"); + return 0; + } + string value = s.Substring(p, 8); + p += 8; + return (int)Convert.ToUInt32(value, 16); + } - private BaseKey3 ReadHexKey3Safe(string s, ref int p) - { - int x = ReadHexIntSafe(s, ref p); - uint y = (uint)ReadHexIntSafe(s, ref p); - uint z = (uint)ReadHexIntSafe(s, ref p); - return new BaseKey3((uint)x, y, z); - } + private BaseKey3 ReadHexKey3Safe(string s, ref int p) + { + int x = this.ReadHexIntSafe(s, ref p); + uint y = (uint)this.ReadHexIntSafe(s, ref p); + uint z = (uint)this.ReadHexIntSafe(s, ref p); + return new BaseKey3((uint)x, y, z); + } } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_VolumeUtil.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_VolumeUtil.cs index 7faed7c..6b39618 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_VolumeUtil.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/ProfileUtils_VolumeUtil.cs @@ -1,78 +1,77 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.ProfileUtils_VolumeUtil using System.Collections.Generic; -using Eden.AutoMorpher.profile; using UnityEngine; public class ProfileUtils_VolumeUtil { - public VolumeData GetVolumeData(Transform originTransform, Transform axisTransform, List points, int sampleStep = 1) - { - if (originTransform == null) - { - Debug.LogError("[ProfileUtils_VolumeUtil] originTransform is null"); - return null; - } - if (axisTransform == null) - { - Debug.LogError("[ProfileUtils_VolumeUtil] axisTransform is null"); - return null; - } - if (points == null || points.Count == 0) - { - Debug.LogError("[ProfileUtils_VolumeUtil] There is No Points to calculate volume"); - return null; - } - VolumeData volumeData = new VolumeData(); - Vector3 forward = axisTransform.forward; - Vector3 right = axisTransform.right; - Vector3 up = axisTransform.up; - float num = float.PositiveInfinity; - float num2 = float.NegativeInfinity; - float num3 = float.PositiveInfinity; - float num4 = float.NegativeInfinity; - float num5 = float.PositiveInfinity; - float num6 = float.NegativeInfinity; - for (int i = 0; i < points.Count; i += sampleStep) - { - Vector3 lhs = points[i] - originTransform.position; - float num7 = Vector3.Dot(lhs, up); - if (num7 < num) - { - num = num7; - } - if (num7 > num2) - { - num2 = num7; - } - float num8 = Vector3.Dot(lhs, forward); - if (num8 < num3) - { - num3 = num8; - } - if (num8 > num4) - { - num4 = num8; - } - float num9 = Vector3.Dot(lhs, right); - if (num9 < num5) - { - num5 = num9; - } - if (num9 > num6) - { - num6 = num9; - } - } - volumeData.forwardDir = forward; - volumeData.rightDir = right; - volumeData.upDir = up; - volumeData.fMaxLocalPos = originTransform.InverseTransformPoint(originTransform.position + forward * num4); - volumeData.fMinLocalPos = originTransform.InverseTransformPoint(originTransform.position + forward * num3); - volumeData.rMaxLocalPos = originTransform.InverseTransformPoint(originTransform.position + right * num6); - volumeData.rMinLocalPos = originTransform.InverseTransformPoint(originTransform.position + right * num5); - volumeData.uMaxLocalPos = originTransform.InverseTransformPoint(originTransform.position + up * num2); - volumeData.uMinLocalPos = originTransform.InverseTransformPoint(originTransform.position + up * num); - return volumeData; - } + public VolumeData GetVolumeData(Transform originTransform, Transform axisTransform, List points, int sampleStep = 1) + { + if (originTransform == null) + { + Debug.LogError("[ProfileUtils_VolumeUtil] originTransform is null"); + return null; + } + if (axisTransform == null) + { + Debug.LogError("[ProfileUtils_VolumeUtil] axisTransform is null"); + return null; + } + if (points == null || points.Count == 0) + { + Debug.LogError("[ProfileUtils_VolumeUtil] There is No Points to calculate volume"); + return null; + } + VolumeData volumeData = new VolumeData(); + Vector3 forward = axisTransform.forward; + Vector3 right = axisTransform.right; + Vector3 up = axisTransform.up; + float num = float.PositiveInfinity; + float num2 = float.NegativeInfinity; + float num3 = float.PositiveInfinity; + float num4 = float.NegativeInfinity; + float num5 = float.PositiveInfinity; + float num6 = float.NegativeInfinity; + for (int i = 0; i < points.Count; i += sampleStep) + { + Vector3 lhs = points[i] - originTransform.position; + float num7 = Vector3.Dot(lhs, up); + if (num7 < num) + { + num = num7; + } + if (num7 > num2) + { + num2 = num7; + } + float num8 = Vector3.Dot(lhs, forward); + if (num8 < num3) + { + num3 = num8; + } + if (num8 > num4) + { + num4 = num8; + } + float num9 = Vector3.Dot(lhs, right); + if (num9 < num5) + { + num5 = num9; + } + if (num9 > num6) + { + num6 = num9; + } + } + volumeData.forwardDir = forward; + volumeData.rightDir = right; + volumeData.upDir = up; + volumeData.fMaxLocalPos = originTransform.InverseTransformPoint(originTransform.position + forward * num4); + volumeData.fMinLocalPos = originTransform.InverseTransformPoint(originTransform.position + forward * num3); + volumeData.rMaxLocalPos = originTransform.InverseTransformPoint(originTransform.position + right * num6); + volumeData.rMinLocalPos = originTransform.InverseTransformPoint(originTransform.position + right * num5); + volumeData.uMaxLocalPos = originTransform.InverseTransformPoint(originTransform.position + up * num2); + volumeData.uMinLocalPos = originTransform.InverseTransformPoint(originTransform.position + up * num); + return volumeData; + } } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/VolumeData.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/VolumeData.cs index 7804d54..d861d7a 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/VolumeData.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/VolumeData.cs @@ -1,4 +1,4 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.VolumeData using System; using UnityEngine; @@ -6,21 +6,21 @@ using UnityEngine; [Serializable] public class VolumeData { - public Vector3 forwardDir; + public Vector3 forwardDir; - public Vector3 rightDir; + public Vector3 rightDir; - public Vector3 upDir; + public Vector3 upDir; - public Vector3 fMaxLocalPos; + public Vector3 fMaxLocalPos; - public Vector3 fMinLocalPos; + public Vector3 fMinLocalPos; - public Vector3 rMaxLocalPos; + public Vector3 rMaxLocalPos; - public Vector3 rMinLocalPos; + public Vector3 rMinLocalPos; - public Vector3 uMaxLocalPos; + public Vector3 uMaxLocalPos; - public Vector3 uMinLocalPos; + public Vector3 uMinLocalPos; } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/profileBVHData.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/profileBVHData.cs index aaa24b5..ae95389 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/profileBVHData.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/profileBVHData.cs @@ -1,10 +1,10 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.profileBVHData public class profileBVHData { - public int verA; + public int verA; - public int verB; + public int verB; - public int verC; + public int verC; } diff --git a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/profileBVHNode.cs b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/profileBVHNode.cs index d14c65d..49dc1bd 100644 --- a/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/profileBVHNode.cs +++ b/Assets/@Eden_Tools/Eden_AutoMorpher/ProfileSaver/Script/profileBVHNode.cs @@ -1,18 +1,18 @@ -// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.profile.profileBVHNode using UnityEngine; public class profileBVHNode { - public Bounds bounds; + public Bounds bounds; - public int leftChild; + public int leftChild; - public int rightChild; + public int rightChild; - public int start; + public int start; - public int count; + public int count; - public bool isLeaf; + public bool isLeaf; }