Пример #1
0
        private static void WriteAnimKey(StreamWriter file, int i, DAT_Animation.DATAnimTrack track, bool rotation)
        {
            file.WriteLine("animData {\n input time;\n output linear;\n weighted 1;\n preInfinity constant;\n postInfinity constant;\n keys {");

            int size = track.keys.Count;

            int   time = 0;
            float cvalue = 0, ctan = 0;

            for (int f = 0; f < size; f++)
            {
                while (track.keys[f].interpolationType == DAT_Animation.InterpolationType.HermiteCurve)
                {
                    f++;
                }

                DAT_Animation.KeyNode no    = track.keys[f];
                DAT_Animation.KeyNode curve = track.keys[f + 1 >= track.keys.Count ? 0: f + 1];

                if (curve.interpolationType == DAT_Animation.InterpolationType.HermiteCurve)
                {
                    cvalue = no.value;
                    ctan   = curve.tan;
                    file.WriteLine(" " + (time + 1) + " {0:N6} fixed fixed 1 1 0 {1:N6} 1 {2:N6} 1;", cvalue * (rotation ? 180 / (float)Math.PI : 1), no.tan, ctan);
                }
                else
                {
                    switch (no.interpolationType)
                    {
                    case DAT_Animation.InterpolationType.Hermite:
                    {
                        cvalue = no.value;
                        ctan   = no.tan;
                        file.WriteLine(" " + (time + 1) + " {0:N6} fixed fixed 1 1 0 {1:N6} 1 {2:N6} 1;", cvalue * (rotation ? 180 / (float)Math.PI : 1), ctan, ctan);
                    }
                    break;

                    case DAT_Animation.InterpolationType.HermiteValue:
                    {
                        cvalue = no.value;
                        ctan   = 0;
                        file.WriteLine(" " + (time + 1) + " {0:N6} fixed fixed 1 1 0 {1:N6} 1 {2:N6} 1;", cvalue * (rotation ? 180 / (float)Math.PI : 1), ctan, ctan);
                    }
                    break;

                    case DAT_Animation.InterpolationType.Step:
                    {
                        cvalue = no.value;
                        file.WriteLine(" " + (time + 1) + " {0:N6} fixed fixed 1 1 0 0 1 0 1;", cvalue * (rotation ? 180 / (float)Math.PI : 1));
                    }
                    break;

                    case DAT_Animation.InterpolationType.Linear:
                    {
                        cvalue = no.value;
                        file.WriteLine(" " + (time + 1) + " {0:N6} linear linear 1 1 0", cvalue * (rotation ? 180 / (float)Math.PI : 1));
                    }
                    break;
                    }
                }

                time += (int)no.frame;
            }

            file.WriteLine(" }");
            file.WriteLine("}");
        }
Пример #2
0
        private static Animation.KeyGroup CreateKeyGroup(int i, DAT_Animation.DATAnimTrack track, bool rotation)
        {
            Animation.KeyGroup group = new Animation.KeyGroup();

            int size = track.keys.Count;

            int   time = 0;
            float cvalue = 0, ctan = 0;

            for (int f = 0; f < size; f++)
            {
                while (track.keys[f].interpolationType == DAT_Animation.InterpolationType.HermiteCurve)
                {
                    f++;
                }

                DAT_Animation.KeyNode no    = track.keys[f];
                DAT_Animation.KeyNode curve = track.keys[f + 1 >= track.keys.Count ? 0 : f + 1];

                if (curve.interpolationType == DAT_Animation.InterpolationType.HermiteCurve)
                {
                    cvalue = no.value;
                    ctan   = curve.tan;
                    group.keys.Add(new Animation.KeyFrame()
                    {
                        weighted = true, Frame = time, Value = cvalue, In = no.tan, Out = ctan, interType = Animation.InterpolationType.Hermite
                    });
                    //file.WriteLine(" " + (time + 1) + " {0:N6} fixed fixed 1 1 0 {1:N6} 1 {2:N6} 1;", cvalue * (rotation ? 180 / (float)Math.PI : 1), no.tan, ctan);
                }
                else
                {
                    switch (no.interpolationType)
                    {
                    case DAT_Animation.InterpolationType.Hermite:
                    {
                        cvalue = no.value;
                        ctan   = no.tan;
                        group.keys.Add(new Animation.KeyFrame()
                            {
                                weighted = true, Frame = time, Value = cvalue, In = ctan, Out = ctan, interType = Animation.InterpolationType.Hermite
                            });
                        //file.WriteLine(" " + (time + 1) + " {0:N6} fixed fixed 1 1 0 {1:N6} 1 {2:N6} 1;", cvalue * (rotation ? 180 / (float)Math.PI : 1), ctan, ctan);
                    }
                    break;

                    case DAT_Animation.InterpolationType.HermiteValue:
                    {
                        cvalue = no.value;
                        ctan   = 0;
                        group.keys.Add(new Animation.KeyFrame()
                            {
                                weighted = true, Frame = time, Value = cvalue, In = ctan, Out = ctan, interType = Animation.InterpolationType.Hermite
                            });
                        //file.WriteLine(" " + (time + 1) + " {0:N6} fixed fixed 1 1 0 {1:N6} 1 {2:N6} 1;", cvalue * (rotation ? 180 / (float)Math.PI : 1), ctan, ctan);
                    }
                    break;

                    case DAT_Animation.InterpolationType.Step:
                    {
                        cvalue = no.value;
                        group.keys.Add(new Animation.KeyFrame()
                            {
                                weighted = false, Frame = time, Value = cvalue, interType = Animation.InterpolationType.Step
                            });
                        //file.WriteLine(" " + (time + 1) + " {0:N6} fixed fixed 1 1 0 0 1 0 1;", cvalue * (rotation ? 180 / (float)Math.PI : 1));
                    }
                    break;

                    case DAT_Animation.InterpolationType.Linear:
                    {
                        cvalue = no.value;
                        group.keys.Add(new Animation.KeyFrame()
                            {
                                weighted = false, Frame = time, Value = cvalue, interType = Animation.InterpolationType.Linear
                            });
                        //file.WriteLine(" " + (time + 1) + " {0:N6} linear linear 1 1 0", cvalue * (rotation ? 180 / (float)Math.PI : 1));
                    }
                    break;
                    }
                }

                time += (int)no.frame;
            }
            return(group);
        }
Пример #3
0
        private Frame[] Bake(int bone)
        {
            Frame[] frames = new Frame[anim.frameCount];
            for (int i = 0; i < frames.Length; i++)
            {
                frames[i] = new Frame(i);
            }

            foreach (DAT_Animation.DATAnimTrack track in anim.nodes[bone])
            {
                int f = 0, ni = 0, currentFrame = 0, nextFrame = 0;
                DAT_Animation.KeyNode node = track.keys[ni++];
                nextFrame = (int)node.frame;
                float cvalue = node.value, ctan = node.tan;
                while (f < anim.frameCount)
                {
                    try
                    {
                        // calculate value
                        float nvalue = -99, ntan = -99;
                        for (int j = ni; j < track.keys.Count; j++)
                        {
                            //if (track.keys[j].interpolationType != DAT_Animation.InterpolationType.HermiteCurve)
                            {
                                if (track.keys[j].interpolationType == DAT_Animation.InterpolationType.HermiteCurve)
                                {
                                    ctan = track.keys[j].tan;
                                }
                                else
                                if (track.keys[j].tan != -99 && ntan == -99)
                                {
                                    ntan = track.keys[j].tan;
                                }
                                if (track.keys[j].value != -99 && nvalue == -99)
                                {
                                    nvalue = track.keys[j].value;
                                }
                                if (nvalue != -99 && ntan != -99)
                                {
                                    break;
                                }
                            }
                        }
                        if (nvalue == -99)
                        {
                            nvalue = track.keys[0].value;
                        }
                        if (ntan == -99)
                        {
                            ntan = 0;
                        }
                        if (ctan == -99)
                        {
                            ctan = 0;
                        }

                        float value = 0;
                        //Console.WriteLine(track.type + " " + node.interpolationType);
                        switch (node.interpolationType)
                        {
                        case DAT_Animation.InterpolationType.Hermite:
                        {
                            cvalue = node.value;
                            //value = Interpolate(f - currentFrame, nextFrame - currentFrame, cvalue, nvalue, ctan, ntan);
                            value = CHR0.interHermite(f, currentFrame, nextFrame + 1, ctan, ntan, cvalue, nvalue);
                        }
                        break;

                        case DAT_Animation.InterpolationType.HermiteValue:
                        {
                            cvalue = node.value;
                            ctan   = 0;
                            //value = Interpolate(f - currentFrame, nextFrame - currentFrame, cvalue, nvalue, ctan, ntan);
                            value = CHR0.interHermite(f, currentFrame, nextFrame + 1, 0, 0, cvalue, nvalue);
                        }
                        break;

                        case DAT_Animation.InterpolationType.Step:
                        {
                            value = node.value;
                        }
                        break;

                        case DAT_Animation.InterpolationType.Linear:
                        {
                            cvalue = node.value;
                            value  = CHR0.lerp(cvalue, nvalue, currentFrame, nextFrame, f);
                        }
                        break;

                        default:
                            Console.WriteLine(node.interpolationType);
                            break;
                        }

                        if (float.IsNaN(value) || f == currentFrame)
                        {
                            value = node.value;
                        }

                        switch (track.type)
                        {
                        case DAT_Animation.AnimType.XROT:
                            //Console.WriteLine(ctan + " " + ntan + " " + node.value + " " + nvalue + " " + f + " " + currentFrame + " " + nextFrame);
                            frames[f].rx = value * 180 / (float)Math.PI;
                            break;

                        case DAT_Animation.AnimType.YROT:
                            //Console.WriteLine(ctan + " " + ntan + " " + cvalue + " " + nvalue + " " + f + " " + currentFrame + " " + nextFrame);

                            frames[f].ry = value * 180 / (float)Math.PI;
                            break;

                        case DAT_Animation.AnimType.ZROT:
                            //Console.WriteLine(ctan + " " + ntan + " " + cvalue + " " + nvalue + " " + f + " " + currentFrame + " " + nextFrame);
                            frames[f].rz = value * 180 / (float)Math.PI;
                            break;

                        case DAT_Animation.AnimType.XPOS: frames[f].x = value; break;

                        case DAT_Animation.AnimType.YPOS: frames[f].y = value; break;

                        case DAT_Animation.AnimType.ZPOS: frames[f].z = value; break;

                        case DAT_Animation.AnimType.XSCA: frames[f].sx = value; break;

                        case DAT_Animation.AnimType.YSCA: frames[f].sy = value; break;

                        case DAT_Animation.AnimType.ZSCA: frames[f].sz = value; break;
                        }

                        f++;
                        if (f > nextFrame)
                        {
                            if (ni >= track.keys.Count)
                            {
                                node = track.keys[0];
                                continue;
                            }
                            node = track.keys[ni++];
                            while (node.interpolationType == DAT_Animation.InterpolationType.HermiteCurve)
                            {
                                node = track.keys[ni++];
                            }
                            currentFrame = f;
                            nextFrame   += (int)node.frame;

                            switch (node.interpolationType)
                            {
                            case DAT_Animation.InterpolationType.Hermite:
                            {
                                ctan = node.tan;
                            }
                            break;
                            }
                        }
                    }
                    catch (IndexOutOfRangeException ex)
                    {
                    }
                }
            }
            return(frames);
        }