How to get the morphed mesh from MorphTargetManager?

It is not possible easily as the interpolation is done in the vertex shader and you can’t get the output of it.

What you can do is replicate the calculation in javascript. They are not very complicated as it is only linear interpolations. From the shader code:

#ifdef MORPHTARGETS
	positionUpdated += (position{X} - position) * morphTargetInfluences[{X}];
	
	#ifdef MORPHTARGETS_NORMAL
	normalUpdated += (normal{X} - normal) * morphTargetInfluences[{X}];
	#endif

	#ifdef MORPHTARGETS_TANGENT
	tangentUpdated.xyz += (tangent{X} - tangent.xyz) * morphTargetInfluences[{X}];
	#endif

    #ifdef MORPHTARGETS_UV
	uvUpdated += (uv_{X} - uv) * morphTargetInfluences[{X}];
	#endif
#endif

position is the unmodified position of the mesh (the one you get by doing mesh.getVerticesData("position")). position{X} are the positions for the target 0, 1, …

For eg, if there are two targets, the computation will be:

positionUpdated += (position0 - position) * morphTargetInfluences[0];
positionUpdated += (position1 - position) * morphTargetInfluences[1];

Same thing for the normal, tangent, uv.

…and welcome to the community!

1 Like