// Function to load the gaze max values from the blend shapes mapper added to the VHP manager. private void LoadBlendshapesValues() { // Loading the blendshapes mapper values to be used for procedural gaze if a mapper preset is added to the VHP manager. if (m_VHPmanager.blendShapesMapperPreset) { BlendShapesMapper blendShapesMapper = m_VHPmanager.blendShapesMapperPreset; // Calling the function to copy the values from the blendshapes mapper added to the VHP manager. CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.BLINK), m_blinkBlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.GAZEUP), m_gazeUpBlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.GAZEDOWN), m_gazeDownBlendShapeValues); } // Displaying a warning message if no blendshapes mapper is added to the VHP manager. else { Debug.LogWarning("No blend shapes preset. Procedural gaze won't be initialized"); return; } }
// Function allowing to load the current character blend shape values contained in the preset. private void LoadBlendShapesValues() { // Temporary list to store the character blend shape values. List <float> blenshapesValues = new List <float>(blendShapesMapper.GetBlenShapeValues(facialPoseToEdit)); int blendShapeIndex = 0; // For each skinned mesh renderer of the character all the blend shape values are loaded from the preset. foreach (SkinnedMeshRenderer skinnedMeshRenderer in skinnedMeshRenderersWithBlendShapes) { for (int i = 0; i < skinnedMeshRenderer.sharedMesh.blendShapeCount; i++) { if (blendShapeIndex < blenshapesValues.Count) { skinnedMeshRenderer.SetBlendShapeWeight(i, blenshapesValues[blendShapeIndex]); blendShapeIndex++; } } } }
// Function to load the emotions max values from the blend shapes mapper added to the VHP manager. private void LoadBlendShapeValues() { // Loading the blend shapes mapper values to be used for procedural emotions if a mapper preset is added to the VHP manager. if (m_VHPmanager.blendShapesMapperPreset) { BlendShapesMapper blendShapesMapper = m_VHPmanager.blendShapesMapperPreset; // Calling the function to copy the values from the blendshapes mapper added to the VHP manager. CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.ANGER), m_angerBlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.DISGUST), m_disgustBlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.FEAR), m_fearBlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.HAPPINESS), m_happinessBlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.SADNESS), m_sadnessBlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.SURPRISE), m_surpriseBlendShapeValues); } // Displaying a warning message if no blend shapes mapper is added to the VHP manager. else { Debug.LogWarning("No blend shapes preset. Procedural emotions won't be initialized"); return; } }
// Function to load the visemes max values from the blend shapes mapper added to the VHP manager. private void LoadBlendShapeValues() { // Loading the blend shapes mapper values to be used for lip synchronization if a mapper preset is added to the VHP manager. if (m_VHPmanager.blendShapesMapperPreset) { BlendShapesMapper blendShapesMapper = m_VHPmanager.blendShapesMapperPreset; // Calling the function to copy the values from the blend shapes mapper added to the VHP manager. CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_sil), m_viseme_sil_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_PP), m_viseme_PP_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_FF), m_viseme_FF_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_TH), m_viseme_TH_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_DD), m_viseme_DD_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_kk), m_viseme_kk_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_CH), m_viseme_CH_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_SS), m_viseme_SS_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_nn), m_viseme_nn_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_RR), m_viseme_RR_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_aa), m_viseme_aa_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_E), m_viseme_E_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_I), m_viseme_I_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_O), m_viseme_O_BlendShapeValues); CopyBlendshapesMappersValues(blendShapesMapper.GetBlenShapeValues(BlendShapesMapper.FacialExpression.VISEME_U), m_viseme_U_BlendShapeValues); } // Displaying a warning message if no blend shapes mapper is added to the VHP manager. else { Debug.LogWarning("No blend shapes mapper preset. Lip synchronization won't be initialized"); return; } }
private void OnGUI() { #region Blendshapes mapper settings GUILayout.Label("Blend shapes mapper settings", EditorStyles.boldLabel); GUILayout.Space(5); // Object field to add the blend shapes mapper to be edited. string blendShapesMapperTooltip = "Blend shapes preset to edit. Use right click -> create -> Virtual Human Project -> BlendShapesMapper in the project window to create a new mapper preset."; blendShapesMapper = (BlendShapesMapper)EditorGUILayout.ObjectField(new GUIContent("Mapper preset", blendShapesMapperTooltip), blendShapesMapper, typeof(BlendShapesMapper), true); GUI.enabled = blendShapesMapper; string facialPoseToEditTooltip = "Facial expression preset to edit."; // Enumeration to choose the facial expression preset to be edited. facialPoseToEdit = (BlendShapesMapper.FacialExpression)EditorGUILayout.EnumPopup(new GUIContent("Facial Expression", facialPoseToEditTooltip), facialPoseToEdit); GUI.enabled = true; #endregion #region Character settings GUILayout.Space(10); GUILayout.Label("Character settings", EditorStyles.boldLabel); GUILayout.Space(5); // Object field to add a character gameobject to get its skinned mesh renderers with blend shapes. string characterTooltip = "Character's root gameobject to extract children skinned mesh renderer blend shapes."; character = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Character root", characterTooltip), character, typeof(GameObject), true); if (character) { // Getting the skinned mesh renderers with blend shapes if the list is empty. if (skinnedMeshRenderersWithBlendShapes.Count == 0) { GetSkinnedMeshRenderersWithBlendShapes(character); } // Serialazation of the skinned mesh renderer list. EditorWindow thisEditorWindow = this; SerializedObject serializedWindows = new SerializedObject(thisEditorWindow); SerializedProperty skinnedMeshRenderersProperty = serializedWindows.FindProperty("skinnedMeshRenderersWithBlendShapes"); // Property field to display/edit the skinned mesh renderers to extract the values from. string skinnedMeshRendererTooltip = "Skinned mesh renderers to extract the blenshapes values from."; EditorGUILayout.PropertyField(skinnedMeshRenderersProperty, new GUIContent("Skinned mesh renderers", skinnedMeshRendererTooltip), true); serializedWindows.ApplyModifiedProperties(); } else { // Clearing the skinned mesh renderer list if it contains data if no character is added to the object field. if (skinnedMeshRenderersWithBlendShapes.Any()) { skinnedMeshRenderersWithBlendShapes.Clear(); } } #endregion #region Blend shapes options GUILayout.Space(10); GUILayout.Label("Blend shapes options", EditorStyles.boldLabel); GUILayout.Space(5); // The save and reset buttons are enabled if a blend shapes mapper and a skinned mesh renderer are added. GUI.enabled = blendShapesMapper && skinnedMeshRenderersWithBlendShapes.Any() ? true : false; // Button calling the function to save the current character blend shapes values in the preset. if (GUILayout.Button("Load blend shape values")) { m_notSavedDataSafetyEnabled = true; } if (m_notSavedDataSafetyEnabled) { EditorGUILayout.HelpBox("Current character blend shape values won't be saved!", MessageType.Warning); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Cancel")) { m_notSavedDataSafetyEnabled = false; } if (GUILayout.Button("Continue")) { LoadBlendShapesValues(); m_notSavedDataSafetyEnabled = false; } EditorGUILayout.EndHorizontal(); } // Button calling the function to save the current character blend shape values in the preset. if (GUILayout.Button("Save blend shape values")) { // Enabling a warning message if existing values will be overwritten. if (blendShapesMapper.GetBlenShapeValues(facialPoseToEdit).Any()) { m_eraseDataSafetyEnabled = true; } else { SaveBlendShapesValues(); } } // Displaying the warning message and asking for a confirmation to overwrite existing data. if (m_eraseDataSafetyEnabled) { EditorGUILayout.HelpBox("Existing " + facialPoseToEdit.ToString() + " blend shape values will be overwritten!", MessageType.Warning); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Cancel")) { m_eraseDataSafetyEnabled = false; } if (GUILayout.Button("Continue")) { SaveBlendShapesValues(); m_eraseDataSafetyEnabled = false; } EditorGUILayout.EndHorizontal(); } // Button calling the function to reset the character blend shape values in the scene. if (GUILayout.Button("Reset character blend shapes")) { ResetBlendShapeValues(); } GUI.enabled = true; #endregion }