Пример #1
0
		/// <summary>
		///     Writes a vertex element to the stream.
		/// </summary>
		/// <param name="x">The X component.</param>
		/// <param name="y">The Y component.</param>
		/// <param name="z">The Z component.</param>
		/// <param name="w">The W component.</param>
		/// <param name="layout">The layout of the element.</param>
		public void WriteElement(float x, float y, float z, float w, VertexElementLayout layout)
		{
			TransformElement(ref x, ref y, ref z, ref w, layout.Usage);

			// This is only enough to support s_rigid_vertex for now
			uint val = 0;
			switch (layout.Type)
			{
				case VertexElementType.UDec4N:
					val = (uint) (x*1023.0f) & 0x3FF;
					val |= ((uint) (y*1023.0f) & 0x3FF) << 10;
					val |= ((uint) (z*1023.0f) & 0x3FF) << 20;
					val |= (uint) (w*3.0f) << 30;
					_writer.WriteUInt32(val);
					break;

				case VertexElementType.UShort2N:
					_writer.WriteUInt16((ushort) (x*65535.0f));
					_writer.WriteUInt16((ushort) (y*65535.0f));
					_writer.WriteUInt16((ushort) (z*65535.0f));
					break;

				case VertexElementType.DHen3N:
					val = (((uint) (x*511.0f) << 22) & 0xFFC00000) >> 22;
					val |= (((uint) (y*1023.0f) << 21) & 0xFFE00000) >> 11;
					val |= ((uint) (z*1023.0f) << 21) & 0xFFE00000;
					_writer.WriteUInt32(val);
					break;

				default:
					throw new NotSupportedException("Unsupported vertex element type: " +
					                                Enum.GetName(typeof (VertexElementType), layout.Type));
			}
		}
Пример #2
0
		public void ProcessVertexElement(float x, float y, float z, float w, VertexElementLayout layout)
		{
			switch (layout.Usage)
			{
				case VertexElementUsage.Position:
					_output.WriteLine("v {0} {1} {2}", x, y, z);
					break;

				case VertexElementUsage.Normal:
					_output.WriteLine("vn {0} {1} {2}", x, y, z);
					break;

				case VertexElementUsage.TexCoords:
					_output.WriteLine("vt {0} {1} {2}", x, y, z);
					break;
			}
		}
Пример #3
0
 /// <summary>
 ///     Adds an element layout to the vertex layout.
 /// </summary>
 /// <param name="element">The element layout to add.</param>
 public void AddElement(VertexElementLayout element)
 {
     _elements.Add(element);
     _availableUsages.Add(element.Usage);
 }
Пример #4
0
		/// <summary>
		///     Reads a vertex element from a stream and sends it to an IVertexProcessor.
		/// </summary>
		/// <param name="reader">The stream to read from. It should be positioned at the start of the element.</param>
		/// <param name="element">The layout of the element to read.</param>
		/// <param name="boundingBox">The bounding box to transform the element with. Can be null.</param>
		/// <param name="processor">The IVertexProcessor to send the element to.</param>
		private static void ReadElement(IReader reader, VertexElementLayout element, BoundingBox boundingBox,
			IVertexProcessor processor)
		{
			// EW EW EW
			// TODO: Implement everything, this is just enough to load some Reach vertices for now...
			float x = 0, y = 0, z = 0, w = 1;
			uint value;
			switch (element.Type)
			{
				case VertexElementType.Float2:
					x = reader.ReadFloat();
					y = reader.ReadFloat();
					break;

				case VertexElementType.Float3:
					x = reader.ReadFloat();
					y = reader.ReadFloat();
					z = reader.ReadFloat();
					break;

				case VertexElementType.Float4:
					x = reader.ReadFloat();
					y = reader.ReadFloat();
					z = reader.ReadFloat();
					w = reader.ReadFloat();
					break;

				case VertexElementType.UByte4:
					x = reader.ReadByte();
					y = reader.ReadByte();
					z = reader.ReadByte();
					w = reader.ReadByte();
					break;

				case VertexElementType.UByte4N:
					x = reader.ReadByte()/255.0f;
					y = reader.ReadByte()/255.0f;
					z = reader.ReadByte()/255.0f;
					w = reader.ReadByte()/255.0f;
					break;

				case VertexElementType.Byte4N:
					x = reader.ReadSByte()/127.0f;
					y = reader.ReadSByte()/127.0f;
					z = reader.ReadSByte()/127.0f;
					w = reader.ReadSByte()/127.0f;
					break;

				case VertexElementType.Float16_2:
					x = Half.ToHalf(reader.ReadUInt16());
					y = Half.ToHalf(reader.ReadUInt16());
					break;

				case VertexElementType.Float16_4:
					x = Half.ToHalf(reader.ReadUInt16());
					y = Half.ToHalf(reader.ReadUInt16());
					z = Half.ToHalf(reader.ReadUInt16());
					w = Half.ToHalf(reader.ReadUInt16());
					break;

				case VertexElementType.UShort2:
					x = reader.ReadUInt16();
					y = reader.ReadUInt16();
					break;

				case VertexElementType.UShort2N:
					x = reader.ReadUInt16()/65535.0f;
					y = reader.ReadUInt16()/65535.0f;
					break;

				case VertexElementType.UShort4N:
					x = reader.ReadUInt16()/65535.0f;
					y = reader.ReadUInt16()/65535.0f;
					z = reader.ReadUInt16()/65535.0f;
					w = reader.ReadUInt16()/65535.0f;
					break;

				case VertexElementType.Short4N:
					x = reader.ReadInt16()/32767.0f;
					y = reader.ReadInt16()/32767.0f;
					z = reader.ReadInt16()/32767.0f;
					w = reader.ReadInt16()/32767.0f;
					break;

				case VertexElementType.D3DColor:
					w = reader.ReadByte()/255.0f; // W is set here because alpha comes first but ends up last in the vector
					y = reader.ReadByte()/255.0f;
					z = reader.ReadByte()/255.0f;
					x = reader.ReadByte()/255.0f;
					break;

				case VertexElementType.DHen3N:
					value = reader.ReadUInt32();
					x = (((int) ((value << 22) & 0xFFC00000)) >> 22)/511.0f;
					y = (((int) ((value << 11) & 0xFFE00000)) >> 21)/1023.0f;
					z = (((int) (value & 0xFFE00000)) >> 21)/1023.0f;
					break;

				case VertexElementType.UDec4N:
					value = reader.ReadUInt32();
					x = (value & 0x3FF)/1023.0f;
					y = ((value >> 10) & 0x3FF)/1023.0f;
					z = ((value >> 20) & 0x3FF)/1023.0f;
					w = (value >> 30)/3.0f;
					break;

				default:
					throw new NotSupportedException("Unsupported vertex element type: " +
					                                Enum.GetName(typeof (VertexElementType), element.Type));
			}

			if (boundingBox != null)
				TransformElement(ref x, ref y, ref z, ref w, element.Usage, boundingBox);

			if (processor != null)
				processor.ProcessVertexElement(x, y, z, w, element);
		}
Пример #5
0
 /// <summary>
 ///     Adds an element layout to the vertex layout.
 /// </summary>
 /// <param name="element">The element layout to add.</param>
 public void AddElement(VertexElementLayout element)
 {
     _elements.Add(element);
     _availableUsages.Add(element.Usage);
 }