Esempio n. 1
0
        /// <summary>
        /// Reads a <see cref="Vector4F"/> instances converted from the given <paramref name="attribFormat"/> and
        /// returns them.
        /// </summary>
        /// <param name="self">The extended <see cref="BinaryDataReader"/>.</param>
        /// <param name="count">The number of instances to read.</param>
        /// <param name="attribFormat">The <see cref="GX2AttribFormat"/> of the data.</param>
        /// <returns>The <see cref="Vector4F"/> instances.</returns>
        public static IList <Vector4F> ReadGX2Attribs(this BinaryDataReader self, int count,
                                                      GX2AttribFormat attribFormat)
        {
            Func <BinaryDataReader, Vector4F> callback = self.GetGX2AttribCallback(attribFormat);

            Vector4F[] values = new Vector4F[count];
            for (int i = 0; i < count; i++)
            {
                values[i] = callback.Invoke(self);
            }
            return(values);
        }
        // ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------

        private Vector4F[] FromRawData(VertexBuffer vertexBuffer, VertexAttrib attrib)
        {
            // Create a reader on the raw bytes of the correct endianness.
            Buffer buffer = vertexBuffer.Buffers[attrib.BufferIndex];

            using (BinaryDataReader reader = new BinaryDataReader(new MemoryStream(buffer.Data[0])))
            {
                reader.ByteOrder = ByteOrder;

                // Get a conversion callback transforming the raw data into a Vector4F instance.
                Func <BinaryDataReader, Vector4F> callback = reader.GetGX2AttribCallback(attrib.Format);

                // Read the elements.
                Vector4F[] elements = new Vector4F[vertexBuffer.VertexCount];
                for (int i = 0; i < vertexBuffer.VertexCount; i++)
                {
                    reader.Position = attrib.Offset + i * buffer.Stride;
                    elements[i]     = callback.Invoke(reader);
                }
                return(elements);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Reads a <see cref="Vector4F"/> instance converted from the given <paramref name="attribFormat"/> and
 /// returns it.
 /// </summary>
 /// <param name="self">The extended <see cref="BinaryDataReader"/>.</param>
 /// <param name="attribFormat">The <see cref="GX2AttribFormat"/> of the data.</param>
 /// <returns>The <see cref="Vector4F"/> instance.</returns>
 public static Vector4F ReadGX2Attrib(this BinaryDataReader self, GX2AttribFormat attribFormat)
 {
     return(self.GetGX2AttribCallback(attribFormat).Invoke(self));
 }