如何计算变换后的皮肤顶点?

时间:2015-07-24 21:37:27

标签: three.js

我试过的代码:

var transformedSkinVertex = function (skin, index) {
    var skinIndices = (new THREE.Vector4 ()).fromAttribute (skin.geometry.getAttribute ('skinIndex'), index);
    var skinWeights = (new THREE.Vector4 ()).fromAttribute (skin.geometry.getAttribute ('skinWeight'), index);
    var skinVertex = (new THREE.Vector3 ()).fromAttribute (skin.geometry.getAttribute ('position'), index).applyMatrix4 (skin.bindMatrix);
    var result = new THREE.Vector3 (), temp = new THREE.Vector3 (), tempMatrix = new THREE.Matrix4 (); properties = ['x', 'y', 'z', 'w'];
    for (var i = 0; i < 4; i++) {
        var boneIndex = skinIndices[properties[i]];
        tempMatrix.multiplyMatrices (skin.skeleton.bones[boneIndex].matrixWorld, skin.skeleton.boneInverses[boneIndex]);
        result.add (temp.copy (skinVertex).multiplyScalar (skinWeights[properties[i]]).applyMatrix4 (tempMatrix));
    }
    return result.applyMatrix4 (skin.bindMatrixInverse);
};

这适用于T pose:

enter image description here

但是随着手臂下降,一些部件会爆炸成天使般的形状:

enter image description here

这里的手臂略有不同:

enter image description here

我目前的理论是,当有&gt; 2块骨头。但是......为什么?

所有权重都正确加起来为1,正如您在上面看到的那样。三个渲染皮肤是正确的。

1 个答案:

答案 0 :(得分:3)

解决。

正确的行是

result.add (temp.copy (skinVertex).applyMatrix4 (tempMatrix).multiplyScalar (skinWeights[properties[i]]));

我认为标量乘法的顺序并不重要。