"matricesWeights" in '.babylon' file

Recommended Posts

Why matricesWeights property comprises information on 4 values. Why they are necessary?

For example:

"matricesWeights": [0, 1, 0, 0, 0, 1, 0, 0,...]

Why each of values is necessary?

Share on other sites

Hey Toly,

when dealing with bones here is how it works:

- Instead of directly applying the world matrix on the vertex, it will use the matricesIndices to get up to 4 matrices

- So we have vertex.position and m0, m1, m2 and m3 matrices

- The weights are used to say ok use a little bit of m0, and a big bunch of m1 but no m2 at all for instance

- Which turned to be: finalPosition = position *(weight0 * m0 + weight1 * m1 + weight2 * m2 + weight3*m3)

Soo for every vertex, you have 4 floats associated in the matriceWeights

Share on other sites

what is m0, m1, m2, m3 and how to calculate them?

Share on other sites

m0, m1,m2 and m3 are related to bones matrices. when you attach a skeleton to your mesh, the skeleton provides an array of matrices that will be used to deform the mesh

Share on other sites

{

"name": "test",
"index": 0,
"matrix": [0.0095, -0.0017, -0.0026, 0, 0.0006, 0.0093, -0.0037, 0, -0.0031, -0.0034, -0.0089, 0, 0.0029, 0.8437, -0.0106, 1],
"parentBoneIndex": -1,
"animation": {
"dataType": 3,
"framePerSecond": 30,
"keys": [{
"frame": 1,
"values": [0.0095, -0.0017, -0.0026, 0, 0.0006, 0.0093, -0.0037, 0, -0.0031, -0.0034, -0.0089, 0, 0.0029, 0.8437, -0.0106, 1]
}, {
"frame": 2,
"values": [0.0097, -0.0008, -0.0024, 0, -0.0001, 0.0093, -0.0036, 0, -0.0025, -0.0035, -0.009, 0, 0.0056, 0.8546, -0.0065, 1]
}, {
"frame": 3,
"values": [0.0099, 0.0003, -0.0017, 0, -0.0009, 0.0092, -0.0038, 0, -0.0015, -0.0039, -0.0091, 0, 0.0059, 0.8707, -0.0067, 1]
}, {
"frame": 4,
"values": [0.0099, 0.0008, -0.0008, 0, -0.0011, 0.0091, -0.004, 0, -0.0004, -0.0041, -0.0091, 0, 0.0053, 0.8852, -0.0073, 1]
}, {
"frame": 5,
"values": [0.01, 0.0007, 0.0001, 0, -0.0006, 0.0091, -0.0042, 0, 0.0004, -0.0041, -0.0091, 0, 0.0079, 0.8951, -0.0067, 1]
}, {
"frame": 6,
"values": [0.01, 0.0006, 0.0006, 0, -0.0003, 0.0092, -0.0039, 0, 0.0008, -0.0039, -0.0092, 0, 0.0115, 0.894, -0.0006, 1]
}, {
"frame": 7,
"values": [0.0099, 0.0006, 0.0008, 0, -0.0003, 0.0094, -0.0035, 0, 0.001, -0.0035, -0.0093, 0, 0.0141, 0.8858, 0.0059, 1]
}, {
"frame": 8,
"values": [0.0099, 0.0008, 0.0008, 0, -0.0005, 0.0094, -0.0033, 0, 0.001, -0.0032, -0.0094, 0, 0.016, 0.874, 0.0157, 1]
}, {
"frame": 9,
"values": [0.0099, 0.001, 0.0009, 0, -0.0007, 0.0095, -0.0032, 0, 0.0012, -0.0031, -0.0094, 0, 0.0188, 0.8543, 0.0353, 1]
}, {
"frame": 10,
"values": [0.0098, 0.0013, 0.0013, 0, -0.0008, 0.0094, -0.0033, 0, 0.0017, -0.0031, -0.0093, 0, 0.0195, 0.8379, 0.0618, 1]
}, {
"frame": 11,
"values": [0.0097, 0.001, 0.0021, 0, -0.0003, 0.0094, -0.0034, 0, 0.0023, -0.0032, -0.0092, 0, 0.0163, 0.8276, 0.0755, 1]
}, {
"frame": 12,
"values": [0.0096, 0.0005, 0.0026, 0, 0.0004, 0.0094, -0.0033, 0, 0.0026, -0.0033, -0.0091, 0, 0.0143, 0.8315, 0.0731, 1]
}, {
"frame": 13,
"values": [0.0097, -0.0001, 0.0024, 0, 0.0009, 0.0094, -0.0033, 0, 0.0023, -0.0034, -0.0091, 0, 0.0149, 0.849, 0.0616, 1]
}, {
"frame": 14,
"values": [0.0098, -0.0009, 0.0016, 0, 0.0014, 0.0093, -0.0034, 0, 0.0011, -0.0036, -0.0093, 0, 0.0161, 0.8666, 0.048, 1]
}, {
"frame": 15,
"values": [0.0099, -0.0015, 0.0005, 0, 0.0016, 0.0092, -0.0037, 0, -0.0001, -0.0037, -0.0093, 0, 0.0164, 0.8816, 0.037, 1]
}, {
"frame": 16,
"values": [0.0099, -0.0015, -0.0003, 0, 0.0013, 0.0091, -0.0039, 0, -0.0009, -0.0038, -0.0092, 0, 0.0137, 0.8971, 0.0264, 1]
}, {
"frame": 17,
"values": [0.0099, -0.0013, -0.0005, 0, 0.001, 0.0092, -0.0038, 0, -0.001, -0.0037, -0.0092, 0, 0.0114, 0.8999, 0.0234, 1]
}, {
"frame": 18,
"values": [0.0099, -0.0011, -0.0006, 0, 0.0008, 0.0093, -0.0036, 0, -0.001, -0.0035, -0.0093, 0, 0.0105, 0.896, 0.0175, 1]
}, {
"frame": 19,
"values": [0.0099, -0.0011, -0.0008, 0, 0.0008, 0.0093, -0.0035, 0, -0.0012, -0.0034, -0.0093, 0, 0.0089, 0.8832, 0.0066, 1]
}, {
"frame": 20,
"values": [0.0098, -0.0015, -0.0012, 0, 0.001, 0.0093, -0.0035, 0, -0.0016, -0.0033, -0.0093, 0, 0.005, 0.8624, 0.0008, 1]
}, {
"frame": 21,
"values": [0.0096, -0.0022, -0.0017, 0, 0.0014, 0.0091, -0.0038, 0, -0.0024, -0.0035, -0.0091, 0, 0.0026, 0.8442, 0.0096, 1]
}, {
"frame": 22,
"values": [0.0095, -0.0022, -0.0023, 0, 0.0012, 0.0091, -0.004, 0, -0.0029, -0.0036, -0.0089, 0, 0.0022, 0.8353, 0.0092, 1]
}, {
"frame": 23,
"values": [0.0095, -0.0017, -0.0026, 0, 0.0006, 0.0093, -0.0037, 0, -0.0031, -0.0034, -0.0089, 0, 0.0029, 0.8437, -0.0106, 1]
}, {
"frame": 250,
"values": [0.0095, -0.0017, -0.0026, 0, 0.0006, 0.0093, -0.0037, 0, -0.0031, -0.0034, -0.0089, 0, 0.0029, 0.8437, -0.0106, 1]
}],
"loopBehavior": 1,
"name": "anim",
"property": "_matrix"
}

}

where here m0, m1, m2 and m3?

Share on other sites

humm..m0, m1, m2 and m3 are matrices defined INSIDE the shader. the shaders received an array of matrices (m[64]) and uses the matricesIndices to get m0 (which could be m[15] for instance, depending on whcich bone influences the current vertex)

so your file here is the description of one bone of the skeleton. This bone will produce (and animate) one matrix of the matrices array sent to the shader

Share on other sites

Here that at me it turned out:

vs:

attribute vec4 boneWeight;
attribute vec4 boneIndex;
...
void main()
{

mat4 m0 = mBone[int(boneIndex.x)] * boneWeight.x;
mat4 m1 = mBone[int(boneIndex.y)] * boneWeight.y;
mat4 m2 = mBone[int(boneIndex.z)] * boneWeight.z;
mat4 m3 = mBone[int(boneIndex.w)] * boneWeight.w;
vec4 pos=MoveMat*((m0 + m1 + m2 + m3)*vec4(position,1.0));
}

boneIndex:

var floatIndices = [];
for (var i = 0; i < boneIndex.length; i++)
{
var matricesIndex = boneIndex;
floatIndices.push(matricesIndex & 0x000000FF);
floatIndices.push((matricesIndex & 0x0000FF00) >> 8);
floatIndices.push((matricesIndex & 0x00FF0000) >> 16);
floatIndices.push(matricesIndex >> 24);
}
it is taken from babylon.js . I send "floatIndices"

mBone:

var _mBone=[],mBone=[];

for(var i=0;i<bonesOnSkeleton.length;i++)
{
_mBone.push(self.gl.getUniformLocation(self._Program,"mBone["+i+"]"));
mBone.push(bonesOnSkeleton.matrix);
//bonesOnSkeleton==(in babylon.js file:  skeletons[0].bones)
}

The program all the same works not correctly

P.S. Syntax errors aren't present

Share on other sites

I don't understand you question

Share on other sites

Example (do not laugh).

Share on other sites

Dear Deltakosh, I do this scene without use of babylon.js

Simply it isn't clear to me why this animation is wrong?

All code which is connected to animation I gave above.

I want to learn, whether the shader code is correctly written, and also, whether correctly I process "matriceIndices" and "matriceWeight"?

Share on other sites

Oh...I thought you use Babylon.js

then my response would be: please use babylon.js this is free, supported by the best community ever and cooked with love:)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.