Exemple #1
0
        public GXVertex this[int i]
        {
            get
            {
                switch (i)
                {
                case 0: return(_x);

                case 1: return(_y);

                case 2: return(_z);
                }
                return(new GXVertex());
            }
            set
            {
                switch (i)
                {
                case 0: _x = value; break;

                case 1: _y = value; break;

                case 2: _z = value; break;
                }
            }
        }
Exemple #2
0
 public bool Contains(GXVertex f)
 {
     if (_x == f)
     {
         return(true);
     }
     if (_y == f)
     {
         return(true);
     }
     if (_z == f)
     {
         return(true);
     }
     return(false);
 }
Exemple #3
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());
        }
Exemple #4
0
 public PointTriangle(GXVertex x, GXVertex y, GXVertex z)
 {
     _x = x;
     _y = y;
     _z = z;
 }