Esempio n. 1
0
        public GrannyAnimationWrapper(IGrannyAnimation inputAnimation)
        {
            wrappedAnimation = inputAnimation;
            Type      myType            = inputAnimation.GetType();
            FieldInfo fm_lstTrackGroups = myType.GetField("m_lstTrackGroups", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            m_lstTrackGroups = (List <IGrannyTrackGroup>)fm_lstTrackGroups.GetValue(inputAnimation);
        }
Esempio n. 2
0
        public static Int32 exportNA2(IGrannyModel model, IGrannyAnimation anim, string filename, Single timeWindowStart, Single timeWindowEnd, Int32 fpsInput, int retryLimit)
        {
            string numberFormat = "f6";

            if (timeWindowStart == -1)
            {
                timeWindowStart = 0;
            }
            if (timeWindowEnd < 0 || timeWindowEnd > anim.Duration)
            {
                timeWindowEnd = anim.Duration;
            }

            int startFrame = -1;
            int endFrame   = -1;
            int frameCount = 0;
            int fps;

            if (fpsInput > 0)
            {
                fps = fpsInput;
            }
            else
            {
                fps = (int)Math.Round(1.0f / anim.TimeStep, 0);
            }
            Single timestep = 1f / fps;
            Single time     = timeWindowStart;

            while (time <= timeWindowEnd)
            {
                if (time >= timeWindowStart && time <= timeWindowEnd)
                {
                    if (startFrame == -1)
                    {
                        startFrame = (int)Math.Round(time / timestep, 0) + 1;
                    }
                    endFrame = (int)Math.Round(time / timestep, 0) + 1;
                    frameCount++;
                }
                time = time + timestep;
            }

            List <IGrannyBone> boneList = new List <IGrannyBone>();

            foreach (IGrannyBone bone in model.Skeleton.Bones)
            {
                boneList.Add(bone);
            }
            time = 0;

            int     retryCount = 0;
            Boolean success    = false;

            List <List <float[]> > boneFrameLists = new List <List <float[]> >();
            int exceptionCount = 0;

            while (success == false && retryCount < retryLimit)
            {
                exceptionCount = 0;
                boneFrameLists = new List <List <float[]> >();
                foreach (IGrannyBone bone in boneList)
                {
                    time = timeWindowStart;
                    List <float[]> kf = new List <float[]>();
                    while (time <= timeWindowEnd)
                    {
                        if (time >= timeWindowStart && time <= timeWindowEnd)
                        {
                            try
                            {
                                float[] skf = anim.SampleBone(model, bone.Name, time);
                                kf.Add(skf);
                            }
                            catch (Exception e) {
                                exceptionCount++;
                            }
                        }
                        time = time + timestep;
                    }
                    boneFrameLists.Add(kf);
                }

                if (exceptionCount > 0)
                {
                    retryCount++;
                }
                else
                {
                    success = true;
                }
            }

            string fileExtension = "__" + timeWindowStart.ToString("f3") + "-" + timeWindowEnd.ToString("f3") + ".na2";

            string outputFilename = filename.Replace(".gr2", fileExtension);

            outputFilename = outputFilename.Replace(".GR2", fileExtension);

            StreamWriter outputWriter = new StreamWriter(new FileStream(outputFilename, FileMode.Create));

            outputWriter.WriteLine("// Nexus Buddy Animation NA2 - Exported from Nexus Buddy 2");

            outputWriter.WriteLine("FrameSets: 1");
            outputWriter.WriteLine("FrameCount: " + frameCount);
            outputWriter.WriteLine("FirstFrame: " + startFrame);
            outputWriter.WriteLine("LastFrame: " + endFrame);
            outputWriter.WriteLine("FPS: " + fps);
            outputWriter.WriteLine("Bones: " + model.Skeleton.Bones.Count);

            for (int bi = 0; bi < model.Skeleton.Bones.Count; bi++)
            {
                IGrannyBone bone = model.Skeleton.Bones[bi];
                outputWriter.WriteLine(bone.Name);
                foreach (float[] kff in boneFrameLists[bi])
                {
                    for (int j = 0; j < 16; j++)
                    {
                        outputWriter.Write(kff[j].ToString(numberFormat, CultureInfo.InvariantCulture) + " ");
                    }
                    outputWriter.Write("\n");
                }
            }

            outputWriter.Close();

            return(retryCount);
        }