void ProcessMesh(Mesh mesh)
 {
     foreach(var face in mesh.Faces)
     {
         for(int b = 0; b < face.Indices.Length / 2; b++)
         {
             var tmp = face.Indices[b];
             face.Indices[b] = face.Indices[face.Indices.Length - 1 - b];
             face.Indices[face.Indices.Length - 1 - b] = tmp;
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Converts a single mesh to left handed coordinates.
        /// </summary>
        void ProcessMesh(Mesh mesh)
        {
            // mirror positions, normals and stuff along the Z axis
            for (int i = 0; i < mesh.Vertices.Length; i++)
            {
                mesh.Vertices[i].Z *= -1.0f;
                if (mesh.HasNormals)
                {
                    mesh.Normals[i].Z *= -1.0f;
                }
                if (mesh.HasTangentsAndBitangets)
                {
                    mesh.Tangents[i].Z *= -1.0f;
                    mesh.Bitangents[i].Z *= -1.0f;
                }
            }

            // mirror offset matrices of all bones
            for (int i = 0; i < mesh.Bones.Length; i++)
            {
                var bone = mesh.Bones[i];
                bone.OffsetMatrix.M13 = -bone.OffsetMatrix.M13;
                bone.OffsetMatrix.M23 = -bone.OffsetMatrix.M23;
                bone.OffsetMatrix.M43 = -bone.OffsetMatrix.M43;
                bone.OffsetMatrix.M31 = -bone.OffsetMatrix.M31;
                bone.OffsetMatrix.M32 = -bone.OffsetMatrix.M32;
                bone.OffsetMatrix.M34 = -bone.OffsetMatrix.M34;
            }

            // mirror bitangents as well as they're derived from the texture coords
            if (mesh.HasTangentsAndBitangets)
            {
                for(int i=0; i<mesh.Vertices.Length; i++)
                {
                    mesh.Bitangents[i] *= -1.0f;
                }
            }
        }