Added BlendShape back.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace AssetStudio
|
namespace AssetStudio
|
||||||
{
|
{
|
||||||
@@ -8,6 +9,8 @@ namespace AssetStudio
|
|||||||
{
|
{
|
||||||
private readonly AnimationClip animationClip;
|
private readonly AnimationClip animationClip;
|
||||||
|
|
||||||
|
public static readonly Regex UnknownPathRegex = new Regex($@"^path_[0-9]{{1,10}}$", RegexOptions.Compiled);
|
||||||
|
|
||||||
private readonly Dictionary<Vector3Curve, List<Keyframe<Vector3>>> m_translations = new Dictionary<Vector3Curve, List<Keyframe<Vector3>>>();
|
private readonly Dictionary<Vector3Curve, List<Keyframe<Vector3>>> m_translations = new Dictionary<Vector3Curve, List<Keyframe<Vector3>>>();
|
||||||
private readonly Dictionary<QuaternionCurve, List<Keyframe<Quaternion>>> m_rotations = new Dictionary<QuaternionCurve, List<Keyframe<Quaternion>>>();
|
private readonly Dictionary<QuaternionCurve, List<Keyframe<Quaternion>>> m_rotations = new Dictionary<QuaternionCurve, List<Keyframe<Quaternion>>>();
|
||||||
private readonly Dictionary<Vector3Curve, List<Keyframe<Vector3>>> m_scales = new Dictionary<Vector3Curve, List<Keyframe<Vector3>>>();
|
private readonly Dictionary<Vector3Curve, List<Keyframe<Vector3>>> m_scales = new Dictionary<Vector3Curve, List<Keyframe<Vector3>>>();
|
||||||
@@ -122,6 +125,10 @@ namespace AssetStudio
|
|||||||
{
|
{
|
||||||
AddAnimatorMuscleCurve(binding, frame.time, frame.keyList[curveIndex].value);
|
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);
|
curveIndex = GetNextCurve(frame, curveIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,6 +163,10 @@ namespace AssetStudio
|
|||||||
{
|
{
|
||||||
AddAnimatorMuscleCurve(binding, time, dense.m_SampleArray[framePosition]);
|
AddAnimatorMuscleCurve(binding, time, dense.m_SampleArray[framePosition]);
|
||||||
}
|
}
|
||||||
|
else if (binding.customType == 20)
|
||||||
|
{
|
||||||
|
AddBlendShapeCurve(binding, path, time, dense.m_SampleArray[framePosition]);
|
||||||
|
}
|
||||||
curveIndex++;
|
curveIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,6 +211,10 @@ namespace AssetStudio
|
|||||||
{
|
{
|
||||||
AddAnimatorMuscleCurve(binding, time, values[framePosition]);
|
AddAnimatorMuscleCurve(binding, time, values[framePosition]);
|
||||||
}
|
}
|
||||||
|
else if (binding.customType == 20)
|
||||||
|
{
|
||||||
|
AddBlendShapeCurve(binding, path, time, values[framePosition]);
|
||||||
|
}
|
||||||
curveIndex++;
|
curveIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,6 +251,10 @@ namespace AssetStudio
|
|||||||
{
|
{
|
||||||
AddAnimatorMuscleCurve(binding, time, constant.data[curveIndex]);
|
AddAnimatorMuscleCurve(binding, time, constant.data[curveIndex]);
|
||||||
}
|
}
|
||||||
|
else if (binding.customType == 20)
|
||||||
|
{
|
||||||
|
AddBlendShapeCurve(binding, path, time, constant.data[curveIndex]);
|
||||||
|
}
|
||||||
curveIndex++;
|
curveIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -377,6 +396,50 @@ namespace AssetStudio
|
|||||||
AddFloatKeyframe(curve, time, value);
|
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<SkinnedMeshRenderer>();
|
||||||
|
}
|
||||||
|
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<MonoScript>());
|
||||||
|
AddFloatKeyframe(curve, time, value);
|
||||||
|
}
|
||||||
|
|
||||||
private void AddFloatKeyframe(FloatCurve curve, float time, float value)
|
private void AddFloatKeyframe(FloatCurve curve, float time, float value)
|
||||||
{
|
{
|
||||||
if (!m_floats.TryGetValue(curve, out List<Keyframe<Float>> floatCurve))
|
if (!m_floats.TryGetValue(curve, out List<Keyframe<Float>> floatCurve))
|
||||||
|
|||||||
Reference in New Issue
Block a user