示例#1
0
        public void GetPreview()
        {
            DdsFile dds;

            CSharpImageLibrary.ImageEngineImage image = null;
            try
            {
                this.Preview = null;
                dds          = new DdsFile(Texture, false);
                dds.Write(File.Open(System.AppDomain.CurrentDomain.BaseDirectory + "\\temp.dds", FileMode.Create, FileAccess.ReadWrite, FileShare.Read), -1);
                int maxDimension = (int)Math.Max(dds.header.width, dds.header.height);

                image        = new CSharpImageLibrary.ImageEngineImage(System.AppDomain.CurrentDomain.BaseDirectory + "\\temp.dds", maxDimension);
                Preview      = null;
                this.Preview = image.GetWPFBitmap(maxDimension, true);

                this.PreviewErrorVisibility = Visibility.Collapsed;
                OnPropertyChanged(nameof(Width));
                OnPropertyChanged(nameof(Height));
                OnPropertyChanged(nameof(TextureInfo));
            }
            catch (Exception ex)
            {
                Preview                     = null;
                this.PreviewError           = "Could not create preview! Export/Import may still work in certain circumstances." + Environment.NewLine + Environment.NewLine + ex.Message;
                this.PreviewErrorVisibility = Visibility.Visible;
            }
            finally
            {
                dds = null;
                image?.Dispose();
                image = null;
            }
        }
示例#2
0
        public void GetPreview()
        {
            DdsFile dds;

            CSharpImageLibrary.ImageEngineImage image = null;
            try
            {
                this.Preview = null;
                dds          = ExportDDS(System.AppDomain.CurrentDomain.BaseDirectory + "\\temp.dds", true, false);
                int maxDimension = (int)Math.Max(dds.header.width, dds.header.height);
                Width  = (int)dds.header.width;
                Height = (int)dds.header.height;

                image        = new CSharpImageLibrary.ImageEngineImage(System.AppDomain.CurrentDomain.BaseDirectory + "\\temp.dds", maxDimension);
                Preview      = null;
                this.Preview = image.GetWPFBitmap(maxDimension, true);

                this.PreviewErrorVisibility = Visibility.Collapsed;
            }
            catch (Exception ex) when(!Debugger.IsAttached)
            {
                Preview                     = null;
                this.PreviewError           = "Could not create preview! Export/Import may still work in certain circumstances." + Environment.NewLine + Environment.NewLine + ex.Message;
                this.PreviewErrorVisibility = Visibility.Visible;
            }
            finally
            {
                dds = null;
                image?.Dispose();
                image = null;
            }
        }
示例#3
0
        private static Dictionary <string, BaseMaterial> LoadMtl(string file)
        {
            Dictionary <string, BaseMaterial> materials = new Dictionary <string, BaseMaterial>();
            string       currentName = "";
            BaseMaterial currentMat  = new SolidMaterial();

            foreach (var s in File.ReadAllLines(file))
            {
                if (String.IsNullOrEmpty(s))
                {
                    continue;
                }
                var    lines = Regex.Split(s, @"\s").Where(l => !String.IsNullOrEmpty(l)).ToList();
                string flag  = lines[0];

                if (flag == "newmtl")
                {
                    materials.Add(currentName, currentMat);
                    currentName = Regex.Replace(s, @"\s*newmtl\s*(.*\S)\s*$", "$1");
                    currentMat  = new SolidMaterial();
                }
                else
                if (flag == "map_Kd")
                {
                    var imageName = Regex.Replace(s, @"\s*map_Kd\s*(.*\S)\s*$", "$1");
                    var img       = new CSharpImageLibrary.ImageEngineImage(imageName);
                    currentMat = new TextureMaterial(img);
                }
                else
                if (flag == "Kd")
                {
                    currentMat = new SolidMaterial(Color.FromArgb(0,
                                                                  (int)(double.Parse(lines[1]) * 255),
                                                                  (int)(double.Parse(lines[2]) * 255),
                                                                  (int)(double.Parse(lines[3]) * 255)));
                }
            }
            materials.Add(currentName, currentMat);
            return(materials);
        }
 public TextureMaterial(CSharpImageLibrary.ImageEngineImage bitmap)
 {
     texture = bitmap.MipMaps[0];
     step    = (texture.Pixels.Length) / (texture.Width * texture.Height);
 }