I found this out: DirectX and OpenGL uses different conventions in dealing with matrix.
I read about it here:
http://www.mindcontrol.org/~hplus/graph ... ayout.html
Traditional mathematicians, and OpenGL, tends to prefer colum vectors. Meanwhile, certain other legacies of computer graphics, as well as DirectX, tend to prefer row vectors, on the left. The confusion gets even more complete when you start talking about "pre-multiplying" and "post-multiplying" matrices. Pre-multiplying may mean multiplying it on the left (if you're the row vector type), or it may mean multiplying it on the right (if you're the OpenGL type) -- if by "pre" you mean that the pre-multiplied operation happens before the target matrix operation. If instead you mean, with pre-multplying, that the matrix you're pre-multiplying goes on the left, then it means that it happens afterward in the OpenGL notation, but it still means that it happens before in the DirectX notation
Considering that the game I'm working with uses DirectX, it is understandable that the matrices stored in the files follows DirectX convention... Three.JS on the otherhand uses WebGL or OpenGL ES 2... A different convention...
I have updated the fiddle but still not yet completely fixed, but seems to be a bit closer:
https://jsfiddle.net/do4037kb/21/
This is the part where I tried to multiply the frame matrix with the bone and its parent bone.
Code: Select all
var modelSpaceMatrix = new THREE.Matrix4();
modelSpaceMatrix.multiplyMatrices(root.skeleton.bones[y].userData.modelMatrix, frameMatrix);
inverseFramematrices.push(new THREE.Matrix4().getInverse(modelSpaceMatrix));
var parentId = root.skeleton.bones[y].userData.parentId;
if (parentId >= 0) {
modelSpaceMatrix.multiplyMatrices(modelSpaceMatrix, inverseFramematrices[parentId]);
}
-------------------------
This is another good read but it's the opposite of what I wanted:
http://gamedev.stackexchange.com/questi ... to-directx
So I guess, transposing the matrix should fix the directx/opengl problem.
-------------------------
Here is an example exporter from Blender into ThreeJS format:
https://github.com/mrdoob/three.js/blob ... ion.py#L56
There should be something interesting there.