简体   繁体   中英

scale animation of a geometry in Three.js

I am making my first steps coding with JavaScript and playing with Three.js too.

I made an scale animation of a geometry because I would like to simulate an slow breathing effect using this code:

  var frame = 0;

  function animate() {
    requestAnimationFrame(animate);

    mesh.scale.z += Math.sin(frame);
    frame += 0.5;

    renderer.render(scene, camera);
  }

    animate();

But I have a problem: If I want to make just a little stretch the animation runs really fast http://jsfiddle.net/ts8ssrk1/12/ and if I want that the animation runs slowly (changing frame += to a smaller number) the geometry will stretch to the infinite.

Do you have some recommendation?

I found a solution. In the case that someone is interested I just change this mesh.scale.z += Math.sin(frame); for this mesh.scale.z += Math.sin(frame)/5;

It was more simple as I was thinking....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM