Ejemplo n.º 1
0
        public VmdFile GenerateVmd()
        {
            VmdFile vmd = new VmdFile();

            int node_count = nodes.Length;

            vmd.nodes = new VmdNode[node_count];

            for (ushort i = 0; i < node_count; i++)
            {
                vmd.nodes[i]                = new VmdNode(i);
                vmd.nodes[i].name           = nodes[i].name;
                vmd.nodes[i].parent_node_id = nodes[i].parent_node_id;
                VmdMat mat = new VmdMat();
                vmd.nodes[i].matrices = new VmdMat[] { mat };
            }

            vmd.GenerateNodemapAndTree();

            return(vmd);
        }
Ejemplo n.º 2
0
        VmdMat[] CreateMatrices(List <VmdNodeFrame> frames)
        {
            frames.Sort();

            VmdMat[] matrices = new VmdMat[frame_length];
            for (int i = 1; i < frames.Count; i++)
            {
                VmdNodeFrame fa = frames[i - 1];
                VmdNodeFrame fb = frames[i];
                for (int index = fa.index; index < fb.index; index++)
                {
                    float  ratio = ((float)(index - fa.index)) / ((float)(fb.index - fa.index));
                    VmdMat mat   = new VmdMat();
                    mat.rotation      = Quaternion.Slerp(fa.rotation, fb.rotation, ratio);
                    mat.translation.X = Lerp(fa.translation.X, fb.translation.X, ratio);
                    mat.translation.Y = Lerp(fa.translation.Y, fb.translation.Y, ratio);
                    mat.translation.Z = Lerp(fa.translation.Z, fb.translation.Z, ratio);
                    matrices[index]   = mat;
                }
                {
                    VmdMat mat = new VmdMat();
                    mat.rotation       = fb.rotation;
                    mat.translation    = fb.translation;
                    matrices[fb.index] = mat;
                }
            }
            {
                VmdNodeFrame last_frame = frames[frames.Count - 1];
                for (int index = last_frame.index; index < frame_length; index++)
                {
                    VmdMat mat = new VmdMat();
                    mat.rotation    = last_frame.rotation;
                    mat.translation = last_frame.translation;
                    matrices[index] = mat;
                }
            }
            return(matrices);
        }