blob: 62a28ece046fd743d22ea415fbc18946c9df7cab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
}
}
|