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

            bool checkedMeshName = false;
            bool fixMeshName     = false;

            bool hasShownShadowWarning = false;

            foreach (NUD.Mesh mesh in nud.Nodes)
            {
                if (BoneTypes[(string)boneTypeComboBox.SelectedItem] == BoneTypes["None"])
                {
                    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);
                    }
                }

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

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

                    // Set the vertex size before tangent/bitangent calculations.
                    if (poly.vertSize == (int)NUD.Polygon.VertexTypes.NormalsHalfFloat) // what is this supposed to mean?
                    {
                        poly.vertSize = 0;
                    }
                    else
                    {
                        poly.vertSize = BoneTypes[(string)boneTypeComboBox.SelectedItem] | VertexTypes[(string)vertTypeComboBox.SelectedItem];
                    }

                    poly.CalculateTangentBitangent();

                    int vertSizeShadowWarning = (int)NUD.Polygon.BoneTypes.HalfFloat | (int)NUD.Polygon.VertexTypes.NormalsTanBiTanHalfFloat;
                    if (!hasShownShadowWarning && poly.vertSize == vertSizeShadowWarning)
                    {
                        MessageBox.Show("Using \"" + (string)boneTypeComboBox.SelectedItem + "\" and \"" + (string)vertTypeComboBox.SelectedItem + "\" can make shadows not appear in-game.",
                                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        hasShownShadowWarning = true;
                    }

                    if (stageMatCB.Checked)
                    {
                        poly.materials.Clear();
                        poly.materials.Add(NUD.Material.GetStageDefault());
                    }

                    foreach (NUD.Vertex v in poly.vertices)
                    {
                        //Scroll UVs V by -1
                        if (transUvVerticalCB.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.color[i] = v.color[i] / 2;
                            }
                        }

                        // Set vertex colors to white.
                        if (vertcolorCB.Checked)
                        {
                            v.color = new Vector4(127, 127, 127, 127);
                        }

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

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

            nud.UpdateVertexData();
        }
Exemplo n.º 2
0
        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();
        }