// Functions /// <summary> /// Returns the index of the blendable in blendSystem that best matches the supplied BlendableInfo. /// </summary> /// <param name="blendable"></param> /// <param name="blendSystem"></param> /// <returns>The index of the blendable if found, or -1 if not.</returns> public int FindBlendable(BlendableInfo blendable, BlendSystem blendSystem) { // First attempts to match based on name, then index. If both fail, returns -1. if (!string.IsNullOrEmpty(blendable.blendableName)) { string cleanName = blendable.blendableName; if (cleanName.Contains("(" + blendable.blendableNumber.ToString() + ")")) { string[] parts = cleanName.Split(new string[] { "(" + blendable.blendableNumber.ToString() + ")" }, System.StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 0) { cleanName = parts[0]; } } string[] blendables = blendSystem.GetBlendables(); for (int a = 0; a < blendables.Length; a++) { string cleanBlendableName = blendables[a]; if (cleanBlendableName.Contains("(" + a.ToString() + ")")) { string[] parts = cleanBlendableName.Split(new string[] { "(" + a.ToString() + ")" }, System.StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 0) { cleanBlendableName = parts[0]; } } if (cleanBlendableName == cleanName) { return(a); } } } if (blendable.blendableNumber < blendSystem.blendableCount) { if (!string.IsNullOrEmpty(blendable.blendableName)) { if (blendable.blendableName != blendSystem.GetBlendables()[blendable.blendableNumber]) { Debug.LogWarning("[LipSync] Blendable " + blendable.blendableName + " used in the '" + this.name + "' preset couldn't be matched based on name, and the blendable at the same index in the " + blendSystem.GetType().Name + " has a different name. This may not be the shape you were expecting."); } } return(blendable.blendableNumber); } return(-1); }
public void CreateFromShapes(PhonemeShape[] phonemes, EmotionShape[] emotions, BlendSystem blendSystem, bool relative) { isRelative = relative; phonemeShapes = new PhonemeShapeInfo[phonemes.Length]; emotionShapes = new EmotionShapeInfo[emotions.Length]; for (int s = 0; s < phonemeShapes.Length; s++) { phonemeShapes[s] = new PhonemeShapeInfo(); phonemeShapes[s].phonemeName = phonemes[s].phonemeName; phonemeShapes[s].blendables = new BlendableInfo[phonemes[s].blendShapes.Count]; for (int b = 0; b < phonemeShapes[s].blendables.Length; b++) { phonemeShapes[s].blendables[b].blendableNumber = phonemes[s].blendShapes[b]; phonemeShapes[s].blendables[b].weight = phonemes[s].weights[b]; if (blendSystem != null) { phonemeShapes[s].blendables[b].blendableName = blendSystem.GetBlendables()[phonemes[s].blendShapes[b]]; } } phonemeShapes[s].bones = new BoneInfo[phonemes[s].bones.Count]; for (int b = 0; b < phonemeShapes[s].bones.Length; b++) { phonemeShapes[s].bones[b].name = phonemes[s].bones[b].bone.name; phonemeShapes[s].bones[b].lockPosition = phonemes[s].bones[b].lockPosition; phonemeShapes[s].bones[b].lockRotation = phonemes[s].bones[b].lockRotation; if (relative) { phonemeShapes[s].bones[b].localPosition = phonemes[s].bones[b].neutralPosition - phonemes[s].bones[b].endPosition; phonemeShapes[s].bones[b].localRotation = phonemes[s].bones[b].neutralRotation - phonemes[s].bones[b].endRotation; } else { phonemeShapes[s].bones[b].localPosition = phonemes[s].bones[b].endPosition; phonemeShapes[s].bones[b].localRotation = phonemes[s].bones[b].endRotation; } } } for (int s = 0; s < emotionShapes.Length; s++) { emotionShapes[s] = new EmotionShapeInfo(); emotionShapes[s].emotion = emotions[s].emotion; emotionShapes[s].blendables = new BlendableInfo[emotions[s].blendShapes.Count]; for (int b = 0; b < emotionShapes[s].blendables.Length; b++) { emotionShapes[s].blendables[b].blendableNumber = emotions[s].blendShapes[b]; emotionShapes[s].blendables[b].weight = emotions[s].weights[b]; if (blendSystem != null) { emotionShapes[s].blendables[b].blendableName = blendSystem.GetBlendables()[emotions[s].blendShapes[b]]; } } emotionShapes[s].bones = new BoneInfo[emotions[s].bones.Count]; for (int b = 0; b < emotionShapes[s].bones.Length; b++) { emotionShapes[s].bones[b].name = emotions[s].bones[b].bone.name; emotionShapes[s].bones[b].lockPosition = emotions[s].bones[b].lockPosition; emotionShapes[s].bones[b].lockRotation = emotions[s].bones[b].lockRotation; if (relative) { emotionShapes[s].bones[b].localPosition = emotions[s].bones[b].neutralPosition - phonemes[s].bones[b].endPosition; emotionShapes[s].bones[b].localRotation = emotions[s].bones[b].neutralRotation - phonemes[s].bones[b].endRotation; } else { emotionShapes[s].bones[b].localPosition = emotions[s].bones[b].endPosition; emotionShapes[s].bones[b].localRotation = emotions[s].bones[b].endRotation; } } } }