Skip to content

Commit

Permalink
1.5.2
Browse files Browse the repository at this point in the history
update existing clip reference in anim retarget.
  • Loading branch information
soupday committed Aug 1, 2023
1 parent ca50991 commit d07b9d5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
21 changes: 17 additions & 4 deletions Editor/AnimRetargetGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public static void DrawRetargeter()
// Lower close, reset and save controls
GUILayout.BeginHorizontal();
GUILayout.BeginVertical("box"); // close button
if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("d_winbtn_win_close_a@2x").image, "Close this window."), GUILayout.Width(smallIconDim), GUILayout.Height(smallIconDim)))
if (GUILayout.Button(new GUIContent(EditorGUIUtility.IconContent("d_clear").image, "Close this window."), GUILayout.Width(smallIconDim), GUILayout.Height(smallIconDim)))
{
CloseRetargeter();
}
Expand Down Expand Up @@ -1316,11 +1316,24 @@ static AnimationClip WriteAnimationToAssetDatabase(AnimationClip workingClip, st
// player/re-tartgeter will be untouched so end users dont see a behaviour change after saving

// **End of addition**
}

AnimationClip asset = AssetDatabase.LoadAssetAtPath<AnimationClip>(assetPath);
if (asset == null)
{
// New
Util.LogInfo("Writing New Asset: " + assetPath);
AssetDatabase.CreateAsset(outputClip, assetPath);
}
else
{
Util.LogInfo("Updating Existing Asset: " + assetPath);
outputClip.name = asset.name;
EditorUtility.CopySerialized(outputClip, asset);
AssetDatabase.SaveAssets();
}

AssetDatabase.CreateAsset(outputClip, assetPath);

AnimationClip asset = AssetDatabase.LoadAssetAtPath<AnimationClip>(assetPath);
asset = AssetDatabase.LoadAssetAtPath<AnimationClip>(assetPath);
Selection.objects = new Object[] { asset };
return asset;
}
Expand Down
6 changes: 3 additions & 3 deletions Editor/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ public GameObject Import(bool batchMode = false)
int animationRetargeted = characterInfo.DualMaterialHair ? 2 : 1;
bool replace = characterInfo.animationRetargeted != animationRetargeted;
if (replace) Util.LogInfo("Retargeting all imported animations.");
AnimRetargetGUI.GenerateCharacterTargetedAnimations(fbxPath, prefabInstance, replace);
characterInfo.animationRetargeted = animationRetargeted;
AnimRetargetGUI.GenerateCharacterTargetedAnimations(fbxPath, prefabInstance, replace);

// create default animator if there isn't one:
// commenting out due to a unity bug in 2022+,
Expand All @@ -378,6 +377,8 @@ public GameObject Import(bool batchMode = false)
}
}

characterInfo.animationRetargeted = animationRetargeted;

// save final prefab instance and remove from scene
GameObject prefabAsset = RL.SaveAndRemovePrefabInstance(prefabInstance, prefabAssetPath);

Expand Down Expand Up @@ -2664,7 +2665,6 @@ public void ProcessMotionFbx(string guid, Avatar sourceAvatar, GameObject target
bool replace = characterInfo.animationRetargeted != animationRetargeted;
if (replace) Util.LogInfo("Retargeting all imported animations: " + motionAssetPath);
AnimRetargetGUI.GenerateCharacterTargetedAnimations(motionAssetPath, targetCharacterModel, replace);
characterInfo.animationRetargeted = animationRetargeted;
}
}
}
Expand Down
48 changes: 33 additions & 15 deletions Editor/ImporterWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public enum Mode { none, single, multi }
private bool buildAfterGUI;
private bool bakeAfterGUI;
private bool bakeHairAfterGUI;
private bool processAnimationsAfterGUI;
private bool restoreHairAfterGUI;
private bool physicsAfterGUI;
public enum ImporterWindowMode { Build, Bake, Settings }
Expand Down Expand Up @@ -459,6 +460,7 @@ private void OnGUI()
bakeHairAfterGUI = false;
restoreHairAfterGUI = false;
physicsAfterGUI = false;
processAnimationsAfterGUI = false;

CheckDragAndDrop();

Expand Down Expand Up @@ -511,6 +513,10 @@ private void OnGUI()
{
EditorApplication.delayCall += RebuildCharacterPhysics;
}
else if (processAnimationsAfterGUI)
{
EditorApplication.delayCall += ProcessAnimations;
}
}

bool doubleClick = false;
Expand Down Expand Up @@ -815,21 +821,7 @@ private void OnGUIActionArea(Rect actionBlock)
if (GUILayout.Button(new GUIContent(iconActionAnims, "Process, extract and rename character animations and create a default animtor controller."),
GUILayout.Width(ACTION_BUTTON_SIZE), GUILayout.Height(ACTION_BUTTON_SIZE)))
{
RL.DoAnimationImport(contextCharacter);
AnimRetargetGUI.GenerateCharacterTargetedAnimations(contextCharacter.path, contextCharacter.Fbx, true);
List<string> motionGuids = contextCharacter.GetMotionGuids();
if (motionGuids.Count > 0)
{
Avatar sourceAvatar = contextCharacter.GetCharacterAvatar();
foreach (string motionGuid in motionGuids)
{
string motionPath = AssetDatabase.GUIDToAssetPath(motionGuid);
AnimRetargetGUI.GenerateCharacterTargetedAnimations(motionPath, contextCharacter.Fbx, true);
}
}
int animationRetargeted = contextCharacter.DualMaterialHair ? 2 : 1;
contextCharacter.animationRetargeted = animationRetargeted;
contextCharacter.Write();
processAnimationsAfterGUI = true;
}
EditorGUI.EndDisabledGroup();
//
Expand Down Expand Up @@ -1407,6 +1399,32 @@ void RebuildCharacterPhysics()
Repaint();
}

void ProcessAnimations()
{
RL.DoAnimationImport(contextCharacter);
GameObject characterPrefab = Util.FindCharacterPrefabAsset(contextCharacter.Fbx);
if (characterPrefab == null)
{
Util.LogWarn("Could not find character prefab for retargeting, using FBX instead.");
characterPrefab = contextCharacter.Fbx;
}

AnimRetargetGUI.GenerateCharacterTargetedAnimations(contextCharacter.path, characterPrefab, true);
List<string> motionGuids = contextCharacter.GetMotionGuids();
if (motionGuids.Count > 0)
{
//Avatar sourceAvatar = contextCharacter.GetCharacterAvatar();
foreach (string motionGuid in motionGuids)
{
string motionPath = AssetDatabase.GUIDToAssetPath(motionGuid);
AnimRetargetGUI.GenerateCharacterTargetedAnimations(motionPath, characterPrefab, true);
}
}
int animationRetargeted = contextCharacter.DualMaterialHair ? 2 : 1;
contextCharacter.animationRetargeted = animationRetargeted;
contextCharacter.Write();
}

public static void ResetAllSceneViewCamera(GameObject targetOverride = null)
{
if (WindowManager.IsPreviewScene)
Expand Down

0 comments on commit d07b9d5

Please sign in to comment.