Animation three.js:使用骨骼动画获取更新的顶点?
与堆栈溢出问题中的问题类似,我感兴趣的是如何通过骨骼动画获得网格顶点的“实际”位置 我已经试着打印出位置值,但它们从未实际更新过(据我所知,这是因为它们是在GPU上计算的,而不是CPU)。上面提到的问题的答案是,在CPU上执行与在GPU上相同的计算,以获取变形目标动画的最新顶点位置,但有没有办法对骨骼动画执行相同的方法?如果是,如何 另外,对于变形目标,有人指出该代码已经存在于Mesh.raycast函数()中。但是,我不知道光线投射如何与骨骼动画网格一起工作——它如何知道面的更新位置Animation three.js:使用骨骼动画获取更新的顶点?,animation,graphics,three.js,Animation,Graphics,Three.js,与堆栈溢出问题中的问题类似,我感兴趣的是如何通过骨骼动画获得网格顶点的“实际”位置 我已经试着打印出位置值,但它们从未实际更新过(据我所知,这是因为它们是在GPU上计算的,而不是CPU)。上面提到的问题的答案是,在CPU上执行与在GPU上相同的计算,以获取变形目标动画的最新顶点位置,但有没有办法对骨骼动画执行相同的方法?如果是,如何 另外,对于变形目标,有人指出该代码已经存在于Mesh.raycast函数()中。但是,我不知道光线投射如何与骨骼动画网格一起工作——它如何知道面的更新位置 谢谢大家
谢谢大家! 不久前,一个类似的话题也在讨论中。我在这里介绍了一个小提琴,它为每帧蒙皮网格计算AABB。该代码实际上通过JavaScript执行相同的顶点置换,就像在顶点着色器中一样。例行程序如下所示:
function updateAABB( skinnedMesh, aabb ) {
var skeleton = skinnedMesh.skeleton;
var boneMatrices = skeleton.boneMatrices;
var geometry = skinnedMesh.geometry;
var index = geometry.index;
var position = geometry.attributes.position;
var skinIndex = geometry.attributes.skinIndex;
var skinWeigth = geometry.attributes.skinWeight;
var bindMatrix = skinnedMesh.bindMatrix;
var bindMatrixInverse = skinnedMesh.bindMatrixInverse;
var i, j, si, sw;
aabb.makeEmpty();
//
if ( index !== null ) {
// indexed geometry
for ( i = 0; i < index.count; i ++ ) {
vertex.fromBufferAttribute( position, index[ i ] );
skinIndices.fromBufferAttribute( skinIndex, index[ i ] );
skinWeights.fromBufferAttribute( skinWeigth, index[ i ] );
// the following code section is normally implemented in the vertex shader
vertex.applyMatrix4( bindMatrix ); // transform to bind space
skinned.set( 0, 0, 0 );
for ( j = 0; j < 4; j ++ ) {
si = skinIndices.getComponent( j );
sw = skinWeights.getComponent( j );
boneMatrix.fromArray( boneMatrices, si * 16 );
// weighted vertex transformation
temp.copy( vertex ).applyMatrix4( boneMatrix ).multiplyScalar( sw );
skinned.add( temp );
}
skinned.applyMatrix4( bindMatrixInverse ); // back to local space
// expand aabb
aabb.expandByPoint( skinned );
}
} else {
// non-indexed geometry
for ( i = 0; i < position.count; i ++ ) {
vertex.fromBufferAttribute( position, i );
skinIndices.fromBufferAttribute( skinIndex, i );
skinWeights.fromBufferAttribute( skinWeigth, i );
// the following code section is normally implemented in the vertex shader
vertex.applyMatrix4( bindMatrix ); // transform to bind space
skinned.set( 0, 0, 0 );
for ( j = 0; j < 4; j ++ ) {
si = skinIndices.getComponent( j );
sw = skinWeights.getComponent( j );
boneMatrix.fromArray( boneMatrices, si * 16 );
// weighted vertex transformation
temp.copy( vertex ).applyMatrix4( boneMatrix ).multiplyScalar( sw );
skinned.add( temp );
}
skinned.applyMatrix4( bindMatrixInverse ); // back to local space
// expand aabb
aabb.expandByPoint( skinned );
}
}
aabb.applyMatrix4( skinnedMesh.matrixWorld );
}
函数更新aabb(skinnedMesh,aabb){
var skeleton=skindmesh.skeleton;
var boneMatrices=skeleton.boneMatrices;
var geometry=skindmesh.geometry;
var指数=几何指数;
变量位置=geometry.attributes.position;
var skindex=geometry.attributes.skindex;
var skinWeigth=geometry.attributes.skinWeight;
var bindMatrix=SkindMesh.bindMatrix;
var bindMatrixInverse=SkindMesh.bindMatrixInverse;
变量i,j,si,sw;
aabb.makeEmpty();
//
如果(索引!==null){
//索引几何
对于(i=0;i
另外,对于变形目标,有人指出该代码已经存在于Mesh.raycast函数中
是的,可以对变形网格进行光线投射。尚未支持对蒙皮网格进行光线投射。Mesh.raycast()
中的代码已经非常复杂。我认为在进一步增强之前,它需要进行一些认真的重构。同时,您可以使用提供的代码片段自行构建解决方案。顶点位移逻辑实际上是最复杂的部分
现场演示:
three.js R107
更新:在-r116中添加了蒙皮网格的光线投射