Example #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);
                }
            }
        }
Example #2
0
        /// <summary>
        /// 从图像文件加载贴图数据到Chunk, 要求图像尺寸与Chunk定义的完全一致
        /// </summary>
        /// <param name="texChunk"></param>
        /// <param name="path"></param>
        public static void LoadTextureDataFromFile(Chunk_CreateTexture2D texChunk, string path)
        {
            D3D11_SUBRESOURCE_DATA[] subDatas = texChunk.pInitialDatas;
            if (subDatas == null)
            {
                Chunk_InitialContents initialChunk = texChunk.chunkManager.GetInitialContentsChunk(texChunk.resourceId);
                if (initialChunk != null)
                {
                    subDatas = initialChunk.subDatas;
                }
            }

            if (subDatas == null)
            {
                Console.WriteLine($"can not find Texture Data of {texChunk}");
                return;
            }

            LoadTextureDataFromFile(subDatas, texChunk.Descriptor, texChunk.chunkManager.section, path);
        }
Example #3
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);
                }
            }
        }