Exemplo 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);
            }
Exemplo 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?)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();
        }
Exemplo 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);
            }
Exemplo 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;
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 6
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("[] = {");
                writer.WriteLine("START");
                List <string> mtls = new List <string>(Material.Count);
                foreach (NJS_MATERIAL item in Material)
                {
                    mtls.Add(item.ToNJA(textures));
                }
                writer.WriteLine("\t" + string.Join("," + Environment.NewLine + "\t", 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);
                        foreach (Poly item in Mesh[i].Poly)
                        {
                            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.ToStruct());
                        }
                        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("\t" + string.Join("," + Environment.NewLine + "\t", 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 + "," + Bounds.Center.Y + "," + Bounds.Center.Z + ",");
            writer.WriteLine("Radius " + Bounds.Radius + ",");
            writer.WriteLine("END");
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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;
     }
 }
Exemplo n.º 9
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];
                switch (chunk.Type)
                {
                case ChunkType.Bits_BlendAlpha:
                {
                    PolyChunkBitsBlendAlpha c2 = (PolyChunkBitsBlendAlpha)chunk;
                    MaterialBuffer.SourceAlpha      = c2.SourceAlpha;
                    MaterialBuffer.DestinationAlpha = c2.DestinationAlpha;
                }
                break;

                case ChunkType.Bits_MipmapDAdjust:
                    break;

                case ChunkType.Bits_SpecularExponent:
                    MaterialBuffer.Exponent = ((PolyChunkBitsSpecularExponent)chunk).SpecularExponent;
                    break;

                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.Tiny_TextureID:
                case ChunkType.Tiny_TextureID2:
                {
                    PolyChunkTinyTextureID c2 = (PolyChunkTinyTextureID)chunk;
                    MaterialBuffer.ClampU      = c2.ClampU;
                    MaterialBuffer.ClampV      = c2.ClampV;
                    MaterialBuffer.FilterMode  = c2.FilterMode;
                    MaterialBuffer.FlipU       = c2.FlipU;
                    MaterialBuffer.FlipV       = c2.FlipV;
                    MaterialBuffer.SuperSample = c2.SuperSample;
                    MaterialBuffer.TextureID   = c2.TextureID;
                }
                break;

                case ChunkType.Material_Diffuse:
                case ChunkType.Material_Ambient:
                case ChunkType.Material_DiffuseAmbient:
                case ChunkType.Material_Specular:
                case ChunkType.Material_DiffuseSpecular:
                case ChunkType.Material_AmbientSpecular:
                case ChunkType.Material_DiffuseAmbientSpecular:
                case ChunkType.Material_Diffuse2:
                case ChunkType.Material_Ambient2:
                case ChunkType.Material_DiffuseAmbient2:
                case ChunkType.Material_Specular2:
                case ChunkType.Material_DiffuseSpecular2:
                case ChunkType.Material_AmbientSpecular2:
                case ChunkType.Material_DiffuseAmbientSpecular2:
                {
                    PolyChunkMaterial c2 = (PolyChunkMaterial)chunk;
                    MaterialBuffer.SourceAlpha      = c2.SourceAlpha;
                    MaterialBuffer.DestinationAlpha = c2.DestinationAlpha;
                    if (c2.Diffuse.HasValue)
                    {
                        MaterialBuffer.DiffuseColor = c2.Diffuse.Value;
                    }
                    if (c2.Specular.HasValue)
                    {
                        MaterialBuffer.SpecularColor = c2.Specular.Value;
                        MaterialBuffer.Exponent      = c2.SpecularExponent;
                    }
                }
                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
                    MaterialBuffer.DoubleSided    = c2.DoubleSide;
                    MaterialBuffer.EnvironmentMap = c2.EnvironmentMapping;
                    MaterialBuffer.FlatShading    = c2.FlatShading;
                    MaterialBuffer.IgnoreLighting = c2.IgnoreLight;
                    MaterialBuffer.IgnoreSpecular = c2.IgnoreSpecular;
                    MaterialBuffer.UseAlpha       = c2.UseAlpha;
                    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 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);
        }
Exemplo n.º 10
0
 private List<MeshInfo> ProcessPolyList(List<PolyChunk> strips, int start)
 {
     List<MeshInfo> result = new List<MeshInfo>();
     for (int i = start; i < strips.Count; i++)
     {
         PolyChunk chunk = strips[i];
         switch (chunk.Type)
         {
             case ChunkType.Bits_BlendAlpha:
             {
                 PolyChunkBitsBlendAlpha c2 = (PolyChunkBitsBlendAlpha)chunk;
                 MaterialBuffer.SourceAlpha = c2.SourceAlpha;
                 MaterialBuffer.DestinationAlpha = c2.DestinationAlpha;
             }
                 break;
             case ChunkType.Bits_MipmapDAdjust:
                 break;
             case ChunkType.Bits_SpecularExponent:
                 MaterialBuffer.Exponent = ((PolyChunkBitsSpecularExponent)chunk).SpecularExponent;
                 break;
             case ChunkType.Bits_CachePolygonList:
                 PolyCache[((PolyChunkBitsCachePolygonList)chunk).List] = new CachedPoly(strips, i + 1);
                 return result;
             case ChunkType.Bits_DrawPolygonList:
                 byte cachenum = ((PolyChunkBitsDrawPolygonList)chunk).List;
                 CachedPoly cached = PolyCache[cachenum];
                 PolyCache[cachenum] = null;
                 result.AddRange(ProcessPolyList(cached.Polys, cached.Index));
                 break;
             case ChunkType.Tiny_TextureID:
             case ChunkType.Tiny_TextureID2:
             {
                 PolyChunkTinyTextureID c2 = (PolyChunkTinyTextureID)chunk;
                 MaterialBuffer.ClampU = c2.ClampU;
                 MaterialBuffer.ClampV = c2.ClampV;
                 MaterialBuffer.FilterMode = c2.FilterMode;
                 MaterialBuffer.FlipU = c2.FlipU;
                 MaterialBuffer.FlipV = c2.FlipV;
                 MaterialBuffer.SuperSample = c2.SuperSample;
                 MaterialBuffer.TextureID = c2.TextureID;
             }
                 break;
             case ChunkType.Material_Diffuse:
             case ChunkType.Material_Ambient:
             case ChunkType.Material_DiffuseAmbient:
             case ChunkType.Material_Specular:
             case ChunkType.Material_DiffuseSpecular:
             case ChunkType.Material_AmbientSpecular:
             case ChunkType.Material_DiffuseAmbientSpecular:
             case ChunkType.Material_Diffuse2:
             case ChunkType.Material_Ambient2:
             case ChunkType.Material_DiffuseAmbient2:
             case ChunkType.Material_Specular2:
             case ChunkType.Material_DiffuseSpecular2:
             case ChunkType.Material_AmbientSpecular2:
             case ChunkType.Material_DiffuseAmbientSpecular2:
             {
                 PolyChunkMaterial c2 = (PolyChunkMaterial)chunk;
                 if (c2.Diffuse.HasValue)
                     MaterialBuffer.DiffuseColor = c2.Diffuse.Value;
                 if (c2.Specular.HasValue)
                 {
                     MaterialBuffer.SpecularColor = c2.Specular.Value;
                     MaterialBuffer.Exponent = c2.SpecularExponent;
                 }
             }
                 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;
                 MaterialBuffer.DoubleSided = c2.DoubleSide;
                 MaterialBuffer.EnvironmentMap = c2.EnvironmentMapping;
                 MaterialBuffer.FlatShading = c2.FlatShading;
                 MaterialBuffer.IgnoreLighting = c2.IgnoreLight;
                 MaterialBuffer.IgnoreSpecular = c2.IgnoreSpecular;
                 MaterialBuffer.UseAlpha = c2.UseAlpha;
                 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>();
                 foreach (PolyChunkStrip.Strip strip in c2.Strips)
                 {
                     Strip str = new Strip(strip.Indexes.Length, strip.Reversed);
                     for (int k = 0; k < strip.Indexes.Length; k++)
                     {
                         str.Indexes[k] = (ushort)verts.AddUnique(new VertexData(
                             VertexBuffer[strip.Indexes[k]],
                             NormalBuffer[strip.Indexes[k]],
                             hasVColor ? (Color?)strip.VColors[k] : null,
                             hasUV ? strip.UVs[k] : null));
                     }
                     polys.Add(str);
                 }
                 result.Add(new MeshInfo(MaterialBuffer, polys.ToArray(), verts.ToArray(), hasUV, hasVColor));
                 MaterialBuffer = new NJS_MATERIAL(MaterialBuffer);
             }
                 break;
         }
     }
     return result;
 }
Exemplo n.º 11
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.AddUnique(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();
 }