From 02b44c07adfcf921da594120b4cd8fc18b982725 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 20 Sep 2021 00:42:33 +0800 Subject: +command buffer --- Assets/Scripts/Utils/TransformUtility.cs | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Assets/Scripts/Utils/TransformUtility.cs (limited to 'Assets/Scripts/Utils/TransformUtility.cs') diff --git a/Assets/Scripts/Utils/TransformUtility.cs b/Assets/Scripts/Utils/TransformUtility.cs new file mode 100644 index 00000000..62a28ece --- /dev/null +++ b/Assets/Scripts/Utils/TransformUtility.cs @@ -0,0 +1,54 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class TransformUtility +{ + + public static Matrix4x4 GetLocalToWorldMatrix(Transform transform) + { + Matrix4x4 mat = Matrix4x4.identity; + while(transform != null) + { + Matrix4x4 m = Matrix4x4.identity; + m.SetTRS2(transform.localPosition, transform.localRotation, transform.localScale); + mat = m * mat; + transform = transform.parent; + } + + return mat; + } + + public static Matrix4x4 GetLocalToWorldMatrixNoScale(Transform transform) + { + Matrix4x4 mat = Matrix4x4.identity; + while (transform != null) + { + Matrix4x4 m = Matrix4x4.identity; + m.SetTR(transform.localPosition, transform.localRotation); + mat = m * mat; + transform = transform.parent; + } + + return mat; + } + + public static Matrix4x4 GetLocalToWorldMatrixRootBone(Transform transform) + { + //Matrix4x4 mat = Matrix4x4.identity; + //while (transform != null) + //{ + // Matrix4x4 m = Matrix4x4.identity; + // m = Matrix4x4.Rotate(transform.localRotation); + // mat = m * mat; + // transform = transform.parent; + //} + //mat.SetColumn(3, new Vector4(trans.position.x, trans.position.y, trans.position.z, 1)); + + Matrix4x4 mat = Matrix4x4.Rotate(transform.rotation); + mat.SetColumn(3, new Vector4(transform.position.x, transform.position.y, transform.position.z, 1)); + + return mat; + } + +} \ No newline at end of file -- cgit v1.1-26-g67d0