Example #1
0
 public PolyChunkMaterial(byte[] file, int address)
 {
     Header   = ByteConverter.ToUInt16(file, address);
     address += sizeof(ushort);
     Size     = ByteConverter.ToUInt16(file, address);
     address += sizeof(ushort);
     switch (Type)
     {
     case ChunkType.Material_Diffuse:
     case ChunkType.Material_DiffuseAmbient:
     case ChunkType.Material_DiffuseSpecular:
     case ChunkType.Material_DiffuseAmbientSpecular:
     case ChunkType.Material_Diffuse2:
     case ChunkType.Material_DiffuseAmbient2:
     case ChunkType.Material_DiffuseSpecular2:
     case ChunkType.Material_DiffuseAmbientSpecular2:
         Diffuse  = VColor.FromBytes(file, address, ColorType.ARGB8888_16);
         address += VColor.Size(ColorType.ARGB8888_16);
         break;
     }
     switch (Type)
     {
     case ChunkType.Material_Ambient:
     case ChunkType.Material_DiffuseAmbient:
     case ChunkType.Material_AmbientSpecular:
     case ChunkType.Material_DiffuseAmbientSpecular:
     case ChunkType.Material_Ambient2:
     case ChunkType.Material_DiffuseAmbient2:
     case ChunkType.Material_AmbientSpecular2:
     case ChunkType.Material_DiffuseAmbientSpecular2:
         Ambient  = VColor.FromBytes(file, address, ColorType.XRGB8888_16);
         address += VColor.Size(ColorType.XRGB8888_16);
         break;
     }
     switch (Type)
     {
     case ChunkType.Material_Specular:
     case ChunkType.Material_DiffuseSpecular:
     case ChunkType.Material_AmbientSpecular:
     case ChunkType.Material_DiffuseAmbientSpecular:
     case ChunkType.Material_Specular2:
     case ChunkType.Material_DiffuseSpecular2:
     case ChunkType.Material_AmbientSpecular2:
     case ChunkType.Material_DiffuseAmbientSpecular2:
         Specular         = VColor.FromBytes(file, address, ColorType.XRGB8888_16);
         SpecularExponent = (byte)(ByteConverter.ToUInt16(file, address + 2) >> 8);
         address         += VColor.Size(ColorType.XRGB8888_16);
         break;
     }
     switch (Type)
     {
     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:
         Second = true;
         break;
     }
 }
Example #2
0
        public VertexChunk(byte[] file, int address)
            : this()
        {
            Header1 = ByteConverter.ToUInt32(file, address);
            Header2 = ByteConverter.ToUInt32(file, address + 4);
            address = address + 8;
            for (int i = 0; i < VertexCount; i++)
            {
                switch (Type)
                {
                case ChunkType.Vertex_VertexSH:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size + sizeof(float);
                    break;

                case ChunkType.Vertex_VertexNormalSH:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size + sizeof(float);
                    Normals.Add(new Vertex(file, address));
                    address += Vertex.Size + sizeof(float);
                    break;

                case ChunkType.Vertex_Vertex:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    break;

                case ChunkType.Vertex_VertexDiffuse8:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    Diffuse.Add(VColor.FromBytes(file, address, ColorType.ARGB8888_32));
                    address += VColor.Size(ColorType.ARGB8888_32);
                    break;

                case ChunkType.Vertex_VertexUserFlags:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    UserFlags.Add(ByteConverter.ToUInt32(file, address));
                    address += sizeof(uint);
                    break;

                case ChunkType.Vertex_VertexNinjaFlags:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    NinjaFlags.Add(ByteConverter.ToUInt32(file, address));
                    address += sizeof(uint);
                    break;

                case ChunkType.Vertex_VertexDiffuseSpecular5:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    uint tmpcolor = ByteConverter.ToUInt32(file, address);
                    address += sizeof(uint);
                    Diffuse.Add(VColor.FromBytes(ByteConverter.GetBytes((ushort)(tmpcolor & 0xFFFF)), 0, ColorType.RGB565));
                    Specular.Add(VColor.FromBytes(ByteConverter.GetBytes((ushort)(tmpcolor >> 16)), 0, ColorType.RGB565));
                    break;

                case ChunkType.Vertex_VertexDiffuseSpecular4:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    tmpcolor = ByteConverter.ToUInt32(file, address);
                    address += sizeof(uint);
                    Diffuse.Add(VColor.FromBytes(ByteConverter.GetBytes((ushort)(tmpcolor & 0xFFFF)), 0, ColorType.ARGB4444));
                    Specular.Add(VColor.FromBytes(ByteConverter.GetBytes((ushort)(tmpcolor >> 16)), 0, ColorType.RGB565));
                    break;

                case ChunkType.Vertex_VertexNormal:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    Normals.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    break;

                case ChunkType.Vertex_VertexNormalDiffuse8:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    Normals.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    Diffuse.Add(VColor.FromBytes(file, address, ColorType.ARGB8888_32));
                    address += VColor.Size(ColorType.ARGB8888_32);
                    break;

                case ChunkType.Vertex_VertexNormalUserFlags:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    Normals.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    UserFlags.Add(ByteConverter.ToUInt32(file, address));
                    address += sizeof(uint);
                    break;

                case ChunkType.Vertex_VertexNormalNinjaFlags:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    Normals.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    NinjaFlags.Add(ByteConverter.ToUInt32(file, address));
                    address += sizeof(uint);
                    break;

                case ChunkType.Vertex_VertexNormalDiffuseSpecular5:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    Normals.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    tmpcolor = ByteConverter.ToUInt32(file, address);
                    address += sizeof(uint);
                    Diffuse.Add(VColor.FromBytes(ByteConverter.GetBytes((ushort)(tmpcolor & 0xFFFF)), 0, ColorType.RGB565));
                    Specular.Add(VColor.FromBytes(ByteConverter.GetBytes((ushort)(tmpcolor >> 16)), 0, ColorType.RGB565));
                    break;

                case ChunkType.Vertex_VertexNormalDiffuseSpecular4:
                    Vertices.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    Normals.Add(new Vertex(file, address));
                    address += Vertex.Size;
                    tmpcolor = ByteConverter.ToUInt32(file, address);
                    address += sizeof(uint);
                    Diffuse.Add(VColor.FromBytes(ByteConverter.GetBytes((ushort)(tmpcolor & 0xFFFF)), 0, ColorType.ARGB4444));
                    Specular.Add(VColor.FromBytes(ByteConverter.GetBytes((ushort)(tmpcolor >> 16)), 0, ColorType.RGB565));
                    break;

                default:
                    throw new NotSupportedException("Unsupported chunk type " + Type + " at " + address.ToString("X8") + ".");
                }
            }
        }
Example #3
0
            public Strip(byte[] file, int address, ChunkType type, byte userFlags)
            {
                Indexes  = new ushort[Math.Abs(ByteConverter.ToInt16(file, address))];
                Reversed = (ByteConverter.ToUInt16(file, address) & 0x8000) == 0x8000;
                address += 2;
                switch (type)
                {
                case ChunkType.Strip_StripUVN:
                case ChunkType.Strip_StripUVH:
                case ChunkType.Strip_StripUVN2:
                case ChunkType.Strip_StripUVH2:
                    UVs = new UV[Indexes.Length];
                    break;

                case ChunkType.Strip_StripColor:
                    VColors = new Color[Indexes.Length];
                    break;

                case ChunkType.Strip_StripUVNColor:
                case ChunkType.Strip_StripUVHColor:
                    UVs     = new UV[Indexes.Length];
                    VColors = new Color[Indexes.Length];
                    break;
                }
                if (userFlags > 0)
                {
                    UserFlags1 = new ushort[Indexes.Length - 2];
                }
                if (userFlags > 1)
                {
                    UserFlags2 = new ushort[Indexes.Length - 2];
                }
                if (userFlags > 2)
                {
                    UserFlags3 = new ushort[Indexes.Length - 2];
                }
                for (int i = 0; i < Indexes.Length; i++)
                {
                    Indexes[i] = ByteConverter.ToUInt16(file, address);
                    address   += 2;
                    switch (type)
                    {
                    case ChunkType.Strip_StripUVN:
                    case ChunkType.Strip_StripUVNColor:
                    case ChunkType.Strip_StripUVN2:
                        UVs[i]   = new UV(file, address, false);
                        address += UV.Size;
                        break;

                    case ChunkType.Strip_StripUVH:
                    case ChunkType.Strip_StripUVHColor:
                    case ChunkType.Strip_StripUVH2:
                        UVs[i]   = new UV(file, address, true);
                        address += UV.Size;
                        break;
                    }
                    switch (type)
                    {
                    case ChunkType.Strip_StripColor:
                    case ChunkType.Strip_StripUVNColor:
                    case ChunkType.Strip_StripUVHColor:
                        VColors[i] = VColor.FromBytes(file, address, ColorType.ARGB8888_16);
                        address   += VColor.Size(ColorType.ARGB8888_16);
                        break;
                    }
                    if (i > 1)
                    {
                        if (userFlags > 0)
                        {
                            UserFlags1[i - 2] = ByteConverter.ToUInt16(file, address);
                            address          += 2;
                            if (userFlags > 1)
                            {
                                UserFlags2[i - 2] = ByteConverter.ToUInt16(file, address);
                                address          += 2;
                                if (userFlags > 2)
                                {
                                    UserFlags3[i - 2] = ByteConverter.ToUInt16(file, address);
                                    address          += 2;
                                }
                            }
                        }
                    }
                }
            }