Beispiel #1
0
        public static Vector3 GetColumn(this GLTF.Math.Matrix4x4 mat, uint columnNum)
        {
            switch (columnNum)
            {
            case 0:
            {
                return(new Vector3(mat.M11, mat.M21, mat.M31));
            }

            case 1:
            {
                return(new Vector3(mat.M12, mat.M22, mat.M32));
            }

            case 2:
            {
                return(new Vector3(mat.M13, mat.M23, mat.M33));
            }

            case 3:
            {
                return(new Vector3(mat.M14, mat.M24, mat.M34));
            }

            default:
                throw new System.Exception("column num is out of bounds");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Convert gltf matrix to a unity matrix
        /// </summary>
        /// <param name="unityMat">unity matrix</param>
        /// <returns>gltf matrix</returns>
        public static GLTF.Math.Matrix4x4 ToGltfMatrix4x4Convert(this Matrix4x4 unityMat)
        {
            Vector3   coordinateSpaceConversionScale = CoordinateSpaceConversionScale.ToUnityVector3Raw();
            Matrix4x4 convert = Matrix4x4.Scale(coordinateSpaceConversionScale);

            GLTF.Math.Matrix4x4 gltfMat = (convert * unityMat * convert).ToGltfMatrix4x4Raw();
            return(gltfMat);
        }
Beispiel #3
0
 public static GLTF.Math.Matrix4x4 ToGltfMatrix4x4Raw(this Matrix4x4 unityMat)
 {
     GLTF.Math.Vector4   c0         = unityMat.GetColumn(0).ToGltfVector4Raw();
     GLTF.Math.Vector4   c1         = unityMat.GetColumn(1).ToGltfVector4Raw();
     GLTF.Math.Vector4   c2         = unityMat.GetColumn(2).ToGltfVector4Raw();
     GLTF.Math.Vector4   c3         = unityMat.GetColumn(3).ToGltfVector4Raw();
     GLTF.Math.Matrix4x4 rawGltfMat = new GLTF.Math.Matrix4x4(c0.X, c0.Y, c0.Z, c0.W, c1.X, c1.Y, c1.Z, c1.W, c2.X, c2.Y, c2.Z, c2.W, c3.X, c3.Y, c3.Z, c3.W);
     return(rawGltfMat);
 }
Beispiel #4
0
        /// <summary>
        /// Convert gltf matrix to a unity matrix
        /// </summary>
        /// <param name="gltfMat">gltf matrix</param>
        /// <returns>unity matrix</returns>
        public static Matrix4x4 ToUnityMatrix4x4Convert(this GLTF.Math.Matrix4x4 gltfMat)
        {
            Matrix4x4 rawUnityMat = gltfMat.ToUnityMatrix4x4Raw();
            Vector3   coordinateSpaceConversionScale = CoordinateSpaceConversionScale.ToUnityVector3Raw();
            Matrix4x4 convert  = Matrix4x4.Scale(coordinateSpaceConversionScale);
            Matrix4x4 unityMat = convert * rawUnityMat * convert;

            return(unityMat);
        }
Beispiel #5
0
        public static Matrix4x4 ToUnityMatrix(this GLTF.Math.Matrix4x4 matrix)
        {
            Matrix4x4 mat = new Matrix4x4();

            mat.SetColumn(0, matrix.GetColumn(0));
            mat.SetColumn(1, matrix.GetColumn(1));
            mat.SetColumn(2, matrix.GetColumn(2));
            mat.SetColumn(3, matrix.GetColumn(3));
            return(mat);
        }
Beispiel #6
0
        // todo: move to utility class
        public static void GetTRSProperties(GLTF.Math.Matrix4x4 mat, out Vector3 position, out Quaternion rotation,
                                            out Vector3 scale)
        {
            position = mat.GetColumn(3);

            scale = new Vector3(
                mat.GetColumn(0).magnitude,
                mat.GetColumn(1).magnitude,
                mat.GetColumn(2).magnitude
                );

            rotation = Quaternion.LookRotation(mat.GetColumn(2), mat.GetColumn(1));
        }
Beispiel #7
0
        public static Matrix4x4 ToUnityMatrix4x4Raw(this GLTF.Math.Matrix4x4 gltfMat)
        {
            Vector4   rawUnityCol0 = gltfMat.GetColumn(0).ToUnityVector4Raw();
            Vector4   rawUnityCol1 = gltfMat.GetColumn(1).ToUnityVector4Raw();
            Vector4   rawUnityCol2 = gltfMat.GetColumn(2).ToUnityVector4Raw();
            Vector4   rawUnityCol3 = gltfMat.GetColumn(3).ToUnityVector4Raw();
            Matrix4x4 rawUnityMat  = new UnityEngine.Matrix4x4();

            rawUnityMat.SetColumn(0, rawUnityCol0);
            rawUnityMat.SetColumn(1, rawUnityCol1);
            rawUnityMat.SetColumn(2, rawUnityCol2);
            rawUnityMat.SetColumn(3, rawUnityCol3);

            return(rawUnityMat);
        }
Beispiel #8
0
 public static Matrix4x4 ToUnityMatrix4x4(this GLTF.Math.Matrix4x4 matrix)
 {
     return(new Matrix4x4()
     {
         m00 = matrix.M11,
         m01 = matrix.M12,
         m02 = matrix.M13,
         m03 = matrix.M14,
         m10 = matrix.M21,
         m11 = matrix.M22,
         m12 = matrix.M23,
         m13 = matrix.M24,
         m20 = matrix.M31,
         m21 = matrix.M32,
         m22 = matrix.M33,
         m23 = matrix.M34,
         m30 = matrix.M41,
         m31 = matrix.M42,
         m32 = matrix.M43,
         m33 = matrix.M44
     });
 }
Beispiel #9
0
 /// <summary>
 /// Get converted unity translation, rotation, and scale from a gltf matrix
 /// </summary>
 /// <param name="gltfMat">gltf matrix to get and convert properties from</param>
 /// <param name="position">unity translation vector</param>
 /// <param name="rotation">unity rotation quaternion</param>
 /// <param name="scale">unity scale vector</param>
 public static void GetTRSProperties(this GLTF.Math.Matrix4x4 gltfMat, out Vector3 position, out Quaternion rotation,
                                     out Vector3 scale)
 {
     gltfMat.ToUnityMatrix4x4Convert().GetTRSProperties(out position, out rotation, out scale);
 }
 /// <summary>
 /// Convert gltf matrix to a unity matrix
 /// </summary>
 /// <param name="gltfMat">gltf matrix</param>
 /// <returns>unity matrix</returns>
 public static Matrix4x4 ToUnityMatrix4x4Convert(this GLTF.Math.Matrix4x4 gltfMat)
 {
     return(gltfMat.ToUnityMatrix4x4Raw().UnityMatrix4x4ConvertFromGLTF());
 }