Exemple #1
0
        public Shape(Mesh mesh)
        {
            Packets = new List <Packet>();

            int indexOffset = 0;

            Descriptor = new ShapeVertexDescriptor();
            Descriptor.SetAttribute(Enums.GXVertexAttribute.PositionMatrixIdx, Enums.VertexInputType.Direct, indexOffset++);

            if (mesh.HasVertices)
            {
                Descriptor.SetAttribute(Enums.GXVertexAttribute.Position, Enums.VertexInputType.Index16, indexOffset++);
            }
            if (mesh.HasNormals)
            {
                Descriptor.SetAttribute(Enums.GXVertexAttribute.Normal, Enums.VertexInputType.Index16, indexOffset++);
            }
            for (int i = 0; i < 2; i++)
            {
                if (mesh.HasVertexColors(i))
                {
                    Descriptor.SetAttribute(Enums.GXVertexAttribute.Color0 + i, Enums.VertexInputType.Index16, indexOffset++);
                }
            }

            for (int i = 0; i < 8; i++)
            {
                if (mesh.HasTextureCoords(i))
                {
                    Descriptor.SetAttribute(Enums.GXVertexAttribute.Tex0 + i, Enums.VertexInputType.Index16, indexOffset++);
                }
            }
        }
Exemple #2
0
        public Primitive(EndianBinaryReader reader, ShapeVertexDescriptor activeAttribs)
        {
            Vertices = new List <Vertex>();

            PrimitiveType = (GXPrimitiveType)(reader.ReadByte() & 0xF8);
            int vertCount = reader.ReadInt16();

            for (int i = 0; i < vertCount; i++)
            {
                Vertex vert = new Vertex();

                foreach (GXVertexAttribute attrib in activeAttribs.Attributes.Keys)
                {
                    switch (activeAttribs.GetAttributeType(attrib))
                    {
                    case VertexInputType.Direct:
                        vert.SetAttributeIndex(attrib, attrib == GXVertexAttribute.PositionMatrixIdx ? (uint)(reader.ReadByte() / 3) : reader.ReadByte());
                        break;

                    case VertexInputType.Index8:
                        vert.SetAttributeIndex(attrib, reader.ReadByte());
                        break;

                    case VertexInputType.Index16:
                        vert.SetAttributeIndex(attrib, reader.ReadUInt16());
                        break;

                    case VertexInputType.None:
                        throw new Exception("Found \"None\" as vertex input type in Primitive(reader, activeAttribs)!");
                    }
                }

                Vertices.Add(vert);
            }
        }
Exemple #3
0
 public Shape(ShapeVertexDescriptor desc, BoundingVolume bounds, List <Packet> prims, int matrixType)
 {
     Descriptor = desc;
     Bounds     = bounds;
     Packets    = prims;
     MatrixType = (byte)matrixType;
 }
Exemple #4
0
        public Shape()
        {
            AttributeData = new VertexData();
            Descriptor    = new ShapeVertexDescriptor();
            Packets       = new List <Packet>();

            m_PositionMatrices = new Vector4[64];
            m_NormalMatrices   = new Vector4[32];
        }
Exemple #5
0
        public void Write(EndianBinaryWriter writer, ShapeVertexDescriptor desc)
        {
            writer.Write((byte)PrimitiveType);
            writer.Write((short)Vertices.Count);

            foreach (Vertex vert in Vertices)
            {
                vert.Write(writer, desc);
            }
        }
Exemple #6
0
        public void ReadPrimitives(EndianBinaryReader reader, ShapeVertexDescriptor desc)
        {
            reader.BaseStream.Seek(m_Offset, System.IO.SeekOrigin.Begin);

            while (true)
            {
                Primitive prim = new Primitive(reader, desc);
                Primitives.Add(prim);

                if (reader.PeekReadByte() == 0 || reader.BaseStream.Position >= m_Size + m_Offset)
                {
                    break;
                }
            }
        }
Exemple #7
0
        public override bool Equals(object obj)
        {
            if (obj.GetType() != typeof(ShapeVertexDescriptor))
            {
                return(false);
            }

            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            ShapeVertexDescriptor compObj = obj as ShapeVertexDescriptor;

            if (Attributes.Count != compObj.Attributes.Count)
            {
                return(false);
            }

            for (int i = 0; i < Attributes.Count; i++)
            {
                KeyValuePair <GXVertexAttribute, Tuple <VertexInputType, int> > thisPair  = Attributes.ElementAt(i);
                KeyValuePair <GXVertexAttribute, Tuple <VertexInputType, int> > otherPair = compObj.Attributes.ElementAt(i);

                if (thisPair.Key != otherPair.Key)
                {
                    return(false);
                }

                if (thisPair.Value.Item1 != otherPair.Value.Item1)
                {
                    return(false);
                }

                if (thisPair.Value.Item2 != otherPair.Value.Item2)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #8
0
        public void Write(EndianBinaryWriter writer, ShapeVertexDescriptor desc)
        {
            if (desc.CheckAttribute(GXVertexAttribute.PositionMatrixIdx))
            {
                WriteAttributeIndex(writer, PositionMatrixIDxIndex * 3, desc.Attributes[GXVertexAttribute.PositionMatrixIdx].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Position))
            {
                WriteAttributeIndex(writer, PositionIndex, desc.Attributes[GXVertexAttribute.Position].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Normal))
            {
                WriteAttributeIndex(writer, NormalIndex, desc.Attributes[GXVertexAttribute.Normal].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Color0))
            {
                WriteAttributeIndex(writer, Color0Index, desc.Attributes[GXVertexAttribute.Color0].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Color1))
            {
                WriteAttributeIndex(writer, Color1Index, desc.Attributes[GXVertexAttribute.Color1].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Tex0))
            {
                WriteAttributeIndex(writer, TexCoord0Index, desc.Attributes[GXVertexAttribute.Tex0].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Tex1))
            {
                WriteAttributeIndex(writer, TexCoord1Index, desc.Attributes[GXVertexAttribute.Tex1].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Tex2))
            {
                WriteAttributeIndex(writer, TexCoord2Index, desc.Attributes[GXVertexAttribute.Tex2].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Tex3))
            {
                WriteAttributeIndex(writer, TexCoord3Index, desc.Attributes[GXVertexAttribute.Tex3].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Tex4))
            {
                WriteAttributeIndex(writer, TexCoord4Index, desc.Attributes[GXVertexAttribute.Tex4].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Tex5))
            {
                WriteAttributeIndex(writer, TexCoord5Index, desc.Attributes[GXVertexAttribute.Tex5].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Tex6))
            {
                WriteAttributeIndex(writer, TexCoord6Index, desc.Attributes[GXVertexAttribute.Tex6].Item1);
            }

            if (desc.CheckAttribute(GXVertexAttribute.Tex7))
            {
                WriteAttributeIndex(writer, TexCoord7Index, desc.Attributes[GXVertexAttribute.Tex7].Item1);
            }
        }