Esempio n. 1
0
            public void LoadVisibilyGroup(Gfbanim.Group visAnim)
            {
                VisibiltyGroup groupAnim = new VisibiltyGroup();

                groupAnim.Name = visAnim.Name;
                AnimGroups.Add(groupAnim);

                if (visAnim.ValueType == Gfbanim.BooleanTrack.FixedBooleanTrack)
                {
                    var track = visAnim.Value <Gfbanim.FixedBooleanTrack>();
                    if (track.HasValue)
                    {
                        var animTrack = new STAnimationTrack();
                        animTrack.KeyFrames.Add(new STKeyFrame(0, track.Value.Value));
                        groupAnim.BooleanTrack = animTrack;
                    }
                }
                else if (visAnim.ValueType == Gfbanim.BooleanTrack.DynamicBooleanTrack)
                {
                    var track = visAnim.Value <Gfbanim.DynamicBooleanTrack>();
                    if (track.HasValue)
                    {
                        groupAnim.BooleanTrack = GfbanimKeyFrameLoader.LoadBooleanTrack(track.Value);
                    }
                }
                else if (visAnim.ValueType == Gfbanim.BooleanTrack.FramedBooleanTrack)
                {
                    var track = visAnim.Value <Gfbanim.FramedBooleanTrack>();
                    if (track.HasValue)
                    {
                        groupAnim.BooleanTrack = GfbanimKeyFrameLoader.LoadBooleanTrack(track.Value);
                    }
                }
            }
Esempio n. 2
0
            public STKeyFrame GetFVGFR(STAnimationTrack t, float frame, float startFrame = 0)
            {
                if (t.KeyFrames.Count == 0)
                {
                    return(new STKeyFrame(frame, 0));
                }
                if (t.KeyFrames.Count == 1)
                {
                    return(t.KeyFrames[0]);
                }

                STKeyFrame RK = t.KeyFrames.Last();

                float Frame = frame - startFrame;

                foreach (STKeyFrame keyFrame in t.KeyFrames)
                {
                    if (keyFrame.Frame >= Frame && keyFrame.Frame < RK.Frame)
                    {
                        RK = keyFrame;
                    }
                }

                return(RK);
            }
Esempio n. 3
0
        public static STAnimationTrack[] LoadVectorTrack(Gfbanim.FramedVectorTrack framedTrack)
        {
            ushort[] frames = framedTrack.GetFramesArray();

            STAnimationTrack[] tracks = new STAnimationTrack[3];
            tracks[0] = new STAnimationTrack(STInterpoaltionType.Linear);
            tracks[1] = new STAnimationTrack(STInterpoaltionType.Linear);
            tracks[2] = new STAnimationTrack(STInterpoaltionType.Linear);

            for (int i = 0; i < framedTrack.ValuesLength; i++)
            {
                var vec   = framedTrack.Values(i).Value;
                int frame = i;

                if (i < frames?.Length)
                {
                    frame = frames[i];
                }

                tracks[0].KeyFrames.Add(new STKeyFrame(frame, vec.X));
                tracks[1].KeyFrames.Add(new STKeyFrame(frame, vec.Y));
                tracks[2].KeyFrames.Add(new STKeyFrame(frame, vec.Z));
            }
            return(tracks);
        }
Esempio n. 4
0
            public STKeyFrame GetFVGFL(STAnimationTrack t, float frame, float startFrame = 0)
            {
                if (t.KeyFrames.Count == 0)
                {
                    return(new STKeyFrame(frame, 0));
                }
                if (t.KeyFrames.Count == 1)
                {
                    return(t.KeyFrames[0]);
                }

                STKeyFrame LK = t.KeyFrames.First();

                float Frame = frame - startFrame;

                foreach (STKeyFrame keyFrame in t.KeyFrames)
                {
                    if (keyFrame.Frame <= Frame)
                    {
                        LK = keyFrame;
                    }
                }

                return(LK);
            }
        private STAnimationTrack ToGeneric(Track track, int trackType)
        {
            STAnimationTrack genericTrack = new STAnimationTrack();

            genericTrack.InterpolationType = STInterpoaltionType.Linear;

            float scale = 1.0f;

            if (trackType == 0) //Set hardcoded scale for translation types
            {
                scale = 1024.0f;
            }

            float currentFrame = 0;

            foreach (var key in track.Keys)
            {
                genericTrack.KeyFrames.Add(new STKeyFrame()
                {
                    Frame = currentFrame,
                    Value = key.Value * scale,
                    Slope = key.Delta,
                });
                currentFrame += key.FrameCount;
            }
            return(genericTrack);
        }
Esempio n. 6
0
        private static STAnimationTrack LoadTrack(STBoneAnimGroup group, FileReader reader)
        {
            STAnimationTrack track = new STAnimationTrack();

            uint keyOffset    = reader.ReadUInt32();
            uint frameCount   = reader.ReadUInt32();
            uint unk          = reader.ReadUInt32(); //0
            uint numKeyFrames = reader.ReadUInt32();
            uint unk2         = reader.ReadUInt32(); //0
            uint unk3         = reader.ReadUInt32(); //0

            reader.ReadUInt16();                     // 0
            KeyType type = (KeyType)reader.ReadByte();
            byte    unk4 = reader.ReadByte();

            Console.WriteLine($"numKeyFrames {numKeyFrames} {type} frameCount {frameCount}");

            reader.SeekBegin(keyOffset);
            for (int i = 0; i < numKeyFrames; i++)
            {
                if (type == KeyType.Normal)
                {
                    float frame = reader.ReadUInt32();
                    float value = reader.ReadSingle();

                    Console.WriteLine($"frame {frame} value {value}");

                    track.KeyFrames.Add(new STKeyFrame()
                    {
                        Frame = frame,
                        Value = value,
                    });
                }
                else if (type == KeyType.Hermite)
                {
                    float frame    = reader.ReadUInt32();
                    float value    = reader.ReadSingle();
                    float slopeIn  = reader.ReadSingle();
                    float padding2 = reader.ReadSingle();
                    float slopeOut = reader.ReadSingle();

                    Console.WriteLine($"frame {frame} value {value}");

                    track.KeyFrames.Add(new STHermiteKeyFrame()
                    {
                        Frame = frame,
                        Value = value,
                        // TangentIn = slopeIn,
                        // TangentOut = slopeOut,
                    });
                }
            }
            return(track);
        }
Esempio n. 7
0
 public AnimGroup(KEY_Parser.AnimJoint animJoint)
 {
     PositionX = new AnimationTrack(animJoint.PositionX);
     PositionY = new AnimationTrack(animJoint.PositionY);
     PositionZ = new AnimationTrack(animJoint.PositionZ);
     RotateX   = new AnimationTrack(animJoint.RotateX);
     RotateY   = new AnimationTrack(animJoint.RotateY);
     RotateZ   = new AnimationTrack(animJoint.RotateZ);
     ScaleX    = new AnimationTrack(animJoint.ScaleX);
     ScaleY    = new AnimationTrack(animJoint.ScaleY);
     ScaleZ    = new AnimationTrack(animJoint.ScaleZ);
 }
Esempio n. 8
0
            private STAnimationTrack LoadTrack(float[] Frames, float[] Values)
            {
                STAnimationTrack track = new STAnimationTrack();

                track.InterpolationType = STInterpoaltionType.Linear;
                for (int i = 0; i < Values?.Length; i++)
                {
                    STKeyFrame keyFrame = new STKeyFrame();
                    keyFrame.Value = Values[i];
                    keyFrame.Value = Frames[i];
                    track.KeyFrames.Add(keyFrame);
                }
                return(track);
            }
Esempio n. 9
0
        public static STAnimationTrack LoadBooleanTrack(Gfbanim.DynamicBooleanTrack framedTrack)
        {
            STAnimationTrack track = new STAnimationTrack(STInterpoaltionType.Step);

            for (int i = 0; i < framedTrack.ValuesLength; i++)
            {
                ushort val   = framedTrack.Values(i);
                int    frame = i;

                //Visibily is handled by bits from a ushort
                track.KeyFrames.Add(new STKeyFrame(frame, val));
            }
            return(track);
        }
Esempio n. 10
0
        public static STAnimationTrack[] LoadVectorTrack(Gfbanim.DynamicVectorTrack dynamicTrack)
        {
            STAnimationTrack[] tracks = new STAnimationTrack[3];
            tracks[0] = new STAnimationTrack(STInterpoaltionType.Linear);
            tracks[1] = new STAnimationTrack(STInterpoaltionType.Linear);
            tracks[2] = new STAnimationTrack(STInterpoaltionType.Linear);

            for (int i = 0; i < dynamicTrack.ValuesLength; i++)
            {
                var vec = dynamicTrack.Values(i).Value;
                tracks[0].KeyFrames.Add(new STKeyFrame(i, vec.X));
                tracks[1].KeyFrames.Add(new STKeyFrame(i, vec.Y));
                tracks[2].KeyFrames.Add(new STKeyFrame(i, vec.Z));
            }
            return(tracks);
        }
Esempio n. 11
0
        public static STAnimationTrack[] LoadRotationTrack(Gfbanim.DynamicQuatTrack dynamicTrack)
        {
            STAnimationTrack[] tracks = new STAnimationTrack[3];
            tracks[0] = new STAnimationTrack(STInterpoaltionType.Linear);
            tracks[1] = new STAnimationTrack(STInterpoaltionType.Linear);
            tracks[2] = new STAnimationTrack(STInterpoaltionType.Linear);

            for (int i = 0; i < dynamicTrack.ValuesLength; i++)
            {
                var quat = dynamicTrack.Values(i).Value;
                tracks[0].KeyFrames.Add(new STKeyFrame(i, ConvertRotation(quat.X)));
                tracks[1].KeyFrames.Add(new STKeyFrame(i, ConvertRotation(quat.Y)));
                tracks[2].KeyFrames.Add(new STKeyFrame(i, ConvertRotation(quat.Z)));
            }
            return(tracks);
        }
Esempio n. 12
0
        public static STAnimationTrack LoadBooleanTrack(Gfbanim.FramedBooleanTrack framedTrack)
        {
            ushort[] frames = framedTrack.GetFramesArray();

            STAnimationTrack track = new STAnimationTrack(STInterpoaltionType.Step);

            for (int i = 0; i < framedTrack.ValuesLength; i++)
            {
                ushort val   = framedTrack.Values(i);
                int    frame = i;

                if (i < frames?.Length)
                {
                    frame = frames[i];
                }

                //Visibily is handled by bits from a ushort
                track.KeyFrames.Add(new STKeyFrame(frame, val));
            }
            return(track);
        }
        private void ParseKeyTrack(BfresMeshAsset mesh, STAnimationTrack baseTarget, List <STAnimationTrack> tracks)
        {
            float[] weights = new float[tracks.Count];
            for (int i = 0; i < tracks.Count; i++)
            {
                weights[i] = tracks[i].GetFrameValue(this.Frame);
            }

            float totalWeight = 0;

            foreach (float f in weights)
            {
                totalWeight += f;
            }

            float baseWeight = 1.0f - totalWeight;
            float total      = totalWeight + baseWeight;

            Vector3[] morphPositions = new Vector3[mesh.Shape.Vertices.Count];

            //Trasform the existing track key data
            for (int i = 0; i < mesh.Shape.Vertices.Count; i++)
            {
                var vertex = mesh.Shape.Vertices[i];

                //Determine what vertex to morph from.
                if (baseTarget != null && mesh.KeyGroups.ContainsKey(baseTarget.Name))
                {
                    var keyShape = mesh.KeyGroups[baseTarget.Name];
                    //Add the keyed position target
                    morphPositions[i] = keyShape.Vertices[i].Position;
                }
                else
                {
                    morphPositions[i] = vertex.Position;
                }

                Vector3 position = morphPositions[i];
                position *= baseWeight;

                foreach (var track in tracks)
                {
                    if (!mesh.KeyGroups.ContainsKey(track.Name))
                    {
                        continue;
                    }

                    //The total weight used for a single vertex point
                    var weight = track.GetFrameValue(this.Frame);

                    //Get the track's key shape
                    var keyShape = mesh.KeyGroups[track.Name];
                    //Add the keyed position and weigh it
                    position += keyShape.Vertices[i].Position * weight;
                }

                //Set the output vertex
                position         /= total;
                morphPositions[i] = position;
            }

            mesh.MorphPositions   = morphPositions;
            mesh.UpdateVertexData = true;
        }