Exemple #1
0
 static ChiselPathPoint()
 {
     swizzleYZ.SetColumn(0, unitX);
     swizzleYZ.SetColumn(1, unitZ);
     swizzleYZ.SetColumn(2, unitY);
     swizzleYZ.SetColumn(3, unitW);
 }
Exemple #2
0
 /// <summary>
 /// Convert a TES matrix to a Unity matrix.
 /// </summary>
 /// <returns>The equivalent Unity matrix.</returns>
 /// <param name="mat">The matrix to convert.</param>
 public static UnityEngine.Matrix4x4 ToUnity(this Matrix4 mat)
 {
     UnityEngine.Matrix4x4 umat = UnityEngine.Matrix4x4.identity;
     for (int i = 0; i < 3; ++i)
     {
         umat.SetColumn(i, mat.GetAxis(i).ToUnity(0.0f));
     }
     umat.SetColumn(3, mat.GetAxis(3).ToUnity(1.0f));
     return(umat);
 }
        public static T Create <T>(string name, UnityEngine.Transform parent, Matrix4x4 trsMatrix) where T : ChiselNode
        {
            // TODO: put matrix4x4 -> transform values, into utility method
            var position = trsMatrix.GetColumn(3);

            trsMatrix.SetColumn(3, Vector4.zero);

            var columnX = trsMatrix.GetColumn(0);
            var columnY = trsMatrix.GetColumn(1);
            var columnZ = trsMatrix.GetColumn(2);
            var scaleX  = columnX.magnitude;
            var scaleY  = columnY.magnitude;
            var scaleZ  = columnZ.magnitude;

            columnX /= scaleX;
            columnY /= scaleY;
            columnZ /= scaleZ;

            if (Vector3.Dot(Vector3.Cross(columnZ, columnY), columnX) > 0)
            {
                scaleX  = -scaleX;
                columnX = -columnX;
            }

            var scale    = new Vector3(scaleX, scaleY, scaleZ);
            var rotation = Quaternion.LookRotation(columnZ, columnY);

            //var inverseMatrix = Matrix4x4.TRS(position, rotation, scale).inverse * trsMatrix;
            //Debug.Log(position + " " + rotation + " " + scale + "\n" + inverseMatrix);

            return(Create <T>(name, parent, position, rotation, scale));
        }