如何从一个网格过渡到另一个网格?

how to make a transition from one mesh to another?

我有 mesh1 和 Mesh2。每个都有挤压。

mesh1 ->100 vertices
mesh2 ->200 vertices

在我的代码中,我执行以下操作:

mesh1.geometry.verticesNeedUpdate = true;
mesh1 = Mesh2;
mesh1.geometry.computeBoundingBox ();

所以我设法更新了 mesh1(这在我的原始代码中有效),但我不希望您看到任何突然的变化。我想要一个动画,同时 mesh1 变成几何体 Mesh2。

我一直在使用图书馆 tween.js。例如:

 new TWEEN.Tween (mesh1.scale) .to ({x: 1, and 1, z 1}, 1000) .start ();

但我不知道在这种情况下如何制作动画。 通过过渡或动画,您可以实时看到 mesh2 到 mesh1 的顶点变化。我不想显示任何突然的变化。

你可以用morphTarget。您有一组长度相同但位置不同的顶点。然后设置 morphTargetInfluences 以实现从该组顶点到另一组顶点的过渡。

本文来自 Threejs 几何 documentation

.morphTargets

Array of morph targets. Each morph target is a Javascript object:
{ name: "targetName", vertices: [ new THREE.Vector3(), ... ] } Morph vertices match number and order of primary vertices.

这个不错example。查看它的源代码以便更好地理解。