Example #1
0
        private void btnLoadPartern_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd    = new FolderBrowserDialog();
            DialogResult        result = fbd.ShowDialog();

            if (!string.IsNullOrWhiteSpace(fbd.SelectedPath))
            {
                string[] parternFolders = Directory.GetDirectories(fbd.SelectedPath);
                if (parternFolders.Length == 0)
                {
                    MessageBox.Show("Không tìm thấy mẫu nào.");
                    return;
                }

                new Thread(() =>
                {
                    StartProgressbar();

                    _parternClass.Clear();
                    dataGridView.Rows.Clear();
                    GC.Collect();

                    foreach (var parternFolderName in parternFolders)
                    {
                        var parternDirectory       = new DirectoryInfo(parternFolderName);
                        string[] fileNames         = Directory.GetFiles(parternFolderName);
                        List <TextureModel> models = new List <TextureModel>();
                        List <Bitmap> bitmaps      = new List <Bitmap>();
                        foreach (var image in fileNames)
                        {
                            try
                            {
                                Bitmap imageBitmap = new Bitmap(image);
                                if (bitmaps.Count < NB_PARTERNS)
                                {
                                    bitmaps.Add((Bitmap)imageBitmap.Clone());
                                }
                                TextureModel model = new TextureModel(imageBitmap);
                                models.Add(model);
                            }
                            catch { }
                        }

                        InvokeThreadStart(() =>
                        {
                            object[] dataRow = new object[NB_PARTERNS + 1];
                            dataRow[0]       = parternDirectory.Name;
                            for (int i = 0; i < NB_PARTERNS; i++)
                            {
                                if (bitmaps.Count <= i)
                                {
                                    dataRow[i + 1] = string.Empty;
                                }
                                else
                                {
                                    dataRow[i + 1] = bitmaps[i];
                                }
                            }
                            int id = dataGridView.Rows.Count;
                            dataGridView.Rows.Add(dataRow);
                            dataGridView.Rows[id].Height = 62;
                        });

                        var partern  = new TextureClass(models);
                        partern.Name = parternDirectory.Name;
                        _parternClass.Add(partern);
                    }
                    StopProgressbar();
                    InvokeThreadStart(() =>
                    {
                        lblResult.Text = string.Empty;
                    });
                }).Start();
            }
        }
Example #2
0
    //
    public void CreateTexture()
    {
        TextureClass textureClass = new TextureClass(scaleTexture, offsetX, offsetY);

        heightMapImage = textureClass.GenerateTexture();
    }
        public static void WriteTextureFile(string outputDirectory, string filenameNoExt, Dictionary <string, string> imageMetadataDict, string className, TextureClass textureClass)
        {
            string numberFormat = "f6";

            string instanceName  = "Texture";
            string fileExtension = ".tex";
            string texFilename   = filenameNoExt + fileExtension;

            StreamWriter outputWriter = new StreamWriter(new FileStream(outputDirectory + "\\" + texFilename, FileMode.Create));

            WriteAssetHeader("Texture", outputWriter);

            outputWriter.WriteLine("<m_ExportSettings>");
            outputWriter.WriteLine("<ePixelformat>PF_" + textureClass.PixelFormat + "</ePixelformat>");
            outputWriter.WriteLine("<eFilterType>FT_" + textureClass.MipFilter + "</eFilterType>");
            outputWriter.WriteLine("<bUseMips>" + textureClass.AllowArtistMips.ToString().ToLower() + "</bUseMips>");
            outputWriter.WriteLine("<iNumManualMips>0</iNumManualMips>");
            outputWriter.WriteLine("<bCompleteMipChain>" + textureClass.AllowArtistMips.ToString().ToLower() + "</bCompleteMipChain>");
            outputWriter.WriteLine("<fValueClampMin>" + textureClass.ExportClampMin.ToString(numberFormat, CultureInfo.InvariantCulture) + "</fValueClampMin>");
            outputWriter.WriteLine("<fValueClampMax>" + textureClass.ExportClampMax.ToString(numberFormat, CultureInfo.InvariantCulture) + "</fValueClampMax>");
            outputWriter.WriteLine("<fSupportScale>" + textureClass.MipSupportScale.ToString(numberFormat, CultureInfo.InvariantCulture) + "</fSupportScale>");
            outputWriter.WriteLine("<fGammaIn>" + textureClass.ExportGammaIn.ToString(numberFormat, CultureInfo.InvariantCulture) + "</fGammaIn>");
            outputWriter.WriteLine("<fGammaOut>" + textureClass.ExportGammaOut.ToString(numberFormat, CultureInfo.InvariantCulture) + "</fGammaOut>");
            outputWriter.WriteLine("<iSlabWidth>0</iSlabWidth>");
            outputWriter.WriteLine("<iSlabHeight>0</iSlabHeight>");
            outputWriter.WriteLine("<iColorKeyX>64</iColorKeyX>");
            outputWriter.WriteLine("<iColorKeyY>64</iColorKeyY>");
            outputWriter.WriteLine("<iColorKeyZ>64</iColorKeyZ>");
            outputWriter.WriteLine("<eExportMode>TEXTURE_2D</eExportMode>");
            outputWriter.WriteLine("<bSampleFromTopLayer>false</bSampleFromTopLayer>");
            outputWriter.WriteLine("</m_ExportSettings>");

            WriteCookParams(outputWriter, textureClass.CookParams);
            WriteVersion(outputWriter);

            outputWriter.WriteLine("<m_Height>" + imageMetadataDict["height"] + "</m_Height>");
            outputWriter.WriteLine("<m_Width>" + imageMetadataDict["width"] + "</m_Width>");
            outputWriter.WriteLine("<m_Depth>" + imageMetadataDict["depth"] + "</m_Depth>");
            outputWriter.WriteLine("<m_NumMipMaps>" + imageMetadataDict["mipLevels"] + "</m_NumMipMaps>");

            WriteSourcePathAndTimes(outputWriter);

            WriteClassName(className, outputWriter);

            outputWriter.WriteLine("<m_DataFiles>");
            outputWriter.WriteLine("<Element>");
            outputWriter.WriteLine("<m_ID text=\"DDS\"/>");
            outputWriter.WriteLine("<m_RelativePath text=\"" + filenameNoExt + ".dds\"/>");
            outputWriter.WriteLine("</Element>");
            outputWriter.WriteLine("</m_DataFiles>");

            WriteFooter(className, filenameNoExt, instanceName, outputWriter);

            outputWriter.Close();
        }