Game Development Reference
In-Depth Information
A vertex might be associated with a single bone, but we will still have two skin
indices (a and b) and two skin weights (z and w) associated with it. In this case, one
of the skin weights (z and w) will be 1 and the other would be 0 , denoting that only
one of the bones will affect the vertex.
Loading the rigged model
We will first modify our parsing algorithm to accommodate our newly
discovered arrays.
Open primitive/parseJSON.js in your favorite text editor. We have added a new
parseSkin function as follows:
function parseSkin(data, geometry) {
var i, l, x, y, z, w, a, b, c, d;
if ( data.skinWeights ) {
for ( i = 0, l = data.skinWeights.length; i < l; i += 2 ) {
x = data.skinWeights[ i ];
y = data.skinWeights[ i + 1 ];
z = 0;
w = 0;
geometry.skinWeights.push(x);
geometry.skinWeights.push(y);
geometry.skinWeights.push(z);
geometry.skinWeights.push(w);
}
}
if ( data.skinIndices ) {
for ( i = 0, l = data.skinIndices.length; i < l; i += 2 ) {
a = data.skinIndices[ i ];
b = data.skinIndices[ i + 1 ];
c = 0;
d = 0;
geometry.skinIndices.push(a);
geometry.skinIndices.push(b);
geometry.skinIndices.push(c);
geometry.skinIndices.push(d);
}
}
geometry.bones = data.bones;
geometry.animation = data.animation;
}
 
Search WWH ::




Custom Search