Ejemplo n.º 1
0
        public static void WriteCompressedVector4f(this BinaryWriter writer, vector4f vec4)
        {
            float x = ((vec4.x / 2.0f) + 0.5f).FitRange(0.0f, 1.0f);
            float y = ((vec4.y / 2.0f) + 0.5f).FitRange(0.0f, 1.0f);
            float z = ((vec4.z / 2.0f) + 0.5f).FitRange(0.0f, 1.0f);
            float w = ((vec4.w / 2.0f) + 0.5f).FitRange(0.0f, 1.0f);

            writer.Write((byte)Math.Round(w * 255.0f));
            writer.Write((byte)Math.Round(z * 255.0f));
            writer.Write((byte)Math.Round(y * 255.0f));
            writer.Write((byte)Math.Round(x * 255.0f));
        }
Ejemplo n.º 2
0
 public void Read(BinaryReader data, VertexFormat format)
 {
     if (format == VertexFormat.Pixlit1UvNmap)
     {
         Pos     = data.ReadVector3f();
         Normal  = data.ReadCompressedVector4f();
         Tangent = data.ReadCompressedVector4f();
         Uvs     = new vector4f(data.ReadInt16(), data.ReadInt16(), 0.0f, 0.0f);
     }
     else if (format == VertexFormat.Pixlit3UvNmap)
     {
         Pos     = data.ReadVector3f();
         Normal  = data.ReadCompressedVector4f();
         Tangent = data.ReadCompressedVector4f();
         Uvs     = new vector4f(data.ReadInt16(), data.ReadInt16(), 0.0f, 0.0f);
         data.Skip(8); //Skip other UVs, .obj files only support 1 uv per object so for now need to ignore these. These are usually just 0,0 anyway
     }
     else
     {
         throw new Exception($"{format.ToString()} is an unsupported vertex format! Please show the maintainer of this tool this error and the related mesh file.");
     }
 }