void ApplyHumanPose(GameObject avatar, PumkinsPosePreset hp) { Undo.RegisterFullObjectHierarchyUndo(avatar, "Load Human Pose"); Vector3 pos = avatar.transform.position; Quaternion rot = avatar.transform.rotation; avatar.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); hp.ApplyPreset(avatar); PumkinsAvatarTools.OnPoseWasChanged(PumkinsAvatarTools.PoseChangeType.Normal); avatar.transform.SetPositionAndRotation(pos, rot); }
public static void SetDefaultPoseByName(GameObject avatar, string poseName) { PumkinsPosePreset pose = DefaultPoses.Find(o => o.name.ToLower() == poseName.ToLower()); if (poseName.ToLower() == "tpose") { PumkinsAvatarTools.OnPoseWasChanged(PumkinsAvatarTools.PoseChangeType.Reset); } else { PumkinsAvatarTools.OnPoseWasChanged(PumkinsAvatarTools.PoseChangeType.Normal); } pose.ApplyPreset(avatar); }
/// <summary> /// Sets hardcoded TPose. /// </summary> public static void SetTPoseHardcoded(GameObject avatar) { Undo.RegisterFullObjectHierarchyUndo(avatar, "Set TPose"); var anim = avatar.GetComponent <Animator>(); if (anim && anim.avatar && anim.avatar.isHuman) { Vector3 pos = avatar.transform.position; Quaternion rot = avatar.transform.rotation; avatar.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); var humanPoseHandler = new HumanPoseHandler(anim.avatar, avatar.transform); var humanPose = new HumanPose(); humanPoseHandler.GetHumanPose(ref humanPose); //A long time ago CATS used to export avatars with a Armature scale of 100. This caused issues applying poses. //For now we'll just hardcode search for "Armature". //TODO: Find a better way to get the armature and check if it's scale could cause issues when tposing Transform armature = avatar.transform.Find("Armature"); if (!(armature && armature.localScale == Vector3.one)) { if (humanPose.bodyPosition.y < 1 && !Mathf.Approximately(humanPose.bodyPosition.y, 1)) { humanPose.bodyPosition.y = 1; PumkinsAvatarTools.LogVerbose(Strings.PoseEditor.bodyPositionYTooSmall, LogType.Warning, humanPose.bodyPosition.y.ToString()); } } #region Hardcoded TPose Values humanPose.muscles[0] = -6.830189E-07f; humanPose.muscles[1] = 4.268869E-08f; humanPose.muscles[2] = 4.268868E-08f; humanPose.muscles[3] = -8.537737E-08f; humanPose.muscles[4] = 0f; humanPose.muscles[5] = 0f; humanPose.muscles[6] = 0f; humanPose.muscles[7] = 0f; humanPose.muscles[8] = 0f; humanPose.muscles[9] = 4.268868E-08f; humanPose.muscles[10] = -8.537737E-08f; humanPose.muscles[11] = 4.268868E-08f; humanPose.muscles[12] = 3.415095E-07f; humanPose.muscles[13] = 0f; humanPose.muscles[14] = 0f; humanPose.muscles[15] = 0f; humanPose.muscles[16] = 0f; humanPose.muscles[17] = 0f; humanPose.muscles[18] = 0f; humanPose.muscles[19] = 0f; humanPose.muscles[20] = 0f; humanPose.muscles[21] = 0.5994893f; humanPose.muscles[22] = 0.004985309f; humanPose.muscles[23] = 0.00297395f; humanPose.muscles[24] = 0.9989594f; humanPose.muscles[25] = -0.02284526f; humanPose.muscles[26] = -3.449878E-05f; humanPose.muscles[27] = -0.0015229f; humanPose.muscles[28] = -4.781132E-07f; humanPose.muscles[29] = 0.599489f; humanPose.muscles[30] = 0.004985378f; humanPose.muscles[31] = 0.002974245f; humanPose.muscles[32] = 0.9989589f; humanPose.muscles[33] = -0.02284535f; humanPose.muscles[34] = -3.548912E-05f; humanPose.muscles[35] = -0.001522672f; humanPose.muscles[36] = -1.024528E-07f; humanPose.muscles[37] = -2.429621E-07f; humanPose.muscles[38] = 1.549688E-07f; humanPose.muscles[39] = 0.3847253f; humanPose.muscles[40] = 0.310061f; humanPose.muscles[41] = -0.103543f; humanPose.muscles[42] = 0.9925866f; humanPose.muscles[43] = 0.159403f; humanPose.muscles[44] = -0.01539368f; humanPose.muscles[45] = 0.01405432f; humanPose.muscles[46] = 5.680533E-08f; humanPose.muscles[47] = 2.701393E-07f; humanPose.muscles[48] = 0.3847259f; humanPose.muscles[49] = 0.3100605f; humanPose.muscles[50] = -0.1035404f; humanPose.muscles[51] = 0.9925874f; humanPose.muscles[52] = 0.1593992f; humanPose.muscles[53] = -0.01539393f; humanPose.muscles[54] = 0.01405326f; humanPose.muscles[55] = -0.7706841f; humanPose.muscles[56] = 0.423209f; humanPose.muscles[57] = 0.6456643f; humanPose.muscles[58] = 0.6362566f; humanPose.muscles[59] = 0.6677276f; humanPose.muscles[60] = -0.4597229f; humanPose.muscles[61] = 0.811684f; humanPose.muscles[62] = 0.8116837f; humanPose.muscles[63] = 0.6683907f; humanPose.muscles[64] = -0.5737826f; humanPose.muscles[65] = 0.8116839f; humanPose.muscles[66] = 0.8116843f; humanPose.muscles[67] = 0.6670681f; humanPose.muscles[68] = -0.6459302f; humanPose.muscles[69] = 0.8116837f; humanPose.muscles[70] = 0.8116839f; humanPose.muscles[71] = 0.666789f; humanPose.muscles[72] = -0.4676594f; humanPose.muscles[73] = 0.811684f; humanPose.muscles[74] = 0.8116839f; humanPose.muscles[75] = -0.7706831f; humanPose.muscles[76] = 0.4232127f; humanPose.muscles[77] = 0.6456538f; humanPose.muscles[78] = 0.6362569f; humanPose.muscles[79] = 0.6678051f; humanPose.muscles[80] = -0.4589976f; humanPose.muscles[81] = 0.8116843f; humanPose.muscles[82] = 0.8116842f; humanPose.muscles[83] = 0.668391f; humanPose.muscles[84] = -0.5737844f; humanPose.muscles[85] = 0.811684f; humanPose.muscles[86] = 0.8116837f; humanPose.muscles[87] = 0.6669571f; humanPose.muscles[88] = -0.6492739f; humanPose.muscles[89] = 0.8116841f; humanPose.muscles[90] = 0.8116843f; humanPose.muscles[91] = 0.6667888f; humanPose.muscles[92] = -0.4676568f; humanPose.muscles[93] = 0.8116842f; humanPose.muscles[94] = 0.8116836f; #endregion humanPoseHandler.SetHumanPose(ref humanPose); avatar.transform.SetPositionAndRotation(pos, rot); PumkinsAvatarTools.OnPoseWasChanged(PumkinsAvatarTools.PoseChangeType.Reset); } else { PumkinsAvatarTools.Log(Strings.Log.cantSetPoseNonHumanoid, LogType.Warning, "TPose"); } }
public override bool ApplyPreset(GameObject avatar) { if (!avatar) { return(false); } Undo.RegisterFullObjectHierarchyUndo(avatar, "Apply Pose"); PumkinsAvatarTools.ResetPose(avatar); if (presetMode == PosePresetMode.HumanPose) { Animator anim = avatar.GetComponent <Animator>(); if (anim && anim.avatar && anim.avatar.isHuman) { Vector3 pos = avatar.transform.position; Quaternion rot = avatar.transform.rotation; avatar.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); var humanPoseHandler = new HumanPoseHandler(anim.avatar, avatar.transform); var humanPose = new HumanPose(); humanPoseHandler.GetHumanPose(ref humanPose); humanPose.muscles = muscles; if (PumkinsAvatarTools.Instance.posePresetTryFixSinking) { if (humanPose.bodyPosition.y < 1 && !Mathf.Approximately(humanPose.bodyPosition.y, 0)) { PumkinsAvatarTools.Log(Strings.PoseEditor.bodyPositionYTooSmall, LogType.Warning, humanPose.bodyPosition.y.ToString()); humanPose.bodyPosition.y = 1; } } if (PumkinsAvatarTools.Instance.posePresetApplyBodyPosition) { humanPose.bodyPosition = bodyPosition; } if (PumkinsAvatarTools.Instance.posePresetApplyBodyRotation) { humanPose.bodyRotation = bodyRotation; } humanPoseHandler.SetHumanPose(ref humanPose); avatar.transform.SetPositionAndRotation(pos, rot); PumkinsAvatarTools.OnPoseWasChanged(PumkinsAvatarTools.PoseChangeType.Reset); return(true); } else { PumkinsAvatarTools.Log(Strings.Log.cantSetPoseNonHumanoid, LogType.Error, name); return(false); } } else { if (!avatar) { return(false); } for (int i = 0; i < transformPaths.Count; i++) { var t = avatar.transform.Find(transformPaths[i]); if (t != null) { t.localEulerAngles = transformRotations[i]; } } return(true); } }