Beispiel #1
0
 public UvViewer(Nud sourceNud, Nud.Polygon polygonToRender)
 {
     // We need the nud to generate buffers due to the way nud rendering works.
     InitializeComponent();
     this.sourceNud       = sourceNud;
     this.polygonToRender = polygonToRender;
 }
Beispiel #2
0
        public static void ExportMaterialAsXml(Nud n, string filename)
        {
            XmlDocument doc = new XmlDocument();

            XmlNode      mainNode  = doc.CreateElement("NUDMATERIAL");
            XmlAttribute polycount = doc.CreateAttribute("polycount");

            mainNode.Attributes.Append(polycount);
            doc.AppendChild(mainNode);

            int polyCount = 0;

            foreach (Nud.Mesh m in n.Nodes)
            {
                XmlNode      meshnode = doc.CreateElement("mesh");
                XmlAttribute name     = doc.CreateAttribute("name"); name.Value = m.Text; meshnode.Attributes.Append(name);
                mainNode.AppendChild(meshnode);
                foreach (Nud.Polygon p in m.Nodes)
                {
                    XmlNode      polyNode = doc.CreateElement("polygon");
                    XmlAttribute pid      = doc.CreateAttribute("id"); pid.Value = polyCount.ToString(); polyNode.Attributes.Append(pid);
                    meshnode.AppendChild(polyNode);

                    WriteMaterials(doc, p, polyNode);

                    polyCount++;
                }
            }
            polycount.Value = polyCount.ToString();

            doc.Save(filename);
        }
Beispiel #3
0
        private void SaveMaterialToFile(string fileName)
        {
            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(fileName);
        }
Beispiel #4
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.AddDefaultMaterial();
                    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.vertexIndices.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.uv.Add(vt[g.vt[i]] + Vector2.Zero);
                        }
                    }
                }
                if (m.Nodes.Count > 0)
                {
                    n.Nodes.Add(m);
                }
            }

            n.OptimizeFileSize();
            n.UpdateRenderMeshes();

            return(n);
        }
Beispiel #5
0
        public static void ArrangeBones(VBN vbn, Nud nud)
        {
            Dictionary <int, int> boneReorder = new Dictionary <int, int>();
            int i = 0;

            for (i = 0; i < boneOrder.Count; i++)
            {
                int j = 0;
                for (j = 0; j < vbn.bones.Count; j++)
                {
                    if (vbn.bones[j].Text.Equals(boneOrder[i]))
                    {
                        break;
                    }
                }

                boneReorder.Add(j, i);
            }
            // get rest of the bones
            for (int j = 0; j < vbn.bones.Count; j++)
            {
                if (!boneReorder.Keys.Contains(j))
                {
                    boneReorder.Add(j, i++);
                }
            }

            // reorder vbn
            Bone[] nList = new Bone[vbn.bones.Count];
            foreach (int k in boneReorder.Keys)
            {
                nList[boneReorder[k]] = vbn.bones[k];
                //if (new string(vbn.bones[k].boneName).Equals("RotN")) vbn.bones[k].parentIndex = 0;
                if (vbn.bones[k].parentIndex != -1 && vbn.bones[k].parentIndex != 0x0FFFFFFF)
                {
                    vbn.bones[k].parentIndex = boneReorder[vbn.bones[k].parentIndex];
                }
            }
            vbn.bones.Clear();
            vbn.bones.AddRange(nList);
            vbn.reset();

            // now fix the nud

            foreach (Nud.Mesh mesh in nud.Nodes)
            {
                foreach (Nud.Polygon poly in mesh.Nodes)
                {
                    foreach (Nud.Vertex v in poly.vertices)
                    {
                        for (int k = 0; k < v.boneIds.Count; k++)
                        {
                            v.boneIds[k] = boneReorder[v.boneIds[k]];
                        }
                    }
                }
            }
            nud.UpdateRenderMeshes();
        }
Beispiel #6
0
        private static void SaveNudXml(string sourceDir, string outputDir, string file)
        {
            string xmlName        = ModelViewport.ConvertDirSeparatorsToUnderscore(file, sourceDir);
            Nud    nud            = new Nud(file);
            string outputFileName = $"{ outputDir }\\{ xmlName }.xml";

            MaterialXML.ExportMaterialAsXml(nud, outputFileName);
        }
Beispiel #7
0
 private void SetFineAdjustmentNUD(Nud nud, string title, double min, double max)
 {
     gbFineAdjustment.Visible = true;
     fineAdjustmentRange.Min  = min;
     fineAdjustmentRange.Max  = max;
     fineAdjustmentsNud       = nud;
     gbFineAdjustment.Text    = title;
     fineAdjustmentFactor     = nud == nudIB || nud == nudTE ? 100 : 1;
 }
Beispiel #8
0
 private void setBackColorDependingOnNeutral(Nud nud, Color color, decimal neutralNumber = 0)
 {
     if (nud.Value != neutralNumber)
     {
         nud.BackColor = color;
     }
     else
     {
         nud.BackColor = SystemColors.Window;
     }
 }
Beispiel #9
0
        public Nud toNUD()
        {
            Nud nud = new Nud();
            int j   = 0;

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

                    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.color = v.col;
                            List <Vector2> uvs = new List <Vector2>();
                            uvs.Add(new Vector2(v.tx[0].X, 1 - v.tx[0].Y));
                            vert.uv = uvs;
                            if (vert.boneWeights.Count < 4)
                            {
                                v.weight.Add(0f);
                                v.weight.Add(0f);
                            }
                            vert.boneWeights = v.weight;
                            List <int> nodez = new List <int>();
                            nodez.Add(m.nodeList[0][v.node[0]]);
                            nodez.Add(m.nodeList[0][v.node[1]]);
                            nodez.Add(0);
                            nodez.Add(0);
                            vert.boneIds = nodez;
                            poly.AddVertex(vert);
                        }

                        poly.vertexIndices.Add(indexSim.IndexOf(v));
                    }
                }
            }
            return(nud);
        }
Beispiel #10
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"))
                {
                    NutTexture tex = new Dds(new FileData(b)).ToNutTexture();
                    nut.Nodes.Add(tex);
                    tex.HashId = 0x40000000 + randomNumber;
                    nut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(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.UpdateRenderMeshes();

            return(nud);
        }
Beispiel #11
0
 private void setBackColorDependingOnNeutral(Nud nud1, Color color1, Nud nud2, Color color2, decimal neutralNumber = 0)
 {
     if (nud1.Value != neutralNumber && nud2.Value != neutralNumber)
     {
         nud1.BackColor = color1;
         nud2.BackColor = color2;
     }
     else
     {
         nud1.BackColor = SystemColors.Window;
         nud2.BackColor = SystemColors.Window;
     }
 }
Beispiel #12
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();
 }
Beispiel #13
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);
        }
Beispiel #14
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);
            }
        }
Beispiel #15
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);
        }
Beispiel #16
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);
        }
Beispiel #17
0
        public static void DrawNudMaterialSphere(Shader shader, Nud.Material material, Mesh3D screenTriangle, Dictionary <NudEnums.DummyTexture, Texture> dummyTextures)
        {
            if (!shader.LinkStatusIsOk)
            {
                return;
            }

            shader.UseProgram();

            // Use the same uniforms as the NUD shader.
            var uniformBlock = new UniformBlock(shader, "MaterialProperties")
            {
                BlockBinding = 1
            };

            NudUniforms.SetMaterialPropertyUniforms(uniformBlock, shader, material);

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

            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, 15);
            shader.SetTexture("uvTex", sphereUvTex, 16);
            shader.SetTexture("tanTex", sphereTanTex, 17);
            shader.SetTexture("bitanTex", sphereBitanTex, 18);

            // Draw full screen "quad" (big triangle)
            ScreenDrawing.DrawScreenTriangle(shader, screenTriangle);
        }
Beispiel #18
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();
        }
Beispiel #19
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;
                }
            }
        }
Beispiel #20
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();
        }
Beispiel #21
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.Nodes.Count);
             * foreach (NUD.Mesh nudmesh in n.Nodes)
             * {
             *  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();*/
        }
Beispiel #22
0
        public void Apply(Nud nud)
        {
            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 (Collada.HasInitialUnderscoreId(mesh.Text))
                    {
                        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)
                {
                    mesh.Text = Collada.RemoveInitialUnderscoreId(mesh.Text);
                }

                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);
                        }
                    }
                }
            }

            // Wait until after the model is rotated.
            nud.GenerateBoundingSpheres();
        }
Beispiel #23
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.tType = 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");*/
        }
Beispiel #24
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]).vertexIndices.Add(((Nud.Polygon)mes.Nodes[0]).vertices.Count);
                            ((Nud.Polygon)mes.Nodes[0]).vertices.Add(vert);
                        }
                    }
                }
            }

            nud.OptimizeFileSize();
            nud.UpdateRenderMeshes();
            return(nud);
        }
Beispiel #25
0
 public MakeMetal(Nud nud)
 {
     InitializeComponent();
     this.nud = nud;
 }