コード例 #1
0
ファイル: FSHP.cs プロジェクト: cano159/Switch-Toolbox
        private void CopyUVChannelAction(object sender, EventArgs args)
        {
            if (!vertexAttributes.Any(x => x.Name == "_u0"))
            {
                return;
            }

            if (!vertexAttributes.Any(x => x.Name == "_u1"))
            {
                DialogResult dialogResult = MessageBox.Show("This model has no second uv channel to copy to. Create one?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    VertexAttribute att = new VertexAttribute();
                    att.Name   = "_u1";
                    att.Format = ResGFX.AttribFormat.Format_16_16_Single;
                    vertexAttributes.Add(att);
                }
            }

            if (GetUVAttributes().Count > 1)
            {
                CopyUVChannelDialog dialog = new CopyUVChannelDialog();
                dialog.LoadUVAttributes();
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    CopyUVChannel(dialog.SourceIndex, dialog.DestIndex);
                    SaveVertexBuffer();
                    UpdateVertexData();
                    Cursor.Current = Cursors.Default;
                }
            }
            else
            {
                throw new Exception("Only one UV found. No destination UV can be applied");
            }
        }
コード例 #2
0
        public void CopyUVChannels()
        {
            CopyUVChannelDialog dialog = new CopyUVChannelDialog();

            dialog.LoadUVAttributes();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                int dest   = dialog.DestIndex;
                int source = dialog.SourceIndex;

                bool CanCreateUV = false;
                bool HasDestUV   = false;
                bool ShownDialog = false;

                foreach (var shape in shapes)
                {
                    //If no source, there's nothing to copy from
                    if (!shape.vertexAttributes.Any(x => x.Name == $"_u{source}"))
                    {
                        continue;
                    }

                    if ((!shape.vertexAttributes.Any(x => x.Name == $"_u{dest}")))
                    {
                        //Only show the dialog once for creating UV channels
                        if (!CanCreateUV && !ShownDialog)
                        {
                            DialogResult dialogResult = MessageBox.Show($"Some of the objects are missing the destenation uv channel ({dest}) to copy to. Create one?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dialogResult == DialogResult.Yes)
                            {
                                CanCreateUV = true;
                                ShownDialog = true;
                            }
                        }

                        if (CanCreateUV)
                        {
                            FSHP.VertexAttribute att = new FSHP.VertexAttribute();
                            att.Name   = $"_u{dest}";
                            att.Format = ResGFX.AttribFormat.Format_16_16_Single;
                            shape.vertexAttributes.Add(att);

                            HasDestUV = true;
                        }
                    }
                    else
                    {
                        HasDestUV = true;
                    }

                    if (HasDestUV)
                    {
                        Cursor.Current = Cursors.WaitCursor;
                        shape.CopyUVChannel(dialog.SourceIndex, dialog.DestIndex);
                        shape.SaveVertexBuffer();
                        UpdateVertexData();
                        Cursor.Current = Cursors.Default;
                    }

                    shape.CopyUVChannel(dialog.SourceIndex, dialog.DestIndex);
                    shape.SaveVertexBuffer();
                }
            }

            UpdateVertexData();
        }