Clamping of length

Hi, community!
I can’t say that I’ve discovered something unusual. I just want to show to beginners (like me :baby:) the using of .clampLength() method of THREE.Vector3(). It allows to make an interesting effect: morphing the points from one formation to another, having the same constant speed for each vertex, when you know its start and end coordinates.

https://jsfiddle.net/prisoner849/d9ar8j07/

Constant_speed_of_vertices_2

P.S. Long ago, I’ve seen a very similar question on SO (though I couldn’t find it), and a guy seriously wanted to make the same effect, using Tween.js for each point :dizzy_face:

P.P.S. I know it could be done with shaders, but this topic is for the beginners :slight_smile:

5 Likes

In this case I suggest you try to avoid such statements in your code since they are hard to read.

clampedDirLength.copy(morphV.dir).multiplyScalar(currentDuration * morph.speed).clampLength(0, morphV.dist);

Split them up into multiple lines and add some comments which explain what’s happening and why.

3 Likes

Fair enough, Michael :slight_smile:
Done. The fiddle is updated.

2 Likes