Exemplo n.º 1
0
        public Vector3 CalcInterpolatedVertexPosition(Md5Vertex v, Md5Anim a, float frame)
        {
            int   frame1 = (int)frame;
            int   frame2 = (int)(frame + 1);
            float alpha  = frame - (float)frame1;

            return(CalcVertexPosition(v, a, frame1) * (1 - alpha) + CalcVertexPosition(v, a, frame2) * alpha);
        }
Exemplo n.º 2
0
        public IResource Load(FileSystemNode n)
        {
            reader = new StreamReader(n.getStream());
            string[] line;
            anim = new Md5Anim();

            while ((line = ReadLineTokens()) != null)
            {
                switch (line[0])
                {
                case "numFrames":
                    anim.Frames = new Md5Frame[int.Parse(line[1])];
                    break;

                case "numJoints":
                    anim.NumJoints = int.Parse(line[1]);
                    break;

                case "frameRate":
                    anim.FrameRate = int.Parse(line[1]);
                    break;

                case "numAnimatedComponents":
                    anim.NumAnimatedComponents = int.Parse(line[1]);
                    break;

                case "hierarchy":
                    LoadHierarchy();
                    break;

                case "baseframe":
                    anim.BaseFrame = LoadFrame(true);
                    break;

                case "frame":
                    anim.Frames[int.Parse(line[1])] = LoadFrame(false);
                    break;

                case "MD5Version":
                    anim.Header.Version = int.Parse(line[1]);
                    if (anim.Header.Version != 10)
                    {
                        Console.WriteLine("md5 warning: version is not 10.");
                    }
                    break;

                case "commandline":
                    //HACK
                    break;
                }
            }

            return(anim);
        }
Exemplo n.º 3
0
        public Vector3 CalcVertexPosition(Md5Vertex v, Md5Anim a, int frame)
        {
            Vector3 pos = Vector3.Zero;

            for (int i = v.WeightIndex; i < v.WeightIndex + v.WeightCount; ++i)
            {
                Md5Weight     w = Weights[i];
                Md5JointValue j = a.Frames[frame].Values[w.JointIndex];

                Matrix4 m = Matrix4Extensions.FromTranslation(j.Position) * Matrix4Extensions.FromQuaternion(j.Orientation);
                pos += w.Value * Vector3.Transform(w.Position, m);
            }

            return(pos);
        }
Exemplo n.º 4
0
        public void CreateBuffers(Md5Joint[] joints, Md5Anim anim, float frame)
        {
            if (v == null)
            {
                v = new VertexP3C4T2[Vertices.Length];
            }
            for (int i = 0; i < Vertices.Length; ++i)
            {
                if (anim == null)
                {
                    v[i].position = CalcVertexPosition(i, joints);
                }
                else
                {
                    //v[i].position=CalcVertexPosition(i,anim,frame)*0.12f;
                    v[i].position = CalcInterpolatedVertexPosition(i, anim, frame);
                }
                v[i].color.r    = 1;
                v[i].color.g    = 1;
                v[i].color.b    = 1;
                v[i].color.a    = 1;
                v[i].texture0.X = Vertices[i].TextureU;
                v[i].texture0.Y = Vertices[i].TextureV;
            }
            if (vb == null)
            {
                vb        = Root.Instance.UserInterface.Renderer.CreateDynamicVertexBuffer(Vertices.Length * (3 + 4 + 2) * 4);
                vb.Format = VertexFormat.VF_P3C4T2;
            }
            ((DynamicVertexBuffer)vb).Update(v, Vertices.Length * (3 + 4 + 2) * 4);

            if (ib == null)
            {
                ib        = new IndexBuffer();
                ib.buffer = new int[Triangles.Length * 3];
                for (int i = 0; i < Triangles.Length; ++i)
                {
                    ib.buffer[i * 3]     = Triangles[i][0];
                    ib.buffer[i * 3 + 1] = Triangles[i][1];
                    ib.buffer[i * 3 + 2] = Triangles[i][2];
                }
            }
        }
Exemplo n.º 5
0
        public Vector3 CalcInterpolatedVertexPosition(int index, Md5Anim anim, float frame)
        {
            Md5Vertex v = Vertices[index];

            return(CalcInterpolatedVertexPosition(v, anim, frame));
        }
Exemplo n.º 6
0
        public Vector3 CalcVertexPosition(int index, Md5Anim anim, int frame)
        {
            Md5Vertex v = Vertices[index];

            return(CalcVertexPosition(v, anim, frame));
        }
Exemplo n.º 7
0
        public void CreateBuffers(Md5Joint[] joints,Md5Anim anim, float frame)
        {
            if (v == null)
                v=new VertexP3C4T2[Vertices.Length];
            for(int i=0;i<Vertices.Length;++i)
            {
                if(anim==null)
                    v[i].position = CalcVertexPosition(i,joints);
                else
                    //v[i].position=CalcVertexPosition(i,anim,frame)*0.12f;
                    v[i].position = CalcInterpolatedVertexPosition(i, anim, frame);
                v[i].color.r = 1;
                v[i].color.g=1;
                v[i].color.b=1;
                v[i].color.a=1;
                v[i].texture0.X=Vertices[i].TextureU;
                v[i].texture0.Y = Vertices[i].TextureV;
            }
            if(vb==null)
            {
                vb = Root.Instance.UserInterface.Renderer.CreateDynamicVertexBuffer(Vertices.Length * (3 + 4 + 2) * 4);
                vb.Format = VertexFormat.VF_P3C4T2;
            }
            ((DynamicVertexBuffer)vb).Update(v, Vertices.Length * (3 + 4 + 2) * 4);

            if (ib == null)
            {
                ib = new IndexBuffer();
                ib.buffer = new int[Triangles.Length * 3];
                for (int i = 0; i < Triangles.Length; ++i)
                {
                    ib.buffer[i * 3] = Triangles[i][0];
                    ib.buffer[i * 3 + 1] = Triangles[i][1];
                    ib.buffer[i * 3 + 2] = Triangles[i][2];
                }
            }
        }
Exemplo n.º 8
0
        public Vector3 CalcVertexPosition(Md5Vertex v, Md5Anim a, int frame)
        {
            Vector3 pos = Vector3.Zero;

            for (int i = v.WeightIndex; i < v.WeightIndex + v.WeightCount; ++i)
            {
                Md5Weight w = Weights[i];
                Md5JointValue j = a.Frames[frame].Values[w.JointIndex];

                Matrix4 m = Matrix4Extensions.FromTranslation(j.Position) * Matrix4Extensions.FromQuaternion(j.Orientation);
                pos += w.Value * Vector3.Transform(w.Position,m);
            }

            return pos;
        }
Exemplo n.º 9
0
 public Vector3 CalcVertexPosition(int index, Md5Anim anim, int frame)
 {
     Md5Vertex v = Vertices[index];
     return CalcVertexPosition(v, anim, frame);
 }
Exemplo n.º 10
0
        public Vector3 CalcInterpolatedVertexPosition(Md5Vertex v, Md5Anim a, float frame)
        {
            int frame1 = (int)frame;
            int frame2 = (int)(frame + 1);
            float alpha = frame - (float)frame1;

            return CalcVertexPosition(v, a, frame1) * (1 - alpha) + CalcVertexPosition(v, a, frame2) * alpha;
        }
Exemplo n.º 11
0
 public Vector3 CalcInterpolatedVertexPosition(int index, Md5Anim anim, float frame)
 {
     Md5Vertex v = Vertices[index];
     return CalcInterpolatedVertexPosition(v, anim, frame);
 }
Exemplo n.º 12
0
        public IResource Load(FileSystemNode n)
        {
            reader = new StreamReader(n.getStream());
            string[] line;
            anim = new Md5Anim();

            while ((line = ReadLineTokens()) != null)
            {
                switch (line[0])
                {
                    case "numFrames":
                        anim.Frames = new Md5Frame[int.Parse(line[1])];
                        break;
                    case "numJoints":
                        anim.NumJoints = int.Parse(line[1]);
                        break;
                    case "frameRate":
                        anim.FrameRate = int.Parse(line[1]);
                        break;
                    case "numAnimatedComponents":
                        anim.NumAnimatedComponents = int.Parse(line[1]);
                        break;
                    case "hierarchy":
                        LoadHierarchy();
                        break;
                    case "baseframe":
                        anim.BaseFrame = LoadFrame(true);
                        break;
                    case "frame":
                        anim.Frames[int.Parse(line[1])]=LoadFrame(false);
                        break;
                    case "MD5Version":
                        anim.Header.Version = int.Parse(line[1]);
                        if (anim.Header.Version != 10)
                            Console.WriteLine("md5 warning: version is not 10.");
                        break;
                    case "commandline":
                        //HACK
                        break;
                }
            }

            return anim;
        }