How to get the morphed mesh from MorphTargetManager?

I am using the MorphTargetManager to morph a mesh to targets with sliders like here :

It works perfectly. However, I would like to get the morphed mesh (the one displayed), in order to export it in a .stl file or to measure it size.

If possible, how can I do this ?

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:

	positionUpdated += (position{X} - position) * morphTargetInfluences[{X}];
	normalUpdated += (normal{X} - normal) * morphTargetInfluences[{X}];

	#ifdef MORPHTARGETS_TANGENT += (tangent{X} - * morphTargetInfluences[{X}];

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

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