Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.8 KiB

  1. /************************************************************************************
  2. Filename : OVRLipSyncContextMorphTargetEditor.cs
  3. Content : This bridges the viseme output to the morph targets
  4. Created : December 21st, 2018
  5. Copyright : Copyright Facebook Technologies, LLC and its affiliates.
  6. All rights reserved.
  7. Licensed under the Oculus Audio SDK License Version 3.3 (the "License");
  8. you may not use the Oculus Audio SDK except in compliance with the License,
  9. which is provided at the time of installation or download, or which
  10. otherwise accompanies this software in either electronic or hard copy form.
  11. You may obtain a copy of the License at
  12. https://developer.oculus.com/licenses/audio-3.3/
  13. Unless required by applicable law or agreed to in writing, the Oculus Audio SDK
  14. distributed under the License is distributed on an "AS IS" BASIS,
  15. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. See the License for the specific language governing permissions and
  17. limitations under the License.
  18. ************************************************************************************/
  19. using UnityEngine;
  20. using UnityEditor;
  21. [CustomEditor(typeof(OVRLipSyncContextMorphTarget))]
  22. public class OVRLipSyncContextMorphTargetEditor : Editor
  23. {
  24. SerializedProperty skinnedMeshRenderer;
  25. SerializedProperty visemeToBlendTargets;
  26. SerializedProperty visemeTestKeys;
  27. SerializedProperty laughterKey;
  28. SerializedProperty laughterBlendTarget;
  29. SerializedProperty laughterThreshold;
  30. SerializedProperty laughterMultiplier;
  31. SerializedProperty smoothAmounth;
  32. private static string[] visemeNames = new string[] {
  33. "sil", "PP", "FF", "TH",
  34. "DD", "kk", "CH", "SS",
  35. "nn", "RR", "aa", "E",
  36. "ih", "oh", "ou" };
  37. void OnEnable()
  38. {
  39. skinnedMeshRenderer = serializedObject.FindProperty("skinnedMeshRenderer");
  40. visemeToBlendTargets = serializedObject.FindProperty("visemeToBlendTargets");
  41. visemeTestKeys = serializedObject.FindProperty("visemeTestKeys");
  42. laughterKey = serializedObject.FindProperty("laughterKey");
  43. laughterBlendTarget = serializedObject.FindProperty("laughterBlendTarget");
  44. laughterThreshold = serializedObject.FindProperty("laughterThreshold");
  45. laughterMultiplier = serializedObject.FindProperty("laughterMultiplier");
  46. smoothAmounth = serializedObject.FindProperty("smoothAmount");
  47. }
  48. private void BlendNameProperty(SerializedProperty prop, string name, string[] blendNames = null)
  49. {
  50. if (blendNames == null)
  51. {
  52. EditorGUILayout.PropertyField(prop, new GUIContent(name));
  53. return;
  54. }
  55. var values = new int[blendNames.Length + 1];
  56. var options = new GUIContent[blendNames.Length + 1];
  57. values[0] = -1;
  58. options[0] = new GUIContent(" ");
  59. for(int i = 0; i < blendNames.Length; ++i)
  60. {
  61. values[i + 1] = i;
  62. options[i + 1] = new GUIContent(blendNames[i]);
  63. }
  64. EditorGUILayout.IntPopup(prop, options, values, new GUIContent(name));
  65. }
  66. private string[] GetMeshBlendNames()
  67. {
  68. var morphTarget = (OVRLipSyncContextMorphTarget)serializedObject.targetObject;
  69. if (morphTarget == null || morphTarget.skinnedMeshRenderer == null)
  70. {
  71. return null;
  72. }
  73. var mesh = morphTarget.skinnedMeshRenderer.sharedMesh;
  74. var blendshapeCount = mesh.blendShapeCount;
  75. var blendNames = new string[blendshapeCount];
  76. for(int i = 0; i < mesh.blendShapeCount; ++i)
  77. {
  78. blendNames[i] = mesh.GetBlendShapeName(i);
  79. }
  80. return blendNames;
  81. }
  82. public override void OnInspectorGUI()
  83. {
  84. var blendNames = GetMeshBlendNames();
  85. var morphTarget = (OVRLipSyncContextMorphTarget)serializedObject.targetObject;
  86. serializedObject.Update();
  87. EditorGUILayout.PropertyField(skinnedMeshRenderer);
  88. if (EditorGUILayout.PropertyField(visemeToBlendTargets))
  89. {
  90. EditorGUI.indentLevel++;
  91. for(int i = 1; i < visemeNames.Length; ++i)
  92. {
  93. BlendNameProperty(visemeToBlendTargets.GetArrayElementAtIndex(i), visemeNames[i], blendNames);
  94. }
  95. BlendNameProperty(laughterBlendTarget, "Laughter", blendNames);
  96. EditorGUI.indentLevel--;
  97. }
  98. if (morphTarget)
  99. {
  100. morphTarget.enableVisemeTestKeys = EditorGUILayout.ToggleLeft("Enable Viseme Test Keys", morphTarget.enableVisemeTestKeys);
  101. }
  102. if (EditorGUILayout.PropertyField(visemeTestKeys))
  103. {
  104. EditorGUI.indentLevel++;
  105. for(int i = 1; i < visemeNames.Length; ++i)
  106. {
  107. EditorGUILayout.PropertyField(visemeTestKeys.GetArrayElementAtIndex(i), new GUIContent(visemeNames[i]));
  108. }
  109. EditorGUILayout.PropertyField(laughterKey, new GUIContent("Laughter"));
  110. EditorGUI.indentLevel--;
  111. }
  112. EditorGUILayout.PropertyField(laughterThreshold);
  113. EditorGUILayout.PropertyField(laughterMultiplier);
  114. EditorGUILayout.PropertyField(smoothAmounth);
  115. serializedObject.ApplyModifiedProperties();
  116. }
  117. }