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));
        }
Example #2
0
 public static void Put(this NetDataWriter dw, UnityEngine.Matrix4x4 matrix)
 {
     dw.Put(matrix.GetColumn(0));
     dw.Put(matrix.GetColumn(1));
     dw.Put(matrix.GetColumn(2));
     dw.Put(matrix.GetColumn(3));
 }
Example #3
0
        /// <summary>
        /// Convert an Unity matrix to a TES matrix.
        /// </summary>
        /// <remarks>
        /// Translation of <paramref name="umat"/> is dropped.
        /// </remarks>
        /// <returns>The TES matrix equivalent.</returns>
        /// <param name="umat">The Unity matrix to convert.</param>
        public static Matrix3 FromUnity(UnityEngine.Matrix4x4 umat)
        {
            Matrix3 mat = new Matrix3();
            Vector3 v   = new Vector3();

            for (int i = 0; i < 3; ++i)
            {
                v = Vector3Ext.FromUnity(umat.GetColumn(i));
                mat.SetAxis(i, v);
            }
            return(mat);
        }
Example #4
0
        static StackObject *GetColumn_2(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Int32 @index = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            UnityEngine.Matrix4x4 instance_of_this_method = (UnityEngine.Matrix4x4) typeof(UnityEngine.Matrix4x4).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));

            var result_of_this_method = instance_of_this_method.GetColumn(@index);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);

            __intp.Free(ptr_of_this_method);
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }