Exemplo n.º 1
0
        //-----------------------
        private void UpdateThumbnails()
        {
            // clear thumbnails.
            thumbnailSelector.Clear();

            // iterate through files in the folder.
            if (!_uberTextures)
            {
                string packageFolder    = Bootstrap.Settings.Get().GetWorkingFolder() + "\\data\\" + cbPackage.SelectedItem;
                string packageTexFolder = packageFolder + "\\textures";
                if (Directory.Exists(packageTexFolder))
                {
                    DirectoryInfo texFolder  = new DirectoryInfo(packageTexFolder);
                    FileInfo[]    imageFiles = texFolder.GetFiles(tbFilter.Text);
                    foreach (FileInfo file in imageFiles)
                    {
                        // ignore files that are not .tga or .dds files.
                        if (file.Extension != ".tga" && file.Extension != ".dds")
                        {
                            continue;
                        }

                        // get the thumbnail from the thumbnail manager.
                        Bitmap image = Program.ThumbnailMgr.GetThumbnail(file.FullName);
                        if (image != null)
                        {
                            thumbnailSelector.Add(file.Name, image);
                        }
                    }
                }
            }
            else
            {
                // get the list of ubertextures available to the current scene.
                string        relativePath = "\\data\\" + cbPackage.SelectedItem + "\\uber\\";
                List <string> textureNames = Bootstrap.UberTexture.GetUberTextureList(relativePath);
                foreach (string textureName in textureNames)
                {
                    // get the ubertexture and generate a thumbnail.
                    string texturePath = relativePath + textureName;
                    using (Bootstrap.UberTexture uberTexture = new Bootstrap.UberTexture(texturePath))
                    {
                        // generate a thumbnail and add it to the thumbnail selector.
                        Bitmap thumbnail = uberTexture.MakeThumbnail();
                        if (thumbnail != null)
                        {
                            thumbnailSelector.Add(textureName, thumbnail);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        void Populate()
        {
            NeedPopulate = false;

            // clear the current thumbnails.
            thumbnailSelector.Clear();

            // populate the thumbnail control.
            string[] materialNames = Bootstrap.Material.GetLoadedMaterialNames();

            // iterate through each material and create an icon.
            foreach (string materialName in materialNames)
            {
                // create a new material for the item.
                Bootstrap.Material material = new Bootstrap.Material(materialName);

                // try to get a decent thumbnail for the material.
                Bitmap bitmap = null;
                if (material.PassCount > 0)
                {
                    Bootstrap.MaterialPass pass = material.GetPass(0);
                    string textureName          = pass.DiffuseStage.Texture;
                    if (textureName != null && textureName != "")
                    {
                        bitmap = Program.ThumbnailMgr.GetThumbnail(textureName);
                    }
                    else
                    {
                        string uberTextureName = pass.UberTexture;
                        if (uberTextureName != null && uberTextureName != "")
                        {
                            using (Bootstrap.UberTexture uberTexture = new Bootstrap.UberTexture(uberTextureName))
                            {
                                bitmap = uberTexture.MakeThumbnail();
                            }
                        }
                    }
                }

                // set the bitmap to the error bitmap if no usable preview could
                // be found.
                if (bitmap == null)
                {
                    bitmap = Program.ThumbnailMgr.GetErrorThumbnail();
                }

                // add a new thumbnail and dispose the material.
                thumbnailSelector.Add(material.ShortName, bitmap, materialName);
                material.Dispose();
            }
        }
Exemplo n.º 3
0
        private void bnCreate_Click(object sender, EventArgs e)
        {
            // show the ubertexture creation dialog.
            UberTextureCreationDialog dialog = new UberTextureCreationDialog();
            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                // ubertexture creation.
                string relativePath = "\\data\\" + cbPackage.SelectedItem + "\\uber\\" + dialog.tbName.Text + ".utx";
                int    width        = Convert.ToInt32(dialog.cbWidth.Text);
                int    height       = Convert.ToInt32(dialog.cbHeight.Text);
                using (Bootstrap.UberTexture texture = new Bootstrap.UberTexture(relativePath, width, height))
                {
                    UpdateThumbnails();
                }
            }
        }
Exemplo n.º 4
0
        public Bitmap GetThumbnail(string filePath)
        {
            // try to find the image.
            ThumbnailPair._FindName = filePath;
            ThumbnailPair imagePair = _thumbnails.Find(
                delegate(ThumbnailPair item) { return(item._Name.CompareTo(ThumbnailPair._FindName) == 0); }
                );

            if (imagePair != null)
            {
                return(imagePair._Image);
            }

            // make sure the current image type is supported.
            FileInfo file = new FileInfo(filePath);
            string   ext  = file.Extension.ToLower();

            if (ext != ".tga" && ext != ".dds" && ext != ".utx")
            {
                return(null);
            }

            // check to see if we have an ubertexture.
            Bitmap bmpThumbnail = null;

            if (ext == ".utx")
            {
                Bootstrap.UberTexture uberTexture = new Bootstrap.UberTexture(filePath);
                if (uberTexture.Valid)
                {
                    // make a bitmap.
                    bmpThumbnail = uberTexture.MakeThumbnail();
                }
            }
            else
            {
                // load the current file and generate a thumbnail.
                Bootstrap.Image thumbnail = null;
                using (Bootstrap.Image image = new Bootstrap.Image(filePath))
                {
                    if (!image.IsValid())
                    {
                        return(null);
                    }

                    // add the thumbnail to the selection dialog.
                    thumbnail = image.BuildThumbnail(64);
                }

                // convert the image to a thumbnail.
                bmpThumbnail = thumbnail.ToBitmap(-1, -1);
            }

            // make sure we store the thumbnail.
            ThumbnailPair pair = new ThumbnailPair(filePath, bmpThumbnail);

            _thumbnails.Add(pair);

            // remove the oldest thumbnails if we have too many thumbnails.
            if (_thumbnails.Count > 1024)
            {
                _thumbnails[0]._Image.Dispose();
                _thumbnails.RemoveAt(0);
            }

            // return the thumbnail.
            return(bmpThumbnail);
        }