Closed Amir-Arsalan closed 4 years ago
I just had to make the following changes to [manually] change the coordinate system of FleX to the one that Blender uses:
obj->Transform(RotationMatrix(op.rotate.x, Vec3(1.0f, 0.0f, 0.0f)));
obj->Transform(RotationMatrix(op.rotate.y, Vec3(0.0f, 0.0f, -1.0f)))
obj->Transform(RotationMatrix(op.rotate.z, Vec3(0.0f, 1.0f, 0.0f)));
The way I figured this was I generated three rotation vectors [90, 0, 0]
, [0, 90, 0]
and [0, 0, 90]
and rotated the shapes in FleX. Then I loaded the shapes in Blender and empirically figured rotation on which axis in Blender matches to the shape imported from FleX. I learned that when I rotate the shape on the Y
axis by 90 degrees in Blender, it matches the 90-degree rotation on the Z
axis in FleX. Also, I learned that rotating the object by -90 degrees on the Z
axis in Blender matches with the 90-degree rotation on the Y
axis in FleX.
@mmacklin Now I have a similar issue with Quaternions. I know how to change the rotation matrix for Quaternions but I don't immediately see which parts of quat.h I should change to do this in practice. Things look a bit cryptic in quat.h for me. Could you please guide me on this?
I just had to make the following changes to [manually] change the coordinate system of FleX to the one that Blender uses:
obj->Transform(RotationMatrix(op.rotate.x, Vec3(1.0f, 0.0f, 0.0f))); obj->Transform(RotationMatrix(op.rotate.y, Vec3(0.0f, 0.0f, -1.0f))) obj->Transform(RotationMatrix(op.rotate.z, Vec3(0.0f, 1.0f, 0.0f)));
The way I figured this was I generated three rotation vectors
[90, 0, 0]
,[0, 90, 0]
and[0, 0, 90]
and rotated the shapes in FleX. Then I loaded the shapes in Blender and empirically figured rotation on which axis in Blender matches to the shape imported from FleX. I learned that when I rotate the shape on theY
axis by 90 degrees in Blender, it matches the 90-degree rotation on theZ
axis in FleX. Also, I learned that rotating the object by -90 degrees on theZ
axis in Blender matches with the 90-degree rotation on theY
axis in FleX.@mmacklin Now I have a similar issue with Quaternions. I know how to change the rotation matrix for Quaternions but I don't immediately see which parts of quat.h I should change to do this in practice. Things look a bit cryptic in quat.h for me. Could you please guide me on this?
Take a look at this project, which uses Flex for haptic rendering: FleX-Chai3d
It includes helper functions to convert from the Flex coordinate system to the one that Chai3D uses, which is the standard x,y,z. This might help to convert the quaternions as well.
Vec3 FromChai(const cVector3d& a_vector) {
return Vec3(a_vector.y(), a_vector.z(), a_vector.x());
}
cVector3d ToChai(const Vec3& a_vector) {
return cVector3d(a_vector.z, a_vector.x, a_vector.y);
}
cQuaternion ToChai(const Quat& a_quat) {
return cQuaternion(a_quat.w, a_quat.z, a_quat.x, a_quat.y);
}
cMatrix3d ToChaiRotMat(const Quat& a_quat) {
cMatrix3d rotMat;
ToChai(a_quat).toRotMat(rotMat);
return rotMat;
}
I import a mesh in NVIDIA's FleX, rotate it and store it on disk; I call this mesh
X
. I also import the mesh in Blender and rotate it the same amount; I call this meshY
. After I importedX
in Blender I realized thatX
has a different rotation which means that FleX is either using a different global axes (I think it's-Y
forward andZ
up) or it applies the rotations in a different order or a combination of both. So I am pretty confused now. I do not want to change anything on the FleX side. However, I want to rotateY
in a way that it matches with what FleX exports (X
) after rotation. I also tried with Quaternions but I'm still unable to figure out the way FleX is transforming the object. The only thing that I've been able to figure out empirically is that the value forrx
rotation is applied the same way for both FleX and Blender. This means that objectsX
andY
would overlap completely if imported in on scene in Blender.My goal is to rotate the object in FleX so that object
Y
's rotation matches exactly with objectX
when I import it in Blender. How can I achieve this?Note that I am not changing the rotation order in Blender and I'm using the default
XYZ
order for rotation.Here I are some images of the visual differences between FleX and Blender for such transformations:
Euler rotation vector:
[0, 89.9, 0]
in for objectX
in Blender. After applying the rotation in Blender (objectX
):After applying the same rotation (
[0, 89.9, 0]
) in FleX and importing the objectY
in Blender:Euler rotation vector:
[0, 0, 89.9]
for objectX
in Blender:After applying the same rotation (
[0, 0, 89.9]
) in FleX and importing the objectY
in Blender:It might look it is easy to guess from the images that FleX swaps the
ry
andrz
rotation to do the rotation. If I also swap the rotations in Blender then both X and Y totally overlap with each other. However, if the rotation vector is[-43.964176, 20.641195, -1.2689421]
X
andY
do not overlap anymore and discrepancies start to show up:The discrepancies are more visible if I put a cloth on
Y
in FleX, import the cloth andX
in Blender and rotateX
by[-43.964176, -1.2689421, 20.641195]
(notice that I've swappedry
andrz
:Note that if I import
Y
here, the cloth would be perfectly covering it while touching it on the surface:As you probably know FleX computes and uses its rotation matrices as follow. The top one is used when Euler angles are used and the second one is used when Quaternions are input:
And here's how I apply the Euler rotation vector:
And I think this should be how Transform() is defined: