我想做的是导出因为我设置了动画而改变了位置的蒙皮网格物体。
我一直在跟踪以下代码:How to calculate transformed skin vertices? https://gist.githubusercontent.com/jcarletto27/35b19f811c657ec73b0238d78413f88d/raw/e43389b2851c7a5cfcd284ff4ced9461c79f52d7/OBJExporter.js和[这个问题] Exporting Three.js scene to STL keeping animations intact。
这些链接告诉我,我必须遍历最初处于绑定姿势的顶点,找到影响每个顶点的骨骼(最多可以有4根骨骼),将这些顶点的位置转换为骨骼空间,然后进入全局空间,最后对它们应用新的权重(每个骨骼对顶点的影响程度)。
for(i = 0,l = vertices.count; i 到目前为止,我所获得的输出看起来像这样:warped 什么时候看起来像这样(常规冲锋队):not warped 除了代码之外,我想知道网格有什么问题(是法线,错误的逆矩阵等),如果有人能够直观地识别出这一点。因为如果靠近放大,您可以看到一些网格属性(手指,头盔)。 无论如何,这是我第一次在Stack Overflow上发帖,谢谢大家阅读。 vertex.x = vertices.getX(i);
vertex.y = vertices.getY(i);
vertex.z = vertices.getZ(i);
vertex.applyMatrix4(mesh.matrixWorld);
skinIndex = [];
skinIndex[0] = skinIndices.getX(i);
skinIndex[1] = skinIndices.getY(i);
skinIndex[2] = skinIndices.getZ(i);
skinIndex[3] = skinIndices.getW(i);
skinWeight = [];
skinWeight[0] = weights.getX(i);
skinWeight[1] = weights.getY(i);
skinWeight[2] = weights.getZ(i);
skinWeight[3] = weights.getW(i);
inverses = [];
inverses[0] = mesh.skeleton.boneInverses[skinIndex[0]];
inverses[1] = mesh.skeleton.boneInverses[skinIndex[1]];
inverses[2] = mesh.skeleton.boneInverses[skinIndex[2]];
inverses[3] = mesh.skeleton.boneInverses[skinIndex[3]];
skinMatrices = [];
skinMatrices[0] = mesh.skeleton.bones[skinIndex[0]].matrixWorld;
skinMatrices[1] = mesh.skeleton.bones[skinIndex[1]].matrixWorld;
skinMatrices[2] = mesh.skeleton.bones[skinIndex[2]].matrixWorld;
skinMatrices[3] = mesh.skeleton.bones[skinIndex[3]].matrixWorld;
var finalVector = new THREE.Vector4();
for (var k = 0; k < 4; k++) {
var tempVector = new THREE.Vector4(vertex.x, vertex.y, vertex.z);
tempVector.applyMatrix4(inverses[k]);
tempVector.applyMatrix4(skinMatrices[k]);
tempVector.multiplyScalar(skinWeight[k]);
finalVector.add(tempVector);
}
output += 'v ' + finalVector.x + ' ' + finalVector.y + ' ' + finalVector.z + '\n';
}