Example #1
0
        static Matrix4x4 LookAtMatrix(Vector3 up_vector, Vector3 localPosition)
        {
            var z_axis = localPosition.normalized;
            var x_axis = Vector3.Cross(up_vector, z_axis).normalized;
            var y_axis = Vector3.Cross(z_axis, x_axis).normalized;

            return(UnityExtensions.Matrix4x4FromColumns(x_axis, y_axis, z_axis, new Vector4(0, 0, 0, 1)));
        }
Example #2
0
 public static Matrix4x4 RotationToWorldAxis(this Matrix4x4 m)
 {
     return(UnityExtensions.Matrix4x4FromColumns(
                m.MultiplyVector(Vector3.right),
                m.MultiplyVector(Vector3.up),
                m.MultiplyVector(Vector3.forward),
                new Vector4(0, 0, 0, 1)
                ));
 }
Example #3
0
        public Node CreateNode(int index)
        {
            var x    = Gltf.nodes[index];
            var node = new Node(x.name);

            if (x.matrix != null)
            {
                if (x.matrix.Length != 16)
                {
                    throw new Exception("matrix member is not 16");
                }
                if (x.translation != null && x.translation.Length > 0)
                {
                    throw new Exception("matrix with translation");
                }
                if (x.rotation != null && x.rotation.Length > 0)
                {
                    throw new Exception("matrix with rotation");
                }
                if (x.scale != null && x.scale.Length > 0)
                {
                    throw new Exception("matrix with scale");
                }
                var m = UnityExtensions.MatrixFromArray(x.matrix);

                node.SetLocalMatrix(m, true);
            }
            else
            {
                if (x.translation != null && x.translation.Length == 3)
                {
                    node.LocalTranslation = x.translation.ToVector3();
                }
                if (x.rotation != null && x.rotation.Length == 4)
                {
                    node.LocalRotation = x.rotation.ToQuaternion();
                }
                if (x.scale != null && x.scale.Length == 3)
                {
                    node.LocalScaling = x.scale.ToVector3(Vector3.one);
                }
            }
            return(node);
        }
Example #4
0
        static Matrix4x4 LookAtMatrixFromWorld(Vector3 from, Vector3 target)
        {
            var pos = new Vector4(from.x, from.y, from.z, 1);

            return(LookAtMatrix(UnityExtensions.Matrix4x4FromColumns(Vector3.right, Vector3.up, Vector3.forward, pos), target));
        }