Пример #1
0
        private void UpdatePanel()
        {
            // protect against unintentional changes to settings.
            _populating = true;

            // make sure there are no group-bar items.
            this.gbPasses.GroupBarItems.Clear();

            // set all of the controls.
            if (_material == null)
            {
                // simply clear all of the controls.
                lbName.Text = "No material selected...";

                // return.
                _populating = false;
                return;
            }

            // assign values to all of the controls.
            lbName.Text = _material.Name;

            // get the error image.
            Bitmap errorImage = Program.ThumbnailMgr.GetErrorThumbnail();

            // make sure the material can be presented.
            int passCount = _material.PassCount;

            if (passCount == 0)
            {
                this.pbPreview.Image = errorImage;
                _populating          = false;
                return;
            }

            // if there isn't a diffuse texture, set the error texture.
            Bootstrap.MaterialPass pass = _material.GetPass(0);
            string diffuseTex           = "";

            if (pass.DiffuseStage != null)
            {
                diffuseTex = pass.DiffuseStage.Texture;
            }
            if (diffuseTex == null || diffuseTex == "")
            {
                this.pbPreview.Image = errorImage;
            }
            else
            {
                // try to create the thumbnail.
                Bootstrap.Image image   = new Bootstrap.Image(diffuseTex);
                Bitmap          preview = image.ToBitmap(this.pbPreview.Size.Width, this.pbPreview.Size.Height);
                if (preview != null)
                {
                    this.pbPreview.Image = preview;
                }
                else
                {
                    this.pbPreview.Image = errorImage;
                }
            }

            // setup material states.
            this.cbStipple.Checked = _material.Stipple;

            // populate pass controls.
            for (int i = 0; i < passCount; ++i)
            {
                Bootstrap.MaterialPass curPass = _material.GetPass(i);

                // create the material pass control group.
                Controls.MaterialPassControlGroup materialPassControlGroup = new Controls.MaterialPassControlGroup();
                materialPassControlGroup.SetPass(curPass);

                // create the pass item and add it to the group bar.
                GroupBarItem passItem = new GroupBarItem();
                gbPasses.GroupBarItems.Add(passItem);

                // configure the current group bar item.
                passItem.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(73)))), ((int)(((byte)(73)))), ((int)(((byte)(73)))));
                passItem.Client    = materialPassControlGroup;
                passItem.Text      = "Pass " + (i + 1).ToString();
            }

            // resize the gbPasses
            this.pnGroupBarPanel.AutoScroll = true;
            this.gbPasses.Size = new Size(this.gbPasses.Size.Width, 1100);

            _populating = false;
        }
Пример #2
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);
        }