Esempio n. 1
0
        public ChooserBlock(Action <T1> action1, Action <T2> action2, Action <T3> action3, DataflowBlockOptions dataflowBlockOptions)
        {
            // TODO: take care of options and its cancellation token

            Target1 = new ChooseTarget <T1> (message => MessageArrived(0, action1, message));
            Target2 = new ChooseTarget <T2> (message => MessageArrived(1, action2, message));
            Target3 = new ChooseTarget <T3> (message => MessageArrived(2, action3, message));
        }
Esempio n. 2
0
        public ChooserBlock(
            Action <T1> action1, Action <T2> action2, Action <T3> action3,
            DataflowBlockOptions dataflowBlockOptions)
        {
            Target1 = new ChooseTarget <T1> (this, 0, action1);
            Target2 = new ChooseTarget <T2> (this, 1, action2);
            if (action3 != null)
            {
                Target3 = new ChooseTarget <T3> (this, 2, action3);
            }

            if (dataflowBlockOptions.CancellationToken != CancellationToken.None)
            {
                dataflowBlockOptions.CancellationToken.Register(Cancelled);
            }
        }
        private void SetupForModel(AssetRenderWareModel asset)
        {
            AddRow();
            AddRow();
            AddRow();
            AddRow();

            Button buttonSetVertexColors = new Button()
            {
                Dock = DockStyle.Fill, Text = "Set Vertex Colors", AutoSize = true
            };

            buttonSetVertexColors.Click += (object sender, EventArgs e) =>
            {
                var(color, operation) = ApplyVertexColors.GetColor();

                if (color.HasValue)
                {
                    asset.SetVertexColors(color.Value, operation);
                    archive.UnsavedChanges = true;
                }
            };
            buttonSetVertexColors.Enabled = !asset.IsNativeData;
            tableLayoutPanel1.Controls.Add(buttonSetVertexColors, 0, 2);

            CheckBox ignoreMeshColors = new CheckBox()
            {
                Dock = DockStyle.Fill, Text = "Ignore Mesh Colors", AutoSize = true
            };

            ignoreMeshColors.Checked = true;
            tableLayoutPanel1.Controls.Add(ignoreMeshColors, 0, 3);
            CheckBox flipUVs = new CheckBox()
            {
                Dock = DockStyle.Fill, Text = "Flip UVs", AutoSize = true
            };

            tableLayoutPanel1.Controls.Add(flipUVs, 0, 4);

            Button buttonImport = new Button()
            {
                Dock = DockStyle.Fill, Text = "Import", AutoSize = true
            };

            buttonImport.Click += (object sender, EventArgs e) =>
            {
                OpenFileDialog openFile = new OpenFileDialog()
                {
                    Filter = GetImportFilter(), // "All supported types|*.dae;*.obj;*.bsp|DAE Files|*.dae|OBJ Files|*.obj|BSP Files|*.bsp|All files|*.*",
                };

                if (openFile.ShowDialog() == DialogResult.OK)
                {
                    if (asset.AHDR.assetType == HipHopFile.AssetType.MODL)
                    {
                        asset.Data = Path.GetExtension(openFile.FileName).ToLower().Equals(".dff") ?
                                     File.ReadAllBytes(openFile.FileName) :
                                     ReadFileMethods.ExportRenderWareFile(CreateDFFFromAssimp(openFile.FileName, flipUVs.Checked, ignoreMeshColors.Checked), modelRenderWareVersion(asset.game));
                    }

                    if (asset.AHDR.assetType == HipHopFile.AssetType.BSP)
                    {
                        asset.Data = Path.GetExtension(openFile.FileName).ToLower().Equals(".bsp") ?
                                     File.ReadAllBytes(openFile.FileName) :
                                     ReadFileMethods.ExportRenderWareFile(CreateBSPFromAssimp(openFile.FileName, flipUVs.Checked, ignoreMeshColors.Checked), modelRenderWareVersion(asset.game));
                    }

                    asset.Setup(Program.MainForm.renderer);

                    archive.UnsavedChanges = true;
                }
            };
            tableLayoutPanel1.Controls.Add(buttonImport, 0, 5);

            CheckBox exportTextures = new CheckBox()
            {
                Dock = DockStyle.Fill, Text = "Export Textures", AutoSize = true
            };

            tableLayoutPanel1.Controls.Add(exportTextures, 1, 4);

            Button buttonExport = new Button()
            {
                Dock = DockStyle.Fill, Text = "Export", AutoSize = true
            };

            buttonExport.Click += (object sender, EventArgs e) =>
            {
                (Assimp.ExportFormatDescription format, string textureExtension) = ChooseTarget.GetTarget();

                if (format != null)
                {
                    SaveFileDialog a = new SaveFileDialog()
                    {
                        Filter = format == null ? "RenderWare BSP|*.bsp" : format.Description + "|*." + format.FileExtension,
                    };

                    if (a.ShowDialog() == DialogResult.OK)
                    {
                        if (format == null)
                        {
                            File.WriteAllBytes(a.FileName, asset.Data);
                        }
                        else if (format.FileExtension.ToLower().Equals("obj") && asset.AHDR.assetType == HipHopFile.AssetType.BSP)
                        {
                            ConvertBSPtoOBJ(a.FileName, ReadFileMethods.ReadRenderWareFile(asset.Data), true);
                        }
                        else
                        {
                            ExportAssimp(Path.ChangeExtension(a.FileName, format.FileExtension), ReadFileMethods.ReadRenderWareFile(asset.Data), true, format, textureExtension, Matrix.Identity);
                        }

                        if (exportTextures.Checked)
                        {
                            string folderName = Path.GetDirectoryName(a.FileName);
                            var    bitmaps    = archive.GetTexturesAsBitmaps(asset.Textures);
                            ReadFileMethods.treatStuffAsByteArray = false;
                            foreach (string textureName in bitmaps.Keys)
                            {
                                bitmaps[textureName].Save(folderName + "/" + textureName + ".png", System.Drawing.Imaging.ImageFormat.Png);
                            }
                        }
                    }
                }
            };

            tableLayoutPanel1.Controls.Add(buttonExport, 1, 5);
        }