//--------------------------------------------------------------------------------------------------------- private Dictionary <string, MinMaxFrame> GetAnimationDescriptions(MD2Frame[] frames) { Dictionary <string, MinMaxFrame> groups = new Dictionary <string, MinMaxFrame>(); for (int i = 0; i < frames.Length; i++) { Regex regex = new Regex(@"\d+"); Match math = regex.Match(frames[i].Name); string key = frames[i].Name.Substring(0, math.Index); if (groups.ContainsKey(key) == false) { groups[key] = new MinMaxFrame(i, i); } else { MinMaxFrame minMaxFrame = groups[key]; if (i >= minMaxFrame.Max) { minMaxFrame.Max = i; } else { if (i < minMaxFrame.Min) { minMaxFrame.Min = i; } } } } return(groups); }
//--------------------------------------------------------------------------------------------------------- private void Start() { MD2File md2File = new MD2File(MD2File.bytes); MD2Frame[] frames = md2File.GetAllFrames(); Mesh[] meshes = new Mesh[frames.Length]; for (int i = 0; i < meshes.Length; i++) { meshes[i] = ConvertFrameToMesh(frames[i]); } Dictionary <string, MinMaxFrame> animations = GetAnimationDescriptions(frames); Mesh baseMesh = meshes[0]; foreach (var group in animations) { AddBlendShapesToMesh(baseMesh, meshes, group.Value.Min, group.Value.Max, group.Key); string key = group.Key; MinMaxFrame minMaxFrame = group.Value; Debug.Log(key + " " + minMaxFrame.Min + " " + minMaxFrame.Max); } #if UNITY_EDITOR AssetDatabase.CreateAsset(baseMesh, "Assets/baseMesh.asset"); AssetDatabase.Refresh(); #endif GetComponent <MeshFilter>().mesh = baseMesh; }