Beispiel #1
0
        public bool Read(HSDReader Reader, HSD_AttributeGroup Attributes)
        {
            PrimitiveType = (GXPrimitiveType)Reader.ReadByte();
            if (PrimitiveType == 0)
            {
                return(false);
            }
            Count   = Reader.ReadUInt16();
            Indices = new GXIndexGroup[Count];
            for (int j = 0; j < Count; j++)
            {
                GXIndexGroup g = new GXIndexGroup();
                g.Indices = new ushort[Attributes.Attributes.Count];
                int i = 0;
                Indices[j] = g;
                foreach (GXVertexBuffer att in Attributes.Attributes)
                {
                    switch (att.AttributeType)
                    {
                    case GXAttribType.GX_DIRECT:
                        if (att.Name == GXAttribName.GX_VA_CLR0)
                        {
                            g.Clr0 = ReadGXClr(Reader, (int)att.CompType);
                        }
                        else if (att.Name == GXAttribName.GX_VA_CLR1)
                        {
                            g.Clr1 = ReadGXClr(Reader, (int)att.CompType);
                        }
                        else
                        {
                            g.Indices[i] = Reader.ReadByte();
                        }
                        break;

                    case GXAttribType.GX_INDEX8:
                        g.Indices[i] = Reader.ReadByte();
                        break;

                    case GXAttribType.GX_INDEX16:
                        g.Indices[i] = Reader.ReadUInt16();
                        break;
                    }
                    i++;
                }
            }
            return(true);
        }
Beispiel #2
0
        public void Write(HSDWriter Writer, HSD_AttributeGroup Attributes)
        {
            Writer.Write((byte)PrimitiveType);
            Writer.Write((ushort)Indices.Length);
            foreach (GXIndexGroup ig in Indices)
            {
                GXIndexGroup g = ig;
                int          i = 0;
                foreach (GXVertexBuffer att in Attributes.Attributes)
                {
                    switch (att.AttributeType)
                    {
                    case GXAttribType.GX_DIRECT:
                        if (att.Name != GXAttribName.GX_VA_CLR0)
                        {
                            Writer.Write((byte)g.Indices[i]);
                        }
                        else if (att.Name == GXAttribName.GX_VA_CLR0)
                        {
                            WriteGXClr(g.Clr0, Writer, att.CompType);
                        }
                        else if (att.Name == GXAttribName.GX_VA_CLR1)
                        {
                            WriteGXClr(g.Clr1, Writer, att.CompType);
                        }
                        break;

                    case GXAttribType.GX_INDEX8:
                        Writer.Write((byte)g.Indices[i]);
                        break;

                    case GXAttribType.GX_INDEX16:
                        Writer.Write(g.Indices[i]);
                        break;
                    }
                    i++;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a primitive group for the vertex buffer
        /// </summary>
        /// <param name="type"></param>
        /// <param name="Vertices"></param>
        /// <param name="Attributes"></param>
        /// <returns></returns>
        public GXPrimitiveGroup Compress(GXPrimitiveType type, GXVertex[] Vertices, HSD_AttributeGroup Attributes)
        {
            GXPrimitiveGroup g = new GXPrimitiveGroup();

            g.PrimitiveType = type;
            g.Indices       = new GXIndexGroup[Vertices.Length];
            int IndexGroupIndex = 0;

            foreach (GXVertex v in Vertices)
            {
                GXIndexGroup ig = new GXIndexGroup();
                ig.Indices = new ushort[Attributes.Attributes.Count];

                int i = 0;
                foreach (GXVertexBuffer b in Attributes.Attributes)
                {
                    switch (b.AttributeType)
                    {
                    case GXAttribType.GX_DIRECT:
                        if (b.Name == GXAttribName.GX_VA_CLR0)
                        {
                            ig.Clr0 = new byte[] { (byte)(v.Clr0.R * 0xFF), (byte)(v.Clr0.G * 0xFF), (byte)(v.Clr0.B * 0xFF), (byte)(v.Clr0.A * 0xFF) }
                        }
                        ;
                        else
                        if (b.Name == GXAttribName.GX_VA_CLR1)
                        {
                            ig.Clr1 = new byte[] { (byte)(v.Clr1.R * 0xFF), (byte)(v.Clr1.G * 0xFF), (byte)(v.Clr1.B * 0xFF), (byte)(v.Clr1.A * 0xFF) }
                        }
                        ;
                        else
                        if (b.Name == GXAttribName.GX_VA_PNMTXIDX)
                        {
                            ig.Indices[i] = v.PMXID;
                        }
                        if (b.Name == GXAttribName.GX_VA_TEX0MTXIDX)
                        {
                            ig.Indices[i] = v.TEX0MTXIDX;
                        }
                        break;

                    default:
                        switch (b.Name)
                        {
                        case GXAttribName.GX_VA_POS: ig.Indices[i] = GetIndex(b, v.Pos); break;

                        case GXAttribName.GX_VA_NRM: ig.Indices[i] = GetIndex(b, v.Nrm); break;

                        case GXAttribName.GX_VA_TEX0: ig.Indices[i] = GetIndex(b, v.TEX0); break;

                        case GXAttribName.GX_VA_TEX1: ig.Indices[i] = GetIndex(b, v.TEX1); break;

                        case GXAttribName.GX_VA_CLR0: ig.Indices[i] = GetIndex(b, v.Clr0); break;

                        default:
                            throw new Exception("Error Building " + b.Name);
                        }

                        break;
                    }
                    i++;
                }
                g.Indices[IndexGroupIndex++] = ig;
            }

            return(g);
        }