Beispiel #1
0
        public byte[] GetData(GXVertexBuffer Buffer)
        {
            MemoryStream o      = new MemoryStream();
            HSDWriter    Writer = new HSDWriter(o);

            foreach (object ob in Collection)
            {
                if (ob is GXVector2)
                {
                    WriteData(Writer, ((GXVector2)ob).X, Buffer.CompType, Buffer.Scale);
                    WriteData(Writer, ((GXVector2)ob).Y, Buffer.CompType, Buffer.Scale);
                }
                if (ob is GXVector3)
                {
                    WriteData(Writer, ((GXVector3)ob).X, Buffer.CompType, Buffer.Scale);
                    WriteData(Writer, ((GXVector3)ob).Y, Buffer.CompType, Buffer.Scale);
                    WriteData(Writer, ((GXVector3)ob).Z, Buffer.CompType, Buffer.Scale);
                }
            }
            Writer.Align(0x20);
            byte[] data = o.ToArray();
            Writer.Close();
            o.Close();
            Writer.Dispose();

            return(data);
        }
Beispiel #2
0
        public override void Save(HSDWriter Writer)
        {
            Writer.AddObject(this);
            foreach (GXVertexBuffer v in Attributes)
            {
                v.Save(Writer);
            }
            GXVertexBuffer end = new GXVertexBuffer();

            end.Save(Writer);
        }
Beispiel #3
0
        public override void Open(HSDReader Reader)
        {
            GXVertexBuffer a = new GXVertexBuffer();

            a.Open(Reader);
            while (a.Name != GXAttribName.GX_VA_NULL)
            {
                Attributes.Add(a);
                a = new GXVertexBuffer();
                a.Open(Reader);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Gets the index of a value in the buffer
 /// </summary>
 /// <param name="v"></param>
 /// <param name="o"></param>
 /// <returns></returns>
 private ushort GetIndex(GXVertexBuffer v, object o)
 {
     if (!BufferLinker.ContainsKey(v))
     {
         foreach (GXVertexBuffer buf in BufferLinker.Keys)
         {
             if (buf.Name == v.Name &&
                 buf.Scale == v.Scale &&
                 buf.AttributeType == v.AttributeType &&
                 buf.CompType == v.CompType &&
                 buf.CompCount == v.CompCount)
             {
                 BufferLinker.Add(v, BufferLinker[buf]);
                 return(BufferLinker[buf].GetIndex(o));
             }
         }
         BufferLinker.Add(v, new BufferMaker <object>());
     }
     return(BufferLinker[v].GetIndex(o));
 }
Beispiel #5
0
        public static GXVertex[] GetDecodedVertices(GXPrimitiveGroup PrimitiveGroup, HSD_AttributeGroup Group)
        {
            // Create Vertex List
            List <GXVertex> Vertices = new List <GXVertex>();

            // Prepare vertex buffers for reading
            Dictionary <GXVertexBuffer, HSDReader> Buffers = new Dictionary <GXVertexBuffer, HSDReader>();

            foreach (GXVertexBuffer buffer in Group.Attributes)
            {
                Buffers.Add(buffer, buffer.DataBuffer == null ? null : new HSDReader(new MemoryStream(buffer.DataBuffer)));
            }

            // Decode
            foreach (GXIndexGroup ig in PrimitiveGroup.Indices)
            {
                GXVertex Vertex = new GXVertex();
                for (int i = 0; i < Group.Attributes.Count; i++)
                {
                    GXVertexBuffer Attr         = Group.Attributes[i];
                    HSDReader      VertexBuffer = Buffers[Attr];
                    int            index        = ig.Indices[i];
                    float[]        f            = new float[0];
                    if (VertexBuffer != null)
                    {
                        VertexBuffer.Seek((uint)(Attr.Stride * index));
                        f = Read(VertexBuffer, Attr.CompType, Attr.Stride);
                    }
                    switch (Attr.Name)
                    {
                    case GXAttribName.GX_VA_PNMTXIDX:
                        Vertex.PMXID = (ushort)index;
                        break;

                    case GXAttribName.GX_VA_TEX0MTXIDX:
                        Vertex.TEX0MTXIDX = (ushort)index;
                        break;

                    case GXAttribName.GX_VA_POS:
                        Vertex.Pos.X = f[0] / (float)Math.Pow(2, Attr.Scale);
                        Vertex.Pos.Y = f[1] / (float)Math.Pow(2, Attr.Scale);
                        Vertex.Pos.Z = f[2] / (float)Math.Pow(2, Attr.Scale);
                        break;

                    case GXAttribName.GX_VA_NRM:
                        Vertex.Nrm.X = f[0] / (float)Math.Pow(2, Attr.Scale);
                        Vertex.Nrm.Y = f[1] / (float)Math.Pow(2, Attr.Scale);
                        Vertex.Nrm.Z = f[2] / (float)Math.Pow(2, Attr.Scale);
                        break;

                    case GXAttribName.GX_VA_TEX0:
                        Vertex.TEX0.X = f[0] / (float)Math.Pow(2, Attr.Scale);
                        Vertex.TEX0.Y = f[1] / (float)Math.Pow(2, Attr.Scale);
                        break;

                    case GXAttribName.GX_VA_TEX1:
                        Vertex.TEX1.X = f[0] / (float)Math.Pow(2, Attr.Scale);
                        Vertex.TEX1.Y = f[1] / (float)Math.Pow(2, Attr.Scale);
                        break;

                    case GXAttribName.GX_VA_CLR0:
                        if (Attr.AttributeType == GXAttribType.GX_DIRECT)
                        {
                            Vertex.Clr0.R = ig.Clr0[0] / 255f;
                            Vertex.Clr0.G = ig.Clr0[1] / 255f;
                            Vertex.Clr0.B = ig.Clr0[2] / 255f;
                            Vertex.Clr0.A = ig.Clr0[3] / 255f;
                        }
                        if (Attr.AttributeType == GXAttribType.GX_INDEX8)
                        {
                            Vertex.Clr0.R = f[0];
                            Vertex.Clr0.G = f[1];
                            Vertex.Clr0.B = f[2];
                            Vertex.Clr0.A = f[3];
                        }
                        break;

                    case GXAttribName.GX_VA_CLR1:
                        if (Attr.AttributeType == GXAttribType.GX_DIRECT)
                        {
                            Vertex.Clr1.R = ig.Clr1[0] / 255f;
                            Vertex.Clr1.G = ig.Clr1[1] / 255f;
                            Vertex.Clr1.B = ig.Clr1[2] / 255f;
                            Vertex.Clr1.A = ig.Clr1[3] / 255f;
                        }
                        if (Attr.AttributeType == GXAttribType.GX_INDEX8)
                        {
                            Vertex.Clr1.R = f[0];
                            Vertex.Clr1.G = f[1];
                            Vertex.Clr1.B = f[2];
                            Vertex.Clr1.A = f[3];
                        }
                        break;

                    default:
                        Console.WriteLine("To be implemented: " + Attr.Name);
                        break;
                    }
                }
                Vertices.Add(Vertex);
            }

            foreach (var b in Buffers)
            {
                if (b.Value != null)
                {
                    b.Value.Dispose();
                }
            }


            return(Vertices.ToArray());
        }