From c17d6614715b338044d29a9ac3324414e7dc2cf3 Mon Sep 17 00:00:00 2001 From: soupday <79094830+soupday@users.noreply.github.com> Date: Thu, 3 Aug 2023 00:26:27 +0100 Subject: [PATCH] 1.5.2 Changelog HDRP12 --- CHANGELOG.md | 12 + Editor/AnimPlayerGUI.cs | 332 ++++++---------------------- Editor/AnimPlayerOverlay.cs | 51 +++-- Editor/AnimRetargetGUI.cs | 149 ++++++++----- Editor/AnimRetargetOverlay.cs | 26 ++- Editor/ColliderManagerEditor.cs | 1 - Editor/ImporterMenu.cs | 1 - Editor/ImporterWindow.cs | 9 - Editor/Lodify.cs | 1 - Editor/MeshUtil.cs | 6 +- Editor/Physics.cs | 4 - Editor/Pipeline.cs | 1 - Editor/Util.cs | 3 +- Editor/WeightMapperEditor.cs | 5 - Editor/WindowManager.cs | 81 +------ HDRP/Preview Scene/RL_FloorSpot.mat | 14 +- 16 files changed, 242 insertions(+), 454 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b18d20..03c05a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ Changelog ========= +### 1.5.2 +- Animation Retargeter fixes. + - AnimationMode removed. + - Clip generation file name suffix corrected. + - Animation Clip overwrite no longer breaks references in Unity 2023.1. + - Clip settings (foot IK, mirror, speed) reset to defaults on opening retarget window. +- Character prefab generation no longer breaks references. (Except 2023.1.1-5 due to Unity bugs) +- Rogue usings removed from code. +- Animation processing fixes. + - Correct character prefab used to retarget _motion.fbx files. + - Animation Clip overwrite no longer breaks references in Unity 2023.1. + ### 1.5.1 - Character Build no longer creates and adds a default animation controller due to bugs in Unity 2022/2023 causing memory leaks when applying animation controllers to prefabs. - Instalod and other renamed object/material name matching improvements. diff --git a/Editor/AnimPlayerGUI.cs b/Editor/AnimPlayerGUI.cs index b748e6b..c0cba55 100644 --- a/Editor/AnimPlayerGUI.cs +++ b/Editor/AnimPlayerGUI.cs @@ -84,8 +84,6 @@ public static void ClosePlayer() EditorApplication.update -= UpdateCallback; EditorApplication.playModeStateChanged -= PlayStateChangeCallback; - WindowManager.StopAnimationMode(); - if (CharacterAnimator) { GameObject scenePrefab = Util.GetScenePrefabInstanceRoot(CharacterAnimator.gameObject); @@ -162,16 +160,12 @@ static public void UpdateAnimatorClip(Animator animator, AnimationClip clip) { if (doneInitFace) ResetFace(true, true); - // stop animation mode - WindowManager.StopAnimationMode(); - if (!animator || CharacterAnimator != animator) doneInitFace = false; - CharacterAnimator = animator; + CharacterAnimator = animator; OriginalClip = clip; SetupCharacterAndAnimation(); - //WorkingClip = CloneClip(OriginalClip); AnimRetargetGUI.RebuildClip(); @@ -186,47 +180,6 @@ static public void UpdateAnimatorClip(Animator animator, AnimationClip clip) // finally, apply the face ApplyFace(); - - if (WorkingClip && CharacterAnimator) - { - // also restarts animation mode - //SampleOnce(); - } - - /* Original Code: - - if (doneInitFace) ResetFace(true, true); - - // stop animation mode - WindowManager.StopAnimationMode(); - - if (!animator || CharacterAnimator != animator) doneInitFace = false; - - CharacterAnimator = animator; - OriginalClip = clip; - WorkingClip = CloneClip(OriginalClip); - - AnimRetargetGUI.RebuildClip(); - - MeshFacialProfile = FacialProfileMapper.GetMeshFacialProfile(animator ? animator.gameObject : null); - ClipFacialProfile = FacialProfileMapper.GetAnimationClipFacialProfile(clip); - - time = 0f; - play = false; - - // intitialise the face refs if needed - if (!doneInitFace) InitFace(); - - // finally, apply the face - //ApplyFace(); - - if (WorkingClip && CharacterAnimator) - { - // also restarts animation mode - SampleOnce(); - } - - */ } #region Animator Setup @@ -270,7 +223,7 @@ enum AnimatorFlags // Animaton Override Controller [SerializeField] - private static AnimatorOverrideController animatorOverrideController; + public static AnimatorOverrideController animatorOverrideController; // Playback @@ -327,9 +280,6 @@ public static void SetupCharacterAndAnimation() // reset the animation player ResetAnimationPlayer(); - - - } private static AnimatorController CreateAnimatiorController() @@ -363,7 +313,7 @@ private static AnimatorOverrideController CreateAnimatorOverrideController() private static void ApplyDefaultSettings() { flagSettings = AnimatorFlags.AutoLoopPlayback; - FootIK = true; + SetFootIK(true); CharacterAnimator.SetFloat(paramDirection, 0f); if (CharacterAnimator != null) { @@ -371,6 +321,43 @@ private static void ApplyDefaultSettings() } } + // Important IK enable/disable function used by the retargeter + // (or you can't see the effects of changing the heel curves) + public static void SetFootIK(bool enable) + { + FootIK = enable; + + if (playbackAnimatorController) + { + AnimatorControllerLayer[] allLayer = playbackAnimatorController.layers; + for (int i = 0; i < allLayer.Length; i++) + { + ChildAnimatorState[] states = allLayer[i].stateMachine.states; + for (int j = 0; j < states.Length; j++) + { + if (states[j].state.nameHash == controlStateHash) + { + states[j].state.iKOnFeet = FootIK; + allLayer[i].iKPass = FootIK; + } + } + } + + if (EditorApplication.isPlaying) CharacterAnimator.gameObject.SetActive(false); + playbackAnimatorController.layers = allLayer; + if (EditorApplication.isPlaying) CharacterAnimator.gameObject.SetActive(true); + } + } + + // called by the retargetter to revert all settings to default + public static void ForceSettingsReset() + { + ApplyDefaultSettings(); + SetFootIK(false); + SetClipSettings(WorkingClip); + FirstFrameButton(); + } + private static void SelectOverrideAnimation(AnimationClip clip, AnimatorOverrideController aoc) { ResetAnimationPlayer(); @@ -394,6 +381,22 @@ private static void SelectOverrideAnimation(AnimationClip clip, AnimatorOverride FirstFrameButton(); } + public static void SelectOverrideAnimationWithoutReset(AnimationClip clip, AnimatorOverrideController aoc) + { + WorkingClip = clip; + + List> overrides = new List>(aoc.overridesCount); + aoc.GetOverrides(overrides); + + foreach (var v in overrides) + { + Util.LogInfo("Overrides: " + " Key: " + v.Key + " Value: " + v.Value); + } + + overrides[0] = new KeyValuePair(overrides[0].Key, WorkingClip); + aoc.ApplyOverrides(overrides); + } + private static void ResetAnimationPlayer() { play = false; @@ -424,7 +427,6 @@ private static void SetClipSettings(AnimationClip clip) CharacterAnimator.applyRootMotion = !flagSettings.HasFlag(AnimatorFlags.AnimateOnTheSpot); } - public static void ResetToBaseAnimatorController() { // look up the original prefab corresponding to the model in the preview scene @@ -524,105 +526,6 @@ public static AnimationClip CloneClip(AnimationClip clip) } #region IMGUI - /* //Original DrawPlayer() method - public static void ORIGINALDrawPlayer() - { - GUILayout.BeginVertical(); - EditorGUI.BeginChangeCheck(); - AnimFoldOut = EditorGUILayout.Foldout(AnimFoldOut, "Animation Playback", EditorStyles.foldout); - if (EditorGUI.EndChangeCheck()) - { - //if (foldOut && FacialMorphIMGUI.FoldOut) - // FacialMorphIMGUI.FoldOut = false; - doOnceCatchMouse = true; - } - if (AnimFoldOut) - { - EditorGUI.BeginChangeCheck(); - Animator selectedAnimator = (Animator)EditorGUILayout.ObjectField(new GUIContent("Scene Model", "Animated model in scene"), CharacterAnimator, typeof(Animator), true); - AnimationClip selectedClip = (AnimationClip)EditorGUILayout.ObjectField(new GUIContent("Animation", "Animation to play and manipulate"), OriginalClip, typeof(AnimationClip), false); - if (EditorGUI.EndChangeCheck()) - { - UpdateAnimatorClip(selectedAnimator, selectedClip); - } - - GUI.enabled = WorkingClip && CharacterAnimator; - - EditorGUI.BeginDisabledGroup(!AnimationMode.InAnimationMode()); - - if (WorkingClip != null) - { - float startTime = 0.0f; - float stopTime = WorkingClip.length; - EditorGUI.BeginChangeCheck(); - time = EditorGUILayout.Slider(time, startTime, stopTime); - if (EditorGUI.EndChangeCheck()) - { - ResetFace(); - } - } - else - { - float value = 0f; - value = EditorGUILayout.Slider(value, 0f, 1f); //disabled dummy entry - } - - GUILayout.BeginHorizontal(EditorStyles.toolbar); - // "Animation.FirstKey" - if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("Animation.FirstKey").image, "First Frame"), EditorStyles.toolbarButton)) - { - play = false; - time = 0f; - ResetFace(); - } - // "Animation.PrevKey" - if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("Animation.PrevKey").image, "Previous Frame"), EditorStyles.toolbarButton)) - { - play = false; - time -= 0.0166f; - ResetFace(); - } - // "Animation.Play" - EditorGUI.BeginChangeCheck(); - play = GUILayout.Toggle(play, new GUIContent(EditorGUIUtility.IconContent("Animation.Play").image, "Play (Toggle)"), EditorStyles.toolbarButton); - if (EditorGUI.EndChangeCheck()) - { - ResetFace(); - } - // "PauseButton" - if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("PauseButton").image, "Pause"), EditorStyles.toolbarButton)) - { - play = false; - ResetFace(); - } - // "Animation.NextKey" - if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("Animation.NextKey").image, "Next Frame"), EditorStyles.toolbarButton)) - { - play = false; - time += 0.0166f; - ResetFace(); - } - // "Animation.LastKey" - if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("Animation.LastKey").image, "Last Frame"), EditorStyles.toolbarButton)) - { - play = false; - time = WorkingClip.length; - ResetFace(); - } - - if (!UnityEditorInternal.InternalEditorUtility.isApplicationActive) play = false; - - GUILayout.EndHorizontal(); - - EditorGUI.EndDisabledGroup(); - - GUI.enabled = true; - } - GUILayout.EndVertical(); - } - // - */ - public class Styles { public GUIStyle settingsButton; @@ -686,14 +589,14 @@ public static void DrawPlayer() GUILayout.BeginHorizontal(); GUILayout.Space(4f); - + EditorGUI.BeginDisabledGroup(AnimRetargetGUI.IsPlayerShown()); EditorGUI.BeginChangeCheck(); - FootIK = GUILayout.Toggle(FootIK, new GUIContent("IK", "Toggle feet IK"), guiStyles.settingsButton, GUILayout.Width(24f), GUILayout.Height(24f)); + FootIK = GUILayout.Toggle(FootIK, new GUIContent("IK", FootIK ? "Toggle feet IK - Currently: ON" : "Toggle feet IK - Currently: OFF"), guiStyles.settingsButton, GUILayout.Width(24f), GUILayout.Height(24f)); if (EditorGUI.EndChangeCheck()) { ToggleIKButton(); } - + EditorGUI.EndDisabledGroup(); // Camera Bone Tracker if (!CheckTackingStatus()) @@ -731,11 +634,12 @@ public static void DrawPlayer() ResetCharacterAndPlayer(); } + EditorGUI.BeginDisabledGroup(AnimRetargetGUI.IsPlayerShown()); if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("d__Menu").image, "Animation Clip Preferences"), guiStyles.settingsButton, GUILayout.Width(20f), GUILayout.Height(20f))) { ShowPrefsGenericMenu(); } - + EditorGUI.EndDisabledGroup(); GUILayout.Space(4f); @@ -783,30 +687,23 @@ public static void DrawPlayer() EditorGUI.BeginDisabledGroup(!(CharacterAnimator && WorkingClip)); GUILayout.BeginHorizontal(EditorStyles.toolbar); + // "Animation.FirstKey" if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("Animation.FirstKey").image, "First Frame"), EditorStyles.toolbarButton)) { FirstFrameButton(); } + // "Animation.PrevKey" if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("Animation.PrevKey").image, "Previous Frame"), EditorStyles.toolbarButton)) { PrevFrameButton(); } + // "Animation.Play" Texture playButton = playbackSpeed > 0 ? EditorGUIUtility.IconContent("d_forward@2x").image : EditorGUIUtility.IconContent("d_back@2x").image; Texture pauseButton = EditorGUIUtility.IconContent("PauseButton").image; - /* - if (GUILayout.Button(new GUIContent(playButton, "Play"), EditorStyles.toolbarButton, GUILayout.Height(30f))) - { - PlayButton(); - } - // "PauseButton" - if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("PauseButton").image, "Pause"), EditorStyles.toolbarButton)) - { - PauseButton(); - } - */ + // play/pause: "Animation.Play" / "PauseButton" if (GUILayout.Button(new GUIContent(play ? pauseButton : playButton, play ? "Pause" : "Play"), EditorStyles.toolbarButton, GUILayout.Height(30f))) @@ -819,6 +716,7 @@ public static void DrawPlayer() { NextFrameButton(); } + // "Animation.LastKey" if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("Animation.LastKey").image, "Last Frame"), EditorStyles.toolbarButton)) { @@ -836,24 +734,7 @@ public static void DrawPlayer() ApplicationPlayToggle(); } - - GUILayout.EndHorizontal(); - - /* - EditorGUILayout.Space(28f); - GUILayout.BeginHorizontal(EditorStyles.toolbar); - GUILayout.FlexibleSpace(); - - Texture bigPlayButton = EditorApplication.isPlaying ? EditorGUIUtility.IconContent("preAudioPlayOn").image : EditorGUIUtility.IconContent("preAudioPlayOff").image; - string playToggleTxt = EditorApplication.isPlaying ? "Exit 'Play Mode'." : "Enter 'Play Mode' and focus on the scene view window. This is to be used to evaluate play mode physics whilst allowing visualization of objects such as colliders."; - if (GUILayout.Button(new GUIContent(bigPlayButton, playToggleTxt), EditorStyles.toolbarButton, GUILayout.Height(100f), GUILayout.Width(100f))) - { - ApplicationPlayToggle(); - } - - GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); - */ } GUILayout.EndVertical(); } @@ -867,22 +748,7 @@ private static void ToggleIKButton() { // Alternative method - retrieve a copy of the layers - modify then reapply // find the controlstate by nameHash - AnimatorControllerLayer[] allLayer = playbackAnimatorController.layers; - for (int i = 0; i < allLayer.Length; i++) - { - ChildAnimatorState[] states = allLayer[i].stateMachine.states; - for (int j = 0; j < states.Length; j++) - { - if (states[j].state.nameHash == controlStateHash) - { - states[j].state.iKOnFeet = FootIK; - allLayer[i].iKPass = FootIK; - } - } - } - if (EditorApplication.isPlaying) CharacterAnimator.gameObject.SetActive(false); - playbackAnimatorController.layers = allLayer; - if (EditorApplication.isPlaying) CharacterAnimator.gameObject.SetActive(true); + SetFootIK(FootIK); // originally using the cached default state directly ... // both methods encounter errors when changing foot ik during runtime @@ -903,7 +769,7 @@ private static void ToggleIKButton() CharacterAnimator.Update(time); } } - + // playback speed slider sets speed multiplier directly in edit mode but requires an update in play mode private static void PlaybackSpeedSlider() { @@ -927,13 +793,10 @@ public static void ResetCharacterAndPlayer() // reset the player ResetAnimationPlayer(); - // clear all the animation data ============================================================== - // ============================================================================================ + // clear all the animation data WorkingClip = null; OriginalClip = null; - // ENSURE RESET OF SELECTION FIELDS TOO - // ============================================================================================ - + // clear the animation controller + override controller // remove the on-disk temporary controller ResetToBaseAnimatorController(); @@ -1400,16 +1263,7 @@ private static void DeselectAllBones() }; #endregion Pose reset and bone tracking - public static void SampleOnce() - { - if (CharacterAnimator && WorkingClip) - { - if (!AnimationMode.InAnimationMode()) AnimationMode.StartAnimationMode(); - AnimationMode.BeginSampling(); - AnimationMode.SampleAnimationClip(CharacterAnimator.gameObject, WorkingClip, time); - AnimationMode.EndSampling(); - } - } + #region Update private static void PlayStateChangeCallback(PlayModeStateChange state) @@ -1514,50 +1368,8 @@ private static void UpdateCallback() } } - - #endregion Update - - private static void UpdateDelegate() - { - if (updateTime == 0f) updateTime = EditorApplication.timeSinceStartup; - deltaTime = EditorApplication.timeSinceStartup - updateTime; - updateTime = EditorApplication.timeSinceStartup; - - AdjustEyes(); - - if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode()) - { - if (WorkingClip && CharacterAnimator) - { - if (play) - { - double frameDuration = 1.0f / WorkingClip.frameRate; - - time += (float)deltaTime; - frameTime += deltaTime; - if (time >= WorkingClip.length) - time = 0f; - - if (frameTime < frameDuration) return; - frameTime = 0f; - } - else - frameTime = 1f; - - if (current != time || forceUpdate) - { - AnimationMode.BeginSampling(); - AnimationMode.SampleAnimationClip(CharacterAnimator.gameObject, WorkingClip, time); - AnimationMode.EndSampling(); - SceneView.RepaintAll(); - - AnimPlayerGUI.current = time; - forceUpdate = false; - } - } - } - } + #endregion Update #endregion AnimPlayer diff --git a/Editor/AnimPlayerOverlay.cs b/Editor/AnimPlayerOverlay.cs index 1165e23..eb26d83 100644 --- a/Editor/AnimPlayerOverlay.cs +++ b/Editor/AnimPlayerOverlay.cs @@ -35,7 +35,10 @@ public class AnimPlayerOverlay : IMGUIOverlay, ITransientOverlay private static bool visibility = false; public static bool Visibility { get { return visibility; } } public static float width; - public static float height; + public static float height; + public static float containerHeight; + public static float containerWidth; + public static bool setInitialPosition = false; public static bool AnyVisible() { @@ -45,19 +48,19 @@ public static bool AnyVisible() } return false; } - + public static void ShowAll() { - visibility = true; + visibility = true; foreach (AnimPlayerOverlay apo in createdOverlays) { apo.Show(); - } + } } public static void HideAll() { - visibility = false; + visibility = false; foreach (AnimPlayerOverlay apo in createdOverlays) { apo.Hide(); @@ -65,33 +68,30 @@ public static void HideAll() } AnimPlayerOverlay() - { - isVisible = visibility; + { + isVisible = visibility; } public void Show() - { - isVisible = true; + { if (isInToolbar) Undock(); - collapsed = false; - floatingPosition = new Vector2( - containerWindow.position.width - width - 3f, - containerWindow.position.height - height - 3f - ); + collapsed = false; + setInitialPosition = true; + isVisible = true; } public void Hide() - { + { isVisible = false; } public override void OnCreated() - { - createdOverlays.Add(this); + { + createdOverlays.Add(this); } public override void OnWillBeDestroyed() - { + { if (createdOverlays.Contains(this)) { Hide(); @@ -106,11 +106,18 @@ public override void OnGUI() AnimPlayerGUI.DrawPlayer(); AnimPlayerGUI.DrawFacialMorph(); - if (Event.current.type == EventType.Repaint) + if (setInitialPosition) { - Rect last = GUILayoutUtility.GetLastRect(); - width = last.x + last.width; - height = last.y + last.height; + if (Event.current.type == EventType.Repaint) + { + Rect last = GUILayoutUtility.GetLastRect(); + width = last.x + last.width; + height = last.y + last.height; + containerHeight = this.containerWindow.position.height; + containerWidth = this.containerWindow.position.width; + floatingPosition = new Vector2(containerWidth - width - 14f, containerHeight - height - 23f); + setInitialPosition = false; + } } } } diff --git a/Editor/AnimRetargetGUI.cs b/Editor/AnimRetargetGUI.cs index 6797565..05fc3d8 100644 --- a/Editor/AnimRetargetGUI.cs +++ b/Editor/AnimRetargetGUI.cs @@ -112,9 +112,6 @@ public static void CloseRetargeter() { //EditorApplication.update -= UpdateDelegate; - //if (AnimationMode.InAnimationMode()) - // AnimationMode.StopAnimationMode(); - #if SCENEVIEW_OVERLAY_COMPATIBLE //2021.2.0a17+ AnimRetargetOverlay.HideAll(); @@ -154,11 +151,17 @@ static void Init() unlockedImage = Reallusion.Import.Util.FindTexture(folders, "RLIcon_Unlocked"); RebuildClip(); + + // reset all the clip flags to their default vaules + // set the animation player's Foot IK to off + AnimPlayerGUI.ForceSettingsReset(); + AnimPlayerGUI.UpdateAnimator(); } static void CleanUp() - { - + { + // reset the player fully with the currently selected clip + AnimPlayerGUI.SetupCharacterAndAnimation(); } public static void ResetClip() @@ -271,7 +274,6 @@ public static void DrawRetargeter() // All retarget controls GUILayout.BeginVertical(); // Horizontal Group of 3 controls `Hand` `Jaw` and `Blendshapes` - //EditorGUI.BeginDisabledGroup(!AnimationMode.InAnimationMode()); GUILayout.BeginHorizontal(); GUILayout.BeginVertical("box", GUILayout.Width(baseControlWidth)); // Hand control box - Width used to impose layout footprint for overlay GUILayout.BeginHorizontal(); @@ -279,8 +281,7 @@ public static void DrawRetargeter() { handPose++; if (handPose > 2) handPose = 0; - ApplyPose(handPose); - AnimPlayerGUI.SampleOnce(); + ApplyPose(handPose); } GUILayout.BeginVertical(); @@ -297,7 +298,6 @@ public static void DrawRetargeter() if (EditorGUI.EndChangeCheck()) { ApplyPose(handPose); - AnimPlayerGUI.SampleOnce(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); @@ -309,7 +309,6 @@ public static void DrawRetargeter() { closeMouth = !closeMouth; CloseMouthToggle(closeMouth); - AnimPlayerGUI.SampleOnce(); } GUILayout.EndVertical(); // End of Jaw control @@ -353,7 +352,7 @@ public static void DrawRetargeter() if (GUILayout.Button(new GUIContent(blendshapeImage, "Copy all BlendShape animations from the selected animation clip to all of the relevant objects (e.g. facial hair) in the selected Scene Model."), GUILayout.Width(largeIconDim), GUILayout.Height(largeIconDim))) { RetargetBlendShapes(OriginalClip, WorkingClip, CharacterAnimator.gameObject); - AnimPlayerGUI.SampleOnce(); + AnimPlayerGUI.UpdateAnimator(); } GUI.backgroundColor = backgroundColor; GUI.enabled = true; @@ -371,9 +370,6 @@ public static void DrawRetargeter() if (EditorGUI.EndChangeCheck()) { OffsetShoulders(); - CharacterAnimator.gameObject.transform.position = animatorPosition; - CharacterAnimator.gameObject.transform.rotation = animatorRotation; - AnimPlayerGUI.SampleOnce(); } EditorGUI.BeginChangeCheck(); @@ -384,9 +380,6 @@ public static void DrawRetargeter() if (EditorGUI.EndChangeCheck()) { OffsetArms(); - CharacterAnimator.gameObject.transform.position = animatorPosition; - CharacterAnimator.gameObject.transform.rotation = animatorRotation; - AnimPlayerGUI.SampleOnce(); } EditorGUI.BeginChangeCheck(); @@ -396,10 +389,7 @@ public static void DrawRetargeter() GUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { - OffsetArmsFB(); - CharacterAnimator.gameObject.transform.position = animatorPosition; - CharacterAnimator.gameObject.transform.rotation = animatorRotation; - AnimPlayerGUI.SampleOnce(); + OffsetArmsFB(); } EditorGUI.BeginChangeCheck(); @@ -409,10 +399,7 @@ public static void DrawRetargeter() GUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { - OffsetLegs(); - CharacterAnimator.gameObject.transform.position = animatorPosition; - CharacterAnimator.gameObject.transform.rotation = animatorRotation; - AnimPlayerGUI.SampleOnce(); + OffsetLegs(); } EditorGUI.BeginChangeCheck(); @@ -422,10 +409,7 @@ public static void DrawRetargeter() GUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { - OffsetHeel(); - CharacterAnimator.gameObject.transform.position = animatorPosition; - CharacterAnimator.gameObject.transform.rotation = animatorRotation; - AnimPlayerGUI.SampleOnce(); + OffsetHeel(); } EditorGUI.BeginChangeCheck(); @@ -435,10 +419,7 @@ public static void DrawRetargeter() GUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { - OffsetHeight(); - CharacterAnimator.gameObject.transform.position = animatorPosition; - CharacterAnimator.gameObject.transform.rotation = animatorRotation; - AnimPlayerGUI.SampleOnce(); + OffsetHeight(); } GUILayout.EndVertical(); // End of animation curve adjustment sliders @@ -461,9 +442,6 @@ public static void DrawRetargeter() if (GUILayout.Button(new GUIContent(resetImage, "Reset all slider settings and applied modifications."), GUILayout.Width(smallIconDim), GUILayout.Height(smallIconDim))) { ResetClip(); - CharacterAnimator.gameObject.transform.position = animatorPosition; - CharacterAnimator.gameObject.transform.rotation = animatorRotation; - AnimPlayerGUI.SampleOnce(); } GUILayout.EndVertical(); GUILayout.BeginVertical("box"); // save button @@ -545,8 +523,10 @@ static void CloseMouthToggle(bool close) } jawCurve.keys = jawKeys; } - - AnimationUtility.SetEditorCurve(WorkingClip, targetBinding, jawCurve); + AnimationClip swapClip = AnimPlayerGUI.CloneClip(WorkingClip); + AnimationUtility.SetEditorCurve(swapClip, targetBinding, jawCurve); + AnimPlayerGUI.SelectOverrideAnimationWithoutReset(swapClip, AnimPlayerGUI.animatorOverrideController); + AnimPlayerGUI.UpdateAnimator(); } @@ -571,7 +551,6 @@ static void ApplyPose(int mode) SetPose(closedHandPose); break; } - } } @@ -579,6 +558,8 @@ static void SetPose(Dictionary pose) { if (!(OriginalClip && WorkingClip)) return; + AnimationClip swapClip = AnimPlayerGUI.CloneClip(WorkingClip); + EditorCurveBinding[] curveBindings = AnimationUtility.GetCurveBindings(OriginalClip); foreach (EditorCurveBinding binding in curveBindings) { @@ -593,25 +574,31 @@ static void SetPose(Dictionary pose) keys[i].value = p.Value; } curve.keys = keys; - AnimationUtility.SetEditorCurve(WorkingClip, binding, curve); + AnimationUtility.SetEditorCurve(swapClip, binding, curve); } } } + AnimPlayerGUI.SelectOverrideAnimationWithoutReset(swapClip, AnimPlayerGUI.animatorOverrideController); + AnimPlayerGUI.UpdateAnimator(); } static void ResetPose() { if (!(OriginalClip && WorkingClip)) return; + AnimationClip swapClip = AnimPlayerGUI.CloneClip(WorkingClip); + EditorCurveBinding[] curveBindings = AnimationUtility.GetCurveBindings(OriginalClip); foreach (EditorCurveBinding binding in curveBindings) { if (handCurves.Contains(binding.propertyName)) { AnimationCurve curve = AnimationUtility.GetEditorCurve(OriginalClip, binding); - AnimationUtility.SetEditorCurve(WorkingClip, binding, curve); + AnimationUtility.SetEditorCurve(swapClip, binding, curve); } } + AnimPlayerGUI.SelectOverrideAnimationWithoutReset(swapClip, AnimPlayerGUI.animatorOverrideController); + AnimPlayerGUI.UpdateAnimator(); } static void OffsetALL() @@ -625,9 +612,26 @@ static void OffsetALL() CloseMouthToggle(closeMouth); ApplyPose(handPose); } + + static void SetEditorCurves(AnimationClip clip, List bindings, List curves) + { +#if UNITY_2020_3_OR_NEWER + AnimationUtility.SetEditorCurves(clip, bindings.ToArray(), curves.ToArray()); +#else + int numClips = bindings.Count; + for (int i = 0; i < numClips; i++) + { + AnimationUtility.SetEditorCurve(clip, bindings[i], curves[i]); + } +#endif + } + static void OffsetShoulders() { if (!(OriginalClip && WorkingClip)) return; + + List applicableBindings = new List(); + List applicableCurves = new List(); foreach (KeyValuePair bind in shoulderBindings) { @@ -688,7 +692,6 @@ static void OffsetShoulders() break; } - float diff = shoulderOffset * scale; if (update) { @@ -696,11 +699,8 @@ static void OffsetShoulders() diff = (backgroundArmOffset + armOffset) * scale; } - - for (int a = 0; a < keys.Length; a++) { - keys[a].value = eval ? EvaluateValue(keys[a].value, subtract ? -diff : diff) : keys[a].value + (subtract ? -diff : diff); } curve.keys = keys; @@ -708,14 +708,22 @@ static void OffsetShoulders() { curve.SmoothTangents(b, 0.0f); } - AnimationUtility.SetEditorCurve(WorkingClip, bind.Value, curve); - } + applicableBindings.Add(bind.Value); + applicableCurves.Add(curve); + } + AnimationClip swapClip = AnimPlayerGUI.CloneClip(WorkingClip); + SetEditorCurves(swapClip, applicableBindings, applicableCurves); + AnimPlayerGUI.SelectOverrideAnimationWithoutReset(swapClip, AnimPlayerGUI.animatorOverrideController); + AnimPlayerGUI.UpdateAnimator(); } static void OffsetArms() { if (!(OriginalClip && WorkingClip)) return; + List applicableBindings = new List(); + List applicableCurves = new List(); + foreach (KeyValuePair bind in armBindings) { float scale = 0f; @@ -775,14 +783,22 @@ static void OffsetArms() { curve.SmoothTangents(b, 0.0f); } - AnimationUtility.SetEditorCurve(WorkingClip, bind.Value, curve); + applicableBindings.Add(bind.Value); + applicableCurves.Add(curve); } + AnimationClip swapClip = AnimPlayerGUI.CloneClip(WorkingClip); + SetEditorCurves(swapClip, applicableBindings, applicableCurves); + AnimPlayerGUI.SelectOverrideAnimationWithoutReset(swapClip, AnimPlayerGUI.animatorOverrideController); + AnimPlayerGUI.UpdateAnimator(); } static void OffsetArmsFB() { if (!(OriginalClip && WorkingClip)) return; + List applicableBindings = new List(); + List applicableCurves = new List(); + foreach (KeyValuePair bind in armFBBindings) { float scale = 0f; @@ -828,14 +844,22 @@ static void OffsetArmsFB() { curve.SmoothTangents(b, 0.0f); } - AnimationUtility.SetEditorCurve(WorkingClip, bind.Value, curve); + applicableBindings.Add(bind.Value); + applicableCurves.Add(curve); } + AnimationClip swapClip = AnimPlayerGUI.CloneClip(WorkingClip); + SetEditorCurves(swapClip, applicableBindings, applicableCurves); + AnimPlayerGUI.SelectOverrideAnimationWithoutReset(swapClip, AnimPlayerGUI.animatorOverrideController); + AnimPlayerGUI.UpdateAnimator(); } static void OffsetLegs() { if (!(OriginalClip && WorkingClip)) return; + List applicableBindings = new List(); + List applicableCurves = new List(); + foreach (KeyValuePair bind in legBindings) { float scale = 0f; @@ -889,14 +913,22 @@ static void OffsetLegs() { curve.SmoothTangents(b, 0.0f); } - AnimationUtility.SetEditorCurve(WorkingClip, bind.Value, curve); + applicableBindings.Add(bind.Value); + applicableCurves.Add(curve); } + AnimationClip swapClip = AnimPlayerGUI.CloneClip(WorkingClip); + SetEditorCurves(swapClip, applicableBindings, applicableCurves); + AnimPlayerGUI.SelectOverrideAnimationWithoutReset(swapClip, AnimPlayerGUI.animatorOverrideController); + AnimPlayerGUI.UpdateAnimator(); } static void OffsetHeel() { if (!(OriginalClip && WorkingClip)) return; + List applicableBindings = new List(); + List applicableCurves = new List(); + foreach (KeyValuePair bind in heelBindings) { float scale = 0f; @@ -950,14 +982,22 @@ static void OffsetHeel() { curve.SmoothTangents(b, 0.0f); } - AnimationUtility.SetEditorCurve(WorkingClip, bind.Value, curve); + applicableBindings.Add(bind.Value); + applicableCurves.Add(curve); } + AnimationClip swapClip = AnimPlayerGUI.CloneClip(WorkingClip); + SetEditorCurves(swapClip, applicableBindings, applicableCurves); + AnimPlayerGUI.SelectOverrideAnimationWithoutReset(swapClip, AnimPlayerGUI.animatorOverrideController); + AnimPlayerGUI.UpdateAnimator(); } static void OffsetHeight() { if (!(OriginalClip && WorkingClip)) return; + List applicableBindings = new List(); + List applicableCurves = new List(); + foreach (KeyValuePair bind in heightBindings) { AnimationCurve curve = AnimationUtility.GetEditorCurve(OriginalClip, bind.Value); @@ -974,8 +1014,13 @@ static void OffsetHeight() { curve.SmoothTangents(b, 0.0f); } - AnimationUtility.SetEditorCurve(WorkingClip, bind.Value, curve); + applicableBindings.Add(bind.Value); + applicableCurves.Add(curve); } + AnimationClip swapClip = AnimPlayerGUI.CloneClip(WorkingClip); + SetEditorCurves(swapClip, applicableBindings, applicableCurves); + AnimPlayerGUI.SelectOverrideAnimationWithoutReset(swapClip, AnimPlayerGUI.animatorOverrideController); + AnimPlayerGUI.UpdateAnimator(); } static float EvaluateValue(float currentKeyValue, float deltaValue) diff --git a/Editor/AnimRetargetOverlay.cs b/Editor/AnimRetargetOverlay.cs index ff159b6..58a4978 100644 --- a/Editor/AnimRetargetOverlay.cs +++ b/Editor/AnimRetargetOverlay.cs @@ -34,7 +34,9 @@ public class AnimRetargetOverlay : IMGUIOverlay, ITransientOverlay private static bool visibility = false; public static bool Visibility { get { return visibility; } } public static float width; - public static float height; + public static float height; + public static float containerHeight; + public static bool setInitialPosition = false; public static bool AnyVisible() { @@ -70,14 +72,15 @@ public static void HideAll() public void Show() { - isVisible = true; + setInitialPosition = true; Undock(); Undock(); - collapsed = false; + collapsed = false; floatingPosition = new Vector2( 1f, this.containerWindow.position.height - height - 3f ); + isVisible = true; } public void Hide() @@ -103,14 +106,19 @@ public override void OnWillBeDestroyed() public override void OnGUI() { - //if (!AnimPlayerGUI.useLightIcons) AnimPlayerGUI.useLightIcons = true; - AnimRetargetGUI.DrawRetargeter(); + AnimRetargetGUI.DrawRetargeter(); - if (Event.current.type == EventType.Repaint) + if (setInitialPosition) { - Rect last = GUILayoutUtility.GetLastRect(); - width = last.x + last.width; - height = last.y + last.height; + if (Event.current.type == EventType.Repaint) + { + Rect last = GUILayoutUtility.GetLastRect(); + width = last.x + last.width; + height = last.y + last.height; + containerHeight = this.containerWindow.position.height; + floatingPosition = new Vector2(1f, containerHeight - height - 23f); + setInitialPosition = false; + } } } } diff --git a/Editor/ColliderManagerEditor.cs b/Editor/ColliderManagerEditor.cs index 306b5d3..0b0c1de 100644 --- a/Editor/ColliderManagerEditor.cs +++ b/Editor/ColliderManagerEditor.cs @@ -295,7 +295,6 @@ public void UpdatePrefab(Object component) { WindowManager.HideAnimationPlayer(true); WindowManager.HideAnimationRetargeter(true); - WindowManager.StopAnimationMode(); GameObject prefabRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(component); if (prefabRoot) diff --git a/Editor/ImporterMenu.cs b/Editor/ImporterMenu.cs index 23e27a2..9534ba4 100644 --- a/Editor/ImporterMenu.cs +++ b/Editor/ImporterMenu.cs @@ -20,7 +20,6 @@ using UnityEngine; using UnityEditor; -using System.IO; namespace Reallusion.Import { diff --git a/Editor/ImporterWindow.cs b/Editor/ImporterWindow.cs index c0fb01a..76805ee 100644 --- a/Editor/ImporterWindow.cs +++ b/Editor/ImporterWindow.cs @@ -1267,11 +1267,7 @@ public bool UpdatePreviewCharacter(GameObject prefabAsset) { if (WindowManager.IsPreviewScene) { - bool animationMode = WindowManager.StopAnimationMode(); - WindowManager.GetPreviewScene().UpdatePreviewCharacter(prefabAsset); - - WindowManager.RestartAnimationMode(animationMode); } return WindowManager.IsPreviewScene; @@ -1369,11 +1365,7 @@ bool ShowBakedCharacter(GameObject bakedAsset) { if (WindowManager.IsPreviewScene) { - bool animationMode = WindowManager.StopAnimationMode(); - WindowManager.GetPreviewScene().ShowBakedCharacter(bakedAsset); - - WindowManager.RestartAnimationMode(animationMode); } return WindowManager.IsPreviewScene; @@ -1383,7 +1375,6 @@ void RebuildCharacterPhysics() { WindowManager.HideAnimationPlayer(true); WindowManager.HideAnimationRetargeter(true); - WindowManager.StopAnimationMode(); GameObject prefabAsset = Physics.RebuildPhysics(contextCharacter); diff --git a/Editor/Lodify.cs b/Editor/Lodify.cs index c0948c1..7f2a61b 100644 --- a/Editor/Lodify.cs +++ b/Editor/Lodify.cs @@ -16,7 +16,6 @@ * along with CC_Unity_Tools. If not, see . */ -using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; diff --git a/Editor/MeshUtil.cs b/Editor/MeshUtil.cs index edfbf0e..e48add8 100644 --- a/Editor/MeshUtil.cs +++ b/Editor/MeshUtil.cs @@ -238,9 +238,7 @@ public static Mesh GetMeshFrom(Object obj) } public static bool ReplaceMesh(Object obj, Mesh mesh) - { - bool animationMode = WindowManager.StopAnimationMode(obj); - + { bool replaced = false; Object o = null; @@ -276,8 +274,6 @@ public static bool ReplaceMesh(Object obj, Mesh mesh) PrefabUtility.ApplyPrefabInstance(sceneRoot, InteractionMode.UserAction); } - WindowManager.RestartAnimationMode(animationMode); - return replaced; } diff --git a/Editor/Physics.cs b/Editor/Physics.cs index 97fb65f..5fd9d50 100644 --- a/Editor/Physics.cs +++ b/Editor/Physics.cs @@ -276,15 +276,11 @@ private void ReadPhysicsJson(QuickJSON physicsJson, QuickJSON characterJson) public void AddPhysics(bool applyInstance) { - bool animationMode = WindowManager.StopAnimationMode(); - AddColliders(); AddCloth(); AddSpringBones(); if (applyInstance) PrefabUtility.ApplyPrefabInstance(prefabInstance, InteractionMode.AutomatedAction); - - WindowManager.RestartAnimationMode(animationMode); } public void RemoveAllPhysics() diff --git a/Editor/Pipeline.cs b/Editor/Pipeline.cs index 5cb459b..8897ac8 100644 --- a/Editor/Pipeline.cs +++ b/Editor/Pipeline.cs @@ -19,7 +19,6 @@ using System.Collections.Generic; using UnityEditor; using UnityEngine; -using UnityEngine.Rendering; #if HDRP_10_5_0_OR_NEWER using UnityEngine.Rendering.HighDefinition; using UnityEditor.Rendering.HighDefinition; diff --git a/Editor/Util.cs b/Editor/Util.cs index b144ad6..e0b3c58 100644 --- a/Editor/Util.cs +++ b/Editor/Util.cs @@ -1095,8 +1095,9 @@ public static bool AssetPathExists(string assetPath) public static bool AssetPathIsEmpty(string assetPath) { const string emptyGuid = "00000000000000000000000000000000"; + string pathGUID = AssetDatabase.AssetPathToGUID(assetPath); - return AssetDatabase.AssetPathToGUID(assetPath).Equals(emptyGuid); + return (pathGUID.Equals(emptyGuid) || string.IsNullOrEmpty(pathGUID)); } public static bool HasMaterialKeywords(GameObject obj, params string[] keywords) diff --git a/Editor/WeightMapperEditor.cs b/Editor/WeightMapperEditor.cs index db4413a..cda7786 100644 --- a/Editor/WeightMapperEditor.cs +++ b/Editor/WeightMapperEditor.cs @@ -59,11 +59,7 @@ public void OnClothInspectorGUI() GUI.backgroundColor = Color.Lerp(background, Color.white, 0.25f); if (GUILayout.Button("Rebuild Constraints", GUILayout.Width(BUTTON_WIDTH))) { - bool animationMode = WindowManager.StopAnimationMode(); - weightMapper.ApplyWeightMap(); - - WindowManager.RestartAnimationMode(animationMode); } GUI.backgroundColor = background; GUILayout.FlexibleSpace(); @@ -117,7 +113,6 @@ public void UpdatePrefab(Object component) { WindowManager.HideAnimationPlayer(true); WindowManager.HideAnimationRetargeter(true); - WindowManager.StopAnimationMode(); GameObject prefabRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(component); if (prefabRoot) diff --git a/Editor/WindowManager.cs b/Editor/WindowManager.cs index 5205443..ff8e33b 100644 --- a/Editor/WindowManager.cs +++ b/Editor/WindowManager.cs @@ -147,66 +147,13 @@ public static void OnPlayModeStateChanged(PlayModeStateChange state) break; } } - /* - if (state == PlayModeStateChange.EnteredPlayMode) - { - showPlayerAfterPlayMode = showPlayer; - showRetargetAfterPlayMode = showRetarget; - showPlayer = false; - showRetarget = false; - AnimPlayerGUI.ClosePlayer(); - AnimRetargetGUI.CloseRetargeter(); - - /* - // original - showPlayerAfterPlayMode = showPlayer; - showRetargetAfterPlayMode = showRetarget; - showPlayer = false; - showRetarget = false; - AnimPlayerGUI.ClosePlayer(); - AnimRetargetGUI.CloseRetargeter(); - */ - /* - if (Util.TryDeSerializeBoolFromEditorPrefs(out bool val, WindowManager.sceneFocus)) - { - if (val) - { - SceneView.lastActiveSceneView.Focus(); - Util.SerializeBoolToEditorPrefs(false, WindowManager.sceneFocus); - ShowAnimationPlayer(); - if (Util.TryDeSerializeFloatFromEditorPrefs(out float timeCode, WindowManager.timeKey)) - { - //set the play position - AnimPlayerGUI.time = timeCode; - //slightly delay startup to allow the animator to initialize - AnimPlayerGUI.delayFrames = 10; - } - } - else //no scene view focus grab - replace the oringinal runtime animator controller - { - if (Util.TryDeSerializeBoolFromEditorPrefs(out bool restore, WindowManager.animatorControllerKey)) - { - if (restore) - { - AnimPlayerGUI.RestoreBaseAnimatorController(); - } - } - } - } - } - else if (state == PlayModeStateChange.EnteredEditMode) - { - showPlayer = showPlayerAfterPlayMode; - showRetarget = showRetargetAfterPlayMode; - } - */ } public static void OnBeforeAssemblyReload() { if (AnimationMode.InAnimationMode()) { - Util.LogInfo("Disabling Animation Mode on editor assembly reload."); + Util.LogWarn("Disabling Animation Mode on editor assembly reload."); AnimationMode.StopAnimationMode(); } @@ -527,32 +474,6 @@ public static void HideAnimationRetargeter(bool updateShowRetarget) showRetarget = false; } - public static bool StopAnimationMode(UnityEngine.Object obj = null) - { - bool inAnimationMode = false; - if (AnimationMode.InAnimationMode()) - { - inAnimationMode = true; - AnimationMode.StopAnimationMode(); - if (obj) - { - GameObject scenePrefab = Util.GetScenePrefabInstanceRoot(obj); - Util.TryResetScenePrefab(scenePrefab); - } - } - - return inAnimationMode; - } - - public static void RestartAnimationMode(bool inAnimationMode) - { - if (inAnimationMode) - { - if (!AnimationMode.InAnimationMode()) - AnimationMode.StartAnimationMode(); - } - } - public static void StartTimer(float delay) { timer = delay; diff --git a/HDRP/Preview Scene/RL_FloorSpot.mat b/HDRP/Preview Scene/RL_FloorSpot.mat index 9118bd4..4164579 100644 --- a/HDRP/Preview Scene/RL_FloorSpot.mat +++ b/HDRP/Preview Scene/RL_FloorSpot.mat @@ -2,14 +2,17 @@ %TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: RL_FloorSpot m_Shader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3} - m_ShaderKeywords: _DISABLE_SSR_TRANSPARENT _NORMALMAP_TANGENT_SPACE + m_ValidKeywords: + - _DISABLE_SSR_TRANSPARENT + - _NORMALMAP_TANGENT_SPACE + m_InvalidKeywords: [] m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -116,6 +119,7 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + m_Ints: [] m_Floats: - _AORemapMax: 1 - _AORemapMin: 0 @@ -147,6 +151,7 @@ Material: - _DisplacementLockTilingScale: 1 - _DisplacementMode: 0 - _DoubleSidedEnable: 0 + - _DoubleSidedGIMode: 0 - _DoubleSidedNormalMode: 1 - _DstBlend: 0 - _EmissiveColorMode: 1 @@ -255,4 +260,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: da692e001514ec24dbc4cca1949ff7e8, type: 3} m_Name: m_EditorClassIdentifier: - version: 11 + version: 12 + hdPluginSubTargetMaterialVersions: + m_Keys: [] + m_Values: