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