Пример #1
0
 public ModelContainer()
 {
     ImageKey         = "folder";
     SelectedImageKey = "folder";
     nud     = new NUD();
     nut     = new NUT();
     mta     = new MTA();
     MOI     = new MOI();
     jtb     = new JTB();
     XMB     = new XMBFile();
     Checked = true;
     Refresh();
 }
Пример #2
0
        private void makeMetalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NUD nud = ((NUD)treeView1.SelectedNode.Tag);

            foreach (NUD.Mesh m in nud.mesh)
            {
                foreach (NUD.Polygon p in m.Nodes)
                {
                    foreach (NUD.Material mat in p.materials)
                    {
                        float hash = -1f;
                        if (mat.entries.ContainsKey("NU_materialHash"))
                        {
                            hash = mat.entries["NU_materialHash"][0];
                        }

                        mat.anims.Clear();
                        mat.entries.Clear();

                        mat.flags = 0x9601106B;

                        //textures preserve normal map somehow...

                        int difcol = (int)((long)mat.textures[0].hash & 0xFFFFFF00) | (0xF0);
                        mat.textures.Clear();
                        mat.displayTexId = -1;

                        NUD.Mat_Texture dif = NUD.Polygon.makeDefault();
                        dif.hash = difcol;
                        NUD.Mat_Texture cub = NUD.Polygon.makeDefault();
                        cub.hash = 0x10102000;
                        NUD.Mat_Texture nrm = NUD.Polygon.makeDefault();
                        NUD.Mat_Texture rim = NUD.Polygon.makeDefault();
                        rim.hash = 0x10080000;

                        mat.textures.Add(dif); mat.textures.Add(cub); mat.textures.Add(nrm); mat.textures.Add(rim);

                        // properties
                        mat.entries.Add("NU_colorSamplerUV", new float[] { 1, 1, 0, 0 });
                        mat.entries.Add("NU_fresnelColor", new float[] { 0.6f, 0.6f, 0.6f, 1 });
                        mat.entries.Add("NU_blinkColor", new float[] { 0f, 0f, 0f, 0 });
                        mat.entries.Add("NU_reflectionColor", new float[] { 3f, 3f, 3f, 1 });
                        mat.entries.Add("NU_aoMinGain", new float[] { 0.3f, 0.3f, 0.3f, 1 });
                        mat.entries.Add("NU_lightMapColorOffset", new float[] { 0f, 0f, 0f, 0 });
                        mat.entries.Add("NU_fresnelParams", new float[] { 3.7f, 0f, 0f, 1 });
                        mat.entries.Add("NU_alphaBlendParams", new float[] { 0f, 0f, 0f, 0 });
                        mat.entries.Add("NU_materialHash", new float[] { hash, 0f, 0f, 0 });
                    }
                }
            }
        }
Пример #3
0
        public static void removeLowPolyNr(NUD n)
        {
            List <NUD.Mesh> toRemove = new List <NUD.Mesh>();

            for (int i = 15; i <= 32; i++)
            {
                toRemove.Add((NUD.Mesh)n.Nodes[i]);
            }

            foreach (NUD.Mesh m in toRemove)
            {
                n.Nodes.Remove(m);
            }
        }
Пример #4
0
        public void DeleteNode()
        {
            DialogResult dialogResult = MessageBox.Show("Are you sure? (This cannot be undone)", "Delete Polygon/Mesh", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                if (treeView1.SelectedNode is NUD.Polygon)
                {
                    NUD.Mesh parent = ((NUD.Mesh)treeView1.SelectedNode.Parent);
                    parent.Nodes.Remove((NUD.Polygon)treeView1.SelectedNode);
                    NUD parentn = ((NUD)parent.Parent.Tag);
                    parentn.PreRender();
                }
                else if (treeView1.SelectedNode is NUD.Mesh)
                {
                    NUD parent = ((NUD)treeView1.SelectedNode.Parent.Tag);
                    parent.mesh.Remove((NUD.Mesh)treeView1.SelectedNode);
                    treeView1.SelectedNode.Parent.Nodes.Remove(treeView1.SelectedNode);
                    parent.PreRender();
                }
                else if (treeView1.SelectedNode.Tag is NUD)
                {
                    NUD            model = (NUD)treeView1.SelectedNode.Tag;
                    ModelContainer m     = null;
                    foreach (ModelContainer modelContainer in Runtime.ModelContainers)
                    {
                        if (modelContainer.nud == model)
                        {
                            m = modelContainer;
                        }
                    }
                    if (m != null)
                    {
                        Runtime.ModelContainers.Remove(m);
                    }
                    if (Runtime.TargetVBN == m.vbn)
                    {
                        Runtime.TargetVBN = null;
                    }
                    //if (Runtime.TargetMTA == m.mta)
                    //    Runtime.TargetMTA = null;
                    if (Runtime.TargetNUD == m.nud)
                    {
                        Runtime.TargetNUD = null;
                    }

                    treeView1.Nodes.Remove(treeView1.SelectedNode);
                }
            }
        }
Пример #5
0
        // I'm completely totally serious

        public static NUD Create(VBN vbn)
        {
            Dictionary<string, string> files = new Dictionary<string, string>();
            ZipArchive zip = ZipFile.OpenRead("lib\\Skapon.zip");

            Random random = new Random();
            int randomNumber = random.Next(0, 0xFFFFFF);

            NUT nut = new NUT();
            foreach (ZipArchiveEntry e in zip.Entries)
            {
                byte[] b;
                using (BinaryReader br = new BinaryReader(e.Open()))
                {
                    b = br.ReadBytes((int)e.Length);
                }
                var stream = new StreamReader(new MemoryStream(b));
                string s = stream.ReadToEnd();
                files.Add(e.Name, s);

                if (e.Name.EndsWith(".dds"))
                {
                    NUT_Texture tex = new DDS(new FileData(b)).toNUT_Texture();
                    nut.Nodes.Add(tex);
                    tex.HASHID = 0x40000000 + randomNumber;
                    nut.draw.Add(tex.HASHID, NUT.loadImage(tex));
                }
            }

            NUD nud = new NUD();
            NUD.Mesh head = new NUD.Mesh();
            nud.Nodes.Add(head);
            head.Text = "Skapon";

            head.Nodes.Add(setToBone(scale(readPoly(files["head.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("HeadN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["body.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("BustN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["hand.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("RHandN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["hand.obj"]), -1, -1, 1), vbn.bones[vbn.boneIndex("LHandN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["foot.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("RFootJ")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["foot.obj"]), -1, -1, -1), vbn.bones[vbn.boneIndex("LFootJ")], vbn));

            foreach (NUD.Polygon p in head.Nodes)
            {
                p.materials[0].textures[0].hash = 0x40000000 + randomNumber;
            }

            nud.PreRender();

            return nud;
        }
Пример #6
0
        private static int CalculatePolygonCount(NUD n)
        {
            int polyCount = 0;

            foreach (NUD.Mesh m in n.Nodes)
            {
                foreach (NUD.Polygon p in m.Nodes)
                {
                    polyCount++;
                }
            }

            return(polyCount);
        }
Пример #7
0
        private void addBlankMeshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode.Tag is NUD)
            {
                NUD nud = (NUD)treeView1.SelectedNode.Tag;

                NUD.Mesh m = new NUD.Mesh();

                m.Text = "Blank Mesh";

                nud.mesh.Add(m);

                refresh();
            }
        }
Пример #8
0
 /*
  * This method is for clearing all the GL stuff
  * Don't want wasted buffers :>
  * */
 public void Destroy()
 {
     if (NUD != null)
     {
         NUD.Destroy();
     }
     if (NUT != null)
     {
         NUT.Destroy();
     }
     if (bfres != null)
     {
         bfres.Destroy();
     }
 }
Пример #9
0
        public static List <NUD.Material> ReadMaterialListFromPreset(string file)
        {
            FileData matFile = new FileData(file);
            int      soff    = matFile.readInt();

            NUD.PolyData pol = new NUD.PolyData()
            {
                texprop1 = matFile.readInt(),
                texprop2 = matFile.readInt(),
                texprop3 = matFile.readInt(),
                texprop4 = matFile.readInt()
            };

            List <NUD.Material> presetMaterials = NUD.ReadMaterials(matFile, pol, soff);

            return(presetMaterials);
        }
Пример #10
0
 private void openEditToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (treeView1.SelectedNode.Tag is NUD)
     {
         NUD org = (NUD)treeView1.SelectedNode.Tag;
         foreach (ModelContainer con in Runtime.ModelContainers)
         {
             if (con.nud == org)
             {
                 ModelViewport v = new ModelViewport();
                 v.draw.Add(con);
                 MainForm.Instance.AddDockedControl(v);
                 break;
             }
         }
     }
 }
Пример #11
0
        public void Apply(NUD nud)
        {
            Matrix4 rot = Matrix4.CreateRotationX(0.5f * (float)Math.PI);

            foreach (NUD.Mesh mesh in nud.mesh)
            {
                foreach (NUD.Polygon poly in mesh.polygons)
                {
                    poly.vertSize = (BoneTypes[(string)comboBox2.SelectedItem]) | (VertTypes[(string)comboBox1.SelectedItem]);

                    if (checkBox1.Checked || checkBox4.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 (checkBox4.Checked)
                            {
                                v.pos = Vector3.Transform(v.pos, rot);
                                v.nrm = Vector3.Transform(v.nrm, rot);
                            }
                        }
                    }
                }
            }

            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();
        }
Пример #12
0
 private void treeView1_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == '=')
     {
         if (treeView1.SelectedNode.Tag is NUD.Mesh)
         {
             TreeNode node   = treeView1.SelectedNode;
             TreeNode parent = node.Parent;
             NUD.Mesh m      = (NUD.Mesh)node.Tag;
             NUD      n      = (NUD)parent.Tag;
             int      pos    = n.mesh.IndexOf(m) + 1;
             if (pos >= n.mesh.Count)
             {
                 pos = n.mesh.Count - 1;
             }
             n.mesh.Remove(m);
             n.mesh.Insert(pos, m);
             parent.Nodes.Remove(node);
             parent.Nodes.Insert(pos, node);
             treeView1.SelectedNode = node;
             n.PreRender();
         }
     }
     if (e.KeyChar == '-')
     {
         if (treeView1.SelectedNode.Tag is NUD.Mesh)
         {
             TreeNode node   = treeView1.SelectedNode;
             TreeNode parent = node.Parent;
             NUD.Mesh m      = (NUD.Mesh)node.Tag;
             NUD      n      = (NUD)parent.Tag;
             int      pos    = n.mesh.IndexOf(m) - 1;
             if (pos < 0)
             {
                 pos = 0;
             }
             n.mesh.Remove(m);
             n.mesh.Insert(pos, m);
             parent.Nodes.Remove(node);
             parent.Nodes.Insert(pos, node);
             treeView1.SelectedNode = node;
             n.PreRender();
         }
     }
 }
Пример #13
0
        //Saving Mat
        private void savePresetButton_Click(object sender, EventArgs e)
        {
            using (var sfd = new SaveFileDialog())
            {
                sfd.Filter = "Namco Material (NMT)|*.nmt|" +
                             "All files(*.*)|*.*";

                sfd.InitialDirectory = Path.Combine(MainForm.executableDir, "materials\\");
                Console.WriteLine(sfd.InitialDirectory);
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    sfd.FileName         = sfd.FileName;
                    sfd.RestoreDirectory = true;

                    if (sfd.FileName.EndsWith(".nmt"))
                    {
                        FileOutput m = new FileOutput();
                        FileOutput s = new FileOutput();

                        int[] c = NUD.WriteMaterial(m, currentMaterialList, s);

                        FileOutput fin = new FileOutput();

                        fin.writeInt(0);

                        fin.writeInt(20 + c[0]);
                        for (int i = 1; i < 4; i++)
                        {
                            fin.writeInt(c[i] == c[i - 1] ? 0 : 20 + c[i]);
                        }

                        for (int i = 0; i < 4 - c.Length; i++)
                        {
                            fin.writeInt(0);
                        }

                        fin.writeOutput(m);
                        fin.align(32, 0xFF);
                        fin.writeIntAt(fin.size(), 0);
                        fin.writeOutput(s);
                        fin.save(sfd.FileName);
                    }
                }
            }
        }
Пример #14
0
 private void numericUpDown1_ValueChanged(object sender, EventArgs e)
 {
     if (treeView1.SelectedNode is NUD.Mesh && !changingValue)
     {
         int      pos    = (int)numericUpDown1.Value;
         TreeNode node   = treeView1.SelectedNode;
         TreeNode parent = node.Parent;
         NUD.Mesh m      = (NUD.Mesh)node;
         NUD      n      = (NUD)parent.Tag;
         n.mesh.Remove(m);
         n.mesh.Insert(pos, m);
         parent.Nodes.Remove(node);
         parent.Nodes.Insert(pos, node);
         treeView1.SelectedNode = node;
         n.PreRender();
     }
     changingValue = false;//Set the value back so the user can change values
 }
Пример #15
0
        public static void ImportMaterialAsXml(NUD n, string filename)
        {
            // Creates a list of materials and then trys to apply the materials to the polygons.
            int polyCount = CalculatePolygonCount(n);

            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            List <NUD.Material> materialList      = new List <NUD.Material>();
            List <int>          matCountForPolyId = new List <int>();

            XmlNode main = doc.ChildNodes[0];

            foreach (XmlNode meshNode in main.ChildNodes)
            {
                if (!(meshNode.Name.Equals("mesh")))
                {
                    continue;
                }

                foreach (XmlNode polynode in meshNode.ChildNodes)
                {
                    if (!(polynode.Name.Equals("polygon")))
                    {
                        continue;
                    }

                    matCountForPolyId.Add(polynode.ChildNodes.Count);

                    if (matCountForPolyId.Count > polyCount)
                    {
                        int countDif = matCountForPolyId.Count - polyCount;
                        MessageBox.Show(String.Format("Expected {0} polygons but found {1} in the XML file. " +
                                                      "The last {2} polygon(s) will be ignored.",
                                                      polyCount, matCountForPolyId.Count, countDif));
                    }

                    ReadMaterials(materialList, polynode);
                }
            }

            ApplyMaterials(n, materialList, matCountForPolyId);
        }
Пример #16
0
        public void Move(int type, float move)
        {
            // move mesh over
            foreach (NUD.Polygon p in mesh.Nodes)
            {
                foreach (NUD.Vertex v in p.vertices)
                {
                    // Rotate the mesh normals as well to preserve proper normal direction.
                    switch (type)
                    {
                    case 1: v.pos.X += move; break;

                    case 2: v.pos.Y += move; break;

                    case 3: v.pos.Z += move; break;

                    case 4:
                        v.pos = Vector3.TransformVector(v.pos, Matrix4.CreateRotationX(move * ((float)Math.PI / 180)));
                        v.nrm = Vector3.TransformVector(v.nrm, Matrix4.CreateRotationX(move * ((float)Math.PI / 180))).Normalized();
                        break;

                    case 5:
                        v.pos = Vector3.TransformVector(v.pos, Matrix4.CreateRotationY(move * ((float)Math.PI / 180)));
                        v.nrm = Vector3.TransformVector(v.nrm, Matrix4.CreateRotationY(move * ((float)Math.PI / 180))).Normalized();
                        break;

                    case 6:
                        v.pos = Vector3.TransformVector(v.pos, Matrix4.CreateRotationZ(move * ((float)Math.PI / 180)));
                        v.nrm = Vector3.TransformVector(v.nrm, Matrix4.CreateRotationZ(move * ((float)Math.PI / 180))).Normalized();
                        break;

                    case 7:
                        v.pos = Vector3.Multiply(v.pos, move);
                        break;
                    }
                }
            }

            NUD n = (NUD)mesh.Parent;

            n.UpdateRenderMeshes();
            MainForm.Instance.GetActiveModelViewport()?.glViewport?.Invalidate();
        }
Пример #17
0
        public static void DrawNudMaterialSphere(Shader shader, NUD.Material material, Mesh3D screenTriangle, Dictionary <NUD.DummyTextures, Texture> dummyTextures)
        {
            if (!shader.ProgramCreatedSuccessfully)
            {
                return;
            }

            shader.UseProgram();

            // Use the same uniforms as the NUD shader.
            GenericMaterial genericMaterial = new GenericMaterial();

            NudUniforms.SetMaterialPropertyUniforms(genericMaterial, material);
            genericMaterial.SetShaderUniforms(shader);

            NUD.SetStageLightingUniforms(shader, 0);
            ModelContainer.SetRenderSettingsUniforms(shader);

            nudSphereCamera.UpdateMatrices();
            ModelContainer.SetLightingUniforms(shader, nudSphereCamera);
            ModelContainer.SetCameraMatrixUniforms(nudSphereCamera, shader);

            // Use default textures rather than textures from the NUT.
            NudUniforms.SetTextureUniformsNudMatSphere(shader, material, dummyTextures);

            // These values aren't needed in the shader currently.
            shader.SetVector3("cameraPosition", 0, 0, 0);
            shader.SetFloat("zBufferOffset", 0);
            shader.SetFloat("bloomThreshold", Runtime.bloomThreshold);

            bool isTransparent = (material.srcFactor > 0) || (material.dstFactor > 0) || (material.alphaFunction > 0) || (material.alphaTest > 0);

            shader.SetBoolToInt("isTransparent", isTransparent);

            // Set texture uniforms for the mesh attributes.
            shader.SetTexture("normalTex", sphereNrmTex.Id, TextureTarget.Texture2D, 15);
            shader.SetTexture("uvTex", sphereUvTex.Id, TextureTarget.Texture2D, 16);
            shader.SetTexture("tanTex", sphereTanTex.Id, TextureTarget.Texture2D, 17);
            shader.SetTexture("bitanTex", sphereBitanTex.Id, TextureTarget.Texture2D, 18);

            // Draw full screen "quad" (big triangle)
            ScreenDrawing.DrawScreenTriangle(shader, screenTriangle);
        }
Пример #18
0
 private void treeView1_KeyDown(object sender, KeyEventArgs e)
 {
     e.Handled = false;
     if (e.KeyCode == Keys.Delete)
     {
         e.Handled = true;
         if (treeView1.SelectedNode is NUD.Mesh)
         {
             NUD parent = ((NUD)treeView1.SelectedNode.Parent.Tag);
             parent.mesh.Remove((NUD.Mesh)treeView1.SelectedNode);
             parent.PreRender();
         }
         else if (treeView1.SelectedNode.Tag is NUD)
         {
             NUD            model = (NUD)treeView1.SelectedNode.Tag;
             ModelContainer m     = null;
             foreach (ModelContainer modelContainer in Runtime.ModelContainers)
             {
                 if (modelContainer.nud == model)
                 {
                     m = modelContainer;
                 }
             }
             if (m != null)
             {
                 Runtime.ModelContainers.Remove(m);
             }
             if (Runtime.TargetVBN == m.vbn)
             {
                 Runtime.TargetVBN = null;
             }
             if (Runtime.TargetMTA == m.mta)
             {
                 Runtime.TargetMTA = null;
             }
             if (Runtime.TargetNUD == m.nud)
             {
                 Runtime.TargetNUD = null;
             }
         }
         refresh();
     }
 }
Пример #19
0
        public NUD toNUD()
        {
            NUD nud = new NUD();
            int j   = 0;

            foreach (Mesh m in mesh)
            {
                NUD.Mesh n_mesh = new NUD.Mesh();
                nud.mesh.Add(n_mesh);
                n_mesh.Text = "Mesh_" + j++;
                foreach (List <int> i in m.faces)
                {
                    NUD.Polygon poly = new NUD.Polygon();
                    n_mesh.polygons.Add(poly);
                    poly.setDefaultMaterial();

                    List <Vertex> indexSim = new List <Vertex>();

                    foreach (int index in i)
                    {
                        Vertex v = vertices[index];

                        if (!indexSim.Contains(v))
                        {
                            indexSim.Add(v);
                            NUD.Vertex vert = new NUD.Vertex();
                            vert.pos    = v.pos;
                            vert.nrm    = v.nrm;
                            vert.col    = v.col;
                            vert.tx     = v.tx;
                            vert.weight = v.weight;
                            vert.node   = v.node;
                            poly.AddVertex(vert);
                        }

                        poly.faces.Add(indexSim.IndexOf(v));
                    }
                }
            }
            return(nud);
        }
Пример #20
0
 private void openEditToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (treeView1.SelectedNode is NUD)
     {
         NUD org = (NUD)treeView1.SelectedNode;
         foreach (TreeNode node in treeView1.Nodes)
         {
             if (node is ModelContainer)
             {
                 ModelContainer con = (ModelContainer)node;
                 if (con.NUD == org)
                 {
                     ModelViewport v = new ModelViewport();
                     v.draw.Add(con);
                     MainForm.Instance.AddDockedControl(v);
                     break;
                 }
             }
         }
     }
 }
Пример #21
0
 public void OpenPacs(List <string> pacs)
 {
     foreach (string pac in pacs)
     {
         PAC p = new PAC();
         p.Read(pac);
         byte[] data;
         if (p.Files.TryGetValue("display", out data))
         {
             MTA mta = new MTA();
             mta.read(new FileData(data));
             NUD.ApplyMta(mta, 0);
         }
         if (p.Files.TryGetValue("default.mta", out data))
         {
             MTA mta = new MTA();
             mta.read(new FileData(data));
             NUD.ApplyMta(mta, 0);
         }
     }
 }
Пример #22
0
 public void mergeModel()
 {
     if (treeView1.SelectedNode.Tag is NUD)
     {
         using (var ofd = new OpenFileDialog())
         {
             ofd.Filter = "Namco Model (.nud)|*.nud";
             if (ofd.ShowDialog() == DialogResult.OK)
             {
                 string filename = ofd.FileName;
                 NUD    nud      = new NUD(filename);
                 foreach (NUD.Mesh mesh in nud.mesh)
                 {
                     ((NUD)treeView1.SelectedNode.Tag).mesh.Add((mesh));
                 }
                 ((NUD)treeView1.SelectedNode.Tag).PreRender();
                 refresh();
             }
         }
     }
 }
Пример #23
0
        private void importFromXMLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode.Tag is NUD)
            {
                NUD nud = (NUD)treeView1.SelectedNode.Tag;

                string         filename = "";
                OpenFileDialog save     = new OpenFileDialog();
                save.Filter = "XML Material|*.xml";
                DialogResult result = save.ShowDialog();

                if (result == DialogResult.OK)
                {
                    filename = save.FileName;
                    if (filename.EndsWith(".xml"))
                    {
                        importMaterialAsXML(nud, filename);
                    }
                }
            }
        }
Пример #24
0
        private static void ApplyMaterials(NUD n, List <NUD.Material> materialList, List <int> polyMatCount)
        {
            int matIndex  = 0;
            int polyIndex = 0;

            foreach (NUD.Mesh m in n.Nodes)
            {
                foreach (NUD.Polygon p in m.Nodes)
                {
                    p.materials.Clear();
                    for (int i = 0; i < polyMatCount[polyIndex]; i++)
                    {
                        if (p.materials.Count < 2)
                        {
                            p.materials.Add(materialList[matIndex]);
                        }
                        matIndex += 1;
                    }

                    polyIndex += 1;
                }
            }
        }
Пример #25
0
        public static void effectiveScale(NUD nud, VBN vbn, Matrix4 sca)
        {
            foreach (Bone b in vbn.bones)
            {
                Vector3 pos = Vector3.TransformVector(new Vector3(b.position[0], b.position[1], b.position[2]), sca);
                b.position[0] = pos.X;
                b.position[1] = pos.Y;
                b.position[2] = pos.Z;
            }

            vbn.reset();

            foreach (NUD.Mesh mesh in nud.Nodes)
            {
                foreach (NUD.Polygon poly in mesh.Nodes)
                {
                    foreach (NUD.Vertex v in poly.vertices)
                    {
                        v.pos = Vector3.TransformVector(v.pos, sca);
                    }
                }
            }
            nud.UpdateRenderMeshes();
        }
Пример #26
0
        public static void MakePichu(string path = "C:\\Pichu\\")
        {
            if (!path.EndsWith("\\"))
            {
                path += "\\";
            }
            DAT dat = new DAT();

            dat.Read(new FileData(path + "PlPcNr.dat"));
            dat.PreRender();

            dat.ExportTextures(path, 0x401B1000);

            BoneNameFix(dat.bones);

            // model--------------------------------------------------------
            ModelContainer converted = dat.wrapToNUD();
            NUD            nud       = converted.NUD;
            float          sca       = 0.6f;


            removeLowPolyNr(nud);
            nud.UpdateRenderMeshes();

            //Runtime.ModelContainers.Add(converted);
            //-------------------------------------------------

            Runtime.TargetVBN = converted.VBN;

            MainForm.HashMatch();

            Dictionary <string, SkelAnimation> anims = DAT_Animation.LoadAJ(path + "PlPcAJ.dat", converted.VBN);

            //ArrangeBones(converted.vbn, converted.nud);

            // note bone 40 - 51 is disabled for pika

            foreach (string an in anims.Keys)
            {
                effectiveScale(anims[an], Matrix4.CreateTranslation(0, 0, 0) * Matrix4.CreateScale(sca, sca, sca));
            }
            effectiveScale(converted.NUD, converted.VBN, Matrix4.CreateTranslation(0, 0, 0) * Matrix4.CreateScale(sca, sca, sca));

            Directory.CreateDirectory(path + "build\\model\\body\\c00\\");
            nud.Save(path + "build\\model\\body\\c00\\model.nud");
            converted.VBN.Endian = Endianness.Little;
            converted.VBN.Save(path + "build\\model\\body\\c00\\model.vbn");


            PAC org  = new PAC();
            PAC npac = new PAC();

            org.Read(path + "main.pac");
            foreach (string key in org.Files.Keys)
            {
                byte[] d = org.Files[key];

                foreach (string an in anims.Keys)
                {
                    string name = an.Replace("PlyPichu5K_Share_ACTION_", "").Replace("_figatree", "");
                    if (key.Contains(name))
                    {
                        Console.WriteLine("Matched " + name + " with " + key);

                        if (!anims[an].getNodes(true).Contains(0) && !key.Contains("Cliff"))
                        {
                            KeyNode node = anims[an].getNode(0, 0);
                            node.t_type = 1;
                        }
                        d = OMOOld.createOMO(anims[an], converted.VBN);
                        break;
                    }
                }

                npac.Files.Add(key, d);
            }
            Directory.CreateDirectory(path + "build\\motion\\");
            npac.Save(path + "build\\motion\\main.pac");

            /*FileOutput omo = new FileOutput();
             * converted.vbn.reset();
             * converted.vbn.totalBoneCount = (uint)converted.vbn.bones.Count;
             * omo.writeBytes(OMO.createOMO(anims["PlyPichu5K_Share_ACTION_Wait1_figatree"], converted.vbn));
             * omo.save(path + "PlyPichu5K_Share_ACTION_Wait1_figatree.omo");*/
        }
Пример #27
0
        public NUD toNUD()
        {
            NUD n = new NUD();

            n.hasBones = false;

            foreach (OBJObject o in objects)
            {
                NUD.Mesh m = new NUD.Mesh();
                m.Text       = o.name;
                m.singlebind = -1;
                m.boneflag   = 0x08;

                foreach (OBJGroup g in o.groups)
                {
                    if (g.v.Count == 0)
                    {
                        continue;
                    }

                    NUD.Polygon p = new NUD.Polygon();
                    m.Nodes.Add(p);
                    m.Nodes.Add(p);
                    p.setDefaultMaterial();
                    p.vertSize = 0x06;
                    p.UVSize   = 0x10;
                    p.polflag  = 0x00;

                    Dictionary <int, int> collected = new Dictionary <int, int>();

                    for (int i = 0; i < g.v.Count; i++)
                    {
                        p.faces.Add(p.vertices.Count);
                        NUD.Vertex v = new NUD.Vertex();
                        p.vertices.Add(v);
                        if (g.v.Count > i)
                        {
                            v.pos = this.v[g.v[i]] + Vector3.Zero;
                        }
                        if (g.vn.Count > i)
                        {
                            v.nrm = vn[g.vn[i]] + Vector3.Zero;
                        }
                        ;
                        if (g.vt.Count > i)
                        {
                            v.tx.Add(vt[g.vt[i]] + Vector2.Zero);
                        }
                    }
                }
                if (m.Nodes.Count > 0)
                {
                    n.mesh.Add(m);
                }
            }

            n.Optimize();
            n.PreRender();

            return(n);
        }
Пример #28
0
        // Create from NUD
        public void CreateFromNUD(NUD n)
        {
            //Alrighty.............................
            int meshcount = Nodes.Count;

            // First transfer over the mesh polygons?
            int             i      = 0;
            List <BCH_Mesh> Meshes = new List <BCH_Mesh>();
            List <Vertex>   Verts  = new List <Vertex>();

            Console.WriteLine(n.Nodes.Count + " " + n.meshes.Count);
            foreach (NUD.Mesh nudmesh in n.meshes)
            {
                BCH_Mesh mesh = new BCH_Mesh();
                mesh.Text = Nodes[i].Text; //nudmesh.Text;//
                Console.WriteLine(nudmesh.Text);
                mesh.MaterialIndex = ((BCH_Mesh)Nodes[i]).MaterialIndex;
                i++;
                Meshes.Add(mesh);
                foreach (NUD.Polygon nudpoly in nudmesh.Nodes)
                {
                    BCH_PolyGroup pg = new BCH_PolyGroup();
                    pg.Text = "Polygroup";
                    mesh.Nodes.Add(pg);

                    pg.Faces = new int[nudpoly.display.Length];
                    for (int k = 0; k < nudpoly.display.Length; k++)
                    {
                        pg.Faces[k] = nudpoly.display[k] + Verts.Count;
                    }

                    List <int> boneList = new List <int>();
                    foreach (NUD.dVertex v in nudpoly.vertdata)
                    {
                        Vertex vn = new Vertex();
                        vn.pos    = v.pos;
                        vn.nrm    = v.nrm;
                        vn.tx     = v.uv;
                        vn.col    = v.col;
                        vn.weight = v.weight.Xy;
                        if (!boneList.Contains((int)v.node.X))
                        {
                            boneList.Add((int)v.node.X);
                        }
                        if (!boneList.Contains((int)v.node.Y))
                        {
                            boneList.Add((int)v.node.Y);
                        }

                        vn.bone = new Vector2(boneList.IndexOf((int)v.node.X), boneList.IndexOf((int)v.node.Y));
                        vn.bone = v.node.Xy;
                        Verts.Add(vn);
                    }

                    pg.BoneList = boneList.ToArray();
                }
            }

            //Fill out blank meshes
            while (Meshes.Count < meshcount)
            {
                BCH_Mesh mesh = new BCH_Mesh();
                mesh.Text          = Nodes[i].Text;
                mesh.MaterialIndex = ((BCH_Mesh)Nodes[i]).MaterialIndex;
                mesh.Nodes.Add(new BCH_PolyGroup()
                {
                    Faces    = new int[] { 0, 0, 0 },
                    BoneList = new int[] { 0 }
                });
                Verts.Add(new Vertex());
                Meshes.Add(mesh);
                i++;
            }

            Nodes.Clear();
            Nodes.AddRange(Meshes.ToArray());
            Vertices = Verts.ToArray();
        }
Пример #29
0
        public void Render(Camera camera, int depthMap, Matrix4 lightMatrix, Vector2 screenDimensions, bool drawShadow = false)
        {
            if (!Checked)
            {
                return;
            }

            Shader shader;

            // 3DS MBN
            shader = OpenTKSharedResources.shaders["Mbn"];
            shader.UseProgram();
            SetMbnUniforms(camera, shader);

            // Melee DAT
            shader = OpenTKSharedResources.shaders["Dat"];
            shader.UseProgram();
            SetDatUniforms(shader);

            if (Bch != null)
            {
                foreach (BCH_Model mo in Bch.Models.Nodes)
                {
                    mo.Render(camera.MvpMatrix);
                }
            }

            if (DatMelee != null && OpenTKSharedResources.shaders["Dat"].ProgramCreatedSuccessfully)
            {
                DatMelee.Render(camera.MvpMatrix);
            }

            LightColor diffuseColor = Runtime.lightSetParam.characterDiffuse.diffuseColor;
            LightColor ambientColor = Runtime.lightSetParam.characterDiffuse.ambientColor;

            if (Kcl != null)
            {
                shader = OpenTKSharedResources.shaders["KCL"];
                if (!shader.ProgramCreatedSuccessfully)
                {
                    return;
                }

                shader.UseProgram();

                shader.SetVector3("difLightColor", diffuseColor.R, diffuseColor.G, diffuseColor.B);
                shader.SetVector3("ambLightColor", ambientColor.R, ambientColor.G, ambientColor.B);

                Kcl.Render(camera.MvpMatrix);
            }

            if (Bfres != null)
            {
                Bfres.Render(camera, Runtime.drawNudColorIdPass);
            }

            if (NUD != null && OpenTKSharedResources.shaders["Nud"].ProgramCreatedSuccessfully && OpenTKSharedResources.shaders["NudDebug"].ProgramCreatedSuccessfully)
            {
                // Choose the appropriate shader.
                if (drawShadow)
                {
                    shader = OpenTKSharedResources.shaders["Shadow"];
                }
                else if (Runtime.renderType != Runtime.RenderTypes.Shaded)
                {
                    shader = OpenTKSharedResources.shaders["NudDebug"];
                }
                else
                {
                    shader = OpenTKSharedResources.shaders["Nud"];
                }

                shader.UseProgram();

                // Matrices.
                Matrix4 lightMatrixRef = lightMatrix;
                shader.SetMatrix4x4("lightMatrix", ref lightMatrixRef);
                SetCameraMatrixUniforms(camera, shader);

                SetRenderSettingsUniforms(shader);
                SetLightingUniforms(shader, camera);

                shader.SetInt("renderType", (int)Runtime.renderType);
                shader.SetInt("debugOption", (int)Runtime.uvChannel);
                shader.SetBoolToInt("drawShadow", Runtime.drawModelShadow);

                shader.SetTexture("depthMap", depthMap, TextureTarget.Texture2D, 14);

                SetElapsedDirectUvTime(shader);

                NUD.Render(VBN, camera, drawShadow, Runtime.drawNudColorIdPass);
            }
        }
Пример #30
0
        public static NUD toNUD(string fname)
        {
            StreamReader reader = File.OpenText(fname);
            string       line;

            string current = "";

            NUD nud = new NUD();

            while ((line = reader.ReadLine()) != null)
            {
                line = Regex.Replace(line, @"\s+", " ");
                string[] args = line.Replace(";", "").TrimStart().Split(' ');

                if (args[0].Equals("triangles") || args[0].Equals("end"))
                {
                    current = args[0];
                    continue;
                }

                if (current.Equals("triangles"))
                {
                    string meshName = args[0];
                    if (args[0].Equals(""))
                    {
                        continue;
                    }
                    for (int j = 0; j < 3; j++)
                    {
                        line = reader.ReadLine();
                        line = Regex.Replace(line, @"\s+", " ");
                        args = line.Replace(";", "").TrimStart().Split(' ');
                        // read triangle strip
                        int        parent = int.Parse(args[0]);
                        NUD.Vertex vert   = new NUD.Vertex();
                        vert.pos = new Vector3(float.Parse(args[1]), float.Parse(args[2]), float.Parse(args[3]));
                        vert.nrm = new Vector3(float.Parse(args[4]), float.Parse(args[5]), float.Parse(args[6]));
                        vert.uv.Add(new Vector2(float.Parse(args[7]), float.Parse(args[8])));
                        int wCount = int.Parse(args[9]);
                        int w      = 10;
                        for (int i = 0; i < wCount; i++)
                        {
                            vert.boneIds.Add(int.Parse(args[w++]));
                            vert.boneWeights.Add(float.Parse(args[w++]));
                        }

                        NUD.Mesh mes = null;
                        foreach (NUD.Mesh m in nud.Nodes)
                        {
                            if (m.Text.Equals(meshName))
                            {
                                mes = m;
                            }
                        }
                        if (mes == null)
                        {
                            mes      = new NUD.Mesh();
                            mes.Text = meshName;
                            nud.Nodes.Add(mes);
                        }
                        if (mes.Nodes.Count == 0)
                        {
                            NUD.Polygon poly = new NUD.Polygon();
                            poly.AddDefaultMaterial();
                            mes.Nodes.Add(poly);
                        }
                        {
                            ((NUD.Polygon)mes.Nodes[0]).faces.Add(((NUD.Polygon)mes.Nodes[0]).vertices.Count);
                            ((NUD.Polygon)mes.Nodes[0]).vertices.Add(vert);
                        }
                    }
                }
            }

            nud.OptimizeFileSize();
            nud.UpdateVertexData();
            return(nud);
        }