コード例 #1
0
        /// <summary>
        /// 导出所有支持的贴图
        /// </summary>
        public void ExportTextures()
        {
            string exportDir = $"{Path.GetDirectoryName(path)}/Export_{Path.GetFileNameWithoutExtension(path)}";

            Directory.CreateDirectory(exportDir);
            exportDir += "/Textures";
            Directory.CreateDirectory(exportDir);

            foreach (var kv in chunkManager.resourceChunks)
            {
                IChunk chunk = kv.Value;
                if (chunk.name == null || chunk.resourceId == 0)
                {
                    continue;
                }

                string path = $"{exportDir}/{chunk.resourceId}_{chunk.name}";

                if (kv.Value is Chunk_CreateTexture2D)
                {
                    Chunk_CreateTexture2D texChunk = kv.Value as Chunk_CreateTexture2D;

                    D3DTextureConvert.SaveTextureToFile(texChunk, path);
                }
                else if (kv.Value is Chunk_CreateSwapBuffer)
                {
                    Chunk_CreateSwapBuffer swapChunk = kv.Value as Chunk_CreateSwapBuffer;

                    D3DTextureConvert.SaveTextureToFile(swapChunk, path);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 加载所有贴图数据并替换内存数据
        /// </summary>
        public void LoadTexturesFromFile()
        {
            string exportDir = $"{Path.GetDirectoryName(path)}/Export_{Path.GetFileNameWithoutExtension(path)}/Textures";

            if (!Directory.Exists(exportDir))
            {
                return;
            }

            string [] files = Directory.GetFiles(exportDir, "*.*", SearchOption.TopDirectoryOnly);

            Regex regex = new Regex(@"(\d+)_.*");

            foreach (string path in files)
            {
                Match match = regex.Match(Path.GetFileName(path));
                if (!match.Success)
                {
                    continue;
                }

                int    resourceId = int.Parse(match.Groups[1].Value);
                IChunk chunk      = chunkManager.GetResourceChunk((ulong)resourceId);

                if (chunk is Chunk_CreateTexture2D)
                {
                    Chunk_CreateTexture2D texChunk = chunk as Chunk_CreateTexture2D;

                    D3DTextureConvert.LoadTextureDataFromFile(texChunk, path);
                }
                else if (chunk is Chunk_CreateSwapBuffer)
                {
                    Chunk_CreateSwapBuffer swapChunk = chunk as Chunk_CreateSwapBuffer;

                    D3DTextureConvert.LoadTextureDataFromFile(swapChunk, path);
                }
            }
        }