Three.js: Get updated vertices with morph targets

ⅰ亾dé卋堺 提交于 2019-12-01 22:45:17

Morphs are updated on the GPU, not the CPU. So if you want to know the new vertex position, you have to do the same calculation on the CPU that the GPU is doing.

The method Mesh.raycast() has to do that calculation for raycasting on the CPU, so you can refer to that code as an example.

Here is a simple pattern you can follow. You will have to adapt this for your full application, as this pattern is hardwired to match your simple fiddle.

var morphTargets = mesh.geometry.morphTargets;
var morphInfluences = mesh.morphTargetInfluences;

var vA = new THREE.Vector3();
var tempA = new THREE.Vector3();

var fvA = geometry.vertices[ 0 ]; // the vertex to transform

for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {

    var influence = morphInfluences[ t ];

    if ( influence === 0 ) continue;

    var targets = morphTargets[ t ].vertices;

    vA.addScaledVector( tempA.subVectors( targets[ 0 ], fvA ), influence ); // targets index must match vertex index

}

vA.add( fvA ); // the transformed value

fiddle: https://jsfiddle.net/3wtwzuh3/3/

three.js r.75

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!