Exemplo n.º 1
0
        private static Mesh FromMdlx(
            GraphicsDevice graphics, ArchiveManager archiveManager, string modelName, string textureName)
        {
            var mdlx     = archiveManager.Get <Mdlx>(modelName);
            var textures = archiveManager.Get <ModelTexture>(textureName);

            if (mdlx == null)
            {
                return(null);
            }

            var model = new MdlxParser(mdlx).Model;

            return(new Mesh
            {
                Segments = model.Segments.Select(segment => new Mesh.Segment
                {
                    Vertices = segment.Vertices.Select(vertex => new VertexPositionColorTexture
                    {
                        Position = new Vector3(vertex.X, vertex.Y, vertex.Z),
                        TextureCoordinate = new Vector2(vertex.U, vertex.V),
                        Color = new Color((vertex.Color >> 16) & 0xff, (vertex.Color >> 8) & 0xff, vertex.Color & 0xff, (vertex.Color >> 24) & 0xff)
                    }).ToArray()
                }).ToArray(),
                Parts = model.Parts.Select(part => new Mesh.Part
                {
                    Indices = part.Indices,
                    SegmentId = part.SegmentIndex,
                    TextureId = part.TextureIndex
                }).ToArray(),
                Textures = textures?.Images?.Select(texture => new KingdomTexture(texture, graphics)).ToArray() ?? new KingdomTexture[0]
            });
        }
Exemplo n.º 2
0
 private static MeshGroup FromMdlx(
     GraphicsDevice graphics, ArchiveManager archiveManager, string modelName, string textureName)
 {
     Log.Info($"Load model={modelName} texture={textureName}");
     return(MeshLoader.FromKH2(graphics,
                               archiveManager.Get <Mdlx>(modelName),
                               archiveManager.Get <ModelTexture>(textureName)));
 }
Exemplo n.º 3
0
        private (Layout layout, IEnumerable <ISpriteTexture> textures) GetLayoutResources(string layoutResourceName, string imagesResourceName)
        {
            var layout = _archiveManager.Get <Layout>(layoutResourceName);

            if (!cachedSurfaces.TryGetValue(imagesResourceName, out var images))
            {
                images = cachedSurfaces[imagesResourceName] = _archiveManager.Get <Imgz>(imagesResourceName)
                                                              ?.Images?.Select(x => drawing.CreateSpriteTexture(x)).ToList();
            }

            return(layout, images);
        }
Exemplo n.º 4
0
        private LayoutRenderer CreateLayoutRenderer(string layoutResourceName, string imagesResourceName)
        {
            var layout = _archiveManager.Get <Layout>(layoutResourceName);

            if (!cachedSurfaces.TryGetValue(imagesResourceName, out var images))
            {
                images = cachedSurfaces[imagesResourceName] = _archiveManager.Get <Imgz>(imagesResourceName)
                                                              ?.Images?.Select(x => drawing.CreateSurface(x));
            }

            return(new LayoutRenderer(layout, drawing, images));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initialize debug data<para/>
        /// Инициализация отладочной иноформации
        /// </summary>
        public static void Init()
        {
            //Entities.Camera.Position = new OpenTK.Vector3(375.604f, 58.78056f, -585.3889f);

            rend         = new Graphics.Renderers.DebugRenderer();
            box          = new Graphics.Renderers.DebugRenderer.Box();
            box.LineSize = 2f;
            box.Size     = Vector3.One * 0.5f;
            //rend.Primitives.Add(box);


            AnimationFile fg = new AnimationFile(PathManager.GetAbsolute("anim/ped.ifp"));

            animation = fg["WALK_player"];


            man    = new Model(new ModelFile(ArchiveManager.Get("HFYST.dff"), true), true, true);
            manTex = new TextureDictionary(new TextureFile(ArchiveManager.Get("HFYST.txd"), true), true, true);



            ApplyAnimationFrame(man.Children, animation, 2);

            re    = new Graphics.Renderers.SkinnedRenderer();
            lines = new List <Graphics.Renderers.DebugRenderer.Line>();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initialize debug data<para/>
        /// Инициализация отладочной иноформации
        /// </summary>
        public static void Init()
        {
            //Entities.Camera.Position = new OpenTK.Vector3(-1647.534f, 26.54692f, -667.5128f);

            rend         = new Graphics.Renderers.DebugRenderer();
            box          = new Graphics.Renderers.DebugRenderer.Box();
            box.LineSize = 2f;
            box.Size     = Vector3.One * 0.5f;
            //rend.Primitives.Add(box);

            AnimationFile fg = new AnimationFile(PathManager.GetAbsolute("anim/ped.ifp"));


            man    = new Model(new ModelFile(ArchiveManager.Get("cop.dff"), true), true, true);
            manTex = new TextureDictionary(new TextureFile(ArchiveManager.Get("cop.txd"), true), true, true);



            re = new Graphics.Renderers.SkinnedRenderer();
            RenderBonesRecursively(man.Children);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Process mesh internals<para/>
 /// Обработка данных меша
 /// </summary>
 public void Process(bool needed)
 {
     if (needed)
     {
         if (GroupModel != null)
         {
             if (GroupTextures != null)
             {
                 if (GroupModel.State == Model.ReadyState.Complete && GroupTextures.State == TextureDictionary.ReadyState.Complete)
                 {
                     // Surface is ready to render
                     // Поверхность готова к отрисовке
                     Ready = true;
                     Model.SubMesh[] subs = GroupModel.GetAllSubMeshes();
                     Renderers       = new StaticRenderer[subs.Length];
                     Coords.Position = Coords.Position;
                     for (int i = 0; i < Renderers.Length; i++)
                     {
                         Renderers[i] = new StaticRenderer()
                         {
                             BaseMatrix    = Coords.Matrix,
                             SubmeshMatrix = subs[i].Parent.Matrix,
                             SubMesh       = subs[i],
                             Textures      = GroupTextures,
                             Fading        = false,
                             FadingDelta   = 1
                         };
                     }
                 }
                 else
                 {
                     // Check for model state
                     // Проверка состояния модели
                     if (GroupModel.State != Model.ReadyState.Complete)
                     {
                         if (GroupModel.File.State == Files.RenderWareFile.LoadState.Complete)
                         {
                             if (!ModelManager.IsProcessing(GroupModel))
                             {
                                 ModelManager.ModelProcessQueue.Enqueue(GroupModel);
                             }
                         }
                     }
                     // Check for texture dictionary state
                     // Проверка состояния архива текстур
                     if (GroupTextures.State != TextureDictionary.ReadyState.Complete)
                     {
                         if (GroupTextures.File.State == Files.RenderWareFile.LoadState.Complete)
                         {
                             if (!TextureManager.IsProcessing(GroupTextures))
                             {
                                 TextureManager.TextureProcessQueue.Enqueue(GroupTextures);
                             }
                         }
                     }
                 }
             }
             else
             {
                 // Texture not found - get it
                 // Текстура не найдена - получаем её
                 string tname = ObjectManager.Definitions[Definition.ID].TexDictionary;
                 if (TextureManager.Cached.ContainsKey(tname))
                 {
                     GroupTextures = TextureManager.Cached[tname];
                 }
                 else
                 {
                     TextureFile tf = null;
                     if (TextureManager.CachedFiles.ContainsKey(tname))
                     {
                         tf = TextureManager.CachedFiles[tname];
                     }
                     else
                     {
                         tf = new TextureFile(ArchiveManager.Get(tname + ".txd"), false);
                         TextureManager.CachedFiles.TryAdd(tname, tf);
                         TextureManager.TextureFileProcessQueue.Enqueue(tf);
                     }
                     GroupTextures = new TextureDictionary(tf);
                     TextureManager.Cached.TryAdd(tname, GroupTextures);
                 }
                 GroupTextures.UseCount++;
             }
         }
         else
         {
             // Model not found - get it
             // Модель не найдена - получаем её
             string mname = ObjectManager.Definitions[Definition.ID].ModelName;
             if (ModelManager.Cached.ContainsKey(mname))
             {
                 GroupModel = ModelManager.Cached[mname];
             }
             else
             {
                 ModelFile mf = null;
                 if (ModelManager.CachedFiles.ContainsKey(mname))
                 {
                     mf = ModelManager.CachedFiles[mname];
                 }
                 else
                 {
                     mf = new ModelFile(ArchiveManager.Get(mname + ".dff"), false);
                     ModelManager.CachedFiles.TryAdd(mname, mf);
                     ModelManager.ModelFileProcessQueue.Enqueue(mf);
                 }
                 GroupModel = new Model(mf);
                 ModelManager.Cached.TryAdd(mname, GroupModel);
             }
             GroupModel.UseCount++;
         }
     }
     else
     {
         // Cleaning all the usings
         // Очистка использований
         if (GroupModel != null)
         {
             if (!GroupModel.Important)
             {
                 GroupModel.UseCount--;
             }
             GroupModel = null;
         }
         if (GroupTextures != null)
         {
             if (!GroupTextures.Important)
             {
                 GroupTextures.UseCount--;
             }
             GroupTextures = null;
         }
         if (Renderers != null)
         {
             Renderers = null;
         }
         Ready = false;
     }
 }