73 lines
5.0 KiB
C#
73 lines
5.0 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: Eden.AutoMorpher.profile.ProfilePoseMatchUtil
|
|
// Assembly: EdenAutoMorpherScript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
|
|
// MVID: D39968B3-E151-4276-BDB4-E82752BBAFF0
|
|
// Assembly location: D:\dev\AutoMorpher\Assets\@Eden_Tools\Eden_AutoMorpher\Script\EdenAutoMorpherScript.dll
|
|
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Eden.AutoMorpher.profile;
|
|
|
|
public class ProfilePoseMatchUtil
|
|
{
|
|
private WorldVertexUtil _worldVertexUtil;
|
|
private MeshClassifier meshClassifier;
|
|
|
|
public ProfilePoseMatchUtil()
|
|
{
|
|
this._worldVertexUtil = new WorldVertexUtil();
|
|
this.meshClassifier = new MeshClassifier();
|
|
}
|
|
|
|
public void ProfilePoseMatcher(
|
|
GameObject targetAvatar,
|
|
IReadOnlyList<SkinnedMeshRenderer> targetBodyMeshes,
|
|
GameObject targetCloth,
|
|
ProfileData profileData,
|
|
Dictionary<HumanBodyBones, HashSet<Transform>> clothHumanBonesMap,
|
|
Dictionary<Transform, ClothBoneType> clothBoneTypeMap,
|
|
float neckTargetHeight = 1.5f)
|
|
{
|
|
if (Object.op_Equality((Object)targetAvatar, (Object)null))
|
|
throw new AutoMorpherException("Target Avatar is Null", "[ProfilePoseMatchUtil] ProfilePoseMatcher\n - targetAvatar is null");
|
|
if (Object.op_Equality((Object)targetAvatar.GetComponent<Animator>(), (Object)null))
|
|
throw new AutoMorpherException("Target Avatar Animator is Null", "[ProfilePoseMatchUtil] ProfilePoseMatcher\n - targetAvatar has no animator");
|
|
if (targetBodyMeshes == null || targetBodyMeshes.Count == 0)
|
|
throw new AutoMorpherException("Target Body Meshes are Missing", "[ProfilePoseMatchUtil] ProfilePoseMatcher\n - targetBodyMeshes is null or empty");
|
|
if (Object.op_Equality((Object)targetCloth, (Object)null))
|
|
throw new AutoMorpherException("Target Cloth is Null", "[ProfilePoseMatchUtil] ProfilePoseMatcher\n - targetCloth is null");
|
|
if (profileData == null)
|
|
throw new AutoMorpherException("Profile Data is Null", "[ProfilePoseMatchUtil] ProfilePoseMatcher\n - profileData is null");
|
|
if (clothHumanBonesMap == null || clothHumanBonesMap.Count == 0 || clothBoneTypeMap == null || clothBoneTypeMap.Count == 0)
|
|
throw new AutoMorpherException("Clothing Bone Match Data is Missing", "[ProfilePoseMatchUtil] ProfilePoseMatcher\n - profile Clothe Bone Match Data is null or empty");
|
|
Transform transform1 = targetAvatar.transform;
|
|
Transform transform2 = targetCloth.transform;
|
|
Transform parent1 = transform1.parent;
|
|
transform1.SetParent((Transform)null, true);
|
|
Transform parent2 = transform2.parent;
|
|
transform2.SetParent((Transform)null, true);
|
|
transform2.position = transform1.position;
|
|
Dictionary<HumanBodyBones, HashSet<Transform>> dictionary = this.meshClassifier.MeshHumanoidBoneMatcher(targetAvatar.GetComponent<Animator>(), targetBodyMeshes);
|
|
if (dictionary == null || dictionary.Count == 0)
|
|
throw new AutoMorpherException("Target Avatar Bone Match Data is Missing", "[ProfilePoseMatchUtil] ProfilePoseMatcher\n - target Avatar Bone Match Data is null or empty");
|
|
BodyPoseMatchSetupUtil poseMatchSetupUtil = new BodyPoseMatchSetupUtil();
|
|
Vector3 comprehensiveScale = poseMatchSetupUtil.GetComprehensiveScale(transform2, clothHumanBonesMap, profileData);
|
|
Debug.Log((object)$"ComprehensiveScale: {comprehensiveScale}");
|
|
poseMatchSetupUtil.AdjustAvatarScaleByNeck(transform1, dictionary, neckTargetHeight);
|
|
poseMatchSetupUtil.AdjustAvatarScaleByNeck(transform2, clothHumanBonesMap, neckTargetHeight);
|
|
List<BakedBodyMesh> targetBakedBodyMeshes = new List<BakedBodyMesh>();
|
|
foreach (SkinnedMeshRenderer targetBodyMesh in (IEnumerable<SkinnedMeshRenderer>)targetBodyMeshes)
|
|
targetBakedBodyMeshes.Add(new BakedBodyMesh(targetBodyMesh));
|
|
new BodyPoseMatch_Torso().AlignTorsoByNeck(transform1, (IReadOnlyList<BakedBodyMesh>)targetBakedBodyMeshes, dictionary, clothHumanBonesMap, transform2, profileData, comprehensiveScale);
|
|
BodyPoseMatch_Arm bodyPoseMatchArm = new BodyPoseMatch_Arm();
|
|
bodyPoseMatchArm.AlignUpperArmByArmPcaCenters((IReadOnlyList<BakedBodyMesh>)targetBakedBodyMeshes, dictionary, clothHumanBonesMap, transform2, profileData, comprehensiveScale);
|
|
bodyPoseMatchArm.ScalingBothArmsLength((IReadOnlyList<BakedBodyMesh>)targetBakedBodyMeshes, dictionary, clothHumanBonesMap, profileData, comprehensiveScale);
|
|
BodyPoseMatch_Leg bodyPoseMatchLeg = new BodyPoseMatch_Leg();
|
|
bodyPoseMatchLeg.AlignBothUpperLegs(transform1, (IReadOnlyList<BakedBodyMesh>)targetBakedBodyMeshes, dictionary, transform2, clothHumanBonesMap, profileData, comprehensiveScale);
|
|
bodyPoseMatchLeg.ScalingBothLegsAndFoots(transform1, (IReadOnlyList<BakedBodyMesh>)targetBakedBodyMeshes, dictionary, transform2, clothHumanBonesMap, profileData, comprehensiveScale);
|
|
transform1.SetParent(parent1, true);
|
|
transform2.SetParent(parent2, true);
|
|
}
|
|
}
|