예제 #1
0
        public void UpdateModels()
        {
            for (int i = 0; i < MobList.Count; i++)
            {
                if (MobList[i].IsEnabled)
                {
                    if (MobList[i].Model == null)
                    {
                        //create transform, apply it
                        MeshGeometry3D Geometry = new MeshGeometry3D();

                        List <Point3D>  Vertices  = ModelManager.VertexBufferMap[MobList[i].GetType().Name];
                        List <Vector3D> Normals   = ModelManager.NormalBufferMap[MobList[i].GetType().Name];
                        List <Point>    Texcoords = ModelManager.TexCoordBufferMap[MobList[i].GetType().Name];

                        for (int j = 0; j < Vertices.Count; j++)
                        {
                            Geometry.Positions.Add(Vertices[j]);
                            Geometry.Normals.Add(Normals[j]);
                            Geometry.TextureCoordinates.Add(Texcoords[j]);
                            Geometry.TriangleIndices.Add(j);
                        }
                        MobList[i].Model = new GeometryModel3D();

                        MobList[i].Model.Geometry = Geometry;

                        RenderManager.AddModel(MobList[i].Model, "Mobs" + MobList[i].EntityID);
                    }
                    TranslateTransform3D translation = new TranslateTransform3D(MobList[i].Position.X, MobList[i].Position.Y, MobList[i].Position.Z);
                    MobList[i].Model.Transform = translation;
                }
                else if (!MobList[i].IsEnabled && MobList[i].Model != null)
                {
                    if (RenderManager.HasModelAttached(MobList[i].Model))
                    {
                        RenderManager.RemoveModel("Mobs" + MobList[i].EntityID);
                    }
                }
            }
        }