From 79999929fc6a4b4b93a9eb0b93abb39ceba7af68 Mon Sep 17 00:00:00 2001 From: Razmoth <32140579+Razmoth@users.noreply.github.com> Date: Tue, 25 Oct 2022 23:20:36 +0400 Subject: [PATCH] Added `BlendShape` back. --- AssetStudioUtility/AnimationClipConverter.cs | 63 ++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/AssetStudioUtility/AnimationClipConverter.cs b/AssetStudioUtility/AnimationClipConverter.cs index b62e439..25007f9 100644 --- a/AssetStudioUtility/AnimationClipConverter.cs +++ b/AssetStudioUtility/AnimationClipConverter.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Collections.Generic; +using System.Text.RegularExpressions; namespace AssetStudio { @@ -8,6 +9,8 @@ namespace AssetStudio { private readonly AnimationClip animationClip; + public static readonly Regex UnknownPathRegex = new Regex($@"^path_[0-9]{{1,10}}$", RegexOptions.Compiled); + private readonly Dictionary>> m_translations = new Dictionary>>(); private readonly Dictionary>> m_rotations = new Dictionary>>(); private readonly Dictionary>> m_scales = new Dictionary>>(); @@ -122,6 +125,10 @@ namespace AssetStudio { AddAnimatorMuscleCurve(binding, frame.time, frame.keyList[curveIndex].value); } + else if (binding.customType == 20) + { + AddBlendShapeCurve(binding, path, frame.time, frame.keyList[curveIndex].value); + } curveIndex = GetNextCurve(frame, curveIndex); } } @@ -156,6 +163,10 @@ namespace AssetStudio { AddAnimatorMuscleCurve(binding, time, dense.m_SampleArray[framePosition]); } + else if (binding.customType == 20) + { + AddBlendShapeCurve(binding, path, time, dense.m_SampleArray[framePosition]); + } curveIndex++; } } @@ -200,6 +211,10 @@ namespace AssetStudio { AddAnimatorMuscleCurve(binding, time, values[framePosition]); } + else if (binding.customType == 20) + { + AddBlendShapeCurve(binding, path, time, values[framePosition]); + } curveIndex++; } } @@ -236,6 +251,10 @@ namespace AssetStudio { AddAnimatorMuscleCurve(binding, time, constant.data[curveIndex]); } + else if (binding.customType == 20) + { + AddBlendShapeCurve(binding, path, time, constant.data[curveIndex]); + } curveIndex++; } } @@ -377,6 +396,50 @@ namespace AssetStudio AddFloatKeyframe(curve, time, value); } + private void AddBlendShapeCurve(GenericBinding binding, string path, float time, float value) + { + var attribute = ""; + const string Prefix = "blendShape."; + if (UnknownPathRegex.IsMatch(path)) + { + attribute = Prefix + binding.attribute; + } + + foreach (GameObject root in animationClip.FindRoots().ToArray()) + { + Transform rootTransform = root.GetTransform(); + Transform child = rootTransform.FindChild(path); + if (child == null) + { + continue; + } + SkinnedMeshRenderer skin = null; + if (child.m_GameObject.TryGet(out var gameObject)) + { + skin = gameObject.FindComponent(); + } + if (skin == null) + { + continue; + } + if (!skin.m_Mesh.TryGet(out var mesh)) + { + continue; + } + string shapeName = mesh.FindBlendShapeNameByCRC(binding.attribute); + if (shapeName == null) + { + continue; + } + + attribute = Prefix + shapeName; + } + attribute = Prefix + attribute; + + FloatCurve curve = new FloatCurve(path, attribute, binding.typeID, binding.script.CastTo()); + AddFloatKeyframe(curve, time, value); + } + private void AddFloatKeyframe(FloatCurve curve, float time, float value) { if (!m_floats.TryGetValue(curve, out List> floatCurve))