public void LoadMaterial(BFRES.Mesh p)
        {
            listView1.Items.Clear();
            dataGridView3.Rows.Clear();
            dataGridView4.Rows.Clear();

            textureImageList.ColorDepth = ColorDepth.Depth32Bit;
            textureImageList.ImageSize  = new Size(64, 64);

            poly = p;
            mat  = p.material;

            FillForm();

            textBox1.Text            = mat.Name;
            ShaderArchivelabel1.Text = $"Shader Archive {mat.shaderassign.ShaderArchive}";
            ShaderMdllabel2.Text     = $"Shader Model {mat.shaderassign.ShaderModel}";

            paramColorList.ImageSize = new Size(10, 10);
            listView1.SmallImageList = paramColorList;
            listView1.FullRowSelect  = true;

            TextureRefListView.SmallImageList = textureImageList;
            TextureRefListView.FullRowSelect  = true;
        }
        private void RenderTexture(BFRES.Mesh m = null, BRTI tex = null, FTEX ftex = null)
        {
            Texture     = tex;
            FTEXTexture = ftex;
            mesh        = m;
            mat         = mesh.material;

            foreach (BFRES.MatTexture te in mat.textures)
            {
                if (tex != null)
                {
                    if (te.Name == tex.Text)
                    {
                        Mattex = te;
                        comboBox1.SelectedIndex = te.wrapModeS;
                        comboBox2.SelectedIndex = te.wrapModeT;
                    }
                }
                if (ftex != null)
                {
                    if (te.Name == ftex.Text)
                    {
                        Mattex = te;
                        comboBox1.SelectedIndex = te.wrapModeS;
                        comboBox2.SelectedIndex = te.wrapModeT;
                    }
                }
            }
        }
        public void SetMeshBoneList(BFRES.FMDL_Model mdl, BFRES.Mesh m, bool sb = false)
        {
            listView1.Items.Clear();

            //This list is used for both viewing and also single binding for certain instances
            isSingleBinding = sb;
            msh             = m;
            fmdl            = mdl;

            foreach (var bn in m.BoneIndexList)
            {
                listView1.Items.Add(bn.Value.ToString()).SubItems.Add(bn.Key);
            }
        }
        public static void DrawUVs(BFRES.Mesh p)
        {
            List <int> f = p.lodMeshes[p.DisplayLODIndex].getDisplayFace();

            GL.Disable(EnableCap.Texture2D);

            float ScaleX = 1;
            float ScaleY = 1;

            if (width > height)
            {
                ScaleX = width / height;
            }
            if (height > width)
            {
                ScaleY = height / width;
            }


            GL.Scale(ScaleX, ScaleY, 1);
            int divisionsX = (int)ScaleY * 4;
            int divisionsY = (int)ScaleX * 4;

            for (int i = 0; i < p.lodMeshes[p.DisplayLODIndex].displayFaceSize; i += 3)
            {
                BFRES.Vertex v1 = p.vertices[f[i]];
                BFRES.Vertex v2 = p.vertices[f[i + 1]];
                BFRES.Vertex v3 = p.vertices[f[i + 2]];

                if (Runtime.uvChannel == Runtime.UVChannel.Channel1)
                {
                    BFRES_DrawUVTriangleAndGrid(v1.uv0, v2.uv0, v3.uv0, divisionsX, divisionsY, Color.Red, 1, Color.White, p.material);
                }
                else if (Runtime.uvChannel == Runtime.UVChannel.Channel2)
                {
                    BFRES_DrawUVTriangleAndGrid(v1.uv1, v2.uv1, v3.uv1, divisionsX, divisionsY, Color.Red, 1, Color.White, p.material);
                }
                else if (Runtime.uvChannel == Runtime.UVChannel.Channel3)
                {
                    BFRES_DrawUVTriangleAndGrid(v1.uv2, v2.uv2, v3.uv2, divisionsX, divisionsY, Color.Red, 1, Color.White, p.material);
                }
            }
        }
Exemple #5
0
        private void RenderTexture(BFRES.Mesh m, Texture texture, string TexName)
        {
            Texture = texture;
            mesh    = m;
            mat     = mesh.material;

            foreach (BFRES.MatTexture te in mat.textures)
            {
                if (Texture != null)
                {
                    if (te.Name == TexName)
                    {
                        Mattex = te;
                        comboBox1.SelectedIndex = te.wrapModeS;
                        comboBox2.SelectedIndex = te.wrapModeT;
                    }
                }
            }
        }
        public BfresMeshEditor(BFRES.Mesh p, BFRES.FMDL_Model mdl, BFRES b)
        {
            InitializeComponent();

            button1.Enabled      = false;
            textBox1.Text        = p.Text;
            VertCountlabel1.Text = VertCountlabel1.Text + " " + p.vertices.Count.ToString();
            PolyCountlabel3.Text = PolyCountlabel3.Text + " " + p.lodMeshes[p.DisplayLODIndex].displayFaceSize.ToString();
            skinCountLabel.Text  = skinCountLabel.Text + " " + p.VertexSkinCount.ToString();
            label3.Text          = label3.Text + " " + mdl.skeleton.bones[p.boneIndx].ToString();

            Mesh  = p;
            Model = mdl;
            bfres = b;


            foreach (var lod in p.lodMeshes)
            {
                LODcomboBox3.Items.Add(lod);
            }
            LODcomboBox3.SelectedIndex = p.DisplayLODIndex;

            List <string> attributes = new List <string>();

            foreach (Syroot.NintenTools.NSW.Bfres.GFX.AttribFormat attr in Enum.GetValues(typeof(Syroot.NintenTools.NSW.Bfres.GFX.AttribFormat)))
            {
                attributes.Add(attr.ToString());
            }
            attributes.Sort();
            foreach (string att in attributes)
            {
                comboBox2.Items.Add(att);
            }


            int Height = 2;

            foreach (BFRES.Mesh.VertexAttribute att in p.vertexAttributes)
            {
                comboBox1.Items.Add(att);
            }
        }
 public void LoadTexture(BFRES.Mesh m = null, BRTI tex = null, FTEX ftex = null)
 {
     RenderTexture(m, tex, ftex);
 }
Exemple #8
0
 public void LoadTexture(BFRES.Mesh m, Texture texture, string TexName)
 {
     //Todo go back and redo this editor
     //  RenderTexture(m, texture, TexName);
 }
Exemple #9
0
        public void LoadMaterial(BFRES.Mesh p)
        {
            listView1.Items.Clear();
            dataGridView3.Rows.Clear();
            dataGridView4.Rows.Clear();
            tabTextureMaps.Controls.Clear();
            TexPanelHeight = 31;

            poly = p;

            Console.WriteLine("Material Editor");
            Console.WriteLine(p.Text);


            mat                       = p.material;
            textBox1.Text             = mat.Name;
            ShaderArchivelabel1.Text += $" {mat.shaderassign.ShaderArchive}";
            ShaderMdllabel2.Text     += $" {mat.shaderassign.ShaderModel}";

            int CurParam = 0;

            foreach (var prm in mat.matparam)
            {
                string DisplayValue = "";

                //   listBox2.Items.Add(prm);
                var item = new ListViewItem(prm.Key);

                Color SetColor = Color.White;

                if (prm.Value.Type == ShaderParamType.Float)
                {
                    DisplayValue = mat.matparam[prm.Key].Value_float.ToString();
                }
                if (prm.Value.Type == ShaderParamType.Float2)
                {
                    DisplayValue = mat.matparam[prm.Key].Value_float2.ToString();
                }
                if (prm.Value.Type == ShaderParamType.Float3)
                {
                    DisplayValue = mat.matparam[prm.Key].Value_float3.ToString();

                    bool IsColor = prm.Key.Contains("Color") || prm.Key.Contains("color");

                    if (IsColor)
                    {
                        int someIntX = (int)Math.Ceiling(mat.matparam[prm.Key].Value_float3.X * 255);
                        int someIntY = (int)Math.Ceiling(mat.matparam[prm.Key].Value_float3.Y * 255);
                        int someIntZ = (int)Math.Ceiling(mat.matparam[prm.Key].Value_float3.Z * 255);

                        if (someIntX <= 255 && someIntY <= 255 && someIntZ <= 255)
                        {
                            Console.WriteLine($"{prm.Key} R {someIntX} G {someIntY} B {someIntZ}");

                            SetColor = Color.FromArgb(
                                255,
                                someIntX,
                                someIntY,
                                someIntZ
                                );
                        }
                    }
                }
                if (prm.Value.Type == ShaderParamType.Float4)
                {
                    DisplayValue = mat.matparam[prm.Key].Value_float4.ToString();



                    bool IsColor = prm.Key.Contains("Color") || prm.Key.Contains("color") || prm.Key.Contains("konst0");


                    if (IsColor)
                    {
                        Vector4 col = mat.matparam[prm.Key].Value_float4;

                        int someIntX = (int)Math.Ceiling(col.X);
                        int someIntY = (int)Math.Ceiling(col.Y);
                        int someIntZ = (int)Math.Ceiling(col.Z);

                        if (mat.shaderassign.ShaderArchive == "uking_mat") //BOTW uses gamma correction
                        {
                            someIntX = MathHelper.Clamp((int)((255.0 * System.Math.Pow(255.0, 1.0 / mat.matparam[prm.Key].Value_float4.X)) + 0.5), 255, 0);
                            someIntY = MathHelper.Clamp((int)((255.0 * System.Math.Pow(255.0, 1.0 / mat.matparam[prm.Key].Value_float4.Y)) + 0.5), 255, 0);
                            someIntZ = MathHelper.Clamp((int)((255.0 * System.Math.Pow(255.0, 1.0 / mat.matparam[prm.Key].Value_float4.Z)) + 0.5), 255, 0);
                        }



                        if (someIntX <= 255 && someIntY <= 255 && someIntZ <= 255)
                        {
                            Console.WriteLine($"{prm.Key} R {someIntX} G {someIntY} B {someIntZ}");

                            SetColor = Color.FromArgb(
                                255,
                                someIntX,
                                someIntY,
                                someIntZ
                                );
                        }
                    }
                }

                item.UseItemStyleForSubItems = false;
                item.SubItems.Add(DisplayValue);
                item.SubItems.Add("");
                item.SubItems[2].BackColor = SetColor;
                listView1.View             = View.Details;
                listView1.Items.Add(item);
                CurParam++;
            }
            il.ImageSize             = new Size(10, 10);
            listView1.SmallImageList = il;
            listView1.FullRowSelect  = true;

            foreach (var rnd in mat.renderinfo)
            {
                if (rnd.Type == RenderInfoType.Int32)
                {
                    dataGridView4.Rows.Add(rnd.Name, rnd.Value_Int.ToString(), "Int");
                }
                if (rnd.Type == RenderInfoType.Single)
                {
                    dataGridView4.Rows.Add(rnd.Name, rnd.Value_Float.ToString(), "Float");
                }
                if (rnd.Type == RenderInfoType.String)
                {
                    dataGridView4.Rows.Add(rnd.Name, rnd.Value_String.ToString(), "String");
                }
            }

            foreach (var op in mat.shaderassign.options)
            {
                dataGridView3.Rows.Add(op.Key, op.Value);
            }

            Panel[]  arr    = new Panel[mat.textures.Count];
            Button[] Btnarr = new Button[mat.textures.Count];
            picboxArray = new PictureBox[mat.textures.Count];

            if (BFRES.IsSwitchBFRES == true)
            {
                foreach (BRTI tex in BNTX.textures)
                {
                    foreach (var texure in mat.textures)
                    {
                        if (tex.Text == texure.Name)
                        {
                            Bitmap bmp = textureRGBA(tex.texture, tex.display);

                            SetTexturePanel(bmp, texure);
                        }
                    }
                }
            }
            else
            {
                foreach (var texure in mat.textures)
                {
                    if (BFRES.FTEXtextures.ContainsKey(texure.Name))
                    {
                        Bitmap bmp = FTEXRGBA(BFRES.FTEXtextures[texure.Name].texture, BFRES.FTEXtextures[texure.Name].texture.display);

                        SetTexturePanel(bmp, texure);
                    }
                }
            }
        }
Exemple #10
0
        public void SetVertexBufferList(BFRES.Mesh m, string attName, BFRES.FMDL_Model mdl)
        {
            listView1.Items.Clear();

            //Set public variables so i can use it for other things
            AttName = attName;
            model   = mdl; //For updating meshes
            msh     = m;   //For updating meshes

            foreach (BFRES.Vertex v in msh.vertices)
            {
                if (attName == "_p0")
                {
                    var item = new ListViewItem(v.pos.X.ToString());
                    item.SubItems.Add(v.pos.Y.ToString());
                    item.SubItems.Add(v.pos.Z.ToString());
                    listView1.Items.Add(item);
                }
                if (attName == "_p1")
                {
                    var item = new ListViewItem(v.pos1.X.ToString());
                    item.SubItems.Add(v.pos1.Y.ToString());
                    item.SubItems.Add(v.pos1.Z.ToString());
                    listView1.Items.Add(item);
                }
                if (attName == "_p2")
                {
                    var item = new ListViewItem(v.pos2.X.ToString());
                    item.SubItems.Add(v.pos2.Y.ToString());
                    item.SubItems.Add(v.pos2.Z.ToString());
                    listView1.Items.Add(item);
                }
                if (attName == "_n0")
                {
                    var item = new ListViewItem(v.nrm.X.ToString());
                    item.SubItems.Add(v.nrm.Y.ToString());
                    item.SubItems.Add(v.nrm.Z.ToString());
                    listView1.Items.Add(item);
                }
                if (attName == "_u0")
                {
                    var item = new ListViewItem(v.uv0.X.ToString());
                    item.SubItems.Add(v.uv0.Y.ToString());
                    listView1.Items.Add(item);
                }
                if (attName == "_u1")
                {
                    var item = new ListViewItem(v.uv1.X.ToString());
                    item.SubItems.Add(v.uv1.Y.ToString());
                    listView1.Items.Add(item);
                }
                if (attName == "_u2")
                {
                    var item = new ListViewItem(v.uv2.X.ToString());
                    item.SubItems.Add(v.uv2.Y.ToString());
                    listView1.Items.Add(item);
                }
                if (attName == "_w0")
                {
                    float X = v.boneWeights.Count > 0 ? v.boneWeights[0] : 0;
                    float Y = v.boneWeights.Count > 1 ? v.boneWeights[1] : 0;
                    float Z = v.boneWeights.Count > 2 ? v.boneWeights[2] : 0;
                    float W = v.boneWeights.Count > 3 ? v.boneWeights[3] : 0;

                    var item = new ListViewItem(X.ToString());
                    item.SubItems.Add(Y.ToString());
                    item.SubItems.Add(Z.ToString());
                    item.SubItems.Add(W.ToString());
                    listView1.Items.Add(item);
                }
                if (attName == "_i0")
                {
                    string X = "";
                    string Y = "";
                    string Z = "";
                    string W = "";

                    float iX = v.boneIds.Count > 0 ? v.boneIds[0] : 0;
                    float iY = v.boneIds.Count > 1 ? v.boneIds[1] : 0;
                    float iZ = v.boneIds.Count > 2 ? v.boneIds[2] : 0;
                    float iW = v.boneIds.Count > 3 ? v.boneIds[3] : 0;

                    //Set the bone in the skeleton of it's fmdl.
                    try
                    {
                        if (iX != 0)
                        {
                            X = model.skeleton.bones[model.Node_Array[(int)iX]].Text;
                        }
                        if (iY != 0)
                        {
                            Y = model.skeleton.bones[model.Node_Array[(int)iY]].Text;
                        }
                        if (iZ != 0)
                        {
                            Z = model.skeleton.bones[model.Node_Array[(int)iZ]].Text;
                        }
                        if (iW != 0)
                        {
                            W = model.skeleton.bones[model.Node_Array[(int)iW]].Text;
                        }
                    }
                    catch
                    {
                        X = iX.ToString();
                        Y = iY.ToString();
                        Z = iZ.ToString();
                        W = iW.ToString();
                    }


                    var item = new ListViewItem(X);
                    item.SubItems.Add(Y);
                    item.SubItems.Add(Z);
                    item.SubItems.Add(W);
                    listView1.Items.Add(item);
                }
                if (attName == "_b0")
                {
                    var item = new ListViewItem(v.bitan.X.ToString());
                    item.SubItems.Add(v.bitan.Y.ToString());
                    item.SubItems.Add(v.bitan.Z.ToString());
                    item.SubItems.Add(v.bitan.W.ToString());
                    listView1.Items.Add(item);
                }
                if (attName == "_t0")
                {
                    var item = new ListViewItem(v.tan.X.ToString());
                    item.SubItems.Add(v.tan.Y.ToString());
                    item.SubItems.Add(v.tan.Z.ToString());
                    item.SubItems.Add(v.tan.W.ToString());
                    listView1.Items.Add(item);
                }
                if (attName == "_c0")
                {
                    Color SetColor = Color.White;

                    int someIntX = (int)Math.Ceiling(v.col.X * 255);
                    int someIntY = (int)Math.Ceiling(v.col.Y * 255);
                    int someIntZ = (int)Math.Ceiling(v.col.Z * 255);
                    int someIntW = (int)Math.Ceiling(v.col.W * 255);

                    SetColor = Color.FromArgb(
                        255,
                        someIntX,
                        someIntY,
                        someIntZ
                        );


                    var item = new ListViewItem(v.col.X.ToString());
                    item.BackColor = SetColor;
                    item.SubItems.Add(v.col.Y.ToString());
                    item.SubItems.Add(v.col.Z.ToString());
                    item.SubItems.Add(v.col.W.ToString());
                    listView1.Items.Add(item);
                }
            }
        }