Ejemplo n.º 1
0
            public Strip Clone()
            {
                Strip result = (Strip)MemberwiseClone();

                result.Indexes = (ushort[])Indexes.Clone();
                if (UVs != null)
                {
                    result.UVs = new UV[UVs.Length];
                    for (int i = 0; i < UVs.Length; i++)
                    {
                        result.UVs[i] = UVs[i].Clone();
                    }
                }
                if (VColors != null)
                {
                    result.VColors = (Color[])VColors.Clone();
                }
                if (UserFlags1 != null)
                {
                    result.UserFlags1 = (ushort[])UserFlags1.Clone();
                }
                if (UserFlags2 != null)
                {
                    result.UserFlags2 = (ushort[])UserFlags2.Clone();
                }
                if (UserFlags3 != null)
                {
                    result.UserFlags3 = (ushort[])UserFlags3.Clone();
                }
                return(result);
            }
Ejemplo n.º 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.FromArgb(mesh.VColor[currentstriptotal].R, mesh.VColor[currentstriptotal].G, mesh.VColor[currentstriptotal].B)  : 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();
        }
Ejemplo n.º 3
0
            public override Poly Clone()
            {
                Strip result = (Strip)base.Clone();

                if (result.UserFlags1 != null)
                {
                    result.UserFlags1 = (ushort[])UserFlags1.Clone();
                }
                if (result.UserFlags2 != null)
                {
                    result.UserFlags2 = (ushort[])UserFlags2.Clone();
                }
                if (result.UserFlags3 != null)
                {
                    result.UserFlags3 = (ushort[])UserFlags3.Clone();
                }
                return(result);
            }
Ejemplo n.º 4
0
        public PolyChunkStrip(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);
            int stripCount = Header2 & 0x3FFF;

            Strips = new List <Strip>(stripCount);
            for (int i = 0; i < stripCount; i++)
            {
                Strip str = new Strip(file, address, Type, UserFlags);
                Strips.Add(str);
                address += str.Size;
            }
        }
Ejemplo n.º 5
0
        private List <MeshInfo> ProcessPolyList(string name, List <PolyChunk> strips, int start)
        {
            List <MeshInfo> result = new List <MeshInfo>();

            for (int i = start; i < strips.Count; i++)
            {
                PolyChunk chunk = strips[i];
                MaterialBuffer.UpdateFromPolyChunk(chunk);
                switch (chunk.Type)
                {
                case ChunkType.Bits_CachePolygonList:
                    byte cachenum = ((PolyChunkBitsCachePolygonList)chunk).List;
#if modellog
                    Extensions.Log("Caching Poly List " + name + "[" + (i + 1) + "] to cache #" + cachenum + Environment.NewLine);
#endif
                    PolyCache[cachenum] = new CachedPoly(name, strips, i + 1);
                    return(result);

                case ChunkType.Bits_DrawPolygonList:
                    cachenum = ((PolyChunkBitsDrawPolygonList)chunk).List;
                    CachedPoly cached = PolyCache[cachenum];
#if modellog
                    Extensions.Log("Drawing Poly List " + cached.Name + "[" + cached.Index + "] from cache #" + cachenum + Environment.NewLine);
#endif
                    result.AddRange(ProcessPolyList(cached.Name, cached.Polys, cached.Index));
                    break;

                case ChunkType.Strip_Strip:
                case ChunkType.Strip_StripUVN:
                case ChunkType.Strip_StripUVH:
                case ChunkType.Strip_StripNormal:
                case ChunkType.Strip_StripUVNNormal:
                case ChunkType.Strip_StripUVHNormal:
                case ChunkType.Strip_StripColor:
                case ChunkType.Strip_StripUVNColor:
                case ChunkType.Strip_StripUVHColor:
                case ChunkType.Strip_Strip2:
                case ChunkType.Strip_StripUVN2:
                case ChunkType.Strip_StripUVH2:
                {
                    PolyChunkStrip c2 = (PolyChunkStrip)chunk;
#if modellog
                    Extensions.Log("Strip " + c2.Type + Environment.NewLine);
#endif
                    bool hasVColor = false;
                    switch (chunk.Type)
                    {
                    case ChunkType.Strip_StripColor:
                    case ChunkType.Strip_StripUVNColor:
                    case ChunkType.Strip_StripUVHColor:
                        hasVColor = true;
                        break;
                    }
                    bool hasUV = false;
                    switch (chunk.Type)
                    {
                    case ChunkType.Strip_StripUVN:
                    case ChunkType.Strip_StripUVH:
                    case ChunkType.Strip_StripUVNColor:
                    case ChunkType.Strip_StripUVHColor:
                    case ChunkType.Strip_StripUVN2:
                    case ChunkType.Strip_StripUVH2:
                        hasUV = true;
                        break;
                    }
                    List <Poly>       polys = new List <Poly>();
                    List <VertexData> verts = new List <VertexData>();
#if modellog
                    List <ushort> indexes = new List <ushort>();
#endif
                    foreach (PolyChunkStrip.Strip strip in c2.Strips)
                    {
#if modellog
                        indexes.AddRange(strip.Indexes);
#endif
                        Strip str = new Strip(strip.Indexes.Length, strip.Reversed);
                        for (int k = 0; k < strip.Indexes.Length; k++)
                        {
                            str.Indexes[k] = (ushort)verts.Count;
                            verts.Add(new VertexData(
                                          VertexBuffer[strip.Indexes[k]].Position,
                                          VertexBuffer[strip.Indexes[k]].Normal,
                                          hasVColor ? (Color?)strip.VColors[k] : VertexBuffer[strip.Indexes[k]].Color,
                                          hasUV ? strip.UVs[k] : null));
                        }
                        polys.Add(str);
                    }
                    if (!hasVColor)
                    {
                        hasVColor = verts.Any(a => a.Color.HasValue && a.Color.Value != Color.White);
                    }
#if modellog
                    indexes = new List <ushort>(System.Linq.Enumerable.Distinct(indexes));
                    indexes.Sort();
                    StringBuilder sb  = new StringBuilder("Vertex Usage: ");
                    ushort        ist = indexes[0];
                    for (int k = 0; k < indexes.Count - 1; k++)
                    {
                        if (indexes[k + 1] != indexes[k] + 1)
                        {
                            sb.Append(" " + ist);
                            if (indexes[k] != ist)
                            {
                                sb.Append("-" + indexes[k]);
                            }
                            ist = indexes[++k];
                        }
                    }
                    sb.Append(" " + ist);
                    if (indexes[indexes.Count - 1] != ist)
                    {
                        sb.Append("-" + indexes[indexes.Count - 1]);
                    }
                    sb.Append(Environment.NewLine);
                    Extensions.Log(sb.ToString());
#endif
                    result.Add(new MeshInfo(MaterialBuffer, polys.ToArray(), verts.ToArray(), hasUV, hasVColor));
                    MaterialBuffer = new NJS_MATERIAL(MaterialBuffer);
                }
                break;
                }
            }
            return(result);
        }
Ejemplo n.º 6
0
        public override void ProcessShapeMotionVertexData(NJS_MOTION motion, float 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();
        }
Ejemplo n.º 7
0
        public void ToNJA(TextWriter writer, 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.ToNJA());
                        }
                        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("[]");
                        writer.WriteLine("START");
                        List <string> uvs = new List <string>(Mesh[i].UV.Length);
                        foreach (UV item in Mesh[i].UV)
                        {
                            uvs.Add(item.ToNJA());
                        }
                        writer.WriteLine("\t" + string.Join("," + Environment.NewLine + "\t", uvs.ToArray()) + ",");
                        writer.WriteLine("END");
                        writer.WriteLine();
                    }
                }
                labels.Add(MeshName);
                writer.Write("MESHSET");
                writer.Write("     ");
                writer.Write(MeshName);
                writer.WriteLine("[]");
                writer.WriteLine("START");
                writer.WriteLine();
                List <string> mshs = new List <string>(Mesh.Count);
                foreach (NJS_MESHSET item in Mesh)
                {
                    mshs.Add(item.ToNJA());
                }
                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.ToNJA());
                }
                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.ToNJA());
                }
                writer.WriteLine("\t" + string.Join("," + Environment.NewLine + "\t", vtxs.ToArray()) + ",");
                writer.WriteLine("END");
                writer.WriteLine();
            }
            writer.Write("MODEL");
            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.ToNJA() + ", " + Bounds.Center.Y.ToNJA() + ", " + Bounds.Center.Z.ToNJA() + ",");
            writer.WriteLine("Radius      " + Bounds.Radius.ToNJA() + ",");
            writer.WriteLine("END" + Environment.NewLine);
        }