Provides the ability to create, open and save ZMO files used for motion.
Inheritance: FileLoader
Example #1
0
        public void TestSaveMethod()
        {
            MotionFile motionFile = new MotionFile();
            motionFile.Load(TEST_FILE);

            MemoryStream savedStream = new MemoryStream();
            motionFile.Save(savedStream);

            savedStream.Seek(0, SeekOrigin.Begin);

            MotionFile savedMotionFile = new MotionFile();
            savedMotionFile.Load(savedStream);

            savedStream.Close();

            Assert.AreEqual(motionFile.FramesPerSecond, savedMotionFile.FramesPerSecond, "Frames per second values do not match");
            Assert.AreEqual(motionFile.ChannelCount, savedMotionFile.ChannelCount, "Channel counts do not match");

            for (int i = 0; i < motionFile.ChannelCount; i++) {
                Assert.AreEqual(motionFile[i].Type, savedMotionFile[i].Type, "Channel types do not match");
                Assert.AreEqual(motionFile[i].Index, savedMotionFile[i].Index, "Channel index values do not match");
            }

            Assert.AreEqual(motionFile.FramesPerSecond, savedMotionFile.FramesPerSecond, "Frame counts do not match");
        }
Example #2
0
        public void TestLoadMethod()
        {
            Stream stream = File.OpenRead(TEST_FILE);

            stream.Seek(0, SeekOrigin.End);
            long fileSize = stream.Position;
            stream.Seek(0, SeekOrigin.Begin);

            MotionFile motionFile = new MotionFile();
            motionFile.Load(stream);

            long streamPosition = stream.Position;
            stream.Close();

            Assert.AreEqual(fileSize, streamPosition, "Not all of the file was read");
        }
Example #3
0
    static AnimationClip ImportNodeAnimation(string clipPath, string zmoPath)
    {
        var f = new Revise.Files.ZMO.MotionFile();
        f.Load(rootPath + zmoPath);

        var clip = new AnimationClip();
        clip.wrapMode = WrapMode.Loop;
        clip.frameRate = f.FramesPerSecond;

        for (int i = 0; i < f.ChannelCount; ++i) {
            if (f[i].Index != 0) {
                Debug.LogWarning("Invalid channel index encountered");
                continue;
            }

            if (f[i].Type == Revise.Files.ZMO.ChannelType.Rotation) {
                var c = f[i] as Revise.Files.ZMO.Channels.RotationChannel;
                var curvex = new AnimationCurve();
                var curvey = new AnimationCurve();
                var curvez = new AnimationCurve();
                var curvew = new AnimationCurve();
                for (int j = 0; j < f.FrameCount; ++j) {
                    var frame = rtuRotation(c.Frames[j]);
                    curvex.AddKey((float)j / (float)f.FramesPerSecond, frame.x);
                    curvey.AddKey((float)j / (float)f.FramesPerSecond, frame.y);
                    curvez.AddKey((float)j / (float)f.FramesPerSecond, frame.z);
                    curvew.AddKey((float)j / (float)f.FramesPerSecond, frame.w);
                }
                clip.SetCurve("", typeof(Transform), "localRotation.x", curvex);
                clip.SetCurve("", typeof(Transform), "localRotation.y", curvey);
                clip.SetCurve("", typeof(Transform), "localRotation.z", curvez);
                clip.SetCurve("", typeof(Transform), "localRotation.w", curvew);
            } else if (f[i].Type == Revise.Files.ZMO.ChannelType.Position) {
                var c = f[i] as Revise.Files.ZMO.Channels.PositionChannel;
                var curvex = new AnimationCurve();
                var curvey = new AnimationCurve();
                var curvez = new AnimationCurve();
                for (int j = 0; j < f.FrameCount; ++j) {
                    var frame = rtuPosition(c.Frames[j]) / 100;
                    curvex.AddKey((float)j / (float)f.FramesPerSecond, frame.x);
                    curvey.AddKey((float)j / (float)f.FramesPerSecond, frame.y);
                    curvez.AddKey((float)j / (float)f.FramesPerSecond, frame.z);
                }
                clip.SetCurve("", typeof(Transform), "localPosition.x", curvex);
                clip.SetCurve("", typeof(Transform), "localPosition.y", curvey);
                clip.SetCurve("", typeof(Transform), "localPosition.z", curvez);
            } else {
                Debug.LogWarning("Encountered unknown channel type.");
            }
        }

        AssetDatabase.CreateAsset(clip, clipPath);
        return clip;
    }