Dear friends
I’m trying reconstruct a level from unity to unreal. The position of objects is transformed correctly by exchanging x,y,z.
(Forward, right and up in unity is +z, +x and +y respectively)
But I can’t reconstruct object’s rotation. As I understood, Rotating unity coordinate system 90 degree for x axis, and -90 degree for y axis. So I export euler angle after rotating -90 degree for x axis and 90 degree for y axis.
(I exported data by text and read them from unreal. And then set the ActorRotation(FRotate(degrees… )))
Would you suggest any idea? I really need this.
Thanks.
Instead of messing with quaternions and euler angles, export world matrix from unity, and import it into unreal. (keep in mind that unity uses different matrix layout than unreal, you’ll need to either transpose them first, or take that into account), split it into coordinate system vectors, swap vectors around, then reassemble the matrix.
During import, once you fixed positional component, import objects into scene editor with unmodified rotation, switch to local transform mode (by clicking globe, so it switches to cube). And figure out which axis should point where.
For example, you may notice that object’s local X should point in the direction where local -Y is pointing, etc. So, once you figured out the mapping, just decompose rotational component of matrix into vectors, swap vectors around, then reassemble the matrix.
Example code.
{
FVector x(matrix.M[0][0], matrix.M[0][1], matrix.M[0][2]);
FVector y(matrix.M[1][0], matrix.M[1][1], matrix.M[1][2]);
FVector z(matrix.M[2][0], matrix.M[2][1], matrix.M[2][2]);
FVector x1 = x;
FVector y1 = y;
FVector z1 = z;
x1 = -x;//replace with your own mapping.
z1 = y;
y1 = z;
matrix.M[0][0] = x1.X;
matrix.M[0][1] = x1.Y;
matrix.M[0][2] = x1.Z;
matrix.M[1][0] = y1.X;
matrix.M[1][1] = y1.Y;
matrix.M[1][2] = y1.Z;
matrix.M[2][0] = z1.X;
matrix.M[2][1] = z1.Y;
matrix.M[2][2] = z1.Z;
}
If you’ll try to preserve object hierarchy, it will be much more painful and is probably not worth it.
How about transformation matrix?
I have to convert unity transformation matrix(4x4; including translation, rotation, scale)
but there isn’t any solution about it in this forum.
Could you give me a advice?
I already know the difference between Unity and Unreal.
- Coordinate system must changes from X, Y, Z → -X, Z, Y
- Translation must be multiplied 100 times (Unity use “m” unit, Unreal use “cm” unit)
- Change the order of matrix from Column-major order to Row-major order
- Have to use Quaternion, not euler
I followed the above list but still the values of the two transformation matrix do not match. Am I missing something?
Thank you in advance for your kind response and time.