generated from vrchat-community/template-package
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Rename Face For MMD component (#64)
- Loading branch information
1 parent
8466ddd
commit d6a4003
Showing
32 changed files
with
1,729 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
Packages/enitimeago.non-destructive-mmd/Editor/RenameFaceForMmdComponentEditor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
using VRC.SDK3.Avatars.Components; | ||
using L = enitimeago.NonDestructiveMMD.Localization; | ||
|
||
namespace enitimeago.NonDestructiveMMD | ||
{ | ||
[CustomEditor(typeof(RenameFaceForMmdComponent))] | ||
public class RenameFaceForMmdComponentEditor : Editor | ||
{ | ||
private CommonChecks _commonChecks; | ||
|
||
public void OnEnable() | ||
{ | ||
_commonChecks = new CommonChecks(isEditor: true); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
var data = (RenameFaceForMmdComponent)target; | ||
var avatar = data.GetComponentInParent<VRCAvatarDescriptor>(); | ||
|
||
EditorGUILayout.BeginHorizontal(); | ||
L.DrawLanguagePicker(); | ||
EditorGUILayout.EndHorizontal(); | ||
|
||
// Run asserts, however continue rendering GUI if errors are encountered. | ||
_commonChecks.RunChecks(avatar, ignoreBodyName: true); | ||
if (avatar.VisemeSkinnedMesh.name == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (!EditorApplication.isPlaying) | ||
{ | ||
// Let the user know what will happen. | ||
if (avatar.VisemeSkinnedMesh.name == "Body") | ||
{ | ||
EditorGUILayout.HelpBox(L.Tr("RenameFaceForMmdComponentEditor:AlreadyCalledBody"), MessageType.Info); | ||
} | ||
else | ||
{ | ||
GUILayout.Label(string.Format(L.Tr("RenameFaceForMmdComponentEditor:ActionToPerform"), avatar.VisemeSkinnedMesh.name), EditorStyles.wordWrappedLabel); | ||
|
||
var toRenames = RenameFaceForMmdPass.DetermineRenames(avatar.GetComponentsInChildren<SkinnedMeshRenderer>()); | ||
if (toRenames.Count > 0) | ||
{ | ||
GUILayout.Label(L.Tr("RenameFaceForMmdComponentEditor:ActionToPerformHasConflicts"), EditorStyles.wordWrappedLabel); | ||
} | ||
GUILayout.Label(L.Tr("RenameFaceForMmdComponentEditor:ActionToPerformSuffix"), EditorStyles.wordWrappedLabel); | ||
|
||
// TODO: can this be a table so that the columns are the same width? | ||
EditorGUI.indentLevel++; | ||
{ | ||
foreach (var toRename in toRenames) | ||
{ | ||
EditorGUILayout.BeginHorizontal(); | ||
GUILayout.Label(string.Format("{0} ←", toRename.newName), EditorStyles.wordWrappedLabel); | ||
EditorGUI.BeginDisabledGroup(true); | ||
EditorGUILayout.ObjectField(toRename.skinnedMeshRenderer, typeof(GameObject), true); | ||
EditorGUI.EndDisabledGroup(); | ||
EditorGUILayout.EndHorizontal(); | ||
} | ||
EditorGUILayout.BeginHorizontal(); | ||
GUILayout.Label("Body ←", EditorStyles.wordWrappedLabel); | ||
EditorGUI.BeginDisabledGroup(true); | ||
EditorGUILayout.ObjectField(avatar.VisemeSkinnedMesh, typeof(GameObject), true); | ||
EditorGUI.EndDisabledGroup(); | ||
EditorGUILayout.EndHorizontal(); | ||
} | ||
EditorGUI.indentLevel--; | ||
} | ||
} | ||
else | ||
{ | ||
GUILayout.Label(L.Tr("RenameFaceForMmdComponentEditor:IsPlaying"), EditorStyles.wordWrappedLabel); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Packages/enitimeago.non-destructive-mmd/Editor/RenameFaceForMmdComponentEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
Packages/enitimeago.non-destructive-mmd/Editor/RenameFaceForMmdPass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using nadena.dev.ndmf; | ||
using UnityEngine; | ||
using VRC.SDK3.Avatars.Components; | ||
using L = enitimeago.NonDestructiveMMD.Localization; | ||
|
||
namespace enitimeago.NonDestructiveMMD | ||
{ | ||
public class RenameFaceForMmdPass : Pass<RenameFaceForMmdPass> | ||
{ | ||
public override string DisplayName => "Rename Face For MMD"; | ||
|
||
protected override void Execute(BuildContext context) | ||
{ | ||
Execute(context.AvatarRootObject); | ||
} | ||
|
||
internal void Execute(GameObject avatarRootObject) | ||
{ | ||
// TODO: need some checks but if we run checks we'll see mmd shape keys exist | ||
// var commonChecks = new CommonChecks(isEditor: false); | ||
// if (!commonChecks.RunChecks(avatarRootObject)) | ||
// { | ||
// return; | ||
// } | ||
|
||
var renameFaceForMmdComponent = avatarRootObject.GetComponentInChildren<RenameFaceForMmdComponent>(); | ||
if (renameFaceForMmdComponent == null) | ||
{ | ||
return; | ||
} | ||
var descriptor = avatarRootObject.GetComponent<VRCAvatarDescriptor>(); | ||
if (descriptor.VisemeSkinnedMesh == null) | ||
{ | ||
Debug.LogWarning("No face object to rename for MMD, skipping"); | ||
return; | ||
} | ||
if (descriptor.VisemeSkinnedMesh.name == "Body") | ||
{ | ||
Debug.LogWarning("Face object is already called Body, skipping"); | ||
return; | ||
} | ||
|
||
var skinnedMeshRenderers = avatarRootObject.GetComponentsInChildren<SkinnedMeshRenderer>(); | ||
|
||
// Objects called "Body" on the avatar need to be renamed to something else. | ||
// TODO: maybe this only needs to happen to top-level objects. or only Body needs to be top-level. | ||
var renames = DetermineRenames(skinnedMeshRenderers); | ||
foreach (var rename in renames) | ||
{ | ||
rename.skinnedMeshRenderer.name = rename.newName; | ||
} | ||
|
||
// Rename the face object to "Body". | ||
descriptor.VisemeSkinnedMesh.name = "Body"; | ||
|
||
Object.DestroyImmediate(renameFaceForMmdComponent); | ||
} | ||
|
||
public struct RenameInfo | ||
{ | ||
public SkinnedMeshRenderer skinnedMeshRenderer; | ||
public string newName; | ||
} | ||
|
||
public static List<RenameInfo> DetermineRenames(IEnumerable<SkinnedMeshRenderer> skinnedMeshRenderers) | ||
{ | ||
var renames = new List<RenameInfo>(); | ||
int suffixCount = 0; | ||
var existingNames = skinnedMeshRenderers.Select(smr => smr.name).ToImmutableHashSet(); | ||
foreach (var skinnedMeshRenderer in skinnedMeshRenderers) | ||
{ | ||
if (skinnedMeshRenderer.name == "Body") | ||
{ | ||
string candidateName; | ||
do | ||
{ | ||
candidateName = "Body (Original)" + (suffixCount > 0 ? $" ({suffixCount})" : ""); | ||
suffixCount++; | ||
} | ||
while (existingNames.Contains(candidateName)); | ||
renames.Add(new RenameInfo { skinnedMeshRenderer = skinnedMeshRenderer, newName = candidateName }); | ||
} | ||
} | ||
return renames; | ||
} | ||
} | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
Packages/enitimeago.non-destructive-mmd/Editor/RenameFaceForMmdPass.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
Packages/enitimeago.non-destructive-mmd/Editor/vendor/Animation.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.