NegInfinity/ProjectExodus

How do you do the conversion

Opened this issue · 8 comments

Hi I wanted to ask you the question : How do you do the conversion from the coordinate on Unity to Unreal is there a Multiplication or an equation depending on the axis ?
Thanks

This is not a bug report...

There's no equation.

Unity has X axis pointing right, Z axis pointing forward, Y axis pointing up. And by default uses one meter unit scale.
Unreal has Y axis is right, X axis pointing forward, and Z is up. And by default it uses 1 centimeter unit scale.

So to convert unity world space matrix, you break it into components - position and basis vectors, convert them all to unreal convention and assemble unreal matrix back from them.

Actually you can see how it is done by looking through UnrealUtilities.cpp and reading UnrealUtilities::unityWorldToUe function. The one that does not have localPositionOffset parameter. Currently it is located at line 278 of the file.

Sorry for putting this on Issue :c

Weird because when I import some asset :
Grid 4 :

  • Unity : "pos":{"x":-26.318,"y":-12.544,"z":67.172},"rot":{"x":47.486,"y":359.987,"z":281.519},"scale":{"x":1.0,"y":1.0,"z":1.0}
  • Unreal Engine : Post (X=6717.199707,Y=-2631.800049,Z=-1254.400024) Rot : (Pitch=-47.486000,Yaw=-0.013000,Roll=78.480988) Scale : (X=1.000000,Y=1.000000,Z=1.000000)

Stalagmite :
-Unity : "pos":{"x":-88.336,"y":-63.158,"z":-74.799},"rot":{"x":0.0,"y":42.077,"z":0.0},"scale":{"x":0.7,"y":0.7,"z":0.7}
-Unreal Engine : Pos : (X=-7479.900391,Y=-8833.599609,Z=-6315.800293)Rot : (Pitch=0.000000,Yaw=42.077011,Roll=0.000000)Scale :(X=0.700000,Y=0.700000,Z=0.700000)

@DiabloFox The numbers you posted are completely correct.

X: -26.318; Y:-12.544;Z:67.172 turns respectively into
Y:-2631.8;Z:-1254.4;X:6717.2. Scale does not change, and... yaw pitch roll are not meant to match euler angles, as orientation is stored as 3 vectors.

Basically, see if the object is at the same spot, faces the same direction and is at the same relative scale compared to the parent.

If it looks the same, then it is positioned correctly.

Oh ! Thank you so much !
So it's :
X : Unity(x) -> UE4(y) * 100.0f
Y : Unity(y) -> UE4(z) * 100.0f
Z : Unity(z) -> UE4(x) * 100.0f

@DiabloFox
That's true only if you're dealing with direction.
With position, you'll have to multiply it by 100 (because unreal uses centimeter scale). See
UnrealUtilities.cpp , functions called "unityPosToUe" and "unityVecToUe". "Pos" means Position, "Vec" means vector or direction.

If you have to do a documentation about it try to add this because there is not really anybody talking about this. And it's really good work, I wish you the best ! Thanks again !

Hi, sorry to bother you but how the rotation is convert from unity to unreal standard ?

@DiabloFox As I said before, the plugin does not attempt to convert rotation directly and instead extracts unity object matrix, splits it into basis vectors and then reassembles it on unreal side as a matrix.

A transform matrix is composed from X/Y/Z vectors that determine object orinetation and scale, and position vector that denotes where the object is.

The conversion procedure for matrices is defined within UnrealUtilities.cpp, function UnrealUtilities::unityWorldToUe .

`FMatrix UnrealUtilities::unityWorldToUe(const FMatrix &unityWorld, const FVector &localPositionOffset){
	FVector xAxis, yAxis, zAxis;
	unityWorld.GetScaledAxes(xAxis, yAxis, zAxis);
	FVector pos = unityWorld.GetOrigin();

	pos += xAxis * localPositionOffset.X + yAxis * localPositionOffset.Y + zAxis * localPositionOffset.Z;

	pos = unityPosToUe(pos);//unityToUe(pos)*100.0f;
	//unityPosToUe(pos);
	xAxis = unityVecToUe(xAxis);
	yAxis = unityVecToUe(yAxis);
	zAxis = unityVecToUe(zAxis);

	FMatrix ueMatrix = FMatrix::Identity;//Well, wow. I expected matrix to have a local constructor.
	ueMatrix.SetAxes(&zAxis, &xAxis, &yAxis, &pos);
	return ueMatrix;
}

Which uses following subroutines:

	return FVector(arg.Z, arg.X, arg.Y);
}

FVector UnrealUtilities::unityPosToUe(const FVector& arg){
	return unityVecToUe(arg) * 100.0f;
}

Again, defined in the same file.

To convert rotation this way, you'd need to first convert rotation to rotation matrix, and then convert the matrix on unreal side to the rotation method you prefer.

Meaning the plugin does not directly convert Quaternions or Euler angles or any other form of rotation and deals with matrices only.