Esempio n. 1
0
            public HSFMotionGroupText(AnimationNode group)
            {
                Name       = group.Name;
                ValueIndex = group.ValueIndex;
                Mode       = group.Mode;

                foreach (AnimTrack track in group.GetTracks())
                {
                    Tracks.Add(new HSFMotionTrackText(track));
                }
            }
Esempio n. 2
0
        private static AnimTrack ParseAnimTrack(JsonReader reader, AnimationNode group, STInterpoaltionType type)
        {
            string effect = reader.ReadAsString();

            AnimTrack track = new AnimTrack(group);

            track.ValueIdx          = group.ValueIndex;
            track.TrackMode         = group.Mode;
            track.TrackEffect       = ParseEffect(group.Mode, effect);
            track.InterpolationType = type;
            track.KeyFrames         = new List <STKeyFrame>();
            track.Unknown           = 0;
            reader.Read();
            track.KeyFrames = ParseKeyFrames(reader, type);
            return(track);
        }
        public override void Read(FileReader reader, HsfFile header)
        {
            List <MotionData> anims = reader.ReadMultipleStructs <MotionData>(this.Count);
            long pos = reader.Position;

            for (int i = 0; i < anims.Count; i++)
            {
                HSFMotionAnimation anm = new HSFMotionAnimation();
                Animations.Add(anm);

                anm.Name       = header.GetString(reader, anims[i].NameOffset);
                anm.FrameCount = anims[i].MotionLength;

                reader.SeekBegin(pos + anims[i].TrackDataOffset);
                for (int j = 0; j < anims[i].TrackCount; j++)
                {
                    TrackData track = new TrackData();
                    track.mode             = (TrackMode)reader.ReadByte();
                    track.unk              = reader.ReadByte();
                    track.stringOffset     = reader.ReadInt16();
                    track.valueIndex       = reader.ReadInt16(); //Used if no string (stringOffset = -1)
                    track.effect           = (TrackEffect)reader.ReadInt16();
                    track.interpolate_type = (InterpolationMode)reader.ReadInt16();
                    track.keyframe_count   = reader.ReadInt16();
                    if (track.keyframe_count > 0 && track.interpolate_type != InterpolationMode.Constant)
                    {
                        track.keyframe_offset = reader.ReadInt32();
                    }
                    else
                    {
                        track.Constant = reader.ReadSingle();
                    }

                    Console.WriteLine($"{j} TrackMode {track.mode} valueIndex {track.valueIndex} effect {track.effect} interp {track.interpolate_type} Constant {track.Constant}");

                    if (track.valueIndex != 0)
                    {
                        //Console.WriteLine($"valueIndex {track.valueIndex} str {track.stringOffset}");
                    }

                    anm.trackInfo.Add(track);
                }
            }

            Dictionary <string, AnimationNode> animationNodes = new Dictionary <string, AnimationNode>();

            long dataStart = reader.Position;

            for (int i = 0; i < Animations.Count; i++)
            {
                var anim = Animations[i];
                for (int j = 0; j < anim.trackInfo.Count; j++)
                {
                    var    track = anim.trackInfo[j];
                    string name  = header.GetString(reader, (uint)track.stringOffset);
                    if (track.stringOffset == -1)
                    {
                        name = $"{track.mode}_{track.valueIndex}";
                    }
                    else if (track.valueIndex > 0)
                    {
                        name = $"{name}_{track.valueIndex}";
                    }

                    if (!animationNodes.ContainsKey(name))
                    {
                        animationNodes.Add(name, new AnimationNode()
                        {
                            Name       = name,
                            Mode       = track.mode,
                            ValueIndex = track.valueIndex,
                        });
                    }

                    AnimationNode currentGroup = animationNodes[name];

                    List <STKeyFrame> keyFrames = new List <STKeyFrame>();
                    if (track.keyframe_count > 0 && track.interpolate_type != InterpolationMode.Constant)
                    {
                        reader.SeekBegin(dataStart + track.keyframe_offset);
                        for (int key = 0; key < track.keyframe_count; key++)
                        {
                            switch (track.interpolate_type)
                            {
                            //8 bytes
                            case InterpolationMode.Step:
                            {
                                keyFrames.Add(new STKeyFrame()
                                    {
                                        Frame = reader.ReadSingle(),
                                        Value = reader.ReadSingle(),
                                    });
                            }
                            break;

                            //8 bytes
                            case InterpolationMode.Bitmap:
                            {
                                keyFrames.Add(new STKeyFrame()
                                    {
                                        Frame = reader.ReadSingle(),
                                        Value = reader.ReadInt32(),
                                    });
                            }
                            break;

                            //16 bytes
                            case InterpolationMode.Bezier:
                            {
                                keyFrames.Add(new STBezierKeyFrame()
                                    {
                                        Frame    = reader.ReadSingle(),
                                        Value    = reader.ReadSingle(),
                                        SlopeIn  = reader.ReadSingle(),
                                        SlopeOut = reader.ReadSingle(),
                                    });
                            }
                            break;

                            case InterpolationMode.Linear:
                            {
                                keyFrames.Add(new STKeyFrame()
                                    {
                                        Frame = reader.ReadSingle(),
                                        Value = reader.ReadSingle(),
                                    });
                            }
                            break;

                            default:
                                throw new Exception($"Unsupported interpolation mode! track {j} " + track.interpolate_type);
                            }
                        }
                    }

                    currentGroup.TrackList.Add(new AnimTrack(currentGroup)
                    {
                        ConstantUnk       = track.keyframe_count, //When constant used, value is used for something else?
                        KeyFrames         = keyFrames,
                        TrackEffect       = track.effect,
                        TrackMode         = track.mode,
                        ValueIdx          = track.valueIndex,
                        Unknown           = track.unk,
                        Constant          = track.Constant,
                        InterpolationType = ConvertType(track.interpolate_type),
                    });
                }

                foreach (var group in animationNodes)
                {
                    anim.AnimGroups.Add(group.Value);
                }
            }
        }
 public AnimTrack(AnimationNode group)
 {
     ParentGroup = group;
 }
Esempio n. 5
0
        private static HSFMotionAnimation TextConverter(string text)
        {
            HSFMotionAnimation anim = new HSFMotionAnimation();

            StringReader sr = new StringReader(text);

            using (JsonReader reader = new JsonTextReader(sr))
            {
                AnimationNode group = null;
                while (reader.Read())
                {
                    if (reader.Value == null)
                    {
                        continue;
                    }

                    if (reader.Value.Equals("Name"))
                    {
                        anim.Name = reader.ReadAsString();
                    }
                    else if (reader.Value.Equals("FrameCount"))
                    {
                        anim.FrameCount = (float)reader.ReadAsDecimal();
                    }
                    else if (reader.Value.Equals("Group"))
                    {
                        group = new AnimationNode();
                        anim.AnimGroups.Add(group);

                        string name = reader.ReadAsString();
                        reader.Read();                                  //ID
                        group.ValueIndex = (short)reader.ReadAsInt32(); //index
                        reader.Read();                                  //mode
                        group.Mode = (TrackMode)reader.ReadAsInt32();

                        if (group.Mode == TrackMode.Normal || group.Mode == TrackMode.Object)
                        {
                            group.Name = name;
                        }
                        else
                        {
                            group.Name = "";
                        }
                    }
                    else if (reader.Value.Equals("Track_Constant"))
                    {
                        string effect = reader.ReadAsString();
                        reader.Read(); //Value
                        float value = (float)reader.ReadAsDecimal();
                        reader.Read(); //Flags
                        string flags = reader.ReadAsString().Replace("0x", string.Empty);

                        AnimTrack track = new AnimTrack(group);
                        track.ValueIdx          = group.ValueIndex;
                        track.TrackMode         = group.Mode;
                        track.TrackEffect       = ParseEffect(group.Mode, effect);
                        track.Constant          = value;
                        track.ConstantUnk       = short.Parse(flags, System.Globalization.NumberStyles.HexNumber);
                        track.InterpolationType = STInterpoaltionType.Constant;
                        track.KeyFrames         = new List <STKeyFrame>();
                        track.Unknown           = 0;
                        group.TrackList.Add(track);
                    }
                    else if (reader.Value.Equals("Track_Bezier"))
                    {
                        group.TrackList.Add(ParseAnimTrack(reader, group, STInterpoaltionType.Bezier));
                    }
                    else if (reader.Value.Equals("Track_Linear"))
                    {
                        group.TrackList.Add(ParseAnimTrack(reader, group, STInterpoaltionType.Linear));
                    }
                    else if (reader.Value.Equals("Track_Bezier"))
                    {
                        group.TrackList.Add(ParseAnimTrack(reader, group, STInterpoaltionType.Bezier));
                    }
                    else if (reader.Value.Equals("Track_Bitmap"))
                    {
                        group.TrackList.Add(ParseAnimTrack(reader, group, STInterpoaltionType.Bitmap));
                    }
                    else if (reader.Value.Equals("Track_Step"))
                    {
                        group.TrackList.Add(ParseAnimTrack(reader, group, STInterpoaltionType.Step));
                    }
                }
            }

            return(anim);
        }