private static void ParseTracks(BinaryReader reader, int numTracks, odfANIMSection animSection) { for (int trackIdx = 0; trackIdx < numTracks; trackIdx++) { ObjectID id = new ObjectID(reader.ReadBytes(4)); byte[] alwaysZero = reader.ReadBytes(16); int numKeyframes = reader.ReadInt32(); odfTrack track = new odfTrack(numKeyframes); track.BoneFrameId = id; track.AlwaysZero16 = alwaysZero; for (int i = 0; i < numKeyframes; i++) { odfKeyframe keyframe = new odfKeyframe(); keyframe.Index = reader.ReadSingle(); keyframe.Unknown1 = reader.ReadInt32(); keyframe.FastTranslation = reader.ReadVector3(); keyframe.Unknown2 = reader.ReadInt32(); keyframe.FastRotation = reader.ReadVector3(); keyframe.Unknown3 = reader.ReadInt32(); keyframe.FastScaling = reader.ReadVector3(); keyframe.Matrix = reader.ReadMatrix(); keyframe.ExtraFastRotation = reader.ReadQuaternion(); keyframe.AlwaysZero88 = reader.ReadBytes(88); track.KeyframeList.Add(keyframe); } animSection.AddChild(track); } }
public static void ReplaceAnimation(WorkspaceAnimation wsAnimation, odfParser parser, int resampleCount, bool linear, ReplaceAnimationMethod replaceMethod, string clip, int insertPos, bool negateQuaternionFlips) { if (parser.AnimSection == null) { Report.ReportLog(Path.GetFileName(parser.ODFPath) + " doesn't have an animation section. Skipping this animation"); return; } if (!(wsAnimation.importedAnimation is ImportedKeyframedAnimation)) { Report.ReportLog("The animation has incompatible keyframes."); return; } Report.ReportLog("Replacing animation ..."); List <KeyValuePair <string, ImportedAnimationKeyframe[]> > newTrackList = FbxUtility.CopyKeyframedAnimation(wsAnimation, resampleCount, linear); List <odfTrack> animationNodeList = odf.FindClip(clip, parser).ChildList; ImportedKeyframedAnimation iAnim = new ImportedKeyframedAnimation(); iAnim.TrackList = new List <ImportedAnimationKeyframedTrack>(animationNodeList.Count); Dictionary <string, ImportedAnimationKeyframedTrack> animationNodeDic = null; if (replaceMethod != ReplaceAnimationMethod.Replace) { animationNodeDic = new Dictionary <string, ImportedAnimationKeyframedTrack>(); foreach (odfTrack animationNode in animationNodeList) { ImportedAnimationKeyframedTrack iTrack = new ImportedAnimationKeyframedTrack(); iTrack.Name = odf.FindFrame(animationNode.BoneFrameId, parser.FrameSection.RootFrame).Name; iTrack.Keyframes = Plugins.ODFConverter.ConvertTrack(animationNode.KeyframeList); animationNodeDic.Add(odf.FindFrame(animationNode.BoneFrameId, parser.FrameSection.RootFrame).Name, iTrack); iAnim.TrackList.Add(iTrack); } } foreach (var newTrack in newTrackList) { ImportedAnimationKeyframe[] keyframes = newTrack.Value; Quaternion q = keyframes[0].Rotation; keyframes[0].Rotation *= -1; /* if (keyframes[0].Rotation.Angle == 0 || q.Angle == 0) * { * Report.ReportLog("track " + newTrack.Key + " r=" + keyframes[0].Rotation.Angle + " q=" + q.Angle); * }*/ } FbxUtility.ReplaceAnimation(replaceMethod, insertPos, newTrackList, iAnim, animationNodeDic, negateQuaternionFlips); animationNodeList.Clear(); foreach (var newTrack in iAnim.TrackList) { ImportedAnimationKeyframe[] keyframes = ((ImportedAnimationKeyframedTrack)newTrack).Keyframes; odfTrack animationNode = new odfTrack(keyframes.Length); odf.CreateUnknowns(animationNode); animationNodeList.Add(animationNode); animationNode.KeyframeList = Plugins.ODFConverter.ConvertTrack(keyframes); animationNode.BoneFrameId = odf.FindFrame(newTrack.Name, parser.FrameSection.RootFrame).Id; } }
public static void odfTrack(odfTrack track) { track.AlwaysZero16 = new byte[16]; }
public static void CreateUnknowns(odfTrack track) { UnknownDefaults.odfTrack(track); }