public static void ExtractAllFiles(string ParentPath, TreeNodeCollection Nodes)
        {
            FolderSelectDialog folderDialog = new FolderSelectDialog();

            if (folderDialog.ShowDialog() == DialogResult.OK)
            {
                STProgressBar progressBar = new STProgressBar();
                progressBar.Task = "Extracing Files...";
                progressBar.Refresh();
                progressBar.Value         = 0;
                progressBar.StartPosition = FormStartPosition.CenterScreen;
                progressBar.Show();

                var Collection = TreeViewExtensions.Collect(Nodes);

                int Curfile = 0;
                foreach (TreeNode file in Collection)
                {
                    if (file is ArchiveFileWrapper)
                    {
                        string FilePath      = ((ArchiveFileWrapper)file).ArchiveFileInfo.FileName;
                        string FolderPath    = Path.GetDirectoryName(FilePath.RemoveIllegaleFolderNameCharacters());
                        string FolderPathDir = Path.Combine(folderDialog.SelectedPath, FolderPath);

                        if (!Directory.Exists(FolderPathDir))
                        {
                            Directory.CreateDirectory(FolderPathDir);
                        }

                        string FileName = file.Text.RemoveIllegaleFileNameCharacters();

                        FilePath = Path.Combine(FolderPath, FileName);

                        if (ParentPath != string.Empty)
                        {
                            FilePath = FilePath.Replace(ParentPath, string.Empty);
                        }

                        var path = Path.Combine(folderDialog.SelectedPath, FilePath);

                        progressBar.Task  = $"Extracting File {file}";
                        progressBar.Value = (Curfile++ *100) / Collection.Count();
                        progressBar.Refresh();
                        CreateDirectoryIfExists($"{path}");

                        if (file is ArchiveFileWrapper)
                        {
                            File.WriteAllBytes($"{path}",
                                               ((ArchiveFileWrapper)file).ArchiveFileInfo.FileData);
                        }
                    }
                }

                progressBar.Value = 100;
                progressBar.Refresh();
                progressBar.Close();
            }
        }
        public void SaveBitMap(string FileName, int SurfaceLevel = 0, int MipLevel = 0)
        {
            STProgressBar progressBar = new STProgressBar();

            progressBar.Task          = "Exporting Image Data...";
            progressBar.Value         = 0;
            progressBar.StartPosition = FormStartPosition.CenterScreen;
            progressBar.Show();
            progressBar.Refresh();

            if (ArrayCount > 1)
            {
                progressBar.Task = "Select dialog option... ";

                var result = MessageBox.Show("Multiple image surfaces found! Would you like to export them all?", "Image Exporter",
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    string ext = Path.GetExtension(FileName);

                    int    index = FileName.LastIndexOf('.');
                    string name  = index == -1 ? FileName : FileName.Substring(0, index);

                    for (int i = 0; i < ArrayCount; i++)
                    {
                        progressBar.Task  = $"Decoding Surface [{i}] for image {Text}... ";
                        progressBar.Value = (i * 100) / (int)ArrayCount;
                        progressBar.Refresh();

                        Bitmap arrayBitMap = GetBitmap(i, 0);
                        arrayBitMap.Save($"{name}_Slice_{i}_{ext}");
                        arrayBitMap.Dispose();
                    }

                    progressBar.Value = 100;
                    progressBar.Close();

                    return;
                }
            }

            progressBar.Task  = $"Decoding image {Text}... ";
            progressBar.Value = 20;
            progressBar.Refresh();

            Bitmap bitMap = GetBitmap(SurfaceLevel, MipLevel);

            bitMap.Save(FileName);
            bitMap.Dispose();

            progressBar.Value = 100;
            progressBar.Close();
        }
Example #3
0
        public void SaveFromModel(STGenericModel model, string FileName, List <STGenericTexture> Textures, STSkeleton skeleton = null, List <int> NodeArray = null)
        {
            ExtractedTextures.Clear();

            Scene scene = new Scene();

            scene.RootNode = new Node("RootNode");

            progressBar               = new STProgressBar();
            progressBar.Task          = "Exorting Skeleton...";
            progressBar.Value         = 0;
            progressBar.StartPosition = FormStartPosition.CenterScreen;
            progressBar.Show();
            progressBar.Refresh();

            SaveSkeleton(skeleton, scene.RootNode);
            SaveMaterials(scene, model, FileName, Textures);

            progressBar.Task  = "Exorting Meshes...";
            progressBar.Value = 50;

            SaveMeshes(scene, model, skeleton, FileName, NodeArray);

            progressBar.Task  = "Saving File...";
            progressBar.Value = 80;

            SaveScene(FileName, scene, model.GetObjects());

            progressBar.Value = 100;
            progressBar.Close();
            progressBar.Dispose();
        }
Example #4
0
        private void SaveMaterials(Scene scene, STGenericModel model, string FileName, List <STGenericTexture> Textures)
        {
            string TextureExtension = ".png";
            string TexturePath      = System.IO.Path.GetDirectoryName(FileName);

            for (int i = 0; i < Textures.Count; i++)
            {
                string path = System.IO.Path.Combine(TexturePath, Textures[i].Text + TextureExtension);

                if (!ExtractedTextures.Contains(path))
                {
                    ExtractedTextures.Add(path);

                    progressBar.Task  = $"Exorting Texture {Textures[i].Text}";
                    progressBar.Value = ((i * 100) / Textures.Count);
                    progressBar.Refresh();

                    var bitmap = Textures[i].GetBitmap();
                    bitmap.Save(path);
                    bitmap.Dispose();

                    GC.Collect();
                }
            }

            foreach (var mat in model.Nodes[1].Nodes)
            {
                var genericMat = (STGenericMaterial)mat;

                Material material = new Material();
                material.Name = genericMat.Text;

                foreach (var tex in genericMat.TextureMaps)
                {
                    int index = Textures.FindIndex(r => r.Text.Equals(tex.Name));

                    string path = System.IO.Path.Combine(TexturePath, tex.Name + TextureExtension);

                    if (!File.Exists(path))
                    {
                        continue;
                    }

                    TextureSlot slot2 = new TextureSlot(path, ConvertToAssimpTextureType(tex.Type), 0, TextureMapping.FromUV,
                                                        0, 1.0f, Assimp.TextureOperation.Add, ConvertToAssimpWrapType(tex.wrapModeS), ConvertToAssimpWrapType(tex.wrapModeT), 0);

                    material.AddMaterialTexture(ref slot2);
                }
                scene.Materials.Add(material);
            }
        }