示例#1
0
        private ModelInstance CreateModel(Material material)
        {
            var model  = new EpicModel();
            var parent = Cuboid.CreateCuboid();

            parent.Position   = new Vector3(0.25f, 0.25f, -0.25f);
            parent.MaterialId = material.Id;
            model.ModelParts.Add(parent);
            parent.Size = new Vector3(2, 2, 2);

            model.ModelParts.Add(parent);

            parent.MaterialId = material.Id;

            for (int i = 0; i < ChildCount; i++)
            {
                var child = Cuboid.CreateCuboid();

                child.Position = new Vector3(i, i, -i);
                child.Pivot.SetParent(parent.Pivot, true);
                child.MaterialId = material.Id;

                model.ModelParts.Add(child);
            }

            var emc           = new EpicModelCompiler(model);
            var compiledModel = emc.Compile();

            var modelInstance = new ModelInstance(compiledModel, _materialCache);

            _vertexCount = modelInstance.MeshInstances[0].VertexBuffer.Length;

            return(modelInstance);
        }
示例#2
0
文件: Keyframe.cs 项目: HaKDMoDz/Psy
        public void LoadFromCurrentModelState(EpicModel model)
        {
            ModelPartAnimStates = new List<ModelPartAnimState>();
            foreach (var modelPart in model.ModelParts)
            {
                if (_animation.Ignores(modelPart))
                {
                    continue;
                }

                var modelPartAnimState = ModelPartAnimState.FromModelPart(modelPart);
                ModelPartAnimStates.Add(modelPartAnimState);
            }

            AnchorAnimStates = new List<AnchorAnimState>();
            foreach (var anchor in model.GetAnchorsForAnimation(_animation))
            {
                if (_animation.Ignores(anchor))
                {
                    continue;
                }

                var anchorAnimState = AnchorAnimState.FromAnchor(anchor);
                AnchorAnimStates.Add(anchorAnimState);
            }
        }
示例#3
0
        public void SetUp()
        {
            _materialCache = new MaterialCache();
            _parentMtl     = _materialCache.Add("testmtl1");
            _childMtl      = _materialCache.Add("testmtl2");

            _epicModel = new EpicModel();

            _parentCuboid            = Cuboid.CreateCuboid();
            _parentCuboid.Size       = new Vector3(2, 2, 2);
            _parentCuboid.Rotation   = new Vector3(0, 0, -(float)Math.PI / 4.0f);
            _parentCuboid.MaterialId = _parentMtl.Id;

            _connector          = _parentCuboid.AddAnchor("Connector");
            _connector.Position = new Vector3(1, 1, 0);

            _childCuboid            = Cuboid.CreateCuboid();
            _childCuboid.Position   = new Vector3(-1, -1, 0);
            _childCuboid.Rotation   = new Vector3(0, 0, -(float)Math.PI / 2.0f);
            _childCuboid.MaterialId = _childMtl.Id;


            _epicModel.ModelParts.Add(_parentCuboid);
            _childCuboid.Pivot.SetParent(_connector);

            _compiler      = new EpicModelCompiler(_epicModel);
            _compiledModel = _compiler.Compile();

            _modelInstance = new ModelInstance(_compiledModel, _materialCache);

            _modelInstance.Update(1 / 24.0f);
        }
示例#4
0
        public EpicModel Read(string name)
        {
            _childIds = new Dictionary<Anchor, List<int>>();

            _model = new EpicModel(name);

            ReadHeader();
            ReadModelParts();
            ReadAnimations();

            foreach (var modelPart in _model.ModelParts)
            {
                foreach (var anchor in modelPart.Anchors)
                {
                    if (!_childIds.ContainsKey(anchor))
                        continue;

                    foreach (var i in _childIds[anchor])
                    {
                        var childModelPart = _model.ModelParts.Single(x => x.Id == i);
                        childModelPart.Pivot.SetParent(anchor, false);
                    }
                }
            }

            return _model;
        }
示例#5
0
        public async Task <IActionResult> Put([FromRoute] int epicID, [FromBody] EpicModel epicModel)
        {
            var check_epic = await Task.FromResult(_epicRepository.GetEpicByID(epicID));

            if (check_epic is Epic)
            {
                var model_check = Mappers.EpicModelMapper.Map(check_epic);

                epicModel.ID         = model_check.ID;
                epicModel.Date       = model_check.Date;
                epicModel.Concept    = model_check.Concept;
                epicModel.Author     = model_check.Author;
                epicModel.Categories = model_check.Categories;

                if (epicModel.updateCompleted && epicModel.DateCompleted == DateTime.MinValue)
                {
                    epicModel.DateCompleted = DateTime.UtcNow;
                }

                var changed = await Task.FromResult(_epicRepository.UpdateEpic(Mappers.EpicModelMapper.Map(epicModel)));

                if (changed)
                {
                    return(Ok());
                }
                return(BadRequest());
            }
            return(NotFound());
        }
示例#6
0
文件: Animation.cs 项目: HaKDMoDz/Psy
 public Animation(EpicModel epicModel, AnimationType animationType)
 {
     _epicModel = epicModel;
     AnimationType = animationType;
     _keyframes = new List<Keyframe>(10);
     _ignoredModelParts = new List<ModelPart>();
 }
示例#7
0
        public virtual void SetUp()
        {
            Model = new EpicModel();

            Cuboid = EpicEdit.Model.Factories.Cuboid.CreateCuboid();
            Cuboid.Pivot.Position = new Vector3(-0.5f, 0, 0);
            Cuboid.Position       = new Vector3(1, 1, 0);
            Cuboid.Size           = new Vector3(1, 1, 1);

            Anchor          = Cuboid.AddAnchor("Test_Anchor");
            Anchor.Position = new Vector3(0.5f, 0, 0);
            Anchor.Rotation = new Vector3();

            Model.ModelParts.Add(Cuboid);

            Animation = Model.GetAnimation(AnimationType.Walking, true);

            var frame1 = Animation.AddFrame();

            frame1.Time = 0.0f;

            var frame2 = Animation.AddFrame();

            frame2.Time = 2.0f;

            var anchorAnimState = frame2.AnchorAnimStates.Single(x => x.Anchor == Anchor);

            anchorAnimState.Rotation = new Vector3(0, 0, (float)Math.PI / 2.0f);

            var cuboidAnimState = frame2.ModelPartAnimStates.Single(x => x.ModelPart == Cuboid);

            cuboidAnimState.Position = new Vector3(0, 0, 0);
            cuboidAnimState.Rotation = new Vector3(0, 0, (float)Math.PI / 2.0f);
        }
示例#8
0
 private static void WriteAnimations(BinaryWriter writer, EpicModel model)
 {
     writer.Write(model.Animations.Count);
     foreach (var animation in model.Animations)
     {
         WriteAnimation(writer, animation);
     }
 }
示例#9
0
        public void SaveAndLoad()
        {
            Logger.Add(new TraceLogger {
                LoggerLevel = LoggerLevel.Trace
            });

            _model = new EpicModel();
            var cuboid = Cuboid.CreateCuboid();

            cuboid.MaterialId = 1;
            cuboid.Name       = "Cuboid1";
            cuboid.AddAnchor("a1");
            cuboid.AddAnchor("a2");

            var cuboid2 = Cuboid.CreateCuboid();

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

            var a4 = cuboid2.AddAnchor("a4");

            a4.Position = new Vector3(0.5f, 0.0f, 0.0f);

            cuboid.Pivot.SetParent(a3);

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

            var cuboid3 = Cuboid.CreateCuboid();

            cuboid3.MaterialId = 0;
            _model.ModelParts.Add(cuboid3);

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

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

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

            animation2.AddFrame().Time = 0.0f;

            cuboid2.Rotation = new Vector3(0.0f, 0.0f, (float)(Math.PI / 2.0f));
            cuboid2.Position = new Vector3(-1f, -1f, 0);

            var frame2 = animation2.AddFrame();

            frame2.LoadFromCurrentModelState(_model);
            frame2.Time = 0.519f;

            cuboid2.Rotation = new Vector3();
            cuboid2.Position = new Vector3();

            _compiler      = new EpicModelCompiler(_model);
            _compiledModel = _compiler.Compile();
        }
示例#10
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");
        }
 public static Domain.Models.Epic Map(EpicModel model)
 {
     return(new Domain.Models.Epic {
         ID = model.ID,
         Date = model.Date,
         Title = model.Title,
         Concept = model.Concept,
         Writer = UserModelMapper.Map(model.Author),
         Categories = model.Categories.Select(CategoryModelMapper.Map),
         DateCompleted = model.DateCompleted ?? DateTime.MinValue
     });
 }
示例#12
0
        public async Task <IActionResult> AddEpic([FromBody] EpicModel epic)
        {
            var domain_epic = Mappers.EpicModelMapper.MapAPItoDomain(epic);

            var completed = await Task.FromResult(_epicRepository.AddEpic(domain_epic));

            if (completed)
            {
                return(CreatedAtAction(nameof(GetEpicByID), new { id = epic.ID }, epic));
            }
            return(BadRequest());
        }
        public static Domain.Models.Epic MapAPItoDomain(EpicModel model)
        {
            Domain.Models.User author = new Domain.Models.User {
                ID = model.Author.ID
            };

            return(new Domain.Models.Epic
            {
                Title = model.Title,
                Writer = author,
                Concept = model.Concept
            });
        }
示例#14
0
        private void LoadModelFromFile(string filename)
        {
            Lookup.AddPath(Path.GetDirectoryName(filename));

            using (var reader = new BinaryReader(new FileStream(filename, FileMode.Open)))
            {
                var materialTranslator = new MaterialTranslator(this);
                var epicModelReader    = new EpicModelReader(materialTranslator, reader);

                var model = epicModelReader.Read(filename);

                Model = model;
            }
        }
示例#15
0
        public void SetUp()
        {
            _model = new EpicModel();

            _parent          = Cuboid.CreateCuboid();
            _parent.Position = new Vector3(0.25f, 0.25f, -0.25f);
            _model.ModelParts.Add(_parent);
            _parent.Size = new Vector3(2, 2, 2);

            _connectingAnchor          = _parent.AddAnchor("Connecting_Anchor");
            _connectingAnchor.Position = new Vector3(1, 1, -1);

            _child = Cuboid.CreateCuboid();
            _model.ModelParts.Add(_child);
            _child.Position = new Vector3(2, 2, 0);
            _child.Pivot.SetParent(_connectingAnchor);
        }
示例#16
0
 public EpicModelCompiler(EpicModel epicModel)
 {
     _epicModel = epicModel;
 }
示例#17
0
        public void Render(EpicModel epicModel)
        {
            foreach (var modelPart in epicModel.ModelParts)
            {
                if (!modelPart.IsARootModelPart)
                    continue;

                ResetWorldMatrix();

                Render(modelPart);
            }
        }
示例#18
0
 private void WriteModelParts(BinaryWriter writer, EpicModel model)
 {
     writer.Write(model.ModelParts.Count);
     foreach (var modelPart in model.ModelParts)
     {
         WriteModelPart(writer, modelPart);
     }
 }
示例#19
0
 private void LoadDefaultModel()
 {
     Model = new EpicModel("workspace_model");
 }
示例#20
0
 public void Write(BinaryWriter writer, EpicModel model)
 {
     WriteHeader(writer);
     WriteModelParts(writer, model);
     WriteAnimations(writer, model);
 }