private void m_btnOK_Click(object sender, EventArgs e)
        {
            string error = ValidateData();
            if (string.IsNullOrWhiteSpace(error))
            {
                // create mask map.
                ImageData maskImg = new ImageData();
                maskImg.InitNew(MaskWidth, MaskHeight, ImageDataFORMAT.R8_UNORM);
                if (m_importedMask != null)
                {
                    for (int y = 0; y < maskImg.Height; y++)
                    {
                        for (int x = 0; x < maskImg.Width; x++)
                        {
                            byte src = m_importedMask.GetPixelByte(x, y);
                            maskImg.SetPixel(x, y, src);
                        }
                    }

                    m_importedMask.Dispose();
                    m_importedMask = null;
                }
                maskImg.Save(new Uri(m_maskTxt.Text));
                maskImg.Dispose();
            }
            else
            {
                error = "Error: " + Environment.NewLine + error;
                MessageBox.Show(this, error, "Create Terrain", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            
            DialogResult = System.Windows.Forms.DialogResult.OK;

        }
Example #2
0
        /// <summary>
        /// Computes brush bound in imgdata space.</summary>        
        protected void ComputeBound(ImageData imgData,
                    int x,
                    int y,                    
                    out Bound2di outRect)
        {
            outRect.x1 = 0;
            outRect.x2 = 0;
            outRect.y1 = 0;
            outRect.y2 = 0;

            bool valid = imgData != null && imgData.IsValid;
            System.Diagnostics.Debug.Assert(valid);
            if (!valid) return;


            Bound2di kernelRect;

            kernelRect.x1 = x - Radius;
            kernelRect.y1 = y - Radius;
            kernelRect.x2 = x + Radius + 1;
            kernelRect.y2 = y + Radius + 1;

            Bound2di destRect;
            destRect.x1 = 0;
            destRect.y1 = 0;
            destRect.x2 = imgData.Width;
            destRect.y2 = imgData.Height;
            Bound2di.Intersect(kernelRect, destRect, out outRect);
        }         
        private void m_import_Click(object sender, EventArgs e)
        {
            using (var dlg = new OpenFileDialog())
            {
                dlg.Filter = "Mask (*.png; *.dds; *.bmp; *.tga; *.tif)|*.png;*.dds;*.bmp;*.tga;*.tif";
                dlg.CheckFileExists = true;
                dlg.InitialDirectory = ResourceRoot;
                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string filename = dlg.FileName;
                    string error = string.Empty;
                    m_importedMask = new ImageData();
                    m_importedMask.LoadFromFile(new Uri(filename));
                    m_importedMask.Convert(ImageDataFORMAT.R8_UNORM);
                    if (m_importedMask.IsValid)
                    {
                        m_widthTxt.Text = m_importedMask.Width.ToString();
                        m_heightTxt.Text = m_importedMask.Height.ToString();                        
                    }
                    else
                    {
                        m_importedMask.Dispose();
                        m_importedMask = null;
                        error = "unsupported file type ";
                    }

                    if (!string.IsNullOrEmpty(error))
                    {
                        MessageBox.Show(this, error, "Error importing heightmap", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }                    
                }
            }
        }
        Image IThumbnailResolver.Resolve(Uri resourceUri)
        {
            Image img = null;
            string path = resourceUri.LocalPath;
            if (path == null || !File.Exists(path))
                return null;

            string extension = Path.GetExtension(path).ToLower();
            var res = m_gameEngine.Info.ResourceInfos.GetByType(ResourceTypes.Texture);

            if(res.IsSupported(extension))
            {
                ImageData imgdata = new ImageData();
                imgdata.LoadFromFile(resourceUri);                
                imgdata.Convert(ImageDataFORMAT.B8G8R8A8_UNORM);                
                if (imgdata.IsValid)
                {
                    Bitmap tempImage = new Bitmap((int)imgdata.Width, (int)imgdata.Height, PixelFormat.Format32bppArgb);
                    BitmapData destData = null;

                    try
                    {
                        destData = tempImage.LockBits(
                            new Rectangle(0, 0, tempImage.Width, tempImage.Height),
                            ImageLockMode.WriteOnly,
                            tempImage.PixelFormat);

                        unsafe
                        {
                            byte* srcScan0 = (byte*)imgdata.Data;
                            int srcStride = imgdata.RowPitch;

                            byte* destScan0 = (byte*)destData.Scan0;
                            int destStride = destData.Stride;

                            for (int y = 0; y < tempImage.Height; y++)
                            {
                                uint* srcRow = (uint*)(srcScan0 + y * srcStride);
                                uint* destRow = (uint*)(destScan0 + y * destStride);
                                for (int x = 0; x < tempImage.Width; x++)
                                {
                                    *destRow++ = *srcRow++;
                                    
                                }
                            }

                        }
                    }
                    finally
                    {
                        tempImage.UnlockBits(destData);
                    }

                    int width, height;
                    float aspect = (float)tempImage.Width / (float)tempImage.Height;
                    if (aspect > 1.0f)
                    {
                        width = (int)ThumbnailSize;
                        height = (int)Math.Round(ThumbnailSize / aspect);
                    }
                    else
                    {
                        height = (int)ThumbnailSize;
                        width = (int)Math.Round(ThumbnailSize * aspect);
                    }
                    img = GdiUtil.ResizeImage(tempImage, width, height);
                    tempImage.Dispose();
                    imgdata.Dispose();

                }

            }           
            return img;
        }
Example #5
0
        private void m_import_Click(object sender, EventArgs e)
        {
            using (var dlg = new OpenFileDialog())
            {
                dlg.Filter = "HeightMap (*.png; *.dds; *.bmp; *.tga; *.tif)|*.png;*.dds;*.bmp;*.tga;*.tif";
                dlg.CheckFileExists = true;
                dlg.InitialDirectory = ResourceRoot;
                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string filename = dlg.FileName;
                    string error = string.Empty;

                    if(m_importedHeightMap != null) 
                        m_importedHeightMap.Dispose();

                    m_importedHeightMap = new ImageData();
                    m_importedHeightMap.LoadFromFile(new Uri(filename));
                    m_importedHeightMap.Convert(ImageDataFORMAT.R32_FLOAT);
                    if (m_importedHeightMap.IsValid)
                    {
                       // set rows and cols.
                        foreach(int c in m_hmapColsCmbox.Items)
                        {
                            if (c >= m_importedHeightMap.Width)
                            {
                                m_hmapColsCmbox.SelectedItem = c;
                                break;
                            }
                        }

                        foreach(int r in m_hmapRowsCmbox.Items)
                        {
                            if (r >= m_importedHeightMap.Height)
                            {
                                m_hmapRowsCmbox.SelectedItem = r;
                                break;
                            }
                        }                        
                    }
                    else
                    {
                        m_importedHeightMap.Dispose();
                        m_importedHeightMap = null;
                        error = "unsupported file type ";
                    }
                        
                    if (!string.IsNullOrEmpty(error))
                    {
                        MessageBox.Show(this, error, "Error importing heightmap", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }                    
                }
            }
        }
Example #6
0
        private void OKbtnClick(object sender, EventArgs e)
        {
            string error = ValidateData();
            if (string.IsNullOrEmpty(error))
            {
                ImageData hmImg = new ImageData();
                hmImg.InitNew(HmapCols, HmapRows, ImageDataFORMAT.R32_FLOAT);
                if (m_importedHeightMap != null)
                {
                    float scalehm = ScaleImportedHeightmap;
                    if (m_importedHeightMap != null)
                    {
                        // apply imported heightmap.
                        for (int y = 0; y < hmImg.Height; y++)
                        {
                            for (int x = 0; x < hmImg.Width; x++)
                            {
                                float val = m_importedHeightMap.GetPixelFloat(x, y) * scalehm;
                                hmImg.SetPixel(x, y, val);
                            }
                        }
                    }
                }
                hmImg.Save(new Uri(HeightMapPath));
                hmImg.Dispose();

            }
            else
            {
                error = "Error: " + Environment.NewLine + error;
                MessageBox.Show(this, error, "Create Terrain", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;
        }