transformed-skin-vertex.js 1.1 KB

1234567891011121314151617181920
  1. var transformedSkinVertex = function (skin, index) {
  2. var skinIndices = (new THREE.Vector4 ()).fromAttribute (skin.geometry.getAttribute ('skinIndex'), index);
  3. var skinWeights = (new THREE.Vector4 ()).fromAttribute (skin.geometry.getAttribute ('skinWeight'), index);
  4. var skinVertex = (new THREE.Vector3 ()).fromAttribute (skin.geometry.getAttribute ('position'), index).applyMatrix4 (skin.bindMatrix);
  5. var result = new THREE.Vector3 ()
  6. var temp = new THREE.Vector3 ()
  7. var tempMatrix = new THREE.Matrix4 ()
  8. var properties = ['x', 'y', 'z', 'w'];
  9. for (var i = 0; i < 4; i++) {
  10. var boneIndex = skinIndices[properties[i]];
  11. tempMatrix.multiplyMatrices (skin.skeleton.bones[boneIndex].matrixWorld, skin.skeleton.boneInverses[boneIndex]);
  12. //result.add (temp.copy (skinVertex).multiplyScalar (skinWeights[properties[i]]).applyMatrix4 (tempMatrix));
  13. result.add (temp.copy (skinVertex).applyMatrix4 (tempMatrix).multiplyScalar (skinWeights[properties[i]]));
  14. }
  15. return result.applyMatrix4 (skin.bindMatrixInverse);
  16. };
  17. module.exports = transformedSkinVertex