Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from undefined9071/dev
Browse files Browse the repository at this point in the history
fix blendshape export issue
  • Loading branch information
Razmoth authored Sep 17, 2023
2 parents 96079d4 + 886dfa9 commit d790c96
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
11 changes: 9 additions & 2 deletions AssetStudio/IImported.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,16 @@ public class ImportedKeyframedAnimation
public float SampleRate { get; set; }
public List<ImportedAnimationKeyframedTrack> TrackList { get; set; }

public ImportedAnimationKeyframedTrack FindTrack(string path)
public ImportedAnimationKeyframedTrack FindTrack(string path, string attribute = null)
{
var track = TrackList.Find(x => x.Path == path);
var track = TrackList.Find(t => {
if (attribute == null)
{
return t.Path == path;
} else {
return t.Path == path && t.BlendShape?.ChannelName == attribute;
}
});
if (track == null)
{
track = new ImportedAnimationKeyframedTrack { Path = path };
Expand Down
32 changes: 20 additions & 12 deletions AssetStudioUtility/ModelConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ private void ConvertMeshRenderer(Renderer meshR)
crc.Update(bytes, 0, (uint)bytes.Length);
morphChannelNames[crc.GetDigest()] = blendShapeName;

morphChannelNames[shapeChannel.nameHash] = shapeChannel.name;

channel.Name = shapeChannel.name.Split('.').Last();
channel.KeyframeList = new List<ImportedMorphKeyframe>(shapeChannel.frameCount);
var frameEnd = shapeChannel.frameIndex + shapeChannel.frameCount;
Expand Down Expand Up @@ -870,14 +872,17 @@ private void ConvertAnimations()
channelName = channelName.Substring(dotPos + 1);
}

var path = FixBonePath(animationClip, m_FloatCurve.path);
var path = GetPathByChannelName(channelName);
if (string.IsNullOrEmpty(path))
{
path = GetPathByChannelName(channelName);
path = FixBonePath(animationClip, m_FloatCurve.path);
}
var track = iAnim.FindTrack(path, channelName);
if (track.BlendShape == null)
{
track.BlendShape = new ImportedBlendShape();
track.BlendShape.ChannelName = channelName;
}
var track = iAnim.FindTrack(path);
track.BlendShape = new ImportedBlendShape();
track.BlendShape.ChannelName = channelName;
foreach (var m_Curve in m_FloatCurve.curve.m_Curve)
{
track.BlendShape.Keyframes.Add(new ImportedKeyframe<float>(m_Curve.time, m_Curve.value));
Expand Down Expand Up @@ -984,15 +989,18 @@ private void ReadCurveData(ImportedKeyframedAnimation iAnim, AnimationClipBindin
channelName = channelName.Substring(dotPos + 1);
}

var bPath = FixBonePath(GetPathFromHash(binding.path));
if (string.IsNullOrEmpty(bPath))
var path = GetPathByChannelName(channelName);
if (string.IsNullOrEmpty(path))
{
path = FixBonePath(GetPathFromHash(binding.path));
}
var track = iAnim.FindTrack(path, channelName);
if (track.BlendShape == null)
{
bPath = GetPathByChannelName(channelName);
track.BlendShape = new ImportedBlendShape();
track.BlendShape.ChannelName = channelName;
}
var bTrack = iAnim.FindTrack(bPath);
bTrack.BlendShape = new ImportedBlendShape();
bTrack.BlendShape.ChannelName = channelName;
bTrack.BlendShape.Keyframes.Add(new ImportedKeyframe<float>(time, data[curveIndex++ + offset]));
track.BlendShape.Keyframes.Add(new ImportedKeyframe<float>(time, data[curveIndex++ + offset]));
}
else if (binding.typeID == ClassIDType.Transform)
{
Expand Down

0 comments on commit d790c96

Please sign in to comment.