示例#1
0
        private void SaveModelToFile(string filename)
        {
            FixKeyframes();

            using (var writer = new BinaryWriter(new FileStream(filename, FileMode.Create)))
            {
                var materialTranslator = new MaterialTranslator(this);
                var epicModelWriter    = new EpicModelWriter(materialTranslator);
                epicModelWriter.Write(writer, Model);
            }
        }
示例#2
0
        public void SaveAndLoad()
        {
            _model = new EpicModel("test");
            var cuboid = Cuboid.CreateCuboid();

            cuboid.Name = "Cuboid1";
            cuboid.AddAnchor("a1");
            cuboid.AddAnchor("a2");
            cuboid.Position = new Vector3(1, 1, 0);

            var cuboid2 = Cuboid.CreateCuboid();

            cuboid2.Name = "Cuboid2";
            var a3 = cuboid2.AddAnchor("a3");

            cuboid2.AddAnchor("a4");
            a3.Position = new Vector3(1, 1, 0);

            a3.Rotation = new Vector3(1.0f, 2.0f, 3.0f);

            cuboid.Pivot.SetParent(a3);

            _model.ModelParts.Add(cuboid);
            _model.ModelParts.Add(cuboid2);
            _model.ModelParts.Add(cuboid.Clone());

            var animation = _model.GetAnimation(AnimationType.Drop, true);

            animation.AddFrame().Time = 0.123f;
            animation.AddFrame().Time = 0.265f;
            animation.AddFrame().Time = 0.384f;

            var animation2 = _model.GetAnimation(AnimationType.Death3, true);

            animation2.AddFrame().Time = 0.464f;
            animation2.AddFrame().Time = 0.519f;
            animation2.AddFrame().Time = 0.694f;

            var materialTranslator = new TestMaterialTranslator();

            var memoryStream = new MemoryStream(4096);

            var binaryWriter = new BinaryWriter(memoryStream);
            var writer       = new EpicModelWriter(materialTranslator);

            writer.Write(binaryWriter, _model);

            memoryStream.Position = 0;

            var binaryReader = new BinaryReader(memoryStream);
            var reader       = new EpicModelReader(materialTranslator, binaryReader);

            _readModel = reader.Read("test");
        }