Hello,
I made this armature in Blender and export it to Collada:
I try to play the animation but bone orientations was changes to opposite directions:
Hello,
I made this armature in Blender and export it to Collada:
I try to play the animation but bone orientations was changes to opposite directions:
Still using old blender 2.79 I see. Well, older ones still get the job done fast and simple.
Regarding the issue itself, there isn’t much information provided to sort throught the issue in order to help out. But from the looks, it might have to do with the transformation matrices.
I use Blender 2.67b because I have a weak laptop. Even 2.68 makes my laptop noisy. My laptop was cleaned and my thermal paste was changed. I have 2.79 and 3.0 but I use them in short time when it is very necessary. 2.67b is the best for my simple tasks. Suddenly I have not made any money yet to update my laptop:
Asus K53SV; 8 GB RAM, i3 2.2 GHertz (2 cores); Intel HD Graphics 3000; Nvidia Geforce GT 540M (1 GB); Windows 10
I think it is because the bones have opposite direction of Z. You can see that a body and head are on right positions and they have right animations but another have opposite Z directions. I did not make these animations by myself. I exported by RE1MV. I wrote a script in Python to load animations and to create keyframes:
I used this video to extract models and animations:
The .ani file
15
4 1 2 9 12
0
2 3 6
1 4
1 5
0
1 7
1 8
0
1 10
1 11
0
1 13
1 14
0
0.000 0.000 32.260
0.000 -0.380 12.340
0.000 0.000 0.000
-3.320 -0.440 -3.980
0.200 -0.200 -12.040
0.040 -0.400 -16.160
2.700 -0.440 -3.980
0.020 -0.400 -12.060
0.040 -0.200 -16.160
-5.520 -0.700 11.500
-1.280 -0.140 -8.440
-1.080 0.280 -7.760
5.300 -0.720 11.280
1.320 0.000 -7.980
0.880 0.260 -7.160
25
-0.020 0.000 33.640
-0.791 -0.615 0.703
5.187 -8.615 -1.143
-5.978 8.352 -0.879
12.571 47.297 2.813
72.703 -13.363 -63.385
-25.407 23.209 -12.308
1.670 13.011 -14.330
-7.912 -2.989 0.352
18.198 -14.154 -4.220
0.000 0.352 14.681
-4.571 2.374 -0.176
16.527 -7.560 -2.110
-16.088 -1.582 -1.231
-18.989 -17.495 0.527
3.692 6.681 0.000
-0.020 0.000 33.620
-0.879 -0.527 0.703
4.923 -8.791 -1.055
-5.978 8.352 -0.879
12.571 48.088 3.165
74.637 -11.604 -63.473
-25.758 22.769 -12.308
1.846 13.099 -14.418
-7.736 -2.989 0.352
18.198 -14.505 -4.308
0.088 0.440 14.857
-4.659 2.374 -0.176
16.791 -7.824 -2.198
-16.264 -1.495 -1.319
-19.165 -17.846 0.615
3.780 6.857 0.000
-0.020 0.000 33.580
-0.967 -0.264 0.703
4.835 -8.879 -1.055
-5.978 8.352 -0.879
12.659 48.703 3.429
76.220 -10.198 -63.560
-26.022 22.505 -12.220
2.022 13.187 -14.505
-7.473 -2.989 0.352
18.198 -14.681 -4.396
0.264 0.440 15.033
-4.747 2.374 -0.264
16.967 -8.088 -2.286
-16.440 -1.407 -1.319
-19.341 -18.110 0.703
3.780 6.945 0.000
-0.020 0.000 33.560
-1.055 0.000 0.703
4.659 -8.879 -1.055
-6.066 8.352 -0.879
12.659 49.231 3.604
77.538 -8.967 -63.560
-26.198 22.242 -12.220
2.198 13.187 -14.505
-7.385 -2.989 0.352
18.198 -14.945 -4.484
0.352 0.440 15.121
-4.835 2.374 -0.264
17.143 -8.264 -2.374
-16.615 -1.407 -1.319
-19.429 -18.374 0.703
3.868 7.121 0.000
-0.020 0.000 33.540
-1.055 0.176 0.703
4.571 -8.967 -1.055
-6.066 8.440 -0.879
12.747 49.670 3.780
78.593 -8.088 -63.560
-26.374 22.066 -12.132
2.286 13.275 -14.593
-7.209 -2.989 0.264
18.110 -15.033 -4.484
0.440 0.440 15.209
-4.923 2.374 -0.264
17.231 -8.352 -2.462
-16.703 -1.319 -1.407
-19.516 -18.549 0.791
3.868 7.121 0.000
-0.020 0.000 33.520
-1.055 0.440 0.703
4.484 -9.055 -1.055
-6.066 8.440 -0.879
12.747 49.934 3.956
79.297 -7.385 -63.560
-26.462 21.890 -12.132
2.374 13.275 -14.593
-7.121 -2.989 0.264
18.110 -15.121 -4.571
0.527 0.440 15.297
-4.923 2.374 -0.264
17.319 -8.440 -2.462
-16.791 -1.319 -1.407
-19.604 -18.725 0.791
3.956 7.209 0.000
-0.020 0.000 33.520
-0.967 0.527 0.703
4.484 -9.055 -1.055
-6.066 8.440 -0.879
12.747 50.110 4.044
79.736 -7.033 -63.560
-26.549 21.802 -12.132
2.374 13.275 -14.593
-7.121 -2.989 0.264
18.110 -15.209 -4.571
0.527 0.440 15.297
-4.923 2.374 -0.264
17.319 -8.527 -2.549
-16.791 -1.319 -1.407
-19.692 -18.813 0.791
3.956 7.209 0.000
-0.020 0.000 33.520
-0.967 0.352 0.703
4.484 -9.055 -1.055
-6.066 8.440 -0.879
12.747 50.198 4.044
80.000 -6.857 -63.560
-26.549 21.802 -12.132
2.374 13.275 -14.593
-7.033 -2.989 0.264
18.110 -15.209 -4.571
0.527 0.440 15.297
-4.923 2.374 -0.264
17.407 -8.527 -2.549
-16.791 -1.319 -1.407
-19.692 -18.813 0.791
3.956 7.209 0.000
-0.020 0.000 33.520
-0.967 0.000 0.703
4.484 -9.055 -1.055
-6.066 8.440 -0.879
12.747 50.198 4.044
79.912 -6.857 -63.560
-26.549 21.802 -12.132
2.374 13.275 -14.593
-7.121 -2.989 0.264
18.110 -15.209 -4.571
0.527 0.440 15.297
-4.923 2.374 -0.264
17.407 -8.527 -2.549
-16.791 -1.319 -1.407
-19.692 -18.813 0.791
3.956 7.209 0.000
-0.020 0.000 33.520
-0.967 -0.879 0.703
4.484 -9.055 -1.055
-6.066 8.440 -0.879
12.747 50.110 3.956
79.648 -7.121 -63.560
-26.549 21.890 -12.132
2.374 13.275 -14.593
-7.121 -2.989 0.264
18.110 -15.209 -4.571
0.527 0.440 15.297
-4.923 2.374 -0.264
17.319 -8.527 -2.549
-16.791 -1.319 -1.407
-19.604 -18.725 0.791
3.956 7.209 0.000
-0.020 0.000 33.540
-0.879 -3.341 0.791
4.484 -8.967 -1.055
-6.066 8.440 -0.879
12.747 49.934 3.956
79.297 -7.473 -63.560
-26.462 21.890 -12.132
2.374 13.275 -14.593
-7.121 -2.989 0.264
18.110 -15.121 -4.571
0.527 0.440 15.297
-4.923 2.374 -0.264
17.319 -8.440 -2.462
-16.791 -1.319 -1.407
-19.604 -18.725 0.791
3.956 7.209 0.000
-0.020 0.000 33.540
-0.791 -7.473 0.791
4.571 -8.967 -1.055
-6.066 8.440 -0.879
12.747 49.758 3.868
78.681 -7.912 -63.560
-26.374 22.066 -12.132
2.286 13.275 -14.593
-7.209 -2.989 0.264
18.110 -15.033 -4.484
0.440 0.440 15.209
-4.923 2.374 -0.264
17.231 -8.352 -2.462
-16.703 -1.319 -1.407
-19.604 -18.549 0.791
3.868 7.121 0.000
-0.020 0.000 33.560
-0.703 -12.044 0.879
4.659 -8.967 -1.055
-6.066 8.440 -0.879
12.747 49.495 3.692
78.066 -8.527 -63.560
-26.286 22.154 -12.132
2.198 13.187 -14.593
-7.297 -2.989 0.352
18.198 -14.945 -4.484
0.440 0.440 15.121
-4.835 2.374 -0.264
17.143 -8.264 -2.462
-16.615 -1.407 -1.407
-19.516 -18.462 0.703
3.868 7.121 0.000
-0.020 0.000 33.560
-0.615 -15.736 0.879
4.747 -8.879 -1.055
-6.066 8.352 -0.879
12.659 49.143 3.604
77.275 -9.231 -63.560
-26.110 22.330 -12.220
2.110 13.187 -14.505
-7.385 -2.989 0.352
18.198 -14.857 -4.484
0.352 0.440 15.121
-4.835 2.374 -0.264
17.055 -8.176 -2.374
-16.527 -1.407 -1.319
-19.429 -18.286 0.703
3.868 7.033 0.000
-0.020 0.000 33.580
-0.615 -17.319 0.879
4.747 -8.879 -1.055
-5.978 8.352 -0.879
12.659 48.791 3.429
76.484 -10.022 -63.560
-26.022 22.418 -12.220
2.110 13.187 -14.505
-7.473 -2.989 0.352
18.198 -14.769 -4.396
0.264 0.440 15.033
-4.747 2.374 -0.264
16.967 -8.088 -2.286
-16.440 -1.407 -1.319
-19.341 -18.198 0.703
3.780 7.033 0.000
-0.020 0.000 33.600
-0.615 -15.824 0.879
4.835 -8.791 -1.055
-5.978 8.352 -0.879
12.659 48.440 3.341
75.604 -10.725 -63.473
-25.846 22.593 -12.220
2.022 13.187 -14.505
-7.560 -2.989 0.352
18.198 -14.593 -4.396
0.264 0.352 14.945
-4.747 2.374 -0.264
16.879 -8.000 -2.286
-16.352 -1.495 -1.319
-19.253 -18.022 0.615
3.780 6.945 0.000
-0.020 0.000 33.600
-0.615 -12.220 0.791
4.923 -8.791 -1.055
-5.978 8.352 -0.879
12.571 48.088 3.165
74.725 -11.516 -63.473
-25.758 22.769 -12.308
1.934 13.099 -14.418
-7.648 -2.989 0.352
18.198 -14.505 -4.308
0.176 0.352 14.857
-4.659 2.374 -0.176
16.791 -7.824 -2.198
-16.264 -1.495 -1.319
-19.253 -17.846 0.615
3.780 6.857 0.000
-0.020 0.000 33.620
-0.615 -7.736 0.791
5.011 -8.703 -1.055
-5.978 8.352 -0.879
12.571 47.736 2.989
73.846 -12.308 -63.385
-25.582 22.945 -12.308
1.846 13.099 -14.418
-7.824 -2.989 0.352
18.198 -14.330 -4.308
0.088 0.352 14.769
-4.659 2.374 -0.176
16.703 -7.736 -2.198
-16.176 -1.495 -1.319
-19.165 -17.670 0.615
3.692 6.769 0.000
-0.020 0.000 33.640
-0.703 -3.516 0.703
5.099 -8.703 -1.143
-5.978 8.352 -0.879
12.571 47.473 2.901
73.055 -13.011 -63.385
-25.495 23.121 -12.308
1.758 13.099 -14.330
-7.912 -2.989 0.352
18.198 -14.242 -4.308
0.000 0.352 14.681
-4.571 2.374 -0.176
16.615 -7.648 -2.110
-16.088 -1.582 -1.231
-19.077 -17.582 0.527
3.692 6.769 0.000
-0.020 0.000 33.660
-0.703 -0.703 0.615
5.187 -8.615 -1.143
-5.978 8.352 -0.879
12.571 47.121 2.813
72.352 -13.714 -63.297
-25.319 23.209 -12.308
1.670 13.011 -14.330
-8.000 -2.989 0.352
18.198 -14.154 -4.220
0.000 0.352 14.681
-4.571 2.374 -0.176
16.527 -7.560 -2.110
-16.000 -1.582 -1.231
-18.989 -17.407 0.527
3.604 6.681 0.000
-0.020 0.000 33.660
-0.703 0.176 0.615
5.275 -8.615 -1.143
-5.978 8.264 -0.879
12.484 46.857 2.637
71.736 -14.242 -63.297
-25.231 23.385 -12.308
1.582 13.011 -14.330
-8.088 -2.989 0.352
18.198 -14.066 -4.220
0.000 0.352 14.593
-4.484 2.374 -0.176
16.440 -7.385 -2.022
-16.000 -1.582 -1.231
-18.901 -17.231 0.527
3.604 6.681 0.000
-0.020 0.000 33.680
-0.615 0.440 0.615
5.275 -8.527 -1.143
-5.978 8.264 -0.879
12.484 46.593 2.549
71.209 -14.769 -63.209
-25.143 23.473 -12.396
1.495 13.011 -14.330
-8.176 -2.989 0.352
18.198 -13.978 -4.220
0.000 0.352 14.505
-4.484 2.374 -0.176
16.352 -7.385 -2.022
-15.912 -1.670 -1.231
-18.901 -17.143 0.527
3.604 6.593 0.000
-0.020 0.000 33.680
-0.615 0.088 0.615
5.363 -8.527 -1.143
-5.978 8.264 -0.879
12.484 46.418 2.462
70.769 -15.121 -63.209
-25.055 23.560 -12.396
1.495 13.011 -14.242
-8.176 -2.989 0.352
18.198 -13.890 -4.132
0.000 0.352 14.505
-4.484 2.374 -0.176
16.264 -7.297 -2.022
-15.824 -1.670 -1.231
-18.813 -17.055 0.440
3.604 6.593 0.000
-0.020 0.000 33.680
-0.615 -0.264 0.615
5.363 -8.527 -1.143
-5.978 8.264 -0.879
12.484 46.330 2.462
70.505 -15.385 -63.209
-25.055 23.648 -12.396
1.495 13.011 -14.242
-8.264 -2.989 0.352
18.198 -13.802 -4.132
0.000 0.352 14.505
-4.484 2.374 -0.176
16.264 -7.209 -2.022
-15.824 -1.670 -1.231
-18.813 -17.055 0.440
3.604 6.505 0.000
-0.020 0.000 33.680
-0.615 -0.440 0.615
5.363 -8.527 -1.143
-5.978 8.264 -0.879
12.484 46.242 2.462
70.418 -15.473 -63.209
-25.055 23.648 -12.396
1.495 13.011 -14.242
-8.264 -2.989 0.352
18.198 -13.802 -4.132
0.000 0.352 14.418
-4.396 2.374 -0.176
16.264 -7.209 -1.934
-15.824 -1.670 -1.231
-18.813 -16.967 0.440
3.516 6.505 0.000
contains angles in global coordinates. I used these coordinates to rotate bones globally from script:
for k in reversed(range(15)):
if j == 0:
bpy.ops.pose.group_deselect()
pbone = armature.pose.bones["Bone_0"]
armature.data.bones.active = pbone.bone
bpy.ops.transform.translate(value=(x, 0, 0), constraint_axis=(True, False, False), constraint_orientation="GLOBAL")
bpy.ops.transform.translate(value=(0, y, 0), constraint_axis=(False, True, False), constraint_orientation="GLOBAL")
bpy.ops.transform.translate(value=(0, 0, z), constraint_axis=(False, False, True), constraint_orientation="GLOBAL")
bpy.ops.pose.group_deselect()
pbone = armature.pose.bones["Bone_" + str(k)]
armature.data.bones.active = pbone.bone
rot_xyz = rotations[j]
bpy.ops.transform.rotate(value=rot_xyz[0], axis=(1, 0, 0), constraint_axis=(True, False, False), constraint_orientation="GLOBAL")
bpy.ops.transform.rotate(value=rot_xyz[1], axis=(0, 1, 0), constraint_axis=(False, True, False), constraint_orientation="GLOBAL")
bpy.ops.transform.rotate(value=rot_xyz[2], axis=(0, 0, 1), constraint_axis=(False, False, True), constraint_orientation="GLOBAL")
j += 1
I think maybe the Collada file contains coordinates in local space of bones. I need to check it. But I do not understand it now.
I changed “Roll” in “Edit Mode” to 180 to make Z the same with “body” and “head”:
and I generated the keyframes again, but it did not helped, it looks the same as before. Maybe I will make a separate example with a few bones in Sandbox to show this problem in WebGL.
This is still the same issue as every other bone, which means that they are all inverted in their rotation, and this will be higher accentuated the more you rotate them, meaning that a bone that is rotated 1 degree has less noticeable effect than a bone rotated 120 degress. That being said, try check on your shader if you are mirroring the matrix or inversing it.
My suggestion is, for the sake of it, and for a cleanner debug:
Then check if the bones are inverted, if they are, on the code where you transform your bones an inverse like this:
inverse(jointMat) * boneN
Also, you might want to check out another possible issue which has to do with the Y-axis vs Z-axis coordinate system. For this, check if you are rotating you axis system when importing to your project, sometimes this would lead to undesidered results such as 90 degree rotation of objects.
I deleted all animations in Blender. I made a default pose. I exported 5 bones. You can see very strange effect. For two bones (head and body) it looks good. But for 3 bones (upper arm, lower arm, hand) rotations are inverted. I use all 5 bones in the same way without inversion.
How it looks in Blender:
How it looks in WebGL:
You should export the bones in rest position, are they in rest position? Because the arm bones could already be rotated.
If this is rest position, can you export a different format? maybe the exporter script could be wrong, or try using a newer version of blender just check if its not a file format problem.
From what I see, the origins seem to be right, only the rotations seem wrong, try using the rest position.
try and update this code here in the export script:
for k in reversed(range(15)):
f j == 0:
bpy.ops.pose.group_deselect()
pbone = armature.pose.bones["Bone_0"]
armature.data.bones.active = pbone.bone
bpy.ops.transform.translate(value=(x, 0, 0), constraint_axis=(True, False, False), constraint_orientation="GLOBAL")
bpy.ops.transform.translate(value=(0, y, 0), constraint_axis=(False, True, False), constraint_orientation="GLOBAL")
bpy.ops.transform.translate(value=(0, 0, z), constraint_axis=(False, False, True), constraint_orientation="GLOBAL")
bpy.ops.pose.group_deselect()
pbone = armature.pose.bones["Bone_" + str(k)]
armature.data.bones.active = pbone.bone
rot_xyz = rotations[j]
bpy.ops.transform.rotate(value=-rot_xyz[0], axis=(1, 0, 0), constraint_axis=(True, False, False), constraint_orientation="GLOBAL")
bpy.ops.transform.rotate(value=-rot_xyz[1], axis=(0, 1, 0), constraint_axis=(False, True, False), constraint_orientation="GLOBAL")
bpy.ops.transform.rotate(value=-rot_xyz[2], axis=(0, 0, 1), constraint_axis=(False, False, True), constraint_orientation="GLOBAL")
j += 1
I do not use this script now. I created this armature manually. It was created manually from beginning. Script just rotates bones from file and creates 25 keyframes from .ani file (.ani is exported file from RE1MV). But now I deleted all keyframes and reset angles. I made three keyframes for the rest position.
I tried to open my example in Blender 2.79 and export it to dae. I want to avoid studying a new format for a while. I tried to study glTF but I cannot understand how to export bones. I spend a few weeks for it. I can load only static models from gltf: Plunker - Loading a cube from gltf 2.0. WebGL, JavaScript. I made this animation with skinning with dae in WebGL a few month ago. But my current tasks do not have skinning. Skinning is expensive for browsers. Jill is very simple but I think this problem like a mystic.
The only issue I can really see here, is the global transformation.
Take a look at this:
on this image, you can clearly see that:
then when generating the armature (skeleton), the torso is correct because there is no rotation whatsoever, but the right arm is rotated ~170 degres counterclockwise, as we can see here:
So: the positions are correct, the rotation angles are also correct, but the orientations are not.
My only suggestion would be to check the exportation or the importation process: either it has to do with the rotation angles or with the Global Coordinate system being used here.
Start by making the arm with upwards bones as the same as the body and check if they are well aligned just to clear this suspiscion.
If I set an upper arm bone with 0 angle I see the correct default position of object:
I will have a little strange armature but I will try.
It is how parts of body look:
I made a new skeleton:
Default positions of bones work correctly:
I generated keyframes:
It looks good from the front:
But it looks really bad from the side:
The most interesting thing is that it looks good in Blender from the side:
I see the problem with the pelvis:
Thanks very much!
I forgot to set legs as child of pelvis in my code like this:
modelMatrix = popMatrix();
pushMatrix(modelMatrix);
{
mat4.getTranslation(prevTranslation, keyMatrixes[2][prevFrameIndex]);
mat4.getTranslation(nextTranslation, keyMatrixes[2][nextFrameIndex]);
vec3.lerp(translation, prevTranslation, nextTranslation, progression);
mat4.getRotation(prevRotation, keyMatrixes[2][prevFrameIndex]);
mat4.getRotation(nextRotation, keyMatrixes[2][nextFrameIndex]);
quat.slerp(rotation, prevRotation, nextRotation, progression);
mat4.translate(modelMatrix, modelMatrix, translation);
mat4.fromQuat(rotationMatrix, rotation);
mat4.mul(modelMatrix, modelMatrix, rotationMatrix);
jillParts[2].modelMatrix = modelMatrix;
jillParts[2].draw(projViewMatrix); // Pelvis
pushMatrix(modelMatrix);
{
mat4.getTranslation(prevTranslation, keyMatrixes[3][prevFrameIndex]);
mat4.getTranslation(nextTranslation, keyMatrixes[3][nextFrameIndex]);
vec3.lerp(translation, prevTranslation, nextTranslation, progression);
mat4.getRotation(prevRotation, keyMatrixes[3][prevFrameIndex]);
mat4.getRotation(nextRotation, keyMatrixes[3][nextFrameIndex]);
quat.slerp(rotation, prevRotation, nextRotation, progression);
mat4.translate(modelMatrix, modelMatrix, translation);
mat4.fromQuat(rotationMatrix, rotation);
mat4.mul(modelMatrix, modelMatrix, rotationMatrix);
jillParts[3].modelMatrix = modelMatrix;
jillParts[3].draw(projViewMatrix); // lUpperLeg
pushMatrix(modelMatrix);
{
mat4.getTranslation(prevTranslation, keyMatrixes[4][prevFrameIndex]);
mat4.getTranslation(nextTranslation, keyMatrixes[4][nextFrameIndex]);
vec3.lerp(translation, prevTranslation, nextTranslation, progression);
mat4.getRotation(prevRotation, keyMatrixes[4][prevFrameIndex]);
mat4.getRotation(nextRotation, keyMatrixes[4][nextFrameIndex]);
quat.slerp(rotation, prevRotation, nextRotation, progression);
mat4.translate(modelMatrix, modelMatrix, translation);
mat4.fromQuat(rotationMatrix, rotation);
mat4.mul(modelMatrix, modelMatrix, rotationMatrix);
jillParts[4].modelMatrix = modelMatrix;
jillParts[4].draw(projViewMatrix); // lLowerLeg
pushMatrix(modelMatrix);
{
mat4.getTranslation(prevTranslation, keyMatrixes[5][prevFrameIndex]);
mat4.getTranslation(nextTranslation, keyMatrixes[5][nextFrameIndex]);
vec3.lerp(translation, prevTranslation, nextTranslation, progression);
mat4.getRotation(prevRotation, keyMatrixes[5][prevFrameIndex]);
mat4.getRotation(nextRotation, keyMatrixes[5][nextFrameIndex]);
quat.slerp(rotation, prevRotation, nextRotation, progression);
mat4.translate(modelMatrix, modelMatrix, translation);
mat4.fromQuat(rotationMatrix, rotation);
mat4.mul(modelMatrix, modelMatrix, rotationMatrix);
jillParts[5].modelMatrix = modelMatrix;
jillParts[5].draw(projViewMatrix); // lFoot
}
modelMatrix = popMatrix();
I moved my topic to WebGL section.
I loaded all animation to WebGL from DAE for this character: