Esempio n. 1
0
        public void Apply(NUD nud)
        {
            Matrix4 rot = Matrix4.CreateRotationX(0.5f * (float)Math.PI);

            foreach (NUD.Mesh mesh in nud.mesh)
            {
                if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"])
                {
                    mesh.boneflag = 0;
                }

                foreach (NUD.Polygon poly in mesh.polygons)
                {
                    poly.vertSize = ((poly.vertSize == 0x6 ? 0 : BoneTypes[(string)comboBox2.SelectedItem])) | (VertTypes[(string)comboBox1.SelectedItem]);

                    if (checkBox1.Checked || checkBox4.Checked || vertcolorCB.Checked)
                    {
                        foreach (NUD.Vertex v in poly.vertices)
                        {
                            if (checkBox1.Checked)
                            {
                                for (int i = 0; i < v.tx.Count; i++)
                                {
                                    v.tx[i] = new Vector2(v.tx[i].X, 1 - v.tx[i].Y);
                                }
                            }

                            if (vertcolorCB.Checked)
                            {
                                v.col = new Vector4(0x7F, 0x7F, 0x7F, 0x7F);
                            }

                            if (checkBox4.Checked)
                            {
                                v.pos = Vector3.Transform(v.pos, rot);
                                v.nrm = Vector3.Transform(v.nrm, rot);
                            }
                        }
                    }
                }
            }

            if (VertTypes[(string)comboBox1.SelectedItem] == 3 || VertTypes[(string)comboBox1.SelectedItem] == 7)
            {
                nud.computeTangentBitangent();
            }

            if (checkBox2.Checked)
            {
                foreach (NUD.Mesh mesh in nud.mesh)
                {
                    if (mesh.Text.Length > 5)
                    {
                        mesh.Text = mesh.Text.Substring(5, mesh.Text.Length - 5);
                    }
                }
            }

            nud.PreRender();
        }
Esempio n. 2
0
        public void Apply(NUD nud)
        {
            Matrix4 rot      = Matrix4.CreateRotationX(0.5f * (float)Math.PI);
            float   sc       = 1f;
            bool    hasScale = float.TryParse(scaleTB.Text, out sc);

            bool checkedUVRange = false;
            bool fixUV          = false;

            bool warning = false;

            foreach (NUD.Mesh mesh in nud.meshes)
            {
                if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"])
                {
                    mesh.boneflag = 0;
                }

                foreach (NUD.Polygon poly in mesh.Nodes)
                {
                    if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"])
                    {
                        poly.polflag = 0;
                    }

                    if (smoothCB.Checked)
                    {
                        poly.SmoothNormals();
                    }

                    // we only want to calculate new tangents/bitangents for imports
                    // vanilla models have special tangents/bitangents for mirrored normal maps
                    NUD.computeTangentBitangent(poly);

                    poly.vertSize = ((poly.vertSize == 0x6 ? 0 : BoneTypes[(string)comboBox2.SelectedItem])) | (VertTypes[(string)comboBox1.SelectedItem]);

                    if (!warning && poly.vertSize == 0x27)
                    {
                        MessageBox.Show("Using \"" + (string)comboBox2.SelectedItem + "\" and \"" + (string)comboBox1.SelectedItem + "\" can make shadows not appear in-game",
                                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        warning = true;
                    }

                    if (stagematCB.Checked)
                    {
                        // change to stage material
                        NUD.Mat_Texture tex = poly.materials[0].textures[0];
                        poly.materials[0].textures.Clear();
                        poly.materials.Clear();

                        NUD.Material m = new NUD.Material();
                        poly.materials.Add(m);
                        m.flags    = 0xA2011001;
                        m.RefAlpha = 128;
                        m.cullMode = 1029;

                        m.textures.Clear();
                        m.textures.Add(tex);

                        m.entries.Add("NU_colorSamplerUV", new float[] { 1, 1, 0, 0 });
                        m.entries.Add("NU_diffuseColor", new float[] { 1, 1, 1, 0.5f });
                        m.entries.Add("NU_materialHash", new float[] { BitConverter.ToSingle(new byte[] { 0x12, 0xEE, 0x2A, 0x1B }, 0), 0, 0, 0 });
                    }

                    //if (checkBox1.Checked || checkBox4.Checked || vertcolorCB.Checked || sc != 1f)
                    foreach (NUD.Vertex v in poly.vertices)
                    {
                        if (!checkedUVRange && v.uv.Count > 0 && (Math.Abs(v.uv[0].X) > 4 || Math.Abs(v.uv[0].Y) > 4))
                        {
                            checkedUVRange = true;

                            DialogResult dialogResult = MessageBox.Show("Some UVs are detected to be out of accurate range.\nFix them now?", "Potential UV Problem", MessageBoxButtons.YesNo);
                            if (dialogResult == DialogResult.Yes)
                            {
                                fixUV = true;
                            }
                        }

                        if (fixUV)
                        {
                            for (int h = 0; h < v.uv.Count; h++)
                            {
                                v.uv[h] = new Vector2(v.uv[h].X - (int)v.uv[h].X, v.uv[h].Y - (int)v.uv[h].Y);
                            }
                        }


                        if (flipUVCB.Checked)
                        {
                            for (int i = 0; i < v.uv.Count; i++)
                            {
                                v.uv[i] = new Vector2(v.uv[i].X, 1 - v.uv[i].Y);
                            }
                        }

                        if (vertColorDivCB.Checked)
                        //v.col = v.col / 2;
                        {
                            for (int i = 0; i < 3; i++)
                            {
                                v.col[i] = v.col[i] / 2;
                            }
                        }

                        if (vertcolorCB.Checked)
                        {
                            v.col = new Vector4(0x7F, 0x7F, 0x7F, 0x7F);
                        }

                        if (checkBox4.Checked)
                        {
                            v.pos = Vector3.Transform(v.pos, rot);
                            v.nrm = Vector3.Transform(v.nrm, rot);
                        }
                        if (sc != 1f)
                        {
                            v.pos = Vector3.Multiply(v.pos, sc);
                        }
                    }
                }
            }

            //if (VertTypes[(string)comboBox1.SelectedItem] == 3 || VertTypes[(string)comboBox1.SelectedItem] == 7)


            if (checkBox2.Checked)
            {
                foreach (NUD.Mesh mesh in nud.meshes)
                {
                    if (mesh.Text.Length > 5)
                    {
                        mesh.Text = mesh.Text.Substring(5, mesh.Text.Length - 5);
                    }
                }
            }

            nud.PreRender();
        }
        public void Apply(NUD nud)
        {
            nud.GenerateBoundingBoxes();
            Matrix4 rot      = Matrix4.CreateRotationX(0.5f * (float)Math.PI);
            float   sc       = 1f;
            bool    hasScale = float.TryParse(scaleTB.Text, out sc);

            bool checkedMeshName = false;
            bool fixMeshName     = false;

            bool warning = false;

            foreach (NUD.Mesh mesh in nud.Nodes)
            {
                if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"])
                {
                    mesh.boneflag = 0;
                }

                if (!checkedMeshName)
                {
                    checkedMeshName = true;
                    if (mesh.Text.Length > 5)
                    {
                        string sub = mesh.Text.Substring(0, 5);
                        int    a   = 0;
                        if (sub.StartsWith("_") && sub.EndsWith("_") && int.TryParse(sub.Substring(1, 3), out a))
                        {
                            fixMeshName = DialogResult.Yes == MessageBox.Show("Detected mesh names that start with \"_###_\". Would you like to fix this?\nIt is recommended that you select \"Yes\".", "Mesh Name Fix", MessageBoxButtons.YesNo);
                        }
                    }
                }
                if (fixMeshName)
                {
                    if (mesh.Text.Length > 5)
                    {
                        mesh.Text = mesh.Text.Substring(5, mesh.Text.Length - 5);
                    }
                }

                foreach (NUD.Polygon poly in mesh.Nodes)
                {
                    if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"])
                    {
                        poly.polflag = 0;
                    }

                    //Smooth normals
                    if (smoothCB.Checked)
                    {
                        poly.SmoothNormals();
                    }

                    // we only want to calculate new tangents/bitangents for imports
                    // vanilla models have special tangents/bitangents for mirrored normal maps
                    NUD.computeTangentBitangent(poly);

                    poly.vertSize = ((poly.vertSize == 0x6 ? 0 : BoneTypes[(string)comboBox2.SelectedItem])) | (VertTypes[(string)comboBox1.SelectedItem]);

                    if (!warning && poly.vertSize == 0x27)
                    {
                        MessageBox.Show("Using \"" + (string)comboBox2.SelectedItem + "\" and \"" + (string)comboBox1.SelectedItem + "\" can make shadows not appear in-game.",
                                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        warning = true;
                    }

                    //Use stage material
                    if (stagematCB.Checked)
                    {
                        NUD.Mat_Texture tex = poly.materials[0].textures[0];
                        poly.materials[0].textures.Clear();
                        poly.materials.Clear();

                        NUD.Material m = new NUD.Material();
                        poly.materials.Add(m);
                        m.Flags    = 0xA2001001;
                        m.RefAlpha = 128;
                        m.cullMode = 1029;

                        m.textures.Clear();
                        m.textures.Add(tex);

                        m.entries.Add("NU_colorSamplerUV", new float[] { 1, 1, 0, 0 });
                        m.entries.Add("NU_diffuseColor", new float[] { 1, 1, 1, 0.5f });
                        m.entries.Add("NU_materialHash", new float[] { BitConverter.ToSingle(new byte[] { 0x12, 0xEE, 0x2A, 0x1B }, 0), 0, 0, 0 });
                    }

                    foreach (NUD.Vertex v in poly.vertices)
                    {
                        //Scroll UVs V by -1
                        if (checkBox2.Checked)
                        {
                            for (int i = 0; i < v.uv.Count; i++)
                            {
                                v.uv[i] = new Vector2(v.uv[i].X, v.uv[i].Y + 1);
                            }
                        }

                        //Flip UVs
                        if (flipUVCB.Checked)
                        {
                            for (int i = 0; i < v.uv.Count; i++)
                            {
                                v.uv[i] = new Vector2(v.uv[i].X, 1 - v.uv[i].Y);
                            }
                        }

                        //Halve vertex colors
                        if (vertColorDivCB.Checked)
                        {
                            for (int i = 0; i < 3; i++)
                            {
                                v.col[i] = v.col[i] / 2;
                            }
                        }

                        //Ignore vertex colors
                        if (vertcolorCB.Checked)
                        {
                            v.col = new Vector4(0x7F, 0x7F, 0x7F, 0xFF);
                        }

                        //Rotate 90 degrees
                        if (checkBox4.Checked)
                        {
                            v.pos = Vector3.TransformPosition(v.pos, rot);
                            v.nrm = Vector3.TransformNormal(v.nrm, rot);
                        }

                        //Scale
                        if (sc != 1f)
                        {
                            v.pos = Vector3.Multiply(v.pos, sc);
                        }
                    }
                }
            }

            //if (VertTypes[(string)comboBox1.SelectedItem] == 3 || VertTypes[(string)comboBox1.SelectedItem] == 7)

            nud.PreRender();
        }