예제 #1
0
파일: PolyChunk.cs 프로젝트: inrg/sa_tools
            public virtual Poly Clone()
            {
                Poly result = (Poly)MemberwiseClone();

                Indexes = (ushort[])Indexes.Clone();
                return(result);
            }
예제 #2
0
        public override void ProcessVertexData()
        {
            List <MeshInfo> result = new List <MeshInfo>();

            foreach (NJS_MESHSET mesh in Mesh)
            {
                bool              hasVColor = mesh.VColor != null;
                bool              hasUV     = mesh.UV != null;
                List <Poly>       polys     = new List <Poly>();
                List <VertexData> verts     = new List <VertexData>();
                int currentstriptotal       = 0;
                foreach (Poly poly in mesh.Poly)
                {
                    Poly newpoly = null;
                    switch (mesh.PolyType)
                    {
                    case Basic_PolyType.Triangles:
                        newpoly = new Triangle();
                        break;

                    case Basic_PolyType.Quads:
                        newpoly = new Quad();
                        break;

                    case Basic_PolyType.NPoly:
                    case Basic_PolyType.Strips:
                        newpoly = new Strip(poly.Indexes.Length, ((Strip)poly).Reversed);
                        break;
                    }
                    for (int i = 0; i < poly.Indexes.Length; i++)
                    {
                        newpoly.Indexes[i] = (ushort)verts.Count;
                        verts.Add(new VertexData(
                                      Vertex[poly.Indexes[i]],
                                      Normal[poly.Indexes[i]],
                                      hasVColor ? (Color?)mesh.VColor[currentstriptotal] : null,
                                      hasUV ? mesh.UV[currentstriptotal++] : null));
                    }
                    polys.Add(newpoly);
                }
                NJS_MATERIAL mat = null;
                if (Material != null && mesh.MaterialID < Material.Count)
                {
                    mat = Material[mesh.MaterialID];
                }
                result.Add(new MeshInfo(mat, polys.ToArray(), verts.ToArray(), hasUV, hasVColor));
            }
            MeshInfo = result.ToArray();
        }
예제 #3
0
 public PolyChunkVolume(byte[] file, int address)
 {
     Header   = ByteConverter.ToUInt16(file, address);
     address += sizeof(ushort);
     Size     = ByteConverter.ToUInt16(file, address);
     address += sizeof(ushort);
     Header2  = ByteConverter.ToUInt16(file, address);
     address += sizeof(ushort);
     Polys    = new List <Poly>(PolyCount);
     for (int i = 0; i < PolyCount; i++)
     {
         Poly str = Poly.CreatePoly(Type, file, address, UserFlags);
         Polys.Add(str);
         address += str.Size;
     }
 }
예제 #4
0
        public NJS_MESHSET(Basic_PolyType polyType, int polyCount, bool hasPolyNormal, bool hasUV, bool hasVColor)
        {
            if (polyType == Basic_PolyType.NPoly | polyType == Basic_PolyType.Strips)
            {
                throw new ArgumentException("Cannot create a Poly of that type!\nTry another overload to create Strip-type Polys.", "polyType");
            }
            PolyName = "poly_" + Extensions.GenerateIdentifier();
            PolyType = polyType;
            Poly[] polys      = new Poly[polyCount];
            int    striptotal = 0;

            for (int i = 0; i < polys.Length; i++)
            {
                polys[i]    = SAModel.Poly.CreatePoly(PolyType);
                striptotal += polys[i].Indexes.Length;
            }
            Poly = new ReadOnlyCollection <Poly>(polys);
            if (hasPolyNormal)
            {
                PolyNormalName = "polynormal_" + Extensions.GenerateIdentifier();
                PolyNormal     = new Vertex[polys.Length];
                for (int i = 0; i < polys.Length; i++)
                {
                    PolyNormal[i] = new Vertex();
                }
            }
            if (hasVColor)
            {
                VColorName = "vcolor_" + Extensions.GenerateIdentifier();
                VColor     = new Color[striptotal];
            }
            if (hasUV)
            {
                UVName = "uv_" + Extensions.GenerateIdentifier();
                UV     = new UV[striptotal];
                for (int i = 0; i < striptotal; i++)
                {
                    UV[i] = new UV();
                }
            }
        }
예제 #5
0
        public override void ProcessShapeMotionVertexData(NJS_MOTION motion, int frame, int animindex)
        {
            if (!motion.Models.ContainsKey(animindex))
            {
                ProcessVertexData();
                return;
            }
            Vertex[]      vertdata = Vertex;
            Vertex[]      normdata = Normal;
            AnimModelData data     = motion.Models[animindex];

            if (data.Vertex.Count > 0)
            {
                vertdata = data.GetVertex(frame);
            }
            if (data.Normal.Count > 0)
            {
                normdata = data.GetNormal(frame);
            }
            List <MeshInfo> result = new List <MeshInfo>();

            foreach (NJS_MESHSET mesh in Mesh)
            {
                bool              hasVColor = mesh.VColor != null;
                bool              hasUV     = mesh.UV != null;
                List <Poly>       polys     = new List <Poly>();
                List <VertexData> verts     = new List <VertexData>();
                int currentstriptotal       = 0;
                foreach (Poly poly in mesh.Poly)
                {
                    Poly newpoly = null;
                    switch (mesh.PolyType)
                    {
                    case Basic_PolyType.Triangles:
                        newpoly = new Triangle();
                        break;

                    case Basic_PolyType.Quads:
                        newpoly = new Quad();
                        break;

                    case Basic_PolyType.NPoly:
                    case Basic_PolyType.Strips:
                        newpoly = new Strip(poly.Indexes.Length, ((Strip)poly).Reversed);
                        break;
                    }
                    for (int i = 0; i < poly.Indexes.Length; i++)
                    {
                        newpoly.Indexes[i] = (ushort)verts.Count;
                        verts.Add(new VertexData(
                                      vertdata[poly.Indexes[i]],
                                      normdata[poly.Indexes[i]],
                                      hasVColor ? (Color?)mesh.VColor[currentstriptotal] : null,
                                      hasUV ? mesh.UV[currentstriptotal++] : null));
                    }
                    polys.Add(newpoly);
                }
                NJS_MATERIAL mat = null;
                if (Material != null && mesh.MaterialID < Material.Count)
                {
                    mat = Material[mesh.MaterialID];
                }
                result.Add(new MeshInfo(mat, polys.ToArray(), verts.ToArray(), hasUV, hasVColor));
            }
            MeshInfo = result.ToArray();
        }
예제 #6
0
        public NJS_MESHSET(byte[] file, int address, uint imageBase, Dictionary <int, string> labels)
        {
            MaterialID  = ByteConverter.ToUInt16(file, address);
            PolyType    = (Basic_PolyType)(MaterialID >> 0xE);
            MaterialID &= 0x3FFF;
            Poly[] polys   = new Poly[ByteConverter.ToInt16(file, address + 2)];
            int    tmpaddr = (int)(ByteConverter.ToUInt32(file, address + 4) - imageBase);

            if (labels.ContainsKey(tmpaddr))
            {
                PolyName = labels[tmpaddr];
            }
            else
            {
                PolyName = "poly_" + tmpaddr.ToString("X8");
            }
            int striptotal = 0;

            for (int i = 0; i < polys.Length; i++)
            {
                polys[i]    = SAModel.Poly.CreatePoly(PolyType, file, tmpaddr);
                striptotal += polys[i].Indexes.Length;
                tmpaddr    += polys[i].Size;
            }
            Poly    = new ReadOnlyCollection <Poly>(polys);
            PAttr   = ByteConverter.ToInt32(file, address + 8);
            tmpaddr = ByteConverter.ToInt32(file, address + 0xC);
            if (tmpaddr != 0)
            {
                tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                if (labels.ContainsKey(tmpaddr))
                {
                    PolyNormalName = labels[tmpaddr];
                }
                else
                {
                    PolyNormalName = "polynormal_" + tmpaddr.ToString("X8");
                }
                PolyNormal = new Vertex[polys.Length];
                for (int i = 0; i < polys.Length; i++)
                {
                    PolyNormal[i] = new Vertex(file, tmpaddr);
                    tmpaddr      += Vertex.Size;
                }
            }
            else
            {
                PolyNormalName = "polynormal_" + Extensions.GenerateIdentifier();
            }
            tmpaddr = ByteConverter.ToInt32(file, address + 0x10);
            if (tmpaddr != 0)
            {
                tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                if (labels.ContainsKey(tmpaddr))
                {
                    VColorName = labels[tmpaddr];
                }
                else
                {
                    VColorName = "vcolor_" + tmpaddr.ToString("X8");
                }
                VColor = new Color[striptotal];
                for (int i = 0; i < striptotal; i++)
                {
                    VColor[i] = SAModel.VColor.FromBytes(file, tmpaddr);
                    tmpaddr  += SAModel.VColor.Size(ColorType.ARGB8888_32);
                }
            }
            else
            {
                VColorName = "vcolor_" + Extensions.GenerateIdentifier();
            }
            tmpaddr = ByteConverter.ToInt32(file, address + 0x14);
            if (tmpaddr != 0)
            {
                tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                if (labels.ContainsKey(tmpaddr))
                {
                    UVName = labels[tmpaddr];
                }
                else
                {
                    UVName = "uv_" + tmpaddr.ToString("X8");
                }
                UV = new UV[striptotal];
                for (int i = 0; i < striptotal; i++)
                {
                    UV[i]    = new UV(file, tmpaddr);
                    tmpaddr += SAModel.UV.Size;
                }
            }
            else
            {
                UVName = "uv_" + Extensions.GenerateIdentifier();
            }
        }
예제 #7
0
        public void ToNJA(TextWriter writer, bool DX, List <string> labels, string[] textures)
        {
            if (Material != null && Material.Count > 0 && !labels.Contains(MaterialName))
            {
                labels.Add(MaterialName);
                writer.Write("MATERIAL ");
                writer.Write(MaterialName + "[]" + Environment.NewLine);
                writer.WriteLine("START" + Environment.NewLine);
                List <string> mtls = new List <string>(Material.Count);
                foreach (NJS_MATERIAL item in Material)
                {
                    mtls.Add(item.ToNJA(textures));
                }
                writer.WriteLine(string.Join(Environment.NewLine, mtls.ToArray()));
                writer.WriteLine("END");
                writer.WriteLine();
            }
            if (!labels.Contains(MeshName))
            {
                for (int i = 0; i < Mesh.Count; i++)
                {
                    if (!labels.Contains(Mesh[i].PolyName))
                    {
                        labels.Add(Mesh[i].PolyName);
                        writer.Write("POLYGON ");
                        writer.Write(Mesh[i].PolyName);
                        writer.WriteLine("[]");
                        writer.WriteLine("START");

                        List <string> plys = new List <string>(Mesh[i].Poly.Count);
                        for (int p = 0; p < Mesh[i].Poly.Count; p++)
                        {
                            Poly item = Mesh[i].Poly[p];
                            if (item.PolyType == Basic_PolyType.Strips)
                            {
                                Strip strip = item as Strip;
                                plys.Add("Strip(" + (strip.Reversed ? "0x8000, " : "0x0,") + strip.Indexes.Length.ToString() + ")");
                                plys.Add(item.ToNJA());
                            }
                            else
                            {
                                plys.Add(item.ToNJA());
                            }
                        }
                        writer.WriteLine("\t" + string.Join("," + Environment.NewLine + "\t", plys.ToArray()));
                        writer.WriteLine("END");
                        writer.WriteLine();
                    }
                }
                for (int i = 0; i < Mesh.Count; i++)
                {
                    if (Mesh[i].PolyNormal != null && !labels.Contains(Mesh[i].PolyNormalName))
                    {
                        labels.Add(Mesh[i].PolyNormalName);
                        writer.Write("POLYNORMAL ");
                        writer.Write(Mesh[i].PolyNormalName);
                        writer.WriteLine("[]");
                        writer.WriteLine("START");
                        List <string> plys = new List <string>(Mesh[i].PolyNormal.Length);
                        foreach (Vertex item in Mesh[i].PolyNormal)
                        {
                            plys.Add("PNORM " + item.ToNJA());
                        }
                        writer.WriteLine("\t" + string.Join("," + Environment.NewLine + "\t", plys.ToArray()));
                        writer.WriteLine("END");
                        writer.WriteLine();
                    }
                }
                for (int i = 0; i < Mesh.Count; i++)
                {
                    if (Mesh[i].VColor != null && !labels.Contains(Mesh[i].VColorName))
                    {
                        labels.Add(Mesh[i].VColorName);
                        writer.Write("VERTCOLOR ");
                        writer.Write(Mesh[i].VColorName);
                        writer.WriteLine("[]");
                        writer.WriteLine("START");
                        List <string> vcs = new List <string>(Mesh[i].VColor.Length);
                        foreach (Color item in Mesh[i].VColor)
                        {
                            vcs.Add(item.ToStruct());
                        }
                        writer.WriteLine("\t" + string.Join("," + Environment.NewLine + "\t", vcs.ToArray()));
                        writer.WriteLine("END");
                        writer.WriteLine();
                    }
                }
                for (int i = 0; i < Mesh.Count; i++)
                {
                    if (Mesh[i].UV != null && !labels.Contains(Mesh[i].UVName))
                    {
                        labels.Add(Mesh[i].UVName);
                        writer.Write("VERTUV ");
                        writer.Write(Mesh[i].UVName);
                        writer.WriteLine("[] = {");
                        List <string> uvs = new List <string>(Mesh[i].UV.Length);
                        foreach (UV item in Mesh[i].UV)
                        {
                            uvs.Add(item.ToNJA());                             //someone check this out, i dont understand how it works
                        }
                        writer.WriteLine("\t" + string.Join("," + Environment.NewLine + "\t", uvs.ToArray()));
                        writer.WriteLine("END");
                        writer.WriteLine();
                    }
                }
                labels.Add(MeshName);
                writer.Write("MESHSET");
                if (DX)
                {
                    writer.Write("_SADX");
                }
                writer.Write(" ");
                writer.Write(MeshName);
                writer.WriteLine("[]");
                writer.WriteLine("START");
                List <string> mshs = new List <string>(Mesh.Count);
                foreach (NJS_MESHSET item in Mesh)
                {
                    mshs.Add(item.ToNJA(DX));
                }
                writer.WriteLine(string.Join(Environment.NewLine, mshs.ToArray()));
                writer.WriteLine("END");
                writer.WriteLine();
            }
            if (!labels.Contains(VertexName))
            {
                labels.Add(VertexName);
                writer.Write("POINT ");
                writer.Write(VertexName);
                writer.WriteLine("[]");
                writer.WriteLine("START");
                List <string> vtxs = new List <string>(Vertex.Length);
                foreach (Vertex item in Vertex)
                {
                    vtxs.Add("VERT " + (item != null ? item.ToNJA() : "{ 0 }"));
                }
                writer.WriteLine("\t" + string.Join("," + Environment.NewLine + "\t", vtxs.ToArray()));
                writer.WriteLine("END");
                writer.WriteLine();
            }
            if (Normal != null && !labels.Contains(NormalName))
            {
                labels.Add(VertexName);
                writer.Write("NORMAL ");
                writer.Write(NormalName);
                writer.WriteLine("[]");
                writer.WriteLine("START");
                List <string> vtxs = new List <string>(Normal.Length);
                foreach (Vertex item in Normal)
                {
                    vtxs.Add("NORM " + (item != null ? item.ToNJA() : "{ 0 }"));
                }
                writer.WriteLine("\t" + string.Join("," + Environment.NewLine + "\t", vtxs.ToArray()));
                writer.WriteLine("END");
                writer.WriteLine();
            }
            writer.Write("MODEL");
            if (DX)
            {
                writer.Write("_SADX");
            }
            writer.Write(" ");
            writer.Write(Name);
            writer.WriteLine("[]");
            writer.WriteLine("START");
            writer.WriteLine("Points " + VertexName + ",");
            writer.WriteLine("Normal " + NormalName + ",");
            writer.WriteLine("PointNum " + Vertex.Length + ",");
            writer.WriteLine("Meshset " + MeshName + ",");
            writer.WriteLine("Materials " + MaterialName + ",");
            writer.WriteLine("MeshsetNum " + Mesh.Count + ",");
            writer.WriteLine("MatNum " + Material.Count + ",");
            writer.WriteLine("Center " + Bounds.Center.X.ToC() + ", " + Bounds.Center.Y.ToC() + ", " + Bounds.Center.Z.ToC() + ",");
            writer.WriteLine("Radius " + Bounds.Radius.ToC() + ",");
            writer.WriteLine("END" + Environment.NewLine);
        }
예제 #8
0
 public NJS_MESHSET(Basic_PolyType polyType, int polyCount, bool hasPolyNormal, bool hasUV, bool hasVColor)
 {
     if (polyType == Basic_PolyType.NPoly | polyType == Basic_PolyType.Strips)
     {
         throw new ArgumentException("Cannot create a Poly of that type!\nTry another overload to create Strip-type Polys.", "polyType");
     }
     PolyName = "poly_" + Extensions.GenerateIdentifier();
     PolyType = polyType;
     Poly[] polys = new Poly[polyCount];
     int striptotal = 0;
     for (int i = 0; i < polys.Length; i++)
     {
         polys[i] = SAModel.Poly.CreatePoly(PolyType);
         striptotal += polys[i].Indexes.Length;
     }
     Poly = new ReadOnlyCollection<Poly>(polys);
     if (hasPolyNormal)
     {
         PolyNormalName = "polynormal_" + Extensions.GenerateIdentifier();
         PolyNormal = new Vertex[polys.Length];
         for (int i = 0; i < polys.Length; i++)
             PolyNormal[i] = new Vertex();
     }
     if (hasVColor)
     {
         VColorName = "vcolor_" + Extensions.GenerateIdentifier();
         VColor = new Color[striptotal];
     }
     if (hasUV)
     {
         UVName = "uv_" + Extensions.GenerateIdentifier();
         UV = new UV[striptotal];
         for (int i = 0; i < striptotal; i++)
             UV[i] = new UV();
     }
 }
예제 #9
0
 public NJS_MESHSET(byte[] file, int address, uint imageBase, Dictionary<int, string> labels)
 {
     MaterialID = ByteConverter.ToUInt16(file, address);
     PolyType = (Basic_PolyType)(MaterialID >> 0xE);
     MaterialID &= 0x3FFF;
     Poly[] polys = new Poly[ByteConverter.ToInt16(file, address + 2)];
     int tmpaddr = (int)(ByteConverter.ToUInt32(file, address + 4) - imageBase);
     if (labels.ContainsKey(tmpaddr))
         PolyName = labels[tmpaddr];
     else
         PolyName = "poly_" + tmpaddr.ToString("X8");
     int striptotal = 0;
     for (int i = 0; i < polys.Length; i++)
     {
         polys[i] = SAModel.Poly.CreatePoly(PolyType, file, tmpaddr);
         striptotal += polys[i].Indexes.Length;
         tmpaddr += polys[i].Size;
     }
     Poly = new ReadOnlyCollection<Poly>(polys);
     PAttr = ByteConverter.ToInt32(file, address + 8);
     tmpaddr = ByteConverter.ToInt32(file, address + 0xC);
     if (tmpaddr != 0)
     {
         tmpaddr = (int)unchecked((uint)tmpaddr - imageBase);
         if (labels.ContainsKey(tmpaddr))
             PolyNormalName = labels[tmpaddr];
         else
             PolyNormalName = "polynormal_" + tmpaddr.ToString("X8");
         PolyNormal = new Vertex[polys.Length];
         for (int i = 0; i < polys.Length; i++)
         {
             PolyNormal[i] = new Vertex(file, tmpaddr);
             tmpaddr += Vertex.Size;
         }
     }
     else
         PolyNormalName = "polynormal_" + Extensions.GenerateIdentifier();
     tmpaddr = ByteConverter.ToInt32(file, address + 0x10);
     if (tmpaddr != 0)
     {
         tmpaddr = (int)unchecked((uint)tmpaddr - imageBase);
         if (labels.ContainsKey(tmpaddr))
             VColorName = labels[tmpaddr];
         else
             VColorName = "vcolor_" + tmpaddr.ToString("X8");
         VColor = new Color[striptotal];
         for (int i = 0; i < striptotal; i++)
         {
             VColor[i] = SAModel.VColor.FromBytes(file, tmpaddr);
             tmpaddr += SAModel.VColor.Size(ColorType.ARGB8888_32);
         }
     }
     else
         VColorName = "vcolor_" + Extensions.GenerateIdentifier();
     tmpaddr = ByteConverter.ToInt32(file, address + 0x14);
     if (tmpaddr != 0)
     {
         tmpaddr = (int)unchecked((uint)tmpaddr - imageBase);
         if (labels.ContainsKey(tmpaddr))
             UVName = labels[tmpaddr];
         else
             UVName = "uv_" + tmpaddr.ToString("X8");
         UV = new UV[striptotal];
         for (int i = 0; i < striptotal; i++)
         {
             UV[i] = new UV(file, tmpaddr);
             tmpaddr += SAModel.UV.Size;
         }
     }
     else
         UVName = "uv_" + Extensions.GenerateIdentifier();
 }
예제 #10
0
 public NJS_MESHSET(Poly[] polys, bool hasPolyNormal, bool hasUV, bool hasVColor)
 {
     PolyName = "poly_" + Extensions.GenerateIdentifier();
     PolyType = polys[0].PolyType;
     int striptotal = 0;
     for (int i = 0; i < polys.Length; i++)
         striptotal += polys[i].Indexes.Length;
     Poly = new ReadOnlyCollection<Poly>(polys);
     if (hasVColor)
     {
         VColorName = "vcolor_" + Extensions.GenerateIdentifier();
         VColor = new Color[striptotal];
     }
     if (hasUV)
     {
         UVName = "uv_" + Extensions.GenerateIdentifier();
         UV = new UV[striptotal];
         for (int i = 0; i < striptotal; i++)
             UV[i] = new UV();
     }
 }