public static void WriteBinormalShortVector4(WritableSection section, Quaternion v)
 {
     section.Writer.Write((Int16)(v.X * 32767.0f));
     section.Writer.Write((Int16)(v.Y * 32767.0f));
     section.Writer.Write((Int16)(v.Z * 32767.0f));
     section.Writer.Write((Int16)(v.W * 32767.0f));
 }
Beispiel #2
0
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteInfluences2(section, BoneWeights);
     WriteInfluences2(section, BoneIndices);
     WriteVector3(section, Normal);
 }
Beispiel #3
0
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteInfluences2(section, BoneWeights);
     WriteInfluences2(section, BoneIndices);
     WriteVector2(section, TextureCoordinates0);
 }
Beispiel #4
0
 protected void WriteHalfVector4(WritableSection section, Vector4 v)
 {
     section.Writer.Write(HalfHelpers.SingleToHalf(v.X));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Y));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Z));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.W));
 }
Beispiel #5
0
 protected void WriteVector4(WritableSection section, Vector4 v)
 {
     section.Writer.Write(v.X);
     section.Writer.Write(v.Y);
     section.Writer.Write(v.Z);
     section.Writer.Write(v.W);
 }
Beispiel #6
0
 public static void WriteInfluences(WritableSection section, BoneWeight v)
 {
     section.Writer.Write(v.A);
     section.Writer.Write(v.B);
     section.Writer.Write(v.C);
     section.Writer.Write(v.D);
 }
Beispiel #7
0
 protected void WriteInfluences(WritableSection section, BoneWeight v)
 {
     section.Writer.Write(v.A);
     section.Writer.Write(v.B);
     section.Writer.Write(v.C);
     section.Writer.Write(v.D);
 }
Beispiel #8
0
 public static void WriteVector4(WritableSection section, Vector4 v)
 {
     section.Writer.Write(v.X);
     section.Writer.Write(v.Y);
     section.Writer.Write(v.Z);
     section.Writer.Write(v.W);
 }
Beispiel #9
0
 public static void WriteNormalByteVector4(WritableSection section, Vector4 v)
 {
     section.Writer.Write((byte)(v.X * 255));
     section.Writer.Write((byte)(v.Y * 255));
     section.Writer.Write((byte)(v.Z * 255));
     section.Writer.Write((byte)(v.W * 255));
 }
Beispiel #10
0
 public static void WriteBinormalShortVector3As4(WritableSection section, Vector3 v)
 {
     section.Writer.Write((Int16)(v.X * 32767.0f));
     section.Writer.Write((Int16)(v.Y * 32767.0f));
     section.Writer.Write((Int16)(v.Z * 32767.0f));
     section.Writer.Write((Int16)0);
 }
Beispiel #11
0
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteVector3(section, Normal);
     WriteVector3(section, Tangent);
     WriteVector3(section, Binormal);
 }
Beispiel #12
0
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteVector3(section, Normal);
     WriteVector2(section, TextureCoordinates0);
     WriteVector2(section, TextureCoordinates1);
 }
Beispiel #13
0
 protected void WriteHalfVector3As4(WritableSection section, Vector3 v)
 {
     section.Writer.Write(HalfHelpers.SingleToHalf(v.X));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Y));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Z));
     section.Writer.Write((ushort)0);
 }
Beispiel #14
0
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteVector3(section, Normal);
     WriteVector3(section, Tangent);
     WriteVector3(section, Binormal);
     WriteVector4(section, DiffuseColor0);
     WriteVector2(section, TextureCoordinates0);
 }
        public static void WriteQTangent(WritableSection section, Vector3 normal, Vector3 tangent, Vector3 binormal)
        {
            var     n2         = Vector3.Cross(tangent, binormal).Normalized();
            var     reflection = Vector3.Dot(normal, n2);
            Matrix3 normals    = new Matrix3(tangent, binormal, n2);
            var     qTangent   = MatrixToQTangent(normals, reflection < 0.0f);

            WriteBinormalShortVector4(section, qTangent);
        }
Beispiel #16
0
 public static void WriteVector2(WritableSection section, Vector2 v)
 {
     section.Writer.Write(v.X);
     section.Writer.Write(v.Y);
 }
Beispiel #17
0
 public void Serialize(WritableSection section)
 {
     VertexSerializationHelpers.Serialize(section, this);
 }
Beispiel #18
0
 public static void WriteHalfVector3(WritableSection section, Vector3 v)
 {
     section.Writer.Write(HalfHelpers.SingleToHalf(v.X));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Y));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Z));
 }
Beispiel #19
0
 public abstract void Serialize(WritableSection section);
Beispiel #20
0
        public static void Serialize(WritableSection section, Vertex v)
        {
            var d = v.Format;

            if (d.HasPosition)
            {
                WriteVector3(section, v.Position);
            }

            if (d.HasBoneWeights)
            {
                if (d.NumBoneInfluences == 2)
                {
                    WriteInfluences2(section, v.BoneWeights);
                    WriteInfluences2(section, v.BoneIndices);
                }
                else
                {
                    WriteInfluences(section, v.BoneWeights);
                    WriteInfluences(section, v.BoneIndices);
                }
            }

            switch (d.NormalType)
            {
            case NormalType.None: break;

            case NormalType.Float3: WriteVector3(section, v.Normal); break;

            case NormalType.Half4: WriteHalfVector3As4(section, v.Normal); break;

            case NormalType.Short4: WriteBinormalShortVector3As4(section, v.Normal); break;
            }

            switch (d.TangentType)
            {
            case NormalType.None: break;

            case NormalType.Float3: WriteVector3(section, v.Tangent); break;

            case NormalType.Half4: WriteHalfVector3As4(section, v.Tangent); break;

            case NormalType.Short4: WriteBinormalShortVector3As4(section, v.Tangent); break;
            }

            switch (d.BinormalType)
            {
            case NormalType.None: break;

            case NormalType.Float3: WriteVector3(section, v.Binormal); break;

            case NormalType.Half4: WriteHalfVector3As4(section, v.Binormal); break;

            case NormalType.Short4: WriteBinormalShortVector3As4(section, v.Binormal); break;
            }

            switch (d.DiffuseType)
            {
            case DiffuseColorType.None: break;

            case DiffuseColorType.Float4: WriteVector4(section, v.DiffuseColor0); break;

            case DiffuseColorType.Byte4: WriteNormalByteVector4(section, v.DiffuseColor0); break;
            }

            if (d.TextureCoordinates > 0)
            {
                switch (d.TextureCoordinateType)
                {
                case TextureCoordinateType.None: break;

                case TextureCoordinateType.Float2: WriteVector2(section, v.TextureCoordinates0); break;

                case TextureCoordinateType.Half2: WriteHalfVector2(section, v.TextureCoordinates0); break;
                }

                if (d.TextureCoordinates > 1)
                {
                    switch (d.TextureCoordinateType)
                    {
                    case TextureCoordinateType.None: break;

                    case TextureCoordinateType.Float2: WriteVector2(section, v.TextureCoordinates1); break;

                    case TextureCoordinateType.Half2: WriteHalfVector2(section, v.TextureCoordinates1); break;
                    }
                }
            }
        }
Beispiel #21
0
 public void Write(GR2Writer writer, WritableSection section, MemberDefinition member, object obj)
 {
     (obj as Vertex).Serialize(section);
 }
        public static void Serialize(WritableSection section, Vertex v)
        {
            var d = v.Format;

            if (d.HasPosition)
            {
                WriteVector3(section, v.Position);
            }

            if (d.HasBoneWeights)
            {
                if (d.NumBoneInfluences == 2)
                {
                    WriteInfluences2(section, v.BoneWeights);
                    WriteInfluences2(section, v.BoneIndices);
                }
                else
                {
                    WriteInfluences(section, v.BoneWeights);
                    WriteInfluences(section, v.BoneIndices);
                }
            }

            switch (d.NormalType)
            {
            case NormalType.None: break;

            case NormalType.Float3: WriteVector3(section, v.Normal); break;

            case NormalType.Half4: WriteHalfVector3As4(section, v.Normal); break;

            case NormalType.QTangent: WriteQTangent(section, v.Normal, v.Tangent, v.Binormal); break;
            }

            switch (d.TangentType)
            {
            case NormalType.None: break;

            case NormalType.Float3: WriteVector3(section, v.Tangent); break;

            case NormalType.Half4: WriteHalfVector3As4(section, v.Tangent); break;

            case NormalType.QTangent: break;     // Tangent saved into QTangent
            }

            switch (d.BinormalType)
            {
            case NormalType.None: break;

            case NormalType.Float3: WriteVector3(section, v.Binormal); break;

            case NormalType.Half4: WriteHalfVector3As4(section, v.Binormal); break;

            case NormalType.QTangent: break;     // Binormal saved into QTangent
            }

            if (d.ColorMaps > 0)
            {
                for (var i = 0; i < d.ColorMaps; i++)
                {
                    var color = v.GetColor(i);
                    switch (d.ColorMapType)
                    {
                    case ColorMapType.Float4: WriteVector4(section, color); break;

                    case ColorMapType.Byte4: WriteNormalByteVector4(section, color); break;

                    default: throw new Exception($"Cannot unserialize color map: Unsupported format {d.ColorMapType}");
                    }
                }
            }

            if (d.TextureCoordinates > 0)
            {
                for (var i = 0; i < d.TextureCoordinates; i++)
                {
                    var uv = v.GetUV(i);
                    switch (d.TextureCoordinateType)
                    {
                    case TextureCoordinateType.Float2: WriteVector2(section, uv); break;

                    case TextureCoordinateType.Half2: WriteHalfVector2(section, uv); break;

                    default: throw new Exception($"Cannot serialize UV map: Unsupported format {d.TextureCoordinateType}");
                    }
                }
            }
        }
Beispiel #23
0
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
 }
Beispiel #24
0
 protected void WriteVector2(WritableSection section, Vector2 v)
 {
     section.Writer.Write(v.X);
     section.Writer.Write(v.Y);
 }